VirtualBox

Changeset 83734 in vbox for trunk/src/VBox/ValidationKit


Ignore:
Timestamp:
Apr 17, 2020 7:36:20 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
137252
Message:

Validation Kit/Shared Folders: Added first testing for auto-unmounting.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/tests/additions/tdAddSharedFolders1.py

    r82968 r83734  
    6464            'E:/vboxvalidationkit/${OS/ARCH}/FsPerf${EXESUFF}',
    6565        ];
     66        self.sGuestSlash = '';
    6667
    6768    def parseOption(self, asArgs, iArg):
     
    9495        return True;
    9596
     97    def mountShareEx(self, oSession, oTxsSession, sShareName, sHostPath, sGuestMountPoint, fMustSucceed):
     98        """
     99        Automount a shared folder in the guest, extended version.
     100
     101        Returns success status, based on fMustSucceed.
     102        """
     103        reporter.testStart('Automounting "%s"' % (sShareName,));
     104
     105        reporter.log2('Creating shared folder "%s" at "%s" ...' % (sShareName, sGuestMountPoint));
     106        try:
     107            oConsole = oSession.o.console;
     108            oConsole.createSharedFolder(sShareName, sHostPath, True, True, sGuestMountPoint);
     109        except:
     110            if fMustSucceed:
     111                reporter.errorXcpt('createSharedFolder(%s,%s,True,True,%s)' % (sShareName, sHostPath, sGuestMountPoint));
     112            else:
     113                reporter.log('createSharedFolder(%s,%s,True,True,%s) failed, good' % (sShareName, sHostPath, sGuestMountPoint));
     114            reporter.testDone();
     115            return False is fMustSucceed;
     116
     117        # Check whether we can see the shared folder now.  Retry for 30 seconds.
     118        msStart = base.timestampMilli();
     119        while True:
     120            fRc = oTxsSession.syncIsDir(sGuestMountPoint + self.sGuestSlash + 'candle.dir');
     121            reporter.log2('candle.dir check -> %s' % (fRc,));
     122            if fRc is fMustSucceed:
     123                break;
     124            if base.timestampMilli() - msStart > 10 * 90000:
     125                reporter.error('Shared folder mounting timed out!');
     126                break;
     127            self.oTstDrv.sleep(1);
     128
     129        reporter.testDone();
     130
     131        return fRc == fMustSucceed;
     132
     133    def mountShare(self, oSession, oTxsSession, sShareName, sHostPath, sGuestMountPoint):
     134        """
     135        Automount a shared folder in the guest.
     136
     137        Returns success status.
     138        """
     139        return self.mountShareEx(oSession, oTxsSession, sShareName, sHostPath, sGuestMountPoint, fMustSucceed = True);
     140
     141    def unmountShareEx(self, oSession, oTxsSession, sShareName, sGuestMountPoint, fMustSucceed):
     142        """
     143        Unmounts a shared folder in the guest.
     144
     145        Returns success status, based on fMustSucceed.
     146        """
     147        reporter.log2('Autounmount');
     148        try:
     149            oConsole = oSession.o.console;
     150            oConsole.removeSharedFolder(sShareName);
     151        except:
     152            if fMustSucceed:
     153                reporter.errorXcpt('removeSharedFolder(%s)' % (sShareName,));
     154            else:
     155                reporter.log('removeSharedFolder(%s)' % (sShareName,));
     156            reporter.testDone();
     157            return False is fMustSucceed;
     158
     159        # Check whether the shared folder is gone on the guest now.  Retry for 30 seconds.
     160        msStart = base.timestampMilli();
     161        while True:
     162            fRc2 = oTxsSession.syncIsDir(sGuestMountPoint + self.sGuestSlash + 'candle.dir');
     163            reporter.log2('candle.dir check -> %s' % (fRc2,));
     164            if fRc2 is not fMustSucceed:
     165                break;
     166            if base.timestampMilli() - msStart > 10 * 90000:
     167                reporter.error('Shared folder unmounting timed out!');
     168                fRc = False;
     169                break;
     170            self.oTstDrv.sleep(1);
     171
     172        reporter.testDone();
     173
     174        return fRc is fMustSucceed;
     175
     176    def unmountShare(self, oSession, oTxsSession, sShareName, sGuestMountPoint):
     177        """
     178        Unmounts a shared folder in the guest, extended version.
     179
     180        Returns success status, based on fMustSucceed.
     181        """
     182        return self.unmountShareEx(oSession, oTxsSession, sShareName, sGuestMountPoint, fMustSucceed = True);
     183
    96184    def testIt(self, oTestVm, oSession, oTxsSession):
    97185        """
     
    109197            return (None, oTxsSession);
    110198
     199        # Guess a free mount point inside the guest.
     200        if oTestVm.isWindows() or oTestVm.isOS2():
     201            self.sGuestSlash  = '\\';
     202        else:
     203            self.sGuestSlash  = '/';
     204
    111205        #
    112206        # Create the host directory to share. Empty except for a 'candle.dir' subdir
    113207        # that we use to check that it mounted correctly.
    114208        #
    115         sSharedFolder1 = os.path.join(self.oTstDrv.sScratchPath, 'shfl1');
    116         reporter.log2('Creating shared host folder "%s"...' % (sSharedFolder1,));
    117         if os.path.exists(sSharedFolder1):
    118             try:    shutil.rmtree(sSharedFolder1);
    119             except: return (reporter.errorXcpt('shutil.rmtree(%s)' % (sSharedFolder1,)), oTxsSession);
    120         try:    os.mkdir(sSharedFolder1);
    121         except: return (reporter.errorXcpt('os.mkdir(%s)' % (sSharedFolder1,)), oTxsSession);
    122         try:    os.mkdir(os.path.join(sSharedFolder1, 'candle.dir'));
    123         except: return (reporter.errorXcpt('os.mkdir(%s)' % (sSharedFolder1,)), oTxsSession);
     209        sShareName1     = 'shfl1';
     210        sShareHostPath1 = os.path.join(self.oTstDrv.sScratchPath, sShareName1);
     211        reporter.log2('Creating shared host folder "%s"...' % (sShareHostPath1,));
     212        if os.path.exists(sShareHostPath1):
     213            try:    shutil.rmtree(sShareHostPath1);
     214            except: return (reporter.errorXcpt('shutil.rmtree(%s)' % (sShareHostPath1,)), oTxsSession);
     215        try:    os.mkdir(sShareHostPath1);
     216        except: return (reporter.errorXcpt('os.mkdir(%s)' % (sShareHostPath1,)), oTxsSession);
     217        try:    os.mkdir(os.path.join(sShareHostPath1, 'candle.dir'));
     218        except: return (reporter.errorXcpt('os.mkdir(%s)' % (sShareHostPath1,)), oTxsSession);
    124219
    125220        # Guess a free mount point inside the guest.
    126221        if oTestVm.isWindows() or oTestVm.isOS2():
    127222            sMountPoint1 = 'V:';
    128             sGuestSlash  = '\\';
    129223        else:
    130             sMountPoint1 = '/mnt/shfl1';
    131             sGuestSlash  = '/';
    132 
    133         #
    134         # Automount a shared folder in the guest.
    135         #
    136         reporter.testStart('Automount');
    137 
    138         reporter.log2('Creating shared folder shfl1...');
    139         try:
    140             oConsole = oSession.o.console;
    141             oConsole.createSharedFolder('shfl1', sSharedFolder1, True, True, sMountPoint1);
    142         except:
    143             reporter.errorXcpt('createSharedFolder(shfl1,%s,True,True,%s)' % (sSharedFolder1,sMountPoint1));
    144             reporter.testDone();
    145             return (False, oTxsSession);
    146 
    147         # Check whether we can see the shared folder now.  Retry for 30 seconds.
    148         msStart = base.timestampMilli();
    149         while True:
    150             fRc = oTxsSession.syncIsDir(sMountPoint1 + sGuestSlash + 'candle.dir');
    151             reporter.log2('candle.dir check -> %s' % (fRc,));
    152             if fRc is not False:
    153                 break;
    154             if base.timestampMilli() - msStart > 30000:
    155                 reporter.error('Shared folder mounting timed out!');
    156                 break;
    157             self.oTstDrv.sleep(1);
    158 
    159         reporter.testDone();
     224            sMountPoint1 = '/mnt/' + sShareName1;
     225
     226        fRc = self.mountShare(oSession, oTxsSession, sShareName1, sShareHostPath1, sMountPoint1);
    160227        if fRc is not True:
    161228            return (False, oTxsSession); # skip the remainder if we cannot auto mount the folder.
     
    166233        fSkip = 'fsperf' not in self.asTests;
    167234        if fSkip is False:
    168             cMbFree = utils.getDiskUsage(sSharedFolder1);
     235            cMbFree = utils.getDiskUsage(sShareHostPath1);
    169236            if cMbFree >= 16:
    170237                reporter.log2('Free space: %u MBs' % (cMbFree,));
    171238            else:
    172                 reporter.log('Skipping FsPerf because only %u MB free on %s' % (cMbFree, sSharedFolder1,));
     239                reporter.log('Skipping FsPerf because only %u MB free on %s' % (cMbFree, sShareHostPath1,));
    173240                fSkip = True;
    174241        if fSkip is False:
    175242            # Common arguments:
    176             asArgs = ['FsPerf', '-d', sMountPoint1 + sGuestSlash + 'fstestdir-1', '-s8'];
     243            asArgs = ['FsPerf', '-d', sMountPoint1 + self.sGuestSlash + 'fstestdir-1', '-s8'];
    177244
    178245            # Skip part of mmap on older windows systems without CcCoherencyFlushAndPurgeCache (>= w7).
     
    217284            reporter.log2('FsPerf -> %s' % (fRc,));
    218285
    219             sTestDir = os.path.join(sSharedFolder1, 'fstestdir-1');
     286            sTestDir = os.path.join(sShareHostPath1, 'fstestdir-1');
    220287            if os.path.exists(sTestDir):
    221288                fRc = reporter.errorXcpt('test directory lingers: %s' % (sTestDir,));
     
    226293            reporter.testDone(fSkip or fRc is None);
    227294
     295        #
     296        # Check if auto-unmounting works.
     297        #
     298        if fRc is True:
     299            fRc = self.unmountShare(oSession, oTxsSession, sShareName1, sMountPoint1);
     300
     301        ## @todo Add tests for multiple automount shares, random unmounting, reboot test.
     302
    228303        return (fRc, oTxsSession);
    229 
    230304
    231305    def _locateGstFsPerf(self, oTxsSession):
     
    244318    reporter.error('Cannot run standalone, use tdAddBasic1.py');
    245319    sys.exit(1);
    246 
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette