示例#1
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);

            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;
示例#2
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
    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;
示例#5
0
文件: tdPython1.py 项目: mcenirm/vbox
 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;
示例#7
0
文件: tdPython1.py 项目: mcenirm/vbox
 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;
示例#8
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
    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;
示例#10
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;
示例#12
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 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
示例#15
0
    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 _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;
示例#17
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
示例#18
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;
示例#20
0
文件: tdPython1.py 项目: mcenirm/vbox
    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;
示例#21
0
文件: tdPython1.py 项目: mcenirm/vbox
    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 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      = 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 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
示例#25
0
    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;
    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);
示例#27
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;
    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;
示例#29
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;
示例#30
0
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