Esempio n. 1
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.oTstDrv.oVBoxMgr.waitForEvents(cMsTimeout)
                except:
                    reporter.errorXcpt()
                    break
                if not isinstance(rc, int):
                    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
Esempio n. 2
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;
Esempio n. 3
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.oTstDrv.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.oTstDrv.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.oTstDrv.oVBoxMgr.waitForEvents(cMsTimeout)
                except:
                    reporter.errorXcpt()
                else:
                    msElapsed = base.timestampMilli() - msNow

                    # Check the return code and elapsed time.
                    if not isinstance(rc, int):
                        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
Esempio n. 4
0
    def testUsbOneCfg(self, sVmName, sUsbCtrl, sSpeed, sUsbTest):
        """
        Runs the specified VM thru one specified test.

        Returns a success indicator on the general test execution. This is not
        the actual test result.
        """
        oVM = self.getVmByName(sVmName)

        # Reconfigure the VM
        fRc = True
        oSession = self.openSession(oVM)
        if oSession is not None:
            fRc = fRc and oSession.enableVirtEx(True)
            fRc = fRc and oSession.enableNestedPaging(True)

            # Make sure controllers are disabled initially.
            fRc = fRc and oSession.enableUsbOhci(False)
            fRc = fRc and oSession.enableUsbEhci(False)
            fRc = fRc and oSession.enableUsbXhci(False)

            if sUsbCtrl == 'OHCI':
                fRc = fRc and oSession.enableUsbOhci(True)
            elif sUsbCtrl == 'EHCI':
                fRc = fRc and oSession.enableUsbEhci(True)
            elif sUsbCtrl == 'XHCI':
                fRc = fRc and oSession.enableUsbXhci(True)
            fRc = fRc and oSession.saveSettings()
            fRc = oSession.close() and fRc and True
            # pychecker hack.
            oSession = None
        else:
            fRc = False

        # Start up.
        if fRc is True:
            self.logVmInfo(oVM)
            oSession, oTxsSession = self.startVmAndConnectToTxsViaTcp(
                sVmName, fCdWait=False, fNatForwardingForTxs=False)
            if oSession is not None:
                self.addTask(oSession)

                # Fudge factor - Allow the guest to finish starting up.
                self.sleep(5)

                sCaptureFile = None
                if self.fUsbCapture:
                    sCaptureFile = self.getCaptureFilePath(sUsbCtrl, sSpeed)

                if sUsbTest == 'Compliance':
                    fRc = self.testUsbCompliance(oSession, oTxsSession,
                                                 sUsbCtrl, sSpeed,
                                                 sCaptureFile)
                elif sUsbTest == 'Reattach':
                    fRc = self.testUsbReattach(oSession, oTxsSession, sUsbCtrl,
                                               sSpeed, sCaptureFile)

                # cleanup.
                self.removeTask(oTxsSession)
                self.terminateVmBySession(oSession)

                # Add the traffic dump if it exists and the test failed
                if reporter.testErrorCount() > 0 \
                   and sCaptureFile is not None \
                   and os.path.exists(sCaptureFile):
                    reporter.addLogFile(sCaptureFile, 'misc/other',
                                        'USB traffic dump')
            else:
                fRc = False
        return fRc
    def test2OneCfg(self, sVmBaseName, cCpus, fHwVirt, fNestedPaging):
        """
        Runs the specified VM thru test #1.
        """

        # Reconfigure the source VM.
        oVmSrc = self.getVmByName(sVmBaseName + '-1');
        fRc = True;
        oSession = self.openSession(oVmSrc);
        if oSession is not None:
            fRc = fRc and oSession.enableVirtEx(fHwVirt);
            fRc = fRc and oSession.enableNestedPaging(fNestedPaging);
            fRc = fRc and oSession.setCpuCount(cCpus);
            fRc = fRc and oSession.setupTeleporter(False, uPort=6501, sPassword='******');
            fRc = fRc and oSession.saveSettings();
            fRc = oSession.close() and fRc and True; # pychecker hack.
            oSession = None;
        else:
            fRc = False;

        # Reconfigure the destination VM.
        oVmDst = self.getVmByName(sVmBaseName + '-2');
        oSession = self.openSession(oVmDst);
        if oSession is not None:
            fRc = fRc and oSession.enableVirtEx(fHwVirt);
            fRc = fRc and oSession.enableNestedPaging(fNestedPaging);
            fRc = fRc and oSession.setCpuCount(cCpus);
            fRc = fRc and oSession.setupTeleporter(True, uPort=6502, sPassword='******');
            fRc = fRc and oSession.saveSettings();
            fRc = oSession.close() and fRc and True; # pychecker hack.
            oSession = None;
        else:
            fRc = False;

        # Simple test.
        if fRc is True:
            self.logVmInfo(oVmSrc);
            self.logVmInfo(oVmDst);

            # Start the source VM.
            oSessionSrc = self.startVm(oVmSrc);
            if oSessionSrc is not None:
                self.addTask(oSessionSrc);

                # Simple back and forth to test the ice...
                cTeleportations = 0;
                oVmSrc, oSessionSrc, oVmDst = self.test2Teleport(oVmSrc, oSessionSrc, oVmDst);
                if reporter.testErrorCount() == 0:
                    cTeleportations += 1;
                    oVmSrc, oSessionSrc, oVmDst = self.test2Teleport(oVmSrc, oSessionSrc, oVmDst);

                # Teleport back and forth for a while.
                msStart = base.timestampMilli();
                while reporter.testErrorCount() == 0:
                    cTeleportations += 1;
                    if oSessionSrc.txsTryConnectViaTcp(2500, 'localhost') is True:
                        break;
                    oVmSrc, oSessionSrc, oVmDst = self.test2Teleport(oVmSrc, oSessionSrc, oVmDst);
                    cMsElapsed = base.timestampMilli() - msStart;
                    if cMsElapsed > 5*60000:
                        reporter.testFailure('TXS did not show up after %u min of teleporting (%u)...' \
                                             % (cMsElapsed / 60000.0, cTeleportations));
                        break;

                # Clean up the source VM.
                self.terminateVmBySession(oSessionSrc)
        return None;
    def test2OneCfg(self, sVmBaseName, cCpus, fHwVirt, fNestedPaging):
        """
        Runs the specified VM thru test #1.
        """

        # Reconfigure the source VM.
        oVmSrc = self.getVmByName(sVmBaseName + '-1')
        fRc = True
        oSession = self.openSession(oVmSrc)
        if oSession is not None:
            fRc = fRc and oSession.enableVirtEx(fHwVirt)
            fRc = fRc and oSession.enableNestedPaging(fNestedPaging)
            fRc = fRc and oSession.setCpuCount(cCpus)
            fRc = fRc and oSession.setupTeleporter(
                False, uPort=6501, sPassword='******')
            fRc = fRc and oSession.saveSettings()
            fRc = oSession.close() and fRc and True
            # pychecker hack.
            oSession = None
        else:
            fRc = False

        # Reconfigure the destination VM.
        oVmDst = self.getVmByName(sVmBaseName + '-2')
        oSession = self.openSession(oVmDst)
        if oSession is not None:
            fRc = fRc and oSession.enableVirtEx(fHwVirt)
            fRc = fRc and oSession.enableNestedPaging(fNestedPaging)
            fRc = fRc and oSession.setCpuCount(cCpus)
            fRc = fRc and oSession.setupTeleporter(
                True, uPort=6502, sPassword='******')
            fRc = fRc and oSession.saveSettings()
            fRc = oSession.close() and fRc and True
            # pychecker hack.
            oSession = None
        else:
            fRc = False

        # Simple test.
        if fRc is True:
            self.logVmInfo(oVmSrc)
            self.logVmInfo(oVmDst)

            # Start the source VM.
            oSessionSrc = self.startVm(oVmSrc)
            if oSessionSrc is not None:
                # Simple back and forth to test the ice...
                cTeleportations = 0
                oVmSrc, oSessionSrc, oVmDst = self.test2Teleport(
                    oVmSrc, oSessionSrc, oVmDst)
                if reporter.testErrorCount() == 0:
                    cTeleportations += 1
                    oVmSrc, oSessionSrc, oVmDst = self.test2Teleport(
                        oVmSrc, oSessionSrc, oVmDst)

                # Teleport back and forth for a while.
                msStart = base.timestampMilli()
                while reporter.testErrorCount() == 0:
                    cTeleportations += 1
                    if oSessionSrc.txsTryConnectViaTcp(2500,
                                                       'localhost') is True:
                        break
                    oVmSrc, oSessionSrc, oVmDst = self.test2Teleport(
                        oVmSrc, oSessionSrc, oVmDst)
                    cMsElapsed = base.timestampMilli() - msStart
                    if cMsElapsed > 5 * 60000:
                        reporter.testFailure('TXS did not show up after %u min of teleporting (%u)...' \
                                             % (cMsElapsed / 60000.0, cTeleportations))
                        break

                # Clean up the source VM.
                self.terminateVmBySession(oSessionSrc)
        return None
Esempio n. 7
0
    def actionExecute(self, oTestDrv, fnCallback): # pylint: disable=R0914
        """
        For base.TestDriver.actionExecute.  Calls the callback function for
        each of the VMs and basic configuration variations (virt-mode and cpu
        count).

        Returns True if all fnCallback calls returned True, otherwise False.

        The callback can return True, False or None. The latter is for when the
        test is skipped.  (True is for success, False is for failure.)
        """

        self._removeUnsupportedVirtModes(oTestDrv);
        cMaxCpus = oTestDrv.getHostCpuCount();

        #
        # The test loop.
        #
        fRc = True;
        for oTestVm in self.aoTestVms:
            if oTestVm.fSkip and self.fIgnoreSkippedVm:
                reporter.log2('Ignoring VM %s (fSkip = True).' % (oTestVm.sVmName,));
                continue;
            reporter.testStart(oTestVm.sVmName);
            if oTestVm.fSkip:
                reporter.testDone(fSkipped = True);
                continue;

            # Intersect the supported modes and the ones being testing.
            asVirtModesSup = [sMode for sMode in oTestVm.asVirtModesSup if sMode in self.asVirtModes];

            # Ditto for CPUs.
            acCpusSup      = [cCpus for cCpus in oTestVm.acCpusSup      if cCpus in self.acCpus];

            for cCpus in acCpusSup:
                if cCpus == 1:
                    reporter.testStart('1 cpu');
                else:
                    reporter.testStart('%u cpus' % (cCpus));
                    if cCpus > cMaxCpus:
                        reporter.testDone(fSkipped = True);
                        continue;

                cTests = 0;
                for sVirtMode in asVirtModesSup:
                    if sVirtMode == 'raw' and cCpus > 1:
                        continue;

                    for sParavirtMode in oTestVm.asParavirtModes:

                        reporter.testStart("%s/%s" % (g_dsVirtModeDescs[sVirtMode], sParavirtMode if sParavirtMode is not None else "[paravirtualisation provider not set]")); # pylint: disable=C0301

                        # Reconfigure the VM.
                        try:
                            (rc2, oVM) = oTestVm.getReconfiguredVm(oTestDrv, cCpus, sVirtMode, sParavirtMode=sParavirtMode);
                        except KeyboardInterrupt:
                            raise;
                        except:
                            reporter.errorXcpt(cFrames = 9);
                            rc2 = False;
                        if rc2 is True:
                            try:
                                rc2 = fnCallback(oVM, oTestVm);
                            except KeyboardInterrupt:
                                raise;
                            except:
                                reporter.errorXcpt(cFrames = 9);
                                rc2 = False;
                            if rc2 is False:
                                reporter.maybeErr(reporter.testErrorCount() == 0, 'fnCallback failed');
                        elif rc2 is False:
                            reporter.log('getReconfiguredVm failed');
                        if rc2 is False:
                            fRc = False;

                        cTests = cTests + (rc2 is not None);
                        reporter.testDone(fSkipped = (rc2 is None));

                reporter.testDone(fSkipped = cTests == 0);

            _, cErrors = reporter.testDone();
            if cErrors > 0:
                fRc = False;
        return fRc;
Esempio n. 8
0
    def actionExecute(self, oTestDrv, fnCallback):  # pylint: disable=R0914
        """
        For base.TestDriver.actionExecute.  Calls the callback function for
        each of the VMs and basic configuration variations (virt-mode and cpu
        count).

        Returns True if all fnCallback calls returned True, otherwise False.

        The callback can return True, False or None. The latter is for when the
        test is skipped.  (True is for success, False is for failure.)
        """

        self._removeUnsupportedVirtModes(oTestDrv)
        cMaxCpus = oTestDrv.getHostCpuCount()

        #
        # The test loop.
        #
        fRc = True
        for oTestVm in self.aoTestVms:
            if oTestVm.fSkip and self.fIgnoreSkippedVm:
                reporter.log2('Ignoring VM %s (fSkip = True).' %
                              (oTestVm.sVmName, ))
                continue
            reporter.testStart(oTestVm.sVmName)
            if oTestVm.fSkip:
                reporter.testDone(fSkipped=True)
                continue

            # Intersect the supported modes and the ones being testing.
            asVirtModesSup = [
                sMode for sMode in oTestVm.asVirtModesSup
                if sMode in self.asVirtModes
            ]

            # Ditto for CPUs.
            acCpusSup = [
                cCpus for cCpus in oTestVm.acCpusSup if cCpus in self.acCpus
            ]

            # Ditto for paravirtualization modes, except if not specified we got a less obvious default.
            if self.asParavirtModes is not None and oTestDrv.fpApiVer >= 5.0:
                asParavirtModes = [
                    sPvMode for sPvMode in oTestVm.asParavirtModesSup
                    if sPvMode in self.asParavirtModes
                ]
                assert None not in asParavirtModes
            elif oTestDrv.fpApiVer >= 5.0:
                asParavirtModes = (oTestVm.asParavirtModesSup[0], )
                assert asParavirtModes[0] is not None
            else:
                asParavirtModes = (None, )

            for cCpus in acCpusSup:
                if cCpus == 1:
                    reporter.testStart('1 cpu')
                else:
                    reporter.testStart('%u cpus' % (cCpus))
                    if cCpus > cMaxCpus:
                        reporter.testDone(fSkipped=True)
                        continue

                cTests = 0
                for sVirtMode in asVirtModesSup:
                    if sVirtMode == 'raw' and cCpus > 1:
                        continue
                    reporter.testStart('%s' % (g_dsVirtModeDescs[sVirtMode], ))
                    cStartTests = cTests

                    for sParavirtMode in asParavirtModes:
                        if sParavirtMode is not None:
                            assert oTestDrv.fpApiVer >= 5.0
                            reporter.testStart('%s' % (sParavirtMode, ))

                        # Reconfigure the VM.
                        try:
                            (rc2, oVM) = oTestVm.getReconfiguredVm(
                                oTestDrv,
                                cCpus,
                                sVirtMode,
                                sParavirtMode=sParavirtMode)
                        except KeyboardInterrupt:
                            raise
                        except:
                            reporter.errorXcpt(cFrames=9)
                            rc2 = False
                        if rc2 is True:
                            # Do the testing.
                            try:
                                rc2 = fnCallback(oVM, oTestVm)
                            except KeyboardInterrupt:
                                raise
                            except:
                                reporter.errorXcpt(cFrames=9)
                                rc2 = False
                            if rc2 is False:
                                reporter.maybeErr(
                                    reporter.testErrorCount() == 0,
                                    'fnCallback failed')
                        elif rc2 is False:
                            reporter.log('getReconfiguredVm failed')
                        if rc2 is False:
                            fRc = False

                        cTests = cTests + (rc2 is not None)
                        if sParavirtMode is not None:
                            reporter.testDone(fSkipped=(rc2 is None))

                    reporter.testDone(fSkipped=cTests == cStartTests)

                reporter.testDone(fSkipped=cTests == 0)

            _, cErrors = reporter.testDone()
            if cErrors > 0:
                fRc = False
        return fRc
    def actionExecute(self, oTestDrv, fnCallback): # pylint: disable=R0914
        """
        For base.TestDriver.actionExecute.  Calls the callback function for
        each of the VMs and basic configuration variations (virt-mode and cpu
        count).

        Returns True if all fnCallback calls returned True, otherwise False.

        The callback can return True, False or None. The latter is for when the
        test is skipped.  (True is for success, False is for failure.)
        """

        self._removeUnsupportedVirtModes(oTestDrv);
        cMaxCpus = oTestDrv.getHostCpuCount();

        #
        # The test loop.
        #
        fRc = True;
        for oTestVm in self.aoTestVms:
            if oTestVm.fSkip and self.fIgnoreSkippedVm:
                reporter.log2('Ignoring VM %s (fSkip = True).' % (oTestVm.sVmName,));
                continue;
            reporter.testStart(oTestVm.sVmName);
            if oTestVm.fSkip:
                reporter.testDone(fSkipped = True);
                continue;

            # Intersect the supported modes and the ones being testing.
            asVirtModesSup = [sMode for sMode in oTestVm.asVirtModesSup if sMode in self.asVirtModes];

            # Ditto for CPUs.
            acCpusSup      = [cCpus for cCpus in oTestVm.acCpusSup      if cCpus in self.acCpus];

            # Ditto for paravirtualization modes, except if not specified we got a less obvious default.
            if self.asParavirtModes is not None  and  oTestDrv.fpApiVer >= 5.0:
                asParavirtModes = [sPvMode for sPvMode in oTestVm.asParavirtModesSup if sPvMode in self.asParavirtModes];
                assert None not in asParavirtModes;
            elif oTestDrv.fpApiVer >= 5.0:
                asParavirtModes = (oTestVm.asParavirtModesSup[0],);
                assert asParavirtModes[0] is not None;
            else:
                asParavirtModes = (None,);

            for cCpus in acCpusSup:
                if cCpus == 1:
                    reporter.testStart('1 cpu');
                else:
                    reporter.testStart('%u cpus' % (cCpus));
                    if cCpus > cMaxCpus:
                        reporter.testDone(fSkipped = True);
                        continue;

                cTests = 0;
                for sVirtMode in asVirtModesSup:
                    if sVirtMode == 'raw' and cCpus > 1:
                        continue;
                    reporter.testStart('%s' % ( g_dsVirtModeDescs[sVirtMode], ) );
                    cStartTests = cTests;

                    for sParavirtMode in asParavirtModes:
                        if sParavirtMode is not None:
                            assert oTestDrv.fpApiVer >= 5.0;
                            reporter.testStart('%s' % ( sParavirtMode, ) );

                        # Reconfigure the VM.
                        try:
                            (rc2, oVM) = oTestVm.getReconfiguredVm(oTestDrv, cCpus, sVirtMode, sParavirtMode = sParavirtMode);
                        except KeyboardInterrupt:
                            raise;
                        except:
                            reporter.errorXcpt(cFrames = 9);
                            rc2 = False;
                        if rc2 is True:
                            # Do the testing.
                            try:
                                rc2 = fnCallback(oVM, oTestVm);
                            except KeyboardInterrupt:
                                raise;
                            except:
                                reporter.errorXcpt(cFrames = 9);
                                rc2 = False;
                            if rc2 is False:
                                reporter.maybeErr(reporter.testErrorCount() == 0, 'fnCallback failed');
                        elif rc2 is False:
                            reporter.log('getReconfiguredVm failed');
                        if rc2 is False:
                            fRc = False;

                        cTests = cTests + (rc2 is not None);
                        if sParavirtMode is not None:
                            reporter.testDone(fSkipped = (rc2 is None));

                    reporter.testDone(fSkipped = cTests == cStartTests);

                reporter.testDone(fSkipped = cTests == 0);

            _, cErrors = reporter.testDone();
            if cErrors > 0:
                fRc = False;
        return fRc;
Esempio n. 10
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 testUsbOneCfg(self, sVmName, sUsbCtrl, sSpeed, sUsbTest):
        """
        Runs the specified VM thru one specified test.

        Returns a success indicator on the general test execution. This is not
        the actual test result.
        """
        oVM = self.getVmByName(sVmName);

        # Reconfigure the VM
        fRc = True;
        oSession = self.openSession(oVM);
        if oSession is not None:
            fRc = fRc and oSession.enableVirtEx(True);
            fRc = fRc and oSession.enableNestedPaging(True);

            # Make sure controllers are disabled initially.
            fRc = fRc and oSession.enableUsbOhci(False);
            fRc = fRc and oSession.enableUsbEhci(False);
            fRc = fRc and oSession.enableUsbXhci(False);

            if sUsbCtrl == 'OHCI':
                fRc = fRc and oSession.enableUsbOhci(True);
            elif sUsbCtrl == 'EHCI':
                fRc = fRc and oSession.enableUsbEhci(True);
            elif sUsbCtrl == 'XHCI':
                fRc = fRc and oSession.enableUsbXhci(True);
            fRc = fRc and oSession.saveSettings();
            fRc = oSession.close() and fRc and True; # pychecker hack.
            oSession = None;
        else:
            fRc = False;

        # Start up.
        if fRc is True:
            self.logVmInfo(oVM);
            oSession, oTxsSession = self.startVmAndConnectToTxsViaTcp(sVmName, fCdWait = False, fNatForwardingForTxs = False);
            if oSession is not None:
                self.addTask(oTxsSession);

                # Fudge factor - Allow the guest to finish starting up.
                self.sleep(5);

                sCaptureFile = None;
                if self.fUsbCapture:
                    sCaptureFile = self.getCaptureFilePath(sUsbCtrl, sSpeed);

                if sUsbTest == 'Compliance':
                    fRc = self.testUsbCompliance(oSession, oTxsSession, sUsbCtrl, sSpeed, sCaptureFile);
                elif sUsbTest == 'Reattach':
                    fRc = self.testUsbReattach(oSession, oTxsSession, sUsbCtrl, sSpeed, sCaptureFile);

                # cleanup.
                self.removeTask(oTxsSession);
                self.terminateVmBySession(oSession)

                # Add the traffic dump if it exists and the test failed
                if reporter.testErrorCount() > 0 \
                   and sCaptureFile is not None \
                   and os.path.exists(sCaptureFile):
                    reporter.addLogFile(sCaptureFile, 'misc/other', 'USB traffic dump');
            else:
                fRc = False;
        return fRc;