Exemple #1
0
    def equalFile(self, oFile):
        """ Compares the content of oFile with self.abContent. """

        # Check the size first.
        try:
            cbFile = os.fstat(oFile.fileno()).st_size;
        except:
            return reporter.errorXcpt();
        if cbFile != self.cbContent:
            return reporter.error('file size differs: %s, cbContent=%s' % (cbFile, self.cbContent));

        # Compare the bytes next.
        offFile = 0;
        try:
            oFile.seek(offFile);
        except:
            return reporter.error('seek error');
        while offFile < self.cbContent:
            cbToRead = self.cbContent - offFile;
            if cbToRead > 256*1024:
                cbToRead = 256*1024;
            try:
                abRead = oFile.read(cbToRead);
            except:
                return reporter.error('read error at offset %s' % (offFile,));
            cbRead = len(abRead);
            if cbRead == 0:
                return reporter.error('premature end of file at offset %s' % (offFile,));
            if not utils.areBytesEqual(abRead, self.abContent[offFile:(offFile + cbRead)]):
                return reporter.error('%s byte block at offset %s differs' % (cbRead, offFile,));
            # Advance:
            offFile += cbRead;

        return True;
    def testOneCfg(self, oVM, oTestVm):
        """
        Runs the specified VM thru the tests.

        Returns a success indicator on the general test execution. This is not
        the actual test result.
        """
        fRc = False

        sXmlFile = self.prepareResultFile()
        asEnv = ['IPRT_TEST_FILE=' + sXmlFile]

        self.logVmInfo(oVM)
        oSession = self.startVm(oVM, sName=oTestVm.sVmName, asEnv=asEnv)
        if oSession is not None:
            cMsTimeout = 15 * 60 * 1000
            if not reporter.isLocal(
            ):  ## @todo need to figure a better way of handling timeouts on the testboxes ...
                cMsTimeout = self.adjustTimeoutMs(180 * 60000)

            oRc = self.waitForTasks(cMsTimeout)
            if oRc == oSession:
                fRc = oSession.assertPoweredOff()
            else:
                reporter.error('oRc=%s, expected %s' % (oRc, oSession))

            reporter.addSubXmlFile(sXmlFile)
            self.terminateVmBySession(oSession)
        return fRc
Exemple #3
0
    def _darwinUnmountDmg(self, fIgnoreError):
        """
        Umount any DMG on at the default mount point.
        """
        sMountPath = self._darwinDmgPath()
        if not os.path.exists(sMountPath):
            return True

        # Unmount.
        fRc = self._executeSync(['hdiutil', 'detach', sMountPath])
        if not fRc and not fIgnoreError:
            # In case it's busy for some reason or another, just retry after a little delay.
            for iTry in range(6):
                time.sleep(5)
                reporter.error('Retry #%s unmount DMT at %s' % (
                    iTry + 1,
                    sMountPath,
                ))
                fRc = self._executeSync(['hdiutil', 'detach', sMountPath])
                if fRc:
                    break
            if not fRc:
                reporter.error('Failed to unmount DMG at %s' % (sMountPath, ))

        # Remove dir.
        try:
            os.rmdir(sMountPath)
        except:
            if not fIgnoreError:
                reporter.errorXcpt('Failed to remove directory %s' %
                                   (sMountPath, ))
        return fRc
    def testCreateVMWithDefaults(self):
        """
        Test create VM with defaults.
        """
        if not self.oTstDrv.importVBoxApi():
            return reporter.error('importVBoxApi');

        # Get the guest OS types.
        try:
            aoGuestTypes = self.oTstDrv.oVBoxMgr.getArray(self.oTstDrv.oVBox, 'guestOSTypes')
            if aoGuestTypes is None or not aoGuestTypes:
                return reporter.error('No guest OS types');
        except:
            return reporter.errorXcpt();

        # Create VMs with defaults for each of the guest types.
        fRc = True
        for oGuestType in aoGuestTypes:
            try:
                sGuestType = oGuestType.id;
            except:
                fRc = reporter.errorXcpt();
            else:
                reporter.testStart(sGuestType);
                fRc = self.createVMWithDefaults(sGuestType) and fRc;
                reporter.testDone();
        return fRc
Exemple #5
0
 def actionVerify(self):
     if self.sVBoxValidationKitIso is None or not os.path.isfile(self.sVBoxValidationKitIso):
         reporter.error('Cannot find the VBoxValidationKit.iso! (%s)'
                        'Please unzip a Validation Kit build in the current directory or in some parent one.'
                        % (self.sVBoxValidationKitIso,) );
         return False;
     return vbox.TestDriver.actionVerify(self);
    def testOneVmConfig(self, oVM, oTestVm):
        """
        Install guest OS and wait for result
        """

        self.logVmInfo(oVM)
        reporter.testStart('Installing %s' % (oTestVm.sVmName,))

        cMsTimeout = 40*60000;
        if not reporter.isLocal(): ## @todo need to figure a better way of handling timeouts on the testboxes ...
            cMsTimeout = 180 * 60000; # will be adjusted down.

        oSession, _ = self.startVmAndConnectToTxsViaTcp(oTestVm.sVmName, fCdWait = False, cMsTimeout = cMsTimeout);
        if oSession is not None:
            # The guest has connected to TXS, so we're done (for now anyways).
            reporter.log('Guest reported success')
            ## @todo Do save + restore.

            reporter.testDone()
            fRc = self.terminateVmBySession(oSession)
            return fRc is True

        reporter.error('Installation of %s has failed' % (oTestVm.sVmName,))
        oTestVm.detatchAndDeleteHd(self); # Save space.
        reporter.testDone()
        return False
Exemple #7
0
    def testOneCfg(self, oVM, oTestVm):
        """
        Runs the specified VM thru the tests.

        Returns a success indicator on the general test execution. This is not
        the actual test result.
        """
        fRc = False

        sXmlFile = self.prepareResultFile()
        asEnv = ['IPRT_TEST_FILE=' + sXmlFile]

        self.logVmInfo(oVM)
        oSession = self.startVm(oVM, sName=oTestVm.sVmName, asEnv=asEnv)
        if oSession is not None:
            self.addTask(oSession)

            oRc = self.waitForTasks(15 * 60 * 1000)
            self.removeTask(oSession)
            if oRc == oSession:
                fRc = oSession.assertPoweredOff()
            else:
                reporter.error('oRc=%s, expected %s' % (oRc, oSession))

            reporter.addSubXmlFile(sXmlFile)
            self.terminateVmBySession(oSession)
        return fRc
    def __uploadFallback(self, oTxsSession, sTarFileGst, oTstDrv):
        """
        Fallback upload method.
        """
        sVtsTarExe = 'vts_tar' + self.oTestVm.getGuestExeSuff()
        sVtsTarHst = os.path.join(oTstDrv.sVBoxValidationKit,
                                  self.oTestVm.getGuestOs(),
                                  self.oTestVm.getGuestArch(), sVtsTarExe)
        sVtsTarGst = self.oTestVm.pathJoin(self.sBasePath, sVtsTarExe)

        if oTxsSession.syncUploadFile(sVtsTarHst, sVtsTarGst) is not True:
            return reporter.error(
                'Failed to upload "%s" to the guest as "%s"!' % (
                    sVtsTarHst,
                    sVtsTarGst,
                ))

        fRc = oTxsSession.syncExec(sVtsTarGst, [
            sVtsTarGst,
            '-xzf',
            sTarFileGst,
            '-C',
            self.sBasePath,
        ],
                                   fWithTestPipe=False)
        if fRc is not True:
            return reporter.error('vts_tar failed!')
        return True
Exemple #9
0
    def testOneVmConfig(self, oVM, oTestVm):
        """
        Install guest OS and wait for result
        """

        self.logVmInfo(oVM)
        reporter.testStart('Installing %s' % (oTestVm.sVmName, ))

        cMsTimeout = 40 * 60000
        if not reporter.isLocal(
        ):  ## @todo need to figure a better way of handling timeouts on the testboxes ...
            cMsTimeout = 180 * 60000
            # will be adjusted down.

        oSession, _ = self.startVmAndConnectToTxsViaTcp(oTestVm.sVmName,
                                                        fCdWait=False,
                                                        cMsTimeout=cMsTimeout)
        if oSession is not None:
            # The guest has connected to TXS, so we're done (for now anyways).
            reporter.log('Guest reported success')
            ## @todo Do save + restore.

            reporter.testDone()
            fRc = self.terminateVmBySession(oSession)
            return fRc is True

        reporter.error('Installation of %s has failed' % (oTestVm.sVmName, ))
        oTestVm.detatchAndDeleteHd(self)
        # Save space.
        reporter.testDone()
        return False
    def testDoInstallGuestOs(self):
        """
        Install guest OS and wait for result
        """

        self.logVmInfo(self.oVM)
        reporter.testStart('Installing %s' % (os.path.basename(self.sIso), ))

        cMsTimeout = 40 * 60000
        if not reporter.isLocal(
        ):  ## @todo need to figure a better way of handling timeouts on the testboxes ...
            cMsTimeout = 180 * 60000
            # will be adjusted down.

        oSession, _ = self.startVmAndConnectToTxsViaTcp(self.sVmName,
                                                        fCdWait=False,
                                                        cMsTimeout=cMsTimeout)
        if oSession is not None:
            # Wait until guest reported success
            reporter.log('Guest reported success')
            reporter.testDone()
            fRc = self.terminateVmBySession(oSession)
            return fRc is True
        reporter.error('Installation of %s has failed' % (self.sIso, ))
        reporter.testDone()
        return False
    def testOneCfg(self, oVM, oTestVm):
        """
        Runs the specified VM thru the tests.

        Returns a success indicator on the general test execution. This is not
        the actual test result.
        """
        fRc = False;

        sXmlFile = self.prepareResultFile();
        asEnv = [ 'IPRT_TEST_FILE=' + sXmlFile];

        self.logVmInfo(oVM);
        oSession = self.startVm(oVM, sName = oTestVm.sVmName, asEnv = asEnv);
        if oSession is not None:
            self.addTask(oSession);

            cMsTimeout = 15*60*1000;
            if not reporter.isLocal(): ## @todo need to figure a better way of handling timeouts on the testboxes ...
                cMsTimeout = self.adjustTimeoutMs(180 * 60000);

            oRc = self.waitForTasks(cMsTimeout);
            self.removeTask(oSession);
            if oRc == oSession:
                fRc = oSession.assertPoweredOff();
            else:
                reporter.error('oRc=%s, expected %s' % (oRc, oSession));

            reporter.addSubXmlFile(sXmlFile);
            self.terminateVmBySession(oSession);
        return fRc;
Exemple #12
0
    def _findFile(self, sRegExp, fMandatory=False):
        """
        Returns the first build file that matches the given regular expression
        (basename only).

        Returns None if no match was found, logging it as an error if
        fMandatory is set.
        """
        oRegExp = re.compile(sRegExp)

        reporter.log('_findFile: %s' % (sRegExp, ))
        for sFile in self._asBuildFiles:
            if oRegExp.match(
                    os.path.basename(sFile)) and os.path.exists(sFile):
                return sFile

        # If we didn't unpack the build files, search all the files in the scratch area:
        if not self._fUnpackedBuildFiles:
            for sDir, _, asFiles in os.walk(self.sScratchPath):
                for sFile in asFiles:
                    #reporter.log('_findFile: considering %s' % (sFile,));
                    if oRegExp.match(sFile):
                        return os.path.join(sDir, sFile)

        if fMandatory:
            reporter.error('Failed to find a file matching "%s" in %s.' % (
                sRegExp,
                self._asBuildFiles,
            ))
        return None
Exemple #13
0
    def _getVBoxInstallPath(self, fFailIfNotFound):
        """ Returns the default VBox installation path. """
        sHost = utils.getHostOs()
        if sHost == 'win':
            sProgFiles = os.environ.get('ProgramFiles', 'C:\\Program Files')
            asLocs = [
                os.path.join(sProgFiles, 'Oracle', 'VirtualBox'),
                os.path.join(sProgFiles, 'OracleVM', 'VirtualBox'),
                os.path.join(sProgFiles, 'Sun', 'VirtualBox'),
            ]
        elif sHost == 'linux' or sHost == 'solaris':
            asLocs = [
                '/opt/VirtualBox', '/opt/VirtualBox-3.2',
                '/opt/VirtualBox-3.1', '/opt/VirtualBox-3.0'
            ]
        elif sHost == 'darwin':
            asLocs = ['/Applications/VirtualBox.app/Contents/MacOS']
        else:
            asLocs = ['/opt/VirtualBox']
        if 'VBOX_INSTALL_PATH' in os.environ:
            asLocs.insert(0, os.environ.get('VBOX_INSTALL_PATH', None))

        for sLoc in asLocs:
            if os.path.isdir(sLoc):
                return sLoc
        if fFailIfNotFound:
            reporter.error('Failed to locate VirtualBox installation: %s' %
                           (asLocs, ))
        else:
            reporter.log2('Failed to locate VirtualBox installation: %s' %
                          (asLocs, ))
        return None
Exemple #14
0
    def equalMemory(self, abBuf, offFile=0):
        if not abBuf:
            return True

        if not self.checkRange(len(abBuf), offFile):
            return False

        if utils.areBytesEqual(abBuf, bytearray(len(abBuf))):
            return True

        cErrors = 0
        offBuf = 0
        while offBuf < len(abBuf):
            bByte = abBuf[offBuf]
            if not isinstance(bByte, int):
                bByte = ord(bByte)
            if bByte != 0:
                reporter.error('Mismatch @ %s/%s: %#x, expected 0!' % (
                    offFile,
                    offBuf,
                    bByte,
                ))
                cErrors += 1
                if cErrors > 32:
                    return False
            offBuf += 1
        return cErrors == 0
    def _getVBoxInstallPath(self, fFailIfNotFound):
        """ Returns the default VBox installation path. """
        sHost = utils.getHostOs();
        if sHost == 'win':
            sProgFiles = os.environ.get('ProgramFiles', 'C:\\Program Files');
            asLocs = [
                os.path.join(sProgFiles, 'Oracle', 'VirtualBox'),
                os.path.join(sProgFiles, 'OracleVM', 'VirtualBox'),
                os.path.join(sProgFiles, 'Sun', 'VirtualBox'),
            ];
        elif sHost == 'linux' or sHost == 'solaris':
            asLocs = [ '/opt/VirtualBox', '/opt/VirtualBox-3.2', '/opt/VirtualBox-3.1', '/opt/VirtualBox-3.0'];
        elif sHost == 'darwin':
            asLocs = [ '/Applications/VirtualBox.app/Contents/MacOS' ];
        else:
            asLocs = [ '/opt/VirtualBox' ];
        if 'VBOX_INSTALL_PATH' in os.environ:
            asLocs.insert(0, os.environ.get('VBOX_INSTALL_PATH', None));

        for sLoc in asLocs:
            if os.path.isdir(sLoc):
                return sLoc;
        if fFailIfNotFound:
            reporter.error('Failed to locate VirtualBox installation: %s' % (asLocs,));
        else:
            reporter.log2('Failed to locate VirtualBox installation: %s' % (asLocs,));
        return None;
 def actionVerify(self):
     if self.sVBoxValidationKitIso is None or not os.path.isfile(self.sVBoxValidationKitIso):
         reporter.error('Cannot find the VBoxValidationKit.iso! (%s)'
                        'Please unzip a Validation Kit build in the current directory or in some parent one.'
                        % (self.sVBoxValidationKitIso,) );
         return False;
     return vbox.TestDriver.actionVerify(self);
Exemple #17
0
    def testOneVmConfig(self, oVM, oTestVm): # type: (Any, UnattendedVm) -> bool
        """
        Install guest OS and wait for result
        """

        self.logVmInfo(oVM)
        reporter.testStart('Installing %s%s' % (oTestVm.sVmName, ' with GAs' if oTestVm.fOptInstallAdditions else ''))

        cMsTimeout = 40*60000;
        if not reporter.isLocal(): ## @todo need to figure a better way of handling timeouts on the testboxes ...
            cMsTimeout = 180 * 60000; # will be adjusted down.

        oSession, oTxsSession = self.startVmAndConnectToTxsViaTcp(oTestVm.sVmName, fCdWait = False, cMsTimeout = cMsTimeout);
        #oSession = self.startVmByName(oTestVm.sVmName); # (for quickly testing waitForGAs)
        if oSession is not None:
            # The guest has connected to TXS.
            reporter.log('Guest reported success via TXS.');
            reporter.testDone();

            fRc = True;
            # Kudge: GAs doesn't come up correctly, so we have to reboot the guest first:
            #        Looks like VBoxService isn't there.
            if oTestVm.fOptInstallAdditions:
                reporter.testStart('Rebooting');
                fRc, oTxsSession = self.txsRebootAndReconnectViaTcp(oSession, oTxsSession);
                reporter.testDone();

            # If we're installing GAs, wait for them to come online:
            if oTestVm.fOptInstallAdditions and fRc is True:
                reporter.testStart('Guest additions');
                aenmRunLevels = [vboxcon.AdditionsRunLevelType_Userland,];
                if oTestVm.isLoggedOntoDesktop():
                    aenmRunLevels.append(vboxcon.AdditionsRunLevelType_Desktop);
                fRc = self.waitForGAs(oSession, cMsTimeout = cMsTimeout / 2, aenmWaitForRunLevels = aenmRunLevels,
                                      aenmWaitForActive = (vboxcon.AdditionsFacilityType_VBoxGuestDriver,
                                                           vboxcon.AdditionsFacilityType_VBoxService,));
                reporter.testDone();

            # Now do a save & restore test:
            if fRc is True and self.fTestSaveAndRestore:
                fRc, oSession, oTxsSession = self.testSaveAndRestore(oSession, oTxsSession, oTestVm);

            # Test GAs if requested:
            if oTestVm.fOptInstallAdditions and fRc is True:
                for oSubTstDrv in self.aoSubTstDrvs:
                    if oSubTstDrv.fEnabled:
                        reporter.testStart(oSubTstDrv.sTestName);
                        fRc2, oTxsSession = oSubTstDrv.testIt(oTestVm, oSession, oTxsSession);
                        reporter.testDone(fRc2 is None);
                        if fRc2 is False:
                            fRc = False;

            if oSession is not None:
                fRc = self.terminateVmBySession(oSession) and fRc;
            return fRc is True

        reporter.error('Installation of %s has failed' % (oTestVm.sVmName,))
        #oTestVm.detatchAndDeleteHd(self); # Save space.
        reporter.testDone()
        return False
Exemple #18
0
    def _isExcluded(self, sTest, dExclList):
        """ Checks if the testcase is excluded or not. """
        if sTest in dExclList:
            sFullExpr = dExclList[sTest].replace(' ', '').strip()
            if sFullExpr == '':
                return True

            # Consider each exclusion expression. These are generally ranges,
            # either open ended or closed: "<4.3.51r12345", ">=4.3.0 && <=4.3.4".
            asExprs = sFullExpr.split(';')
            for sExpr in asExprs:

                # Split it on the and operator and process each sub expression.
                fResult = True
                for sSubExpr in sExpr.split('&&'):
                    # Split out the comparison operator and the version value.
                    if sSubExpr.startswith('<=') or sSubExpr.startswith('>='):
                        sOp = sSubExpr[:2]
                        sValue = sSubExpr[2:]
                    elif sSubExpr.startswith('<') or sSubExpr.startswith(
                            '>') or sSubExpr.startswith('='):
                        sOp = sSubExpr[:1]
                        sValue = sSubExpr[1:]
                    else:
                        sOp = sValue = ''

                    # Convert the version value, making sure we've got a valid one.
                    try:
                        aiValue = [
                            int(sComp)
                            for sComp in sValue.replace('r', '.').split('.')
                        ]
                    except:
                        aiValue = ()
                    if not aiValue or len(aiValue) > 4:
                        reporter.error(
                            'Invalid exclusion expression for %s: "%s" [%s]' %
                            (sTest, sSubExpr, dExclList[sTest]))
                        return True

                    # Do the compare.
                    iCmp = self._compareVersion(aiValue)
                    if sOp == '>=' and iCmp < 0:
                        fResult = False
                    elif sOp == '>' and iCmp <= 0:
                        fResult = False
                    elif sOp == '<' and iCmp >= 0:
                        fResult = False
                    elif sOp == '>=' and iCmp < 0:
                        fResult = False
                    reporter.log2(
                        'iCmp=%s; %s %s %s -> %s' %
                        (iCmp, self.aiVBoxVer, sOp, aiValue, fResult))

                # Did the expression match?
                if fResult:
                    return True

        return False
Exemple #19
0
 def testEventQueueWaitingThreadProc(self):
     """ Thread procedure for checking that waitForEvents fails when not called by the main thread. """
     try:
         rc2 = self.oTstDrv.oVBoxMgr.waitForEvents(0);
     except:
         return True;
     reporter.error('waitForEvents() returned "%s" when called on a worker thread, expected exception.' % (rc2,));
     return False;
Exemple #20
0
 def testEventQueueWaitingThreadProc(self):
     """ Thread procedure for checking that waitForEvents fails when not called by the main thread. """
     try:
         rc2 = self.oVBoxMgr.waitForEvents(0);
     except:
         return True;
     reporter.error('waitForEvents() returned "%s" when called on a worker thread, expected exception.' % (rc2,));
     return False;
    def _installVBox(self):
        """
        Download / copy the build files into the scratch area and install them.
        """
        reporter.testStart('Installing VirtualBox');
        reporter.log('CWD=%s' % (os.getcwd(),)); # curious

        #
        # Download the build files.
        #
        for i in range(len(self._asBuildUrls)):
            if webutils.downloadFile(self._asBuildUrls[i], self._asBuildFiles[i],
                                     self.sBuildPath, reporter.log, reporter.log) is not True:
                reporter.testDone(fSkipped = True);
                return None; # Failed to get binaries, probably deleted. Skip the test run.

        #
        # Unpack anything we know what is and append it to the build files
        # list.  This allows us to use VBoxAll*.tar.gz files.
        #
        for sFile in list(self._asBuildFiles):
            if self._maybeUnpackArchive(sFile, fNonFatal = True) is not True:
                reporter.testDone(fSkipped = True);
                return None; # Failed to unpack. Probably local error, like busy
                             # DLLs on windows, no reason for failing the build.

        #
        # Go to system specific installation code.
        #
        sHost = utils.getHostOs()
        if   sHost == 'darwin':     fRc = self._installVBoxOnDarwin();
        elif sHost == 'linux':      fRc = self._installVBoxOnLinux();
        elif sHost == 'solaris':    fRc = self._installVBoxOnSolaris();
        elif sHost == 'win':        fRc = self._installVBoxOnWindows();
        else:
            reporter.error('Unsupported host "%s".' % (sHost,));
        if fRc is False:
            reporter.testFailure('Installation error.');
        elif fRc is not True:
            reporter.log('Seems installation was skipped. Old version lurking behind? Not the fault of this build/test run!');

        #
        # Install the extension pack.
        #
        if fRc is True  and  self._fAutoInstallPuelExtPack:
            fRc = self._installExtPack();
            if fRc is False:
                reporter.testFailure('Extension pack installation error.');

        # Some debugging...
        try:
            cMbFreeSpace = utils.getDiskUsage(self.sScratchPath);
            reporter.log('Disk usage after VBox install: %d MB available at %s' % (cMbFreeSpace, self.sScratchPath,));
        except:
            reporter.logXcpt('Unable to get disk free space. Ignored. Continuing.');

        reporter.testDone(fRc is None);
        return fRc;
Exemple #22
0
    def _installVBox(self):
        """
        Download / copy the build files into the scratch area and install them.
        """
        reporter.testStart('Installing VirtualBox');
        reporter.log('CWD=%s' % (os.getcwd(),)); # curious

        #
        # Download the build files.
        #
        for i in range(len(self._asBuildUrls)):
            if webutils.downloadFile(self._asBuildUrls[i], self._asBuildFiles[i],
                                     self.sBuildPath, reporter.log, reporter.log) is not True:
                reporter.testDone(fSkipped = True);
                return None; # Failed to get binaries, probably deleted. Skip the test run.

        #
        # Unpack anything we know what is and append it to the build files
        # list.  This allows us to use VBoxAll*.tar.gz files.
        #
        for sFile in list(self._asBuildFiles):
            if self._maybeUnpackArchive(sFile, fNonFatal = True) is not True:
                reporter.testDone(fSkipped = True);
                return None; # Failed to unpack. Probably local error, like busy
                             # DLLs on windows, no reason for failing the build.

        #
        # Go to system specific installation code.
        #
        sHost = utils.getHostOs()
        if   sHost == 'darwin':     fRc = self._installVBoxOnDarwin();
        elif sHost == 'linux':      fRc = self._installVBoxOnLinux();
        elif sHost == 'solaris':    fRc = self._installVBoxOnSolaris();
        elif sHost == 'win':        fRc = self._installVBoxOnWindows();
        else:
            reporter.error('Unsupported host "%s".' % (sHost,));
        if fRc is False:
            reporter.testFailure('Installation error.');
        elif fRc is not True:
            reporter.log('Seems installation was skipped. Old version lurking behind? Not the fault of this build/test run!');

        #
        # Install the extension pack.
        #
        if fRc is True  and  self._fAutoInstallPuelExtPack:
            fRc = self._installExtPack();
            if fRc is False:
                reporter.testFailure('Extension pack installation error.');

        # Some debugging...
        try:
            cMbFreeSpace = utils.getDiskUsage(self.sScratchPath);
            reporter.log('Disk usage after VBox install: %d MB available at %s' % (cMbFreeSpace, self.sScratchPath,));
        except:
            reporter.logXcpt('Unable to get disk free space. Ignored. Continuing.');

        reporter.testDone(fRc is None);
        return fRc;
Exemple #23
0
 def checkRange(self, cbRange, offFile = 0):
     """ Check if the specified range is entirely within the file or not. """
     if offFile >= self.cbContent:
         return reporter.error('buffer @ %s LB %s is beyond the end of the file (%s bytes)!'
                               % (offFile, cbRange, self.cbContent,));
     if offFile + cbRange > self.cbContent:
         return reporter.error('buffer @ %s LB %s is partially beyond the end of the file (%s bytes)!'
                               % (offFile, cbRange, self.cbContent,));
     return True;
Exemple #24
0
    def _installVBoxOnWindows(self):
        """ Installs VBox on Windows."""
        sExe = self._findFile('^VirtualBox-.*-(MultiArch|Win).exe$')
        if sExe is None:
            return False

        # TEMPORARY HACK - START
        # It seems that running the NDIS cleanup script upon uninstallation is not
        # a good idea, so let's run it before installing VirtualBox.
        #sHostName = socket.getfqdn();
        #if    not sHostName.startswith('testboxwin3') \
        #  and not sHostName.startswith('testboxharp2') \
        #  and not sHostName.startswith('wei01-b6ka-3') \
        #  and utils.getHostOsVersion() in ['8', '8.1', '9', '2008Server', '2008ServerR2', '2012Server']:
        #    reporter.log('Peforming extra NDIS cleanup...');
        #    sMagicScript = os.path.abspath(os.path.join(g_ksValidationKitDir, 'testdriver', 'win-vbox-net-uninstall.ps1'));
        #    fRc2, _ = self._sudoExecuteSync(['powershell.exe', '-Command', 'set-executionpolicy unrestricted']);
        #    if not fRc2:
        #        reporter.log('set-executionpolicy failed.');
        #    self._sudoExecuteSync(['powershell.exe', '-Command', 'get-executionpolicy']);
        #    fRc2, _ = self._sudoExecuteSync(['powershell.exe', '-File', sMagicScript]);
        #    if not fRc2:
        #        reporter.log('NDIS cleanup failed.');
        # TEMPORARY HACK - END

        # Uninstall any previous vbox version first.
        fRc = self._uninstallVBoxOnWindows('install')
        if fRc is not True:
            return None
            # There shouldn't be anything to uninstall, and if there is, it's not our fault.

        # Install the new one.
        asArgs = [sExe, '-vvvv', '--silent', '--logging']
        asArgs.extend(['--msiparams', 'REBOOT=ReallySuppress'])
        sVBoxInstallPath = os.environ.get('VBOX_INSTALL_PATH', None)
        if sVBoxInstallPath is not None:
            asArgs.extend(['INSTALLDIR="%s"' % (sVBoxInstallPath, )])

        fRc2, iRc = self._sudoExecuteSync(asArgs)
        if fRc2 is False:
            if iRc == 3010:  # ERROR_SUCCESS_REBOOT_REQUIRED
                reporter.error(
                    'Installer required a reboot to complete installation (ERROR_SUCCESS_REBOOT_REQUIRED)'
                )
            else:
                reporter.error('Installer failed, exit code: %s' % (iRc, ))
            fRc = False

        sLogFile = os.path.join(tempfile.gettempdir(), 'VirtualBox',
                                'VBoxInstallLog.txt')
        if os.path.isfile(sLogFile):
            reporter.addLogFile(sLogFile, 'log/installer',
                                "Verbose MSI installation log file")
        self._waitForTestManagerConnectivity(30)
        return fRc
Exemple #25
0
    def _isExcluded(self, sTest, dExclList):
        """ Checks if the testcase is excluded or not. """
        if sTest in dExclList:
            sFullExpr = dExclList[sTest].replace(" ", "").strip()
            if sFullExpr == "":
                return True

            # Consider each exclusion expression. These are generally ranges,
            # either open ended or closed: "<4.3.51r12345", ">=4.3.0 && <=4.3.4".
            asExprs = sFullExpr.split(";")
            for sExpr in asExprs:

                # Split it on the and operator and process each sub expression.
                fResult = True
                for sSubExpr in sExpr.split("&&"):
                    # Split out the comparison operator and the version value.
                    if sSubExpr.startswith("<=") or sSubExpr.startswith(">="):
                        sOp = sSubExpr[:2]
                        sValue = sSubExpr[2:]
                    elif sSubExpr.startswith("<") or sSubExpr.startswith(">") or sSubExpr.startswith("="):
                        sOp = sSubExpr[:1]
                        sValue = sSubExpr[1:]
                    else:
                        sOp = sValue = ""

                    # Convert the version value, making sure we've got a valid one.
                    try:
                        aiValue = [int(sComp) for sComp in sValue.replace("r", ".").split(".")]
                    except:
                        aiValue = ()
                    if len(aiValue) == 0 or len(aiValue) > 4:
                        reporter.error(
                            'Invalid exclusion expression for %s: "%s" [%s]' % (sTest, sSubExpr, dExclList[sTest])
                        )
                        return True

                    # Do the compare.
                    iCmp = self._compareVersion(aiValue)
                    if sOp == ">=" and iCmp < 0:
                        fResult = False
                    elif sOp == ">" and iCmp <= 0:
                        fResult = False
                    elif sOp == "<" and iCmp >= 0:
                        fResult = False
                    elif sOp == ">=" and iCmp < 0:
                        fResult = False
                    reporter.log2("iCmp=%s; %s %s %s -> %s" % (iCmp, self.aiVBoxVer, sOp, aiValue, fResult))

                # Did the expression match?
                if fResult:
                    return True

        return False
Exemple #26
0
 def interruptWaitEventsThreadProc(self):
     """ Thread procedure that's used for waking up the main thread. """
     time.sleep(2);
     try:
         rc2 = self.oTstDrv.oVBoxMgr.interruptWaitEvents();
     except:
         reporter.errorXcpt();
     else:
         if rc2 is True:
             return True;
         reporter.error('interruptWaitEvents returned "%s" when called from other thread, expected True' % (rc2,));
     return False;
Exemple #27
0
 def interruptWaitEventsThreadProc(self):
     """ Thread procedure that's used for waking up the main thread. """
     time.sleep(2);
     try:
         rc2 = self.oVBoxMgr.interruptWaitEvents();
     except:
         reporter.errorXcpt();
     else:
         if rc2 is True:
             return True;
         reporter.error('interruptWaitEvents returned "%s" when called from other thread, expected True' % (rc2,));
     return False;
Exemple #28
0
    def testInstallAdditions(self, oSession, oTxsSession, oTestVm):
        """
        Tests installing the guest additions
        """
        if oTestVm.isWindows():
            (fRc, oTxsSession) = self.testWindowsInstallAdditions(
                oSession, oTxsSession, oTestVm)
        elif oTestVm.isLinux():
            (fRc, oTxsSession) = self.testLinuxInstallAdditions(
                oSession, oTxsSession, oTestVm)
        else:
            reporter.error(
                'Guest Additions installation not implemented for %s yet! (%s)'
                % (
                    oTestVm.sKind,
                    oTestVm.sVmName,
                ))
            fRc = False

        #
        # Verify installation of Guest Additions using commmon bits.
        #
        if fRc is True:
            #
            # Wait for the GAs to come up.
            #

            ## @todo need to signed up for a OnAdditionsStateChanged and wait runlevel to
            #  at least reach Userland.

            #
            # Check if the additions are operational.
            #
            try:
                oGuest = oSession.o.console.guest
            except:
                reporter.errorXcpt('Getting IGuest failed.')
                return (False, oTxsSession)

            # Check the additionsVersion attribute. It must not be empty.
            reporter.testStart('IGuest::additionsVersion')
            fRc = self.testIGuest_additionsVersion(oGuest)
            reporter.testDone()

            reporter.testStart('IGuest::additionsRunLevel')
            self.testIGuest_additionsRunLevel(oGuest, oTestVm)
            reporter.testDone()

            ## @todo test IAdditionsFacilities.

        return (fRc, oTxsSession)
    def _isExcluded(self, sTest, dExclList):
        """ Checks if the testcase is excluded or not. """
        if sTest in dExclList:
            sFullExpr = dExclList[sTest].replace(' ', '').strip();
            if sFullExpr == '':
                return True;

            # Consider each exclusion expression. These are generally ranges,
            # either open ended or closed: "<4.3.51r12345", ">=4.3.0 && <=4.3.4".
            asExprs = sFullExpr.split(';');
            for sExpr in asExprs:

                # Split it on the and operator and process each sub expression.
                fResult = True;
                for sSubExpr in sExpr.split('&&'):
                    # Split out the comparison operator and the version value.
                    if sSubExpr.startswith('<=') or sSubExpr.startswith('>='):
                        sOp = sSubExpr[:2];
                        sValue = sSubExpr[2:];
                    elif sSubExpr.startswith('<') or sSubExpr.startswith('>') or sSubExpr.startswith('='):
                        sOp = sSubExpr[:1];
                        sValue = sSubExpr[1:];
                    else:
                        sOp = sValue = '';

                    # Convert the version value, making sure we've got a valid one.
                    try:    aiValue = [int(sComp) for sComp in sValue.replace('r', '.').split('.')];
                    except: aiValue = ();
                    if len(aiValue) == 0 or len(aiValue) > 4:
                        reporter.error('Invalid exclusion expression for %s: "%s" [%s]' % (sTest, sSubExpr, dExclList[sTest]));
                        return True;

                    # Do the compare.
                    iCmp = self._compareVersion(aiValue);
                    if sOp == '>=' and iCmp < 0:
                        fResult = False;
                    elif sOp == '>' and iCmp <= 0:
                        fResult = False;
                    elif sOp == '<' and iCmp >= 0:
                        fResult = False;
                    elif sOp == '>=' and iCmp < 0:
                        fResult = False;
                    reporter.log2('iCmp=%s; %s %s %s -> %s' % (iCmp, self.aiVBoxVer, sOp, aiValue, fResult));

                # Did the expression match?
                if fResult:
                    return True;

        return False;
Exemple #30
0
 def locateGstBinary(self, oSession, oTxsSession, asPaths):
     """
     Locates a guest binary on the guest by checking the paths in \a asPaths.
     """
     for sCurPath in asPaths:
         reporter.log2('Checking for \"%s\" ...' % (sCurPath))
         if self.txsIsFile(oSession,
                           oTxsSession,
                           sCurPath,
                           fIgnoreErrors=True):
             return (True, sCurPath)
     reporter.error(
         'Unable to find guest binary in any of these places:\n%s' %
         ('\n'.join(asPaths), ))
     return (False, "")
Exemple #31
0
    def checkFacilityStatus(self, oGuest, eFacilityType, sDesc, fMustSucceed = True):
        """
        Prints the current status of a Guest Additions facility.

        Return success status.
        """

        fRc = True;

        try:
            eStatus, tsLastUpdatedMs = oGuest.getFacilityStatus(eFacilityType);
        except:
            if fMustSucceed:
                reporter.errorXcpt('Getting facility status for "%s" failed' % (sDesc,));
                fRc = False;
        else:
            if eStatus == vboxcon.AdditionsFacilityStatus_Inactive:
                sStatus = "INACTIVE";
            elif eStatus == vboxcon.AdditionsFacilityStatus_Paused:
                sStatus = "PAUSED";
            elif eStatus == vboxcon.AdditionsFacilityStatus_PreInit:
                sStatus = "PREINIT";
            elif eStatus == vboxcon.AdditionsFacilityStatus_Init:
                sStatus = "INIT";
            elif eStatus == vboxcon.AdditionsFacilityStatus_Active:
                sStatus = "ACTIVE";
            elif eStatus == vboxcon.AdditionsFacilityStatus_Terminating:
                sStatus = "TERMINATING";
                fRc = not fMustSucceed;
            elif eStatus == vboxcon.AdditionsFacilityStatus_Terminated:
                sStatus = "TERMINATED";
                fRc = not fMustSucceed;
            elif eStatus == vboxcon.AdditionsFacilityStatus_Failed:
                sStatus = "FAILED";
                fRc = not fMustSucceed;
            elif eStatus == vboxcon.AdditionsFacilityStatus_Unknown:
                sStatus = "UNKNOWN";
                fRc = not fMustSucceed;
            else:
                sStatus = "???";
                fRc = not fMustSucceed;

        reporter.log('Guest Additions facility "%s": %s (last updated: %sms)' % (sDesc, sStatus, str(tsLastUpdatedMs)));
        if      fMustSucceed \
        and not fRc:
            reporter.error('Guest Additions facility "%s" did not report expected status (is "%s")' % (sDesc, sStatus));

        return fRc;
Exemple #32
0
    def _findFile(self, sRegExp, sTestBuildDir):
        """
        Returns a filepath based on the given regex and path to look into
        or None if no matching file is found.
        """

        oRegExp = re.compile(sRegExp);

        asFiles = os.listdir(sTestBuildDir);

        for sFile in asFiles:
            if oRegExp.match(os.path.basename(sFile)) and os.path.exists(sTestBuildDir + '/' + sFile):
                return sTestBuildDir + '/' + sFile;

        reporter.error('Failed to find a file matching "%s" in %s.' % (sRegExp, sTestBuildDir));
        return None;
    def _findFile(self, sRegExp, fMandatory = False):
        """
        Returns the first build file that matches the given regular expression
        (basename only).

        Returns None if no match was found, logging it as an error if
        fMandatory is set.
        """
        oRegExp = re.compile(sRegExp);

        for sFile in self._asBuildFiles:
            if oRegExp.match(os.path.basename(sFile)) and os.path.exists(sFile):
                return sFile;

        if fMandatory:
            reporter.error('Failed to find a file matching "%s" in %s.' % (sRegExp, self._asBuildFiles,));
        return None;
    def _findFile(self, sRegExp, fMandatory = False):
        """
        Returns the first build file that matches the given regular expression
        (basename only).

        Returns None if no match was found, logging it as an error if
        fMandatory is set.
        """
        oRegExp = re.compile(sRegExp);

        for sFile in self._asBuildFiles:
            if oRegExp.match(os.path.basename(sFile)) and os.path.exists(sFile):
                return sFile;

        if fMandatory:
            reporter.error('Failed to find a file matching "%s" in %s.' % (sRegExp, self._asBuildFiles,));
        return None;
Exemple #35
0
    def unattendedDetectOs(self, oIUnattended,
                           oTestDrv):  # type: (Any, vbox.TestDriver) -> bool
        """
        Does the detectIsoOS operation and checks that the detect OSTypeId matches.

        Returns True on success, False w/ errors logged on failure.
        """

        #
        # Point the installer at the ISO and do the detection.
        #
        sInstallIso = self.sInstallIso
        if not os.path.isabs(sInstallIso):
            sInstallIso = os.path.join(oTestDrv.sResourcePath, sInstallIso)

        try:
            oIUnattended.isoPath = sInstallIso
        except:
            return reporter.errorXcpt('sInstallIso=%s' % (sInstallIso, ))

        try:
            oIUnattended.detectIsoOS()
        except:
            if oTestDrv.oVBoxMgr.xcptIsNotEqual(
                    None, oTestDrv.oVBoxMgr.statuses.E_NOTIMPL):
                return reporter.errorXcpt('sInstallIso=%s' % (sInstallIso, ))

        #
        # Get and log the result.
        #
        # Note! Current (6.0.97) fails with E_NOTIMPL even if it does some work.
        #
        try:
            sDetectedOSTypeId = oIUnattended.detectedOSTypeId
            sDetectedOSVersion = oIUnattended.detectedOSVersion
            sDetectedOSFlavor = oIUnattended.detectedOSFlavor
            sDetectedOSLanguages = oIUnattended.detectedOSLanguages
            sDetectedOSHints = oIUnattended.detectedOSHints
        except:
            return reporter.errorXcpt('sInstallIso=%s' % (sInstallIso, ))

        reporter.log('detectIsoOS result for "%s" (vm %s):' %
                     (sInstallIso, self.sVmName))
        reporter.log('       DetectedOSTypeId: %s' % (sDetectedOSTypeId, ))
        reporter.log('      DetectedOSVersion: %s' % (sDetectedOSVersion, ))
        reporter.log('       DetectedOSFlavor: %s' % (sDetectedOSFlavor, ))
        reporter.log('    DetectedOSLanguages: %s' % (sDetectedOSLanguages, ))
        reporter.log('        DetectedOSHints: %s' % (sDetectedOSHints, ))

        #
        # Check if the OS type matches.
        #
        if self.sKind != sDetectedOSTypeId:
            return reporter.error(
                'sInstallIso=%s: DetectedOSTypeId is %s, expected %s' %
                (sInstallIso, sDetectedOSTypeId, self.sKind))

        return True
Exemple #36
0
    def actionExecuteOnRunnigVM(self):
        """
        Executes the tests in an already configured + running VM.
        """
        if not self.importVBoxApi():
            return False

        fRc = True

        oVM = None
        oVirtualBox = None

        oVirtualBox = self.oVBoxMgr.getVirtualBox()
        try:
            oVM = oVirtualBox.findMachine(self.sRunningVmName)
            if oVM.state != self.oVBoxMgr.constants.MachineState_Running:
                reporter.error(
                    "Machine '%s' is not in Running state (state is %d)" %
                    (self.sRunningVmName, oVM.state))
                fRc = False
        except:
            reporter.errorXcpt("Machine '%s' not found" %
                               (self.sRunningVmName))
            fRc = False

        if fRc:
            oSession = self.openSession(oVM)
            if oSession:
                # Tweak this to your likings.
                oTestVm = vboxtestvms.TestVm('runningvm', sKind='WindowsXP')
                #sKind = 'WindowsXP' # sKind = 'Ubuntu_64'
                (fRc,
                 oTxsSession) = self.txsDoConnectViaTcp(oSession, 30 * 1000)
                if fRc:
                    self.doTest(oTestVm, oSession, oTxsSession)
            else:
                reporter.error("Unable to open session for machine '%s'" %
                               (self.sRunningVmName))
                fRc = False

        if oVM:
            del oVM
        if oVirtualBox:
            del oVirtualBox
        return fRc
Exemple #37
0
    def testInstallAdditions(self, oSession, oTxsSession, oTestVm):
        """
        Tests installing the guest additions
        """
        if oTestVm.isWindows():
            (fRc, oTxsSession) = self.testWindowsInstallAdditions(oSession, oTxsSession, oTestVm)
        else:
            reporter.error(
                "Guest Additions installation not implemented for %s yet! (%s)" % (oTestVm.sKind, oTestVm.sVmName)
            )
            fRc = False

        #
        # Verify installation of Guest Additions using commmon bits.
        #
        if fRc is True:
            #
            # Wait for the GAs to come up.
            #

            ## @todo need to signed up for a OnAdditionsStateChanged and wait runlevel to
            #  at least reach Userland.

            #
            # Check if the additions are operational.
            #
            try:
                oGuest = oSession.o.console.guest
            except:
                reporter.errorXcpt("Getting IGuest failed.")
                return (False, oTxsSession)

            # Check the additionsVersion attribute. It must not be empty.
            reporter.testStart("IGuest::additionsVersion")
            fRc = self.testIGuest_additionsVersion(oGuest)
            reporter.testDone()

            reporter.testStart("IGuest::additionsRunLevel")
            self.testIGuest_additionsRunLevel(oGuest, oTestVm)
            reporter.testDone()

            ## @todo test IAdditionsFacilities.

        return (fRc, oTxsSession)
    def completeOptions(self):
        #
        # Check that we've got what we need.
        #
        if len(self._asBuildUrls) == 0:
            reporter.error('No build files specfiied ("--vbox-build file1[,file2[...]]")');
            return False;
        if len(self._asSubDriver) == 0:
            reporter.error('No sub testdriver specified. (" -- test/stuff/tdStuff1.py args")');
            return False;

        #
        # Construct _asBuildFiles as an array parallel to _asBuildUrls.
        #
        for sUrl in self._asBuildUrls:
            sDstFile = os.path.join(self.sScratchPath, webutils.getFilename(sUrl));
            self._asBuildFiles.append(sDstFile);

        return TestDriverBase.completeOptions(self);
    def completeOptions(self):
        #
        # Check that we've got what we need.
        #
        if not self._asBuildUrls:
            reporter.error('No build files specfiied ("--vbox-build file1[,file2[...]]")');
            return False;
        if not self._asSubDriver:
            reporter.error('No sub testdriver specified. (" -- test/stuff/tdStuff1.py args")');
            return False;

        #
        # Construct _asBuildFiles as an array parallel to _asBuildUrls.
        #
        for sUrl in self._asBuildUrls:
            sDstFile = os.path.join(self.sScratchPath, webutils.getFilename(sUrl));
            self._asBuildFiles.append(sDstFile);

        return TestDriverBase.completeOptions(self);
Exemple #40
0
    def _unattendedConfigure(self, oIUnattended, oTestDrv): # type: (Any, vbox.TestDriver) -> bool
        """
        Configures the unattended install object.

        The ISO attribute has been set and detectIsoOS has been done, the rest of the
        setup is done here.

        Returns True on success, False w/ errors logged on failure.
        """

        #
        # Make it install the TXS.
        #
        try:    oIUnattended.installTestExecService = True;
        except: return reporter.errorXcpt();
        try:    oIUnattended.validationKitIsoPath   = oTestDrv.sVBoxValidationKitIso;
        except: return reporter.errorXcpt();
        oTestDrv.processPendingEvents();

        #
        # Install GAs?
        #
        if self.fOptInstallAdditions:
            if (self.fInstVmFlags & self.kfNoGAs) == 0:
                try:    oIUnattended.installGuestAdditions = True;
                except: return reporter.errorXcpt();
                try:    oIUnattended.additionsIsoPath      = oTestDrv.getGuestAdditionsIso();
                except: return reporter.errorXcpt();
                oTestDrv.processPendingEvents();
            else:
                reporter.log("Warning! Ignoring request to install Guest Additions as kfNoGAs is set!");

        #
        # Product key?
        #
        if self.fInstVmFlags & UnattendedVm.kfKeyFile:
            sKeyFile = '';
            sKey     = '';
            try:
                sKeyFile = oIUnattended.isoPath + '.key';
                oFile = utils.openNoInherit(sKeyFile);
                for sLine in oFile:
                    sLine = sLine.strip();
                    if sLine and not sLine.startswith(';') and not sLine.startswith('#') and not sLine.startswith('//'):
                        sKey = sLine;
                        break;
                oFile.close();
            except:
                return reporter.errorXcpt('sKeyFile=%s' % (sKeyFile,));
            if not sKey:
                return reporter.error('No key in keyfile (%s)!' % (sKeyFile,));
            try:    oIUnattended.productKey = sKey;
            except: return reporter.errorXcpt();

        return True;
Exemple #41
0
    def mountShareEx(self, oSession, oTxsSession, sShareName, sHostPath,
                     sGuestMountPoint, fMustSucceed):
        """
        Automount a shared folder in the guest, extended version.

        Returns success status, based on fMustSucceed.
        """
        reporter.testStart('Automounting "%s"' % (sShareName, ))

        reporter.log2('Creating shared folder "%s" at "%s" ...' %
                      (sShareName, sGuestMountPoint))
        try:
            oConsole = oSession.o.console
            oConsole.createSharedFolder(sShareName, sHostPath, True, True,
                                        sGuestMountPoint)
        except:
            if fMustSucceed:
                reporter.errorXcpt('createSharedFolder(%s,%s,True,True,%s)' %
                                   (sShareName, sHostPath, sGuestMountPoint))
            else:
                reporter.log(
                    'createSharedFolder(%s,%s,True,True,%s) failed, good' %
                    (sShareName, sHostPath, sGuestMountPoint))
            reporter.testDone()
            return False is fMustSucceed

        # Check whether we can see the shared folder now.  Retry for 30 seconds.
        msStart = base.timestampMilli()
        while True:
            fRc = oTxsSession.syncIsDir(sGuestMountPoint + self.sGuestSlash +
                                        'candle.dir')
            reporter.log2('candle.dir check -> %s' % (fRc, ))
            if fRc is fMustSucceed:
                break
            if base.timestampMilli() - msStart > 30000:
                reporter.error('Shared folder mounting timed out!')
                break
            self.oTstDrv.sleep(1)

        reporter.testDone()

        return fRc == fMustSucceed
    def _darwinUnmountDmg(self, fIgnoreError):
        """
        Umount any DMG on at the default mount point.
        """
        sMountPath = self._darwinDmgPath();
        if not os.path.exists(sMountPath):
            return True;

        # Unmount.
        fRc = self._executeSync(['hdiutil', 'detach', sMountPath ]);
        if not fRc and not fIgnoreError:
            reporter.error('Failed to unmount DMG at %s' % sMountPath);

        # Remove dir.
        try:
            os.rmdir(sMountPath);
        except:
            if not fIgnoreError:
                reporter.errorXcpt('Failed to remove directory %s' % sMountPath);
        return fRc;
    def testIGuest_additionsRunLevel(self, oGuest, oTestVm):
        """
        Do run level tests.
        """
        if oTestVm.isLoggedOntoDesktop():
            eExpectedRunLevel = vboxcon.AdditionsRunLevelType_Desktop;
        else:
            eExpectedRunLevel = vboxcon.AdditionsRunLevelType_Userland;

        ## @todo Insert wait for the desired run level.
        try:
            iLevel = oGuest.additionsRunLevel;
        except:
            reporter.errorXcpt('Getting the additions run level failed.');
            return False;
        reporter.log('IGuest::additionsRunLevel=%s' % (iLevel,));

        if iLevel != eExpectedRunLevel:
            reporter.error('Expected runlevel %d, found %d instead' % (eExpectedRunLevel, iLevel));
        return True;
    def testDoInstallGuestOs(self):
        """
        Install guest OS and wait for result
        """
        reporter.testStart('Installing %s' % (os.path.basename(self.sIso),))

        cMsTimeout = 40*60000;
        if not reporter.isLocal(): ## @todo need to figure a better way of handling timeouts on the testboxes ...
            cMsTimeout = 180 * 60000; # will be adjusted down.

        oSession, _ = self.startVmAndConnectToTxsViaTcp(self.sVmName, fCdWait = False, cMsTimeout = cMsTimeout)
        if oSession is not None:
            # Wait until guest reported success
            reporter.log('Guest reported success')
            reporter.testDone()
            fRc = self.terminateVmBySession(oSession)
            return fRc is True
        reporter.error('Installation of %s has failed' % (self.sIso,))
        reporter.testDone()
        return False
    def _darwinUnmountDmg(self, fIgnoreError):
        """
        Umount any DMG on at the default mount point.
        """
        sMountPath = self._darwinDmgPath();
        if not os.path.exists(sMountPath):
            return True;

        # Unmount.
        fRc = self._executeSync(['hdiutil', 'detach', sMountPath ]);
        if not fRc and not fIgnoreError:
            reporter.error('Failed to unmount DMG at %s' % sMountPath);

        # Remove dir.
        try:
            os.rmdir(sMountPath);
        except:
            if not fIgnoreError:
                reporter.errorXcpt('Failed to remove directory %s' % sMountPath);
        return fRc;
Exemple #46
0
    def testIGuest_additionsVersion(self, oGuest):
        """
        Returns False if no version string could be obtained, otherwise True
        even though errors are logged.
        """
        try:
            sVer = oGuest.additionsVersion
        except:
            reporter.errorXcpt("Getting the additions version failed.")
            return False
        reporter.log('IGuest::additionsVersion="%s"' % (sVer,))

        if sVer.strip() == "":
            reporter.error("IGuest::additionsVersion is empty.")
            return False

        if sVer != sVer.strip():
            reporter.error('IGuest::additionsVersion is contains spaces: "%s".' % (sVer,))

        asBits = sVer.split(".")
        if len(asBits) < 3:
            reporter.error(
                'IGuest::additionsVersion does not contain at least tree dot separated fields: "%s" (%d).'
                % (sVer, len(asBits))
            )

        ## @todo verify the format.
        return True
Exemple #47
0
 def actionExecute(self):
     # Too many immediate sub-tests.
     if self.sOptWhich == 'immediate-sub-tests':
         reporter.testStart('Too many immediate sub-tests (negative)');
         for i in range(1024):
             reporter.testStart('subsub%d' % i);
             reporter.testDone();
     # Too many sub-tests in total.
     elif self.sOptWhich == 'total-sub-tests':
         reporter.testStart('Too many sub-tests (negative)');
         # 32 * 256 = 2^(5+8) = 2^13 = 8192.
         for i in range(32):
             reporter.testStart('subsub%d' % i);
             for j in range(256):
                 reporter.testStart('subsubsub%d' % j);
                 reporter.testDone();
             reporter.testDone();
     # Too many immediate values.
     elif self.sOptWhich == 'immediate-values':
         reporter.testStart('Too many immediate values (negative)');
         for i in range(512):
             reporter.testValue('value%d' % i, i, 'times');
     # Too many values in total.
     elif self.sOptWhich == 'total-values':
         reporter.testStart('Too many sub-tests (negative)');
         for i in range(256):
             reporter.testStart('subsub%d' % i);
             for j in range(64):
                 reporter.testValue('value%d' % j, i * 10000 + j, 'times');
             reporter.testDone();
     # Too many failure reasons (only immediate since the limit is extremely low).
     elif self.sOptWhich == 'immediate-messages':
         reporter.testStart('Too many immediate messages (negative)');
         for i in range(16):
             reporter.testFailure('Detail %d' % i);
     else:
         reporter.testStart('Unknown test %s' % (self.sOptWhich,));
         reporter.error('Invalid test selected: %s' % (self.sOptWhich,));
     reporter.testDone();
     return True;
    def _uninstallVBox(self, fIgnoreError = False):
        """
        Uninstall VirtualBox.
        """
        reporter.testStart('Uninstalling VirtualBox');

        sHost = utils.getHostOs()
        if   sHost == 'darwin':     fRc = self._uninstallVBoxOnDarwin();
        elif sHost == 'linux':      fRc = self._uninstallVBoxOnLinux();
        elif sHost == 'solaris':    fRc = self._uninstallVBoxOnSolaris();
        elif sHost == 'win':        fRc = self._uninstallVBoxOnWindows();
        else:
            reporter.error('Unsupported host "%s".' % (sHost,));
        if fRc is False and not fIgnoreError:
            reporter.testFailure('Uninstallation failed.');

        fRc2 = self._uninstallAllExtPacks();
        if not fRc2 and fRc:
            fRc = fRc2;

        reporter.testDone(fSkipped = (fRc is None));
        return fRc;
Exemple #49
0
    def testEventQueueWaiting(self):
        """
        Test event queue waiting.
        """
        reporter.testStart('waitForEvents');

        # Check return values and such.
        for cMsTimeout in (0, 1, 2, 3, 256, 1000, 0):
            iLoop = 0;
            while True:
                try:
                    rc = self.oVBoxMgr.waitForEvents(cMsTimeout);
                except:
                    reporter.errorXcpt();
                    break;
                if not isinstance(rc, types.IntType):
                    reporter.error('waitForEvents returns non-integer type');
                    break;
                if rc == 1:
                    break;
                if rc != 0:
                    reporter.error('waitForEvents returns "%s", expected 0 or 1' % (rc,));
                    break;
                iLoop += 1;
                if iLoop > 10240:
                    reporter.error('waitForEvents returns 0 (success) %u times. '
                                   'Expected 1 (timeout/interrupt) after a call or two.'
                                   % (iLoop,));
                    break;
            if reporter.testErrorCount() != 0:
                break;

        # Check that we get an exception when trying to call the method from
        # a different thread.
        reporter.log('If running a debug build, you will see an ignored assertion now. Please ignore it.')
        sVBoxAssertSaved = os.environ.get('VBOX_ASSERT', 'breakpoint');
        os.environ['VBOX_ASSERT'] = 'ignore';
        oThread = threading.Thread(target=self.testEventQueueWaitingThreadProc);
        oThread.start();
        oThread.join();
        os.environ['VBOX_ASSERT'] = sVBoxAssertSaved;

        return reporter.testDone()[1] == 0;
    def test1OneCfg(self, eStorageController, oDskFmt):
        """
        Runs the specified VM thru test #1.

        Returns a success indicator on the general test execution. This is not
        the actual test result.
        """

        (asExts, aTypes) = oDskFmt.describeFileExtensions()
        for i in range(0, len(asExts)): #pylint: disable=consider-using-enumerate
            if aTypes[i] is vboxcon.DeviceType_HardDisk:
                sExt = '.' + asExts[i]
                break

        if sExt is None:
            return False;

        oOrigBaseHd = self.openMedium('5.3/storage/mergeMedium/t-orig.vdi');
        if oOrigBaseHd is None:
            return False;

        #currently only VDI can be resizable. Medium variant is not checked, because testcase creates disks itself
        fFmtDynamic = oDskFmt.id == 'VDI';
        sOrigWithDiffHd = '5.3/storage/mergeMedium/t-fixed.vdi'
        uOrigCrc = 0x7a417cbb;

        if fFmtDynamic:
            sOrigWithDiffHd = '5.3/storage/mergeMedium/t-resized.vdi';
            uOrigCrc = 0xa8f5daa3;

        oOrigWithDiffHd = self.openMedium(sOrigWithDiffHd);
        if oOrigWithDiffHd is None:
            return False;

        oVM = self.createTestVM('testvm', 1, None);
        if oVM is None:
            return False;

        sController = _ControllerTypeToName(eStorageController);

        # Reconfigure the VM
        oSession = self.openSession(oVM);
        if oSession is None:
            return False;
        # Attach HD

        fRc = True;
        sFile = 't-base' + sExt;
        sHddPath = os.path.join(self.oVBox.oTstDrv.sScratchPath, sFile);
        oHd = oSession.createBaseHd(sHddPath, sFmt=oDskFmt.id, cb=oOrigBaseHd.logicalSize);
        #if oSession.createBaseHd can't create disk because it exists, oHd will point to some stub object anyway
        fRc = fRc and oHd is not None and (oHd.logicalSize == oOrigBaseHd.logicalSize);
        fRc = fRc and self.cloneMedium(oOrigBaseHd, oHd);

        fRc = fRc and oSession.ensureControllerAttached(sController);
        fRc = fRc and oSession.setStorageControllerType(eStorageController, sController);
        fRc = fRc and oSession.saveSettings();
        fRc = fRc and oSession.attachHd(sHddPath, sController, iPort = 0, fImmutable=False, fForceResource=False)

        if fRc:
            oSession.takeSnapshot('Base snapshot');
            oSnapshot = oSession.findSnapshot('Base snapshot');

            if oSnapshot is not None:
                oSnapshotMedium = self.getSnapshotMedium(oSnapshot, sController);
                fRc = oSnapshotMedium is not None;

                if fFmtDynamic:
                    fRc = fRc and self.resizeMedium(oSnapshotMedium, oOrigWithDiffHd.logicalSize);
                fRc = fRc and self.cloneMedium(oOrigWithDiffHd, oSnapshotMedium);
                fRc = fRc and oSession.deleteSnapshot(oSnapshot.id, cMsTimeout = 120 * 1000);

                if fRc:
                    # disk for result test by checksum
                    sResFilePath = os.path.join(self.oVBox.oTstDrv.sScratchPath, 't_res.vmdk');
                    sResFilePathRaw = os.path.join(self.oVBox.oTstDrv.sScratchPath, 't_res-flat.vmdk');
                    oResHd = oSession.createBaseHd(sResFilePath, sFmt='VMDK', cb=oOrigWithDiffHd.logicalSize,
                                                   tMediumVariant = (vboxcon.MediumVariant_Fixed, ));
                    fRc = oResHd is not None;
                    fRc = fRc and self.cloneMedium(oHd, oResHd);

                    uResCrc32 = 0;
                    if fRc:
                        uResCrc32 = crc32_of_file(sResFilePathRaw);
                        if uResCrc32 == uOrigCrc:
                            reporter.log('Snapshot merged successfully. Crc32 is correct');
                            fRc = True;
                        else:
                            reporter.error('Snapshot merging failed. Crc32 is invalid');
                            fRc = False;

                    self.oVBox.deleteHdByMedium(oResHd);

        if oSession is not None:
            if oHd is not None:
                oSession.detachHd(sController, iPort = 0, iDevice = 0);

            oSession.saveSettings(fClose = True);
            if oHd is not None:
                self.oVBox.deleteHdByMedium(oHd);

        self.deleteVM(oVM);
        return fRc;
 def actionExtract(self):
     reporter.error('vboxinstall does not support extracting resources, you have to do that using the sub testdriver.');
     return False;
def main(asArgs):  # pylint: disable=C0111,R0914,R0915
    cMsTimeout = 30 * 1000
    sAddress = "localhost"
    uPort = None
    fReversedSetup = False
    fReboot = False
    fStdTests = True

    i = 1
    while i < len(asArgs):
        if asArgs[i] == "--hostname":
            sAddress = asArgs[i + 1]
            i = i + 2
        elif asArgs[i] == "--port":
            uPort = int(asArgs[i + 1])
            i = i + 2
        elif asArgs[i] == "--reversed-setup":
            fReversedSetup = True
            i = i + 1
        elif asArgs[i] == "--timeout":
            cMsTimeout = long(asArgs[i + 1])
            i = i + 2
        elif asArgs[i] == "--reboot":
            fReboot = True
            fStdTests = False
            i = i + 1
        elif asArgs[i] == "--help":
            print "tst-txsclient.py [--hostname <addr|name>] [--port <num>] [--timeout <cMS>] [--reboot] [--reversed-setup]"
            return 0
        else:
            print "Unknown argument: %s" % (asArgs[i])
            return 2

    if uPort is None:
        oSession = txsclient.openTcpSession(cMsTimeout, sAddress, fReversedSetup=fReversedSetup)
    else:
        oSession = txsclient.openTcpSession(cMsTimeout, sAddress, uPort=uPort, fReversedSetup=fReversedSetup)
    if oSession is None:
        print "openTcpSession failed"
        return 1

    fDone = oSession.waitForTask(30 * 1000)
    print "connect: waitForTask -> %s, result %s" % (fDone, oSession.getResult())
    if fDone is True and oSession.isSuccess():
        if fStdTests:
            # Get the UUID of the remote instance.
            sUuid = oSession.syncUuid()
            if sUuid is not False:
                print "%s: UUID = %s" % (boolRes(True), sUuid)
            else:
                print "%s: UUID" % (boolRes(False),)

            # Create and remove a directory on the scratch area.
            rc = oSession.syncMkDir("${SCRATCH}/testdir1")
            print "%s: MKDIR(${SCRATCH}/testdir1) -> %s" % (boolRes(rc), rc)

            rc = oSession.syncIsDir("${SCRATCH}/testdir1")
            print "%s: ISDIR(${SCRATCH}/testdir1) -> %s" % (boolRes(rc), rc)

            rc = oSession.syncRmDir("${SCRATCH}/testdir1")
            print "%s: RMDIR(${SCRATCH}/testdir1) -> %s" % (boolRes(rc), rc)

            # Create a two-level subdir.
            rc = oSession.syncMkDirPath("${SCRATCH}/testdir2/subdir1")
            print "%s: MKDRPATH(${SCRATCH}/testdir2/subdir1) -> %s" % (boolRes(rc), rc)

            rc = oSession.syncIsDir("${SCRATCH}/testdir2")
            print "%s: ISDIR(${SCRATCH}/testdir2) -> %s" % (boolRes(rc), rc)
            rc = oSession.syncIsDir("${SCRATCH}/testdir2/")
            print "%s: ISDIR(${SCRATCH}/testdir2/) -> %s" % (boolRes(rc), rc)
            rc = oSession.syncIsDir("${SCRATCH}/testdir2/subdir1")
            print "%s: ISDIR(${SCRATCH}/testdir2/subdir1) -> %s" % (boolRes(rc), rc)

            rc = oSession.syncRmTree("${SCRATCH}/testdir2")
            print "%s: RMTREE(${SCRATCH}/testdir2) -> %s" % (boolRes(rc), rc)

            # Check out a simple file.
            rc = oSession.syncUploadString("howdy", "${SCRATCH}/howdyfile")
            print "%s: PUT FILE(${SCRATCH}/howdyfile) -> %s" % (boolRes(rc), rc)

            rc = oSession.syncUploadString("howdy-replaced", "${SCRATCH}/howdyfile")
            print "%s: PUT FILE(${SCRATCH}/howdyfile) -> %s" % (boolRes(rc), rc)

            rc = oSession.syncDownloadString("${SCRATCH}/howdyfile")
            print '%s: GET FILE(${SCRATCH}/howdyfile) -> "%s" expected "howdy-replaced"' % (
                stringRes(rc, "howdy-replaced"),
                rc,
            )

            rc = oSession.syncIsFile("${SCRATCH}/howdyfile")
            print "%s: ISFILE(${SCRATCH}/howdyfile) -> %s" % (boolRes(rc), rc)
            rc = oSession.syncIsDir("${SCRATCH}/howdyfile")
            print "%s: ISDIR(${SCRATCH}/howdyfile) -> %s" % (boolRes(rc, False), rc)
            rc = oSession.syncIsSymlink("${SCRATCH}/howdyfile")
            print "%s: ISSYMLNK(${SCRATCH}/howdyfile) -> %s" % (boolRes(rc, False), rc)

            rc = oSession.syncRmFile("${SCRATCH}/howdyfile")
            print "%s: RMFILE(${SCRATCH}/howdyfile) -> %s" % (boolRes(rc), rc)

            # Unicode filename (may or may not work, LANG/LC_TYPE dependent on some hosts).
            rc = oSession.syncUploadString("howdy", u"${SCRATCH}/Schröder")
            print (u"%s: PUT FILE(${SCRATCH}/Schröder) -> %s" % (boolRes(rc), rc)).encode("ascii", "replace")

            rc = oSession.syncIsFile(u"${SCRATCH}/Schröder")
            print (u"%s: ISFILE(${SCRATCH}/Schröder) -> %s" % (boolRes(rc), rc)).encode("ascii", "replace")

            rc = oSession.syncRmFile(u"${SCRATCH}/Schröder")
            print (u"%s: RMFILE(${SCRATCH}/Schröder) -> %s" % (boolRes(rc), rc)).encode("ascii", "replace")

            # Finally, some file uploading and downloading with unicode filenames.
            strUpFile = "tst-txsclient-upload.bin"
            strDwnFile = "tst-txsclient-download.bin"
            try:
                abRandFile = os.urandom(257897)
            except:
                print "INFO: no urandom... falling back on a simple string."
                abRandFile = "asdflkjasdlfkjasdlfkjq023942relwjgkna9epr865u2nm345;hndafgoukhasre5kb2453km"
                for i in range(1, 64):
                    abRandFile += abRandFile
            try:
                oLocalFile = utils.openNoInherit(strUpFile, "w+b")
                oLocalFile.write(abRandFile)
                oLocalFile.close()
                rc = True
            except:
                rc = False
                print ("%s: creating file (%s) to upload failed...." % (boolRes(rc), strUpFile))

            if rc is True:
                rc = oSession.syncUploadFile(strUpFile, "${SCRATCH}/tst-txsclient-uploaded.bin")
                print ("%s: PUT FILE(%s, ${SCRATCH}/tst-txsclient-uploaded.bin) -> %s" % (boolRes(rc), strUpFile, rc))

                rc = oSession.syncDownloadFile("${SCRATCH}/tst-txsclient-uploaded.bin", strDwnFile)
                print (
                    "%s: GET FILE(${SCRATCH}/tst-txsclient-uploaded.bin, tst-txsclient-downloaded.txt) -> %s"
                    % (boolRes(rc), rc)
                )

                try:
                    oLocalFile = utils.openNoInherit(strDwnFile, "rb")
                    abDwnFile = oLocalFile.read()
                    oLocalFile.close()
                    if abRandFile == abDwnFile:
                        print "%s: downloaded file matches the uploaded file" % (boolRes(True),)
                    else:
                        print "%s: downloaded file does not match the uploaded file" % (boolRes(False),)
                        print "abRandFile=%s" % (abRandFile,)
                        print "abDwnFile =%s" % (abRandFile,)
                except:
                    print "%s: reading downloaded file (%s) failed...." % (boolRes(False), strDwnFile)

                rc = oSession.syncRmFile(u"${SCRATCH}/tst-txsclient-uploaded.bin")
                print "%s: RMFILE(${SCRATCH}/tst-txsclient-uploaded.bin) -> %s" % (boolRes(rc), rc)

            try:
                os.remove(strUpFile)
            except:
                pass
            try:
                os.remove(strDwnFile)
            except:
                pass

            # Execute some simple thing, if available.
            # Intentionally skip this test if file is not available due to
            # another inserted CD-ROM (e.g. not TestSuite.iso).
            sProg = "${CDROM}/${OS/ARCH}/NetPerf${EXESUFF}"
            rc = oSession.syncIsFile(sProg, 30 * 1000, True)
            if rc is True:
                rc = oSession.syncExecEx(sProg, (sProg, "--help"))
                print "%s: EXEC(%s ${SCRATCH}) -> %s" % (boolRes(rc), sProg, rc)

                rc = oSession.syncExecEx(
                    sProg,
                    (sProg, "there", "is no such", "parameter"),
                    oStdOut="${SCRATCH}/stdout",
                    oStdErr="${SCRATCH}/stderr",
                )
                print (
                    "%s: EXEC(%s there is not such parameter > ${SCRATCH}/stdout 2> ${SCRATCH}/stderr) -> %s"
                    % (boolRes(rc, False), sProg, rc)
                )

                rc = oSession.syncDownloadString("${SCRATCH}/stdout")
                print 'INFO:   GET FILE(${SCRATCH}/stdout) -> "%s"' % (rc)
                rc = oSession.syncDownloadString("${SCRATCH}/stderr")
                print 'INFO:   GET FILE(${SCRATCH}/stderr) -> "%s"' % (rc)

                print "TESTING: syncExec..."
                rc = oSession.syncExec(sProg, (sProg, "--version"))
                print "%s: EXEC(%s --version) -> %s" % (boolRes(rc), sProg, rc)

                print "TESTING: syncExec..."
                rc = oSession.syncExec(sProg, (sProg, "--help"))
                print "%s: EXEC(%s --help) -> %s" % (boolRes(rc), sProg, rc)

                # print 'TESTING: syncExec sleep 30...'
                # rc = oSession.syncExec('/usr/bin/sleep', ('/usr/bin/sleep', '30'));
                # print '%s: EXEC(/bin/sleep 30) -> %s' % (boolRes(rc), rc);
            else:
                print "SKIP:   Execution of %s skipped, does not exist on CD-ROM" % (sProg,)

            # Execute a non-existing file on CD-ROM.
            sProg = "${CDROM}/${OS/ARCH}/NonExisting${EXESUFF}"
            rc = oSession.syncExecEx(
                sProg,
                (sProg,),
                oStdIn="/dev/null",
                oStdOut="/dev/null",
                oStdErr="/dev/null",
                oTestPipe="/dev/null",
                sAsUser="",
                cMsTimeout=3600000,
                fIgnoreErrors=True,
            )
            if rc is None:
                rc = True
            else:
                reporter.error('Unexpected value "%s" while executing non-existent file "%s"' % (rc, sProg))
            print "%s: EXEC(%s ${SCRATCH}) -> %s" % (boolRes(rc), sProg, rc)

            # Done
            rc = oSession.syncDisconnect()
            print "%s: disconnect() -> %s" % (boolRes(rc), rc)

        elif fReboot:
            print "TESTING: syncReboot..."
            rc = oSession.syncReboot()
            print "%s: REBOOT() -> %s" % (boolRes(rc), rc)

    if g_cFailures != 0:
        print "tst-txsclient.py: %u out of %u test failed" % (g_cFailures, g_cTests)
        return 1
    print "tst-txsclient.py: all %u tests passed!" % (g_cTests)
    return 0
    def actionExecute(self):
        """
        Execute the testcase itself.
        """
        #self.logVmInfo(self.oVM)

        reporter.testStart('SHUTDOWN GUEST')

        cIter = 0
        fRc = True

        if (self.fExtraVm is True):
            oExtraSession, oExtraTxsSession = self.startVmAndConnectToTxsViaTcp(self.sExtraVmName,
                                                                                fCdWait=False,
                                                                                cMsTimeout=self.kcMsVmStartLimit)
            if oExtraSession is None or oExtraTxsSession is None:
                reporter.error('Unable to start extra VM.')
                if (self.fLocalCatch is True):
                    self._waitKeyboardInterrupt()
                reporter.testDone()
                return False

        while (cIter < self.cShutdownIters):

            cIter += 1

            reporter.log("Starting iteration #%d." % cIter)

            oSession, oTxsSession = self.startVmAndConnectToTxsViaTcp(self.sVmName,
                                                                      fCdWait=False,
                                                                      cMsTimeout=self.kcMsVmStartLimit)
            if oSession is not None and oTxsSession is not None:
                # Wait until guest reported success
                reporter.log('Guest started. Connection to TXS service established.')

                if (self.fSuspendHost is True):
                    reporter.log("Disconnect form TXS.")
                    fRc = fRc and self.txsDisconnect(oSession, oTxsSession)
                    if (fRc is not True):
                        reporter.log("Disconnect form TXS failed.")
                    else:
                        reporter.log('Put host to sleep and resume it automatically after %d seconds.' % self.cSecSuspendTime)
                        fRc = fRc and self._SuspendResume(self.cSecSuspendTime)
                        if (fRc is True):
                            reporter.log("Sleep/resume success.")
                        else:
                            reporter.log("Sleep/resume failed.")
                        reporter.log("Re-connect to TXS in 10 seconds.")
                        self.sleep(10)
                        (fRc, oTxsSession) = self.txsDoConnectViaTcp(oSession, 2 * 60 * 10000)
                        if (fRc is not True):
                            reporter.log("Re-connect to TXS failed.")

                if (fRc is True):
                    reporter.log('Attempt to shutdown guest.')
                    fRc = fRc and oTxsSession.syncShutdown(cMsTimeout=(4 * 60 * 1000))
                    if (fRc is True):
                        reporter.log('Shutdown request issued successfully.')
                        self.waitOnDirectSessionClose(self.oVM, self.kcMsVmShutdownLimit)
                        reporter.log('Shutdown %s.' % ('success' if fRc is True else 'failed'))
                    else:
                        reporter.error('Shutdown request failed.')

                    # Do not terminate failing VM in order to catch it.
                    if (fRc is not True and self.fLocalCatch is True):
                        self._waitKeyboardInterrupt()
                        break

                    fRc = fRc and self.terminateVmBySession(oSession)
                    reporter.log('VM terminated.')

            else:
                reporter.error('Guest did not start (iteration %d of %d)' % (cIter, self.cShutdownIters))
                fRc = False

            # Stop if fail
            if (fRc is not True):
                break

        # Local catch at the end.
        if (self.fLocalCatch is True):
            reporter.log("Test completed. Waiting for user to press CTRL+C.")
            self._waitKeyboardInterrupt()

        if (self.fExtraVm is True):
            fRc = fRc and  self.terminateVmBySession(oExtraSession)

        reporter.testDone()
        return fRc is True
def main(asArgs): # pylint: disable=C0111,R0914,R0915
    cMsTimeout      = long(30*1000);
    sAddress        = 'localhost';
    uPort           = None;
    fReversedSetup  = False;
    fReboot         = False;
    fShutdown       = False;
    fStdTests       = True;

    i = 1;
    while i < len(asArgs):
        if asArgs[i] == '--hostname':
            sAddress = asArgs[i + 1];
            i = i + 2;
        elif asArgs[i] == '--port':
            uPort = int(asArgs[i + 1]);
            i = i + 2;
        elif asArgs[i] == '--reversed-setup':
            fReversedSetup = True;
            i = i + 1;
        elif asArgs[i] == '--timeout':
            cMsTimeout = long(asArgs[i + 1]);
            i = i + 2;
        elif asArgs[i] == '--reboot':
            fReboot   = True;
            fShutdown = False;
            fStdTests = False;
            i = i + 1;
        elif asArgs[i] == '--shutdown':
            fShutdown = True;
            fReboot   = False;
            fStdTests = False;
            i = i + 1;
        elif asArgs[i] == '--help':
            print('tst-txsclient.py [--hostname <addr|name>] [--port <num>] [--timeout <cMS>] '
                  '[--reboot|--shutdown] [--reversed-setup]');
            return 0;
        else:
            print('Unknown argument: %s' % (asArgs[i]));
            return 2;

    if uPort is None:
        oSession = txsclient.openTcpSession(cMsTimeout, sAddress, fReversedSetup = fReversedSetup);
    else:
        oSession = txsclient.openTcpSession(cMsTimeout, sAddress, uPort = uPort, fReversedSetup = fReversedSetup);
    if oSession is None:
        print('openTcpSession failed');
        return 1;

    fDone = oSession.waitForTask(30*1000);
    print('connect: waitForTask -> %s, result %s' % (fDone, oSession.getResult()));
    if fDone is True and oSession.isSuccess():
        if fStdTests:
            # Get the UUID of the remote instance.
            sUuid = oSession.syncUuid();
            if sUuid is not False:
                print('%s: UUID = %s' % (boolRes(True), sUuid));
            else:
                print('%s: UUID' % (boolRes(False),));

            # Create and remove a directory on the scratch area.
            rc = oSession.syncMkDir('${SCRATCH}/testdir1');
            print('%s: MKDIR(${SCRATCH}/testdir1) -> %s' % (boolRes(rc), rc));

            rc = oSession.syncIsDir('${SCRATCH}/testdir1');
            print('%s: ISDIR(${SCRATCH}/testdir1) -> %s' % (boolRes(rc), rc));

            rc = oSession.syncRmDir('${SCRATCH}/testdir1');
            print('%s: RMDIR(${SCRATCH}/testdir1) -> %s' % (boolRes(rc), rc));

            # Create a two-level subdir.
            rc = oSession.syncMkDirPath('${SCRATCH}/testdir2/subdir1');
            print('%s: MKDRPATH(${SCRATCH}/testdir2/subdir1) -> %s' % (boolRes(rc), rc));

            rc = oSession.syncIsDir('${SCRATCH}/testdir2');
            print('%s: ISDIR(${SCRATCH}/testdir2) -> %s' % (boolRes(rc), rc));
            rc = oSession.syncIsDir('${SCRATCH}/testdir2/');
            print('%s: ISDIR(${SCRATCH}/testdir2/) -> %s' % (boolRes(rc), rc));
            rc = oSession.syncIsDir('${SCRATCH}/testdir2/subdir1');
            print('%s: ISDIR(${SCRATCH}/testdir2/subdir1) -> %s' % (boolRes(rc), rc));

            rc = oSession.syncRmTree('${SCRATCH}/testdir2');
            print('%s: RMTREE(${SCRATCH}/testdir2) -> %s' % (boolRes(rc), rc));

            # Check out a simple file.
            rc = oSession.syncUploadString('howdy', '${SCRATCH}/howdyfile');
            print('%s: PUT FILE(${SCRATCH}/howdyfile) -> %s' % (boolRes(rc), rc));

            rc = oSession.syncUploadString('howdy-replaced', '${SCRATCH}/howdyfile');
            print('%s: PUT FILE(${SCRATCH}/howdyfile) -> %s' % (boolRes(rc), rc));

            rc = oSession.syncDownloadString('${SCRATCH}/howdyfile');
            print('%s: GET FILE(${SCRATCH}/howdyfile) -> "%s" expected "howdy-replaced"' % (stringRes(rc, 'howdy-replaced'), rc));

            rc = oSession.syncIsFile('${SCRATCH}/howdyfile');
            print('%s: ISFILE(${SCRATCH}/howdyfile) -> %s' % (boolRes(rc), rc));
            rc = oSession.syncIsDir('${SCRATCH}/howdyfile');
            print('%s: ISDIR(${SCRATCH}/howdyfile) -> %s' % (boolRes(rc, False), rc));
            rc = oSession.syncIsSymlink('${SCRATCH}/howdyfile');
            print('%s: ISSYMLNK(${SCRATCH}/howdyfile) -> %s' % (boolRes(rc, False), rc));

            rc = oSession.syncRmFile('${SCRATCH}/howdyfile');
            print('%s: RMFILE(${SCRATCH}/howdyfile) -> %s' % (boolRes(rc), rc));

            # Unicode filename (may or may not work, LANG/LC_TYPE dependent on some hosts).
            rc = oSession.syncUploadString('howdy', u'${SCRATCH}/Schröder');
            print((u'%s: PUT FILE(${SCRATCH}/Schröder) -> %s' % (boolRes(rc), rc)).encode('ascii', 'replace'));

            rc = oSession.syncIsFile(u'${SCRATCH}/Schröder');
            print((u'%s: ISFILE(${SCRATCH}/Schröder) -> %s' % (boolRes(rc), rc)).encode('ascii', 'replace'));

            rc = oSession.syncRmFile(u'${SCRATCH}/Schröder');
            print((u'%s: RMFILE(${SCRATCH}/Schröder) -> %s' % (boolRes(rc), rc)).encode('ascii', 'replace'));

            # Finally, some file uploading and downloading with unicode filenames.
            strUpFile  = 'tst-txsclient-upload.bin';
            strDwnFile = 'tst-txsclient-download.bin';
            try:
                abRandFile = os.urandom(257897);
            except:
                print('INFO: no urandom... falling back on a simple string.');
                abRandFile = 'asdflkjasdlfkjasdlfkjq023942relwjgkna9epr865u2nm345;hndafgoukhasre5kb2453km';
                for i in range(1, 64):
                    abRandFile += abRandFile;
            try:
                oLocalFile = utils.openNoInherit(strUpFile, 'w+b');
                oLocalFile.write(abRandFile);
                oLocalFile.close();
                rc = True;
            except:
                rc = False;
                print('%s: creating file (%s) to upload failed....' % (boolRes(rc), strUpFile));

            if rc is True:
                rc = oSession.syncUploadFile(strUpFile, '${SCRATCH}/tst-txsclient-uploaded.bin')
                print('%s: PUT FILE(%s, ${SCRATCH}/tst-txsclient-uploaded.bin) -> %s' % (boolRes(rc), strUpFile, rc));

                rc = oSession.syncDownloadFile('${SCRATCH}/tst-txsclient-uploaded.bin', strDwnFile)
                print('%s: GET FILE(${SCRATCH}/tst-txsclient-uploaded.bin, tst-txsclient-downloaded.txt) -> %s'
                      % (boolRes(rc), rc));

                try:
                    oLocalFile = utils.openNoInherit(strDwnFile, "rb");
                    abDwnFile = oLocalFile.read();
                    oLocalFile.close();
                    if abRandFile == abDwnFile:
                        print('%s: downloaded file matches the uploaded file' % (boolRes(True),));
                    else:
                        print('%s: downloaded file does not match the uploaded file' % (boolRes(False),));
                        print('abRandFile=%s' % (abRandFile,));
                        print('abDwnFile =%s' % (abRandFile,));
                except:
                    print('%s: reading downloaded file (%s) failed....' % (boolRes(False), strDwnFile));

                rc = oSession.syncRmFile(u'${SCRATCH}/tst-txsclient-uploaded.bin');
                print('%s: RMFILE(${SCRATCH}/tst-txsclient-uploaded.bin) -> %s' % (boolRes(rc), rc));

            try:    os.remove(strUpFile);
            except: pass;
            try:    os.remove(strDwnFile);
            except: pass;

            # Execute some simple thing, if available.
            # Intentionally skip this test if file is not available due to
            # another inserted CD-ROM (e.g. not TestSuite.iso).
            sProg = '${CDROM}/${OS/ARCH}/NetPerf${EXESUFF}';
            rc = oSession.syncIsFile(sProg, 30 * 1000, True);
            if rc is True:
                rc = oSession.syncExecEx(sProg, (sProg, '--help'));
                print('%s: EXEC(%s ${SCRATCH}) -> %s' % (boolRes(rc), sProg, rc));

                rc = oSession.syncExecEx(sProg, (sProg, 'there', 'is no such', 'parameter'), \
                                         oStdOut='${SCRATCH}/stdout', \
                                         oStdErr='${SCRATCH}/stderr');
                print('%s: EXEC(%s there is not such parameter > ${SCRATCH}/stdout 2> ${SCRATCH}/stderr) -> %s'
                      % (boolRes(rc, False), sProg, rc));

                rc = oSession.syncDownloadString('${SCRATCH}/stdout');
                print('INFO:   GET FILE(${SCRATCH}/stdout) -> "%s"' % (rc));
                rc = oSession.syncDownloadString('${SCRATCH}/stderr');
                print('INFO:   GET FILE(${SCRATCH}/stderr) -> "%s"' % (rc));

                print('TESTING: syncExec...');
                rc = oSession.syncExec(sProg, (sProg, '--version'));
                print('%s: EXEC(%s --version) -> %s' % (boolRes(rc), sProg, rc));

                print('TESTING: syncExec...');
                rc = oSession.syncExec(sProg, (sProg, '--help'));
                print('%s: EXEC(%s --help) -> %s' % (boolRes(rc), sProg, rc));

                #print('TESTING: syncExec sleep 30...'
                #rc = oSession.syncExec('/usr/bin/sleep', ('/usr/bin/sleep', '30')));
                #print('%s: EXEC(/bin/sleep 30) -> %s' % (boolRes(rc), rc));
            else:
                print('SKIP:   Execution of %s skipped, does not exist on CD-ROM' % (sProg,));

            # Execute a non-existing file on CD-ROM.
            sProg = '${CDROM}/${OS/ARCH}/NonExisting${EXESUFF}';
            rc = oSession.syncExecEx(sProg, (sProg,), oStdIn = '/dev/null', oStdOut = '/dev/null', \
                                     oStdErr = '/dev/null', oTestPipe = '/dev/null', \
                                     sAsUser = '', cMsTimeout = 3600000, fIgnoreErrors = True);
            if rc is None:
                rc = True;
            else:
                reporter.error('Unexpected value \"%s\" while executing non-existent file "%s"' % (rc, sProg));
            print('%s: EXEC(%s ${SCRATCH}) -> %s' % (boolRes(rc), sProg, rc));

            # Done
            rc = oSession.syncDisconnect();
            print('%s: disconnect() -> %s' % (boolRes(rc), rc));

        elif fReboot:
            print('TESTING: syncReboot...');
            rc = oSession.syncReboot();
            print('%s: REBOOT() -> %s' % (boolRes(rc), rc));
        elif fShutdown:
            print('TESTING: syncShutdown...');
            rc = oSession.syncShutdown();
            print('%s: SHUTDOWN() -> %s' % (boolRes(rc), rc));


    if g_cFailures != 0:
        print('tst-txsclient.py: %u out of %u test failed' % (g_cFailures, g_cTests));
        return 1;
    print('tst-txsclient.py: all %u tests passed!' % (g_cTests));
    return 0;
    def _detectPaths(self):
        """
        Internal worker for actionVerify and actionExecute that detects paths.

        This sets sVBoxInstallRoot and sUnitTestsPathBase and returns True/False.
        """

        #
        # We need a VBox install (/ build) to test.
        #
        if False:
            if not self.importVBoxApi():
                reporter.error('Unabled to import the VBox Python API.')
                return False
        else:
            self._detectBuild();
            if self.oBuild is None:
                reporter.error('Unabled to detect the VBox build.');
                return False;

        #
        # Where are the files installed?
        # Solaris requires special handling because of it's multi arch subdirs.
        #
        self.sVBoxInstallRoot = self.oBuild.sInstallPath
        if not self.oBuild.isDevBuild() and utils.getHostOs() == 'solaris':
            sArchDir = utils.getHostArch();
            if sArchDir == 'x86': sArchDir = 'i386';
            self.sVBoxInstallRoot = os.path.join(self.sVBoxInstallRoot, sArchDir);

        # Add the installation root to the PATH on windows so we can get DLLs from it.
        if utils.getHostOs() == 'win':
            sPathName = 'PATH';
            if not sPathName in os.environ:
                sPathName = 'Path';
            sPath = os.environ.get(sPathName, '.');
            if len(sPath) > 0 and sPath[-1] != ';':
                sPath += ';';
            os.environ[sPathName] = sPath + self.sVBoxInstallRoot + ';';

        #
        # The unittests are generally not installed, so look for them.
        #
        sBinOrDist = 'dist' if utils.getHostOs() in [ 'darwin', ] else 'bin';
        asCandidates = [
            self.oBuild.sInstallPath,
            os.path.join(self.sScratchPath, sBinOrDist + '.' + utils.getHostArch()),
            os.path.join(self.sScratchPath, sBinOrDist, utils.getHostArch()),
            os.path.join(self.sScratchPath, sBinOrDist),
        ];
        if utils.getHostOs() == 'darwin':
            for i in range(1, len(asCandidates)):
                asCandidates[i] = os.path.join(asCandidates[i], 'VirtualBox.app', 'Contents', 'MacOS');

        for sCandidat in asCandidates:
            if os.path.exists(os.path.join(sCandidat, 'testcase', 'tstVMStructSize' + self.sExeSuff)):
                self.sUnitTestsPathBase = sCandidat;
                return True;

        reporter.error('Unable to find unit test dir. Candidates: %s' % (asCandidates,))
        return False;
Exemple #56
0
    def testEventQueueInterrupt(self):
        """
        Test interrupting an event queue wait.
        """
        reporter.testStart('interruptWait');

        # interrupt ourselves first and check the return value.
        for i in range(0, 10):
            try:
                rc = self.oVBoxMgr.interruptWaitEvents();
            except:
                reporter.errorXcpt();
                break;
            if rc is not True:
                reporter.error('interruptWaitEvents returned "%s" expected True' % (rc,));
                break

        if reporter.testErrorCount() == 0:
            #
            # Interrupt a waitForEvents call.
            #
            # This test ASSUMES that no other events are posted to the thread's
            # event queue once we've drained it.  Also ASSUMES the box is
            # relatively fast and not too busy because we're timing sensitive.
            #
            for i in range(0, 4):
                # Try quiesce the event queue.
                for _ in range(1, 100):
                    self.oVBoxMgr.waitForEvents(0);

                # Create a thread that will interrupt us in 2 seconds.
                try:
                    oThread = threading.Thread(target=self.interruptWaitEventsThreadProc);
                    oThread.setDaemon(False);
                except:
                    reporter.errorXcpt();
                    break;

                cMsTimeout = 20000;
                if i == 2:
                    cMsTimeout = -1;
                elif i == 3:
                    cMsTimeout = -999999;

                # Do the wait.
                oThread.start();
                msNow = base.timestampMilli();
                try:
                    rc = self.oVBoxMgr.waitForEvents(cMsTimeout);
                except:
                    reporter.errorXcpt();
                else:
                    msElapsed = base.timestampMilli() - msNow;

                    # Check the return code and elapsed time.
                    if not isinstance(rc, types.IntType):
                        reporter.error('waitForEvents returns non-integer type after %u ms, expected 1' % (msElapsed,));
                    elif rc != 1:
                        reporter.error('waitForEvents returned "%s" after %u ms, expected 1' % (rc, msElapsed));
                    if msElapsed > 15000:
                        reporter.error('waitForEvents after %u ms, expected just above 2-3 seconds' % (msElapsed,));
                    elif msElapsed < 100:
                        reporter.error('waitForEvents after %u ms, expected more than 100 ms.' % (msElapsed,));

                oThread.join();
                oThread = None;
                if reporter.testErrorCount() != 0:
                    break;
                reporter.log('Iteration %u was successful...' % (i + 1,));
        return reporter.testDone()[1] == 0;
    def testAutostartRunProgs(self, oSession, oTxsSession, sVmName):
        """
        Test VirtualBoxs autostart feature in a VM.
        """
        reporter.testStart('Autostart ' + sVmName);

        oGuestOsHlp = None;

        if sVmName == self.ksOsLinux:
            oGuestOsHlp = tdAutostartOsLinux(self, self.sTestBuildDir);
        elif sVmName == self.ksOsSolaris:
            oGuestOsHlp = tdAutostartOsSolaris(self, self.sTestBuildDir);
        elif sVmName == self.ksOsDarwin:
            oGuestOsHlp = tdAutostartOsDarwin(self.sTestBuildDir);
        elif sVmName == self.ksOsWindows:
            oGuestOsHlp = tdAutostartOsWin(self.sTestBuildDir);

        sTestUserAllow = 'test1';
        sTestUserDeny = 'test2';
        sTestVmName = 'TestVM';

        if oGuestOsHlp is not None:
            # Create two new users
            fRc = oGuestOsHlp.createUser(oTxsSession, sTestUserAllow);
            fRc = fRc and oGuestOsHlp.createUser(oTxsSession, sTestUserDeny);
            if fRc is True:
                # Install VBox first
                fRc = oGuestOsHlp.installVirtualBox(oSession, oTxsSession);
                if fRc is True:
                    fRc = oGuestOsHlp.configureAutostart(oSession, oTxsSession, 'allow',
                                                         (sTestUserAllow,), (sTestUserDeny,));
                    if fRc is True:
                        # Create a VM with autostart enabled in the guest for both users
                        fRc = oGuestOsHlp.createTestVM(oSession, oTxsSession, sTestUserAllow, sTestVmName);
                        fRc = fRc and oGuestOsHlp.createTestVM(oSession, oTxsSession, sTestUserDeny, sTestVmName);
                        if fRc is True:
                            # Reboot the guest
                            (fRc, oTxsSession) = self.txsRebootAndReconnectViaTcp(oSession, oTxsSession, cMsTimeout = 3 * 60000, \
                                                                                  fNatForwardingForTxs = True);
                            if fRc is True:
                                # Fudge factor - Allow the guest to finish starting up.
                                self.sleep(5);
                                fRc = oGuestOsHlp.checkForRunningVM(oSession, oTxsSession, sTestUserAllow, sTestVmName);
                                if fRc is False:
                                    reporter.error('Test VM is not running inside the guest for allowed user');

                                fRc = oGuestOsHlp.checkForRunningVM(oSession, oTxsSession, sTestUserDeny, sTestVmName);
                                if fRc is True:
                                    reporter.error('Test VM is running inside the guest for denied user');
                            else:
                                reporter.log('Rebooting the guest failed');
                        else:
                            reporter.log('Creating test VM failed');
                    else:
                        reporter.log('Configuring autostart in the guest failed');
                else:
                    reporter.log('Installing VirtualBox in the guest failed');
            else:
                reporter.log('Creating test users failed');
        else:
            reporter.log('Guest OS helper not created for VM %s' % (sVmName));
            fRc = False;

        reporter.testDone(not fRc);
        return fRc;
    def testLinuxInstallAdditions(self, oSession, oTxsSession, oTestVm):
        oSession = oSession;
        oTestVm = oTestVm;

        fRc = False;

        # Install Kernel headers, which are required for actually installing the Linux Additions.
        if oTestVm.sKind.startswith('Debian') \
        or oTestVm.sKind.startswith('Ubuntu'):
            fRc = self.txsRunTest(oTxsSession, 'Installing Kernel headers', 5 * 60 *1000,
                                  '/usr/bin/apt-get', ('/usr/bin/apt-get', 'install', '-y', 'linux-headers-generic'));
            if not fRc:
                reporter.error('Error installing Kernel headers');
            fRc = self.txsRunTest(oTxsSession, 'Installing Guest Additions depdendencies', 5 * 60 *1000, \
                                  '/usr/bin/apt-get', ('/usr/bin/apt-get', 'install', '-y', 'build-essential', 'perl'));
            if not fRc:
                reporter.error('Error installing additional installer dependencies');
        elif oTestVm.sKind.startswith('OL') \
        or   oTestVm.sKind.startswith('Oracle') \
        or   oTestVm.sKind.startswith('RHEL') \
        or   oTestVm.sKind.startswith('Redhat') \
        or   oTestVm.sKind.startswith('Cent'):
            fRc = self.txsRunTest(oTxsSession, 'Installing Kernel headers', 5 * 60 *1000,
                                  '/usr/bin/yum', ('/usr/bin/yum', '-y', 'install', 'kernel-headers'));
            if not fRc:
                reporter.error('Error installing Kernel headers');
            fRc = self.txsRunTest(oTxsSession, 'Installing Guest Additions depdendencies', 5 * 60 *1000, \
                                  '/usr/bin/yum', ('/usr/bin/yum', '-y', 'install', \
                                                   'make', 'automake', 'gcc', 'kernel-devel', 'dkms', 'bzip2', 'perl'));
            if not fRc:
                reporter.error('Error installing additional installer dependencies');
        else:
            reporter.error('Installing Linux Additions for kind "%s" is not supported yet' % oTestVm.sKind);
            return (False, oTxsSession);

        if fRc:
            #
            # The actual install.
            # Also tell the installer to produce the appropriate log files.
            #
            fRc = self.txsRunTest(oTxsSession, 'VBoxLinuxAdditions.run', 5 * 60 * 1000,
                '/bin/sh', ('/bin/sh', '${CDROM}/VBoxLinuxAdditions.run'));
            if not fRc:
                reporter.error('Installing Linux Additions failed (see log file for details)');

            #
            # Download log files.
            # Ignore errors as all files above might not be present for whatever reason.
            #
            asLogFile = [];
            asLogFile.append('/var/log/vboxadd-install.log');
            self.txsDownloadFiles(oSession, oTxsSession, asLogFile, fIgnoreErrors = True);

        if fRc:
            (fRc, oTxsSession) = self.txsRebootAndReconnectViaTcp(oSession, oTxsSession, cMsTimeout = 3 * 60000);

        return (fRc, oTxsSession);
    def _executeTestCase(self, sName, sFullPath, sTestCaseSubDir, oDevNull): # pylint: disable=R0914
        """
        Executes a test case.
        """

        fSkipped = False;

        #
        # If hardening is enabled, some test cases and their dependencies
        # needs to be copied to and execute from the sVBoxInstallRoot
        # directory in order to work. They also have to be executed as
        # root, i.e. via sudo.
        #
        fHardened       = False;
        asFilesToRemove = []; # Stuff to clean up.
        asDirsToRemove  = []; # Ditto.
        if    sName in self.kasHardened \
          and self.sUnitTestsPathBase != self.sVBoxInstallRoot:

            sDstDir = os.path.join(self.sVBoxInstallRoot, sTestCaseSubDir);
            if not os.path.exists(sDstDir):
                self._hardenedMkDir(sDstDir);
                asDirsToRemove.append(sDstDir);

            sDst = os.path.join(sDstDir, os.path.basename(sFullPath));
            self._hardenedCopyFile(sFullPath, sDst, 0755);
            asFilesToRemove.append(sDst);

            # Copy any associated .dll/.so/.dylib.
            for sSuff in [ '.dll', '.so', '.dylib' ]:
                sSrc = os.path.splitext(sFullPath)[0] + sSuff;
                if os.path.exists(sSrc):
                    sDst = os.path.join(sDstDir, os.path.basename(sSrc));
                    self._hardenedCopyFile(sSrc, sDst, 0644);
                    asFilesToRemove.append(sDst);

            # Copy any associated .r0, .rc and .gc modules.
            offDriver = sFullPath.rfind('Driver')
            if offDriver > 0:
                for sSuff in [ '.r0', 'RC.rc', 'RC.gc' ]:
                    sSrc = sFullPath[:offDriver] + sSuff;
                    if os.path.exists(sSrc):
                        sDst = os.path.join(sDstDir, os.path.basename(sSrc));
                        self._hardenedCopyFile(sSrc, sDst, 0644);
                        asFilesToRemove.append(sDst);

            sFullPath = os.path.join(sDstDir, os.path.basename(sFullPath));
            fHardened = True;

        #
        # Set up arguments and environment.
        #
        asArgs = [sFullPath,]
        if sName in self.kdArguments:
            asArgs.extend(self.kdArguments[sName]);

        os.environ['IPRT_TEST_OMIT_TOP_TEST'] = '1';
        os.environ['IPRT_TEST_FILE'] = sXmlFile = os.path.join(self.sScratchPath, 'result.xml');
        if os.path.exists(sXmlFile):
            try:    os.unlink(sXmlFile);
            except: self._hardenedDeleteFile(sXmlFile);

        #
        # Execute the test case.
        #
        # Windows is confusing output.  Trying a few things to get rid of this.
        # First, flush both stderr and stdout before running the child.  Second,
        # assign the child stderr to stdout.  If this doesn't help, we'll have
        # to capture the child output.
        #
        reporter.log('*** Executing %s%s...' % (asArgs, ' [hardened]' if fHardened else ''));
        try:    sys.stdout.flush();
        except: pass;
        try:    sys.stderr.flush();
        except: pass;
        if not self.fDryRun:
            try:
                if fHardened:
                    oChild = utils.sudoProcessPopen(asArgs, stdin = oDevNull, stdout = sys.stdout, stderr = sys.stdout);
                else:
                    oChild = subprocess.Popen(      asArgs, stdin = oDevNull, stdout = sys.stdout, stderr = sys.stdout);
            except:
                if sName in [ 'tstAsmStructsRC',    # 32-bit, may fail to start on 64-bit linux. Just ignore.
                              ]:
                    reporter.logXcpt();
                    fSkipped = True;
                else:
                    reporter.errorXcpt();
                iRc    = 1023;
                oChild = None;

            if oChild is not None:
                self.pidFileAdd(oChild.pid, fSudo = fHardened);
                iRc = oChild.wait();
                self.pidFileRemove(oChild.pid);
        else:
            iRc = 0;

        #
        # Clean up
        #
        for sPath in asFilesToRemove:
            self._hardenedDeleteFile(sPath);
        for sPath in asDirsToRemove:
            self._hardenedRemoveDir(sPath);

        #
        # Report.
        #
        if os.path.exists(sXmlFile):
            reporter.addSubXmlFile(sXmlFile);
            if fHardened:
                self._hardenedDeleteFile(sXmlFile);
            else:
                os.unlink(sXmlFile);

        if iRc == 0:
            reporter.log('*** %s: exit code %d' % (sFullPath, iRc));
            self.cPassed += 1

        elif iRc == 4: # RTEXITCODE_SKIPPED
            reporter.log('*** %s: exit code %d (RTEXITCODE_SKIPPED)' % (sFullPath, iRc));
            fSkipped = True;
            self.cSkipped += 1;

        elif fSkipped:
            reporter.log('*** %s: exit code %d (Skipped)' % (sFullPath, iRc));
            self.cSkipped += 1;

        else:
            sName = self.kdExitCodeNames.get(iRc, '');
            if iRc in self.kdExitCodeNamesWin and utils.getHostOs() == 'win':
                sName = self.kdExitCodeNamesWin[iRc];
            if sName != '':
                sName = ' (%s)' % (sName);

            if iRc != 1:
                reporter.testFailure('Exit status: %d%s' % (iRc, sName));
                reporter.log(  '!*! %s: exit code %d%s' % (sFullPath, iRc, sName));
            else:
                reporter.error('!*! %s: exit code %d%s' % (sFullPath, iRc, sName));
            self.cFailed += 1

        return fSkipped;