def test1Sub3(self, oVM): """ Test that starting a teleportation target VM will fail if we give it a bad address to bind to. """ reporter.testStart('bad IMachine::teleporterAddress'); # re-configure it with a bad bind-to address. fRc = False; oSession = self.openSession(oVM); if oSession is not None: fRc = oSession.setupTeleporter(True, uPort=6502, sAddress='no.such.hostname.should.ever.exist.duh'); if not oSession.saveSettings(fClose=True): fRc = False; oSession = None; if fRc: # Try start it. oSession, oProgress = self.startVmEx(oVM, fWait = False); if oSession is not None: oProgress.wait(); ## TODO: exact error code and look for the IPRT right string. if not oProgress.isCompleted() or oProgress.getResult() >= 0: reporter.testFailure('%s' % (oProgress.stringifyResult(),)); self.terminateVmBySession(oSession, oProgress); # put back the old teleporter setup. self.test1ResetVmConfig(oVM, fTeleporterEnabled = True); else: reporter.testFailure('reconfig #1 failed'); return reporter.testDone()[1] == 0;
def testBenchmark(self, sTargetOs, sBenchmark, sMountpoint, oExecutor): """ Runs the given benchmark on the test host. """ # Create a basic config dCfg = { 'RecordSize': '64k', 'TestsetSize': '100m', 'QueueDepth': '32', 'FilePath': sMountpoint, 'TargetOs': sTargetOs }; oTst = None; if sBenchmark == 'iozone': oTst = IozoneTest(oExecutor, dCfg); elif sBenchmark == 'fio': oTst = FioTest(oExecutor, dCfg); # pylint: disable=R0204 if oTst is not None: reporter.testStart(sBenchmark); fRc = oTst.prepare(); if fRc: fRc = oTst.run(); if fRc: fRc = oTst.reportResult(); else: reporter.testFailure('Running the testcase failed'); else: reporter.testFailure('Preparing the testcase failed'); oTst.cleanup(); reporter.testDone(); return fRc;
def test1(self): """ Executes test #1 - Negative API testing. ASSUMES that the VMs are """ reporter.testStart('Test 1'); # Get the VMs. #oVmHwVirt1 = self.getVmByName('tst-empty-hwvirt-1'); #oVmHwVirt2 = self.getVmByName('tst-empty-hwvirt-2'); oVmRaw1 = self.getVmByName('tst-empty-raw-1'); oVmRaw2 = self.getVmByName('tst-empty-raw-2'); # Reset their teleportation related configuration. fRc = True; #for oVM in (oVmHwVirt1, oVmHwVirt2, oVmRaw1, oVmRaw2): for oVM in (oVmRaw1, oVmRaw2): if not self.test1ResetVmConfig(oVM): fRc = False; # Do the testing (don't both with fRc on the subtests). if fRc: self.test1Sub1(oVmRaw1); self.test1Sub2(oVmRaw2); self.test1Sub3(oVmRaw2); self.test1Sub4(oVmRaw2); self.processPendingEvents(); self.test1Sub5(oVmRaw1, oVmRaw2); self.test1Sub6(oVmRaw1, oVmRaw2); self.test1Sub7(oVmRaw1, oVmRaw2); else: reporter.testFailure('Failed to reset the VM configs') return reporter.testDone()[1] == 0;
def test1Sub5(self, oVmSrc, oVmDst): """ Test that basic teleporting works. xTracker: #4749 """ reporter.testStart('Simple teleportation'); for cSecsX2 in range(0, 10): if self.test1ResetVmConfig(oVmSrc, fTeleporterEnabled = False) \ and self.test1ResetVmConfig(oVmDst, fTeleporterEnabled = True): # Start the target VM. oSessionDst, oProgressDst = self.startVmEx(oVmDst, fWait = False); if oSessionDst is not None: if oProgressDst.waitForOperation(iOperation = -3) == 0: # Start the source VM. oSessionSrc = self.startVm(oVmSrc); if oSessionSrc is not None: self.sleep(cSecsX2 / 2); # Try teleport. oProgressSrc = oSessionSrc.teleport('localhost', 6502, 'password'); if oProgressSrc: oProgressSrc.wait(); oProgressDst.wait(); self.terminateVmBySession(oSessionSrc, oProgressSrc); self.terminateVmBySession(oSessionDst, oProgressDst); else: reporter.testFailure('reconfig failed'); return reporter.testDone()[1] == 0;
def test1Sub2SetPort(self, oSession, uPort, fInvalid = False): """ This can fail, thus fInvalid.""" if not fInvalid: uOld = uPort; else: try: uOld = oSession.o.machine.teleporterPort; except: return reporter.testFailureXcpt(); try: oSession.o.machine.teleporterPort = uPort; except Exception as oXcpt: if not fInvalid or vbox.ComError.notEqual(oXcpt, vbox.ComError.E_INVALIDARG): return reporter.testFailureXcpt('machine.teleporterPort=%u' % (uPort,)); else: if fInvalid: return reporter.testFailureXcpt('machine.teleporterPort=%u succeeded unexpectedly' % (uPort,)); try: uNew = oSession.o.machine.teleporterPort; except: return reporter.testFailureXcpt(); if uNew != uOld: if not fInvalid: reporter.testFailure('machine.teleporterPort=%u but afterwards it is actually %u' % (uPort, uNew)); else: reporter.testFailure('machine.teleporterPort is %u after failure, expected %u' % (uNew, uOld)); return False; return True;
def testBenchmark(self, sTargetOs, sBenchmark, sMountpoint, oExecutor, dTestSet, \ cMsTimeout = 3600000): """ Runs the given benchmark on the test host. """ dTestSet['FilePath'] = sMountpoint; dTestSet['TargetOs'] = sTargetOs; oTst = None; if sBenchmark == 'iozone': oTst = IozoneTest(oExecutor, dTestSet); elif sBenchmark == 'fio': oTst = FioTest(oExecutor, dTestSet); # pylint: disable=R0204 if oTst is not None: fRc = oTst.prepare(); if fRc: fRc = oTst.run(cMsTimeout); if fRc: if self.fReportBenchmarkResults: fRc = oTst.reportResult(); else: reporter.testFailure('Running the testcase failed'); else: reporter.testFailure('Preparing the testcase failed'); oTst.cleanup(); return fRc;
def test1OneCfg(self, oVM, cCpus, fHwVirt, fNestedPaging): """ Runs the specified VM thru test #1. Returns a success indicator on the general test execution. This is not the actual test result. """ # Reconfigure the VM fRc = True oSession = self.openSession(oVM) 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.setupBootLogo(True, 2500) # Race avoidance fudge. fRc = fRc and oSession.saveSettings() fRc = oSession.close() and fRc and True # pychecker hack. oSession = None else: fRc = False # Zap the state (used by the callback). self.fCallbackFired = False self.fCallbackSuccess = False # Start up. if fRc is True: self.logVmInfo(oVM) oSession = self.startVm(oVM) if oSession is not None: # Set up a callback for catching the runtime error. !Races the guest bootup! oConsoleCallbacks = oSession.registerDerivedEventHandler(tdCpuPae1ConsoleCallbacks, {"oTstDrv": self}) fRc = False if oConsoleCallbacks is not None: self.addTask(oSession) # Wait for 30 seconds for something to finish. tsStart = base.timestampMilli() while base.timestampMilli() - tsStart < 30000: oTask = self.waitForTasks(1000) if oTask is not None: break if self.fCallbackFired: break if not self.fCallbackFired: reporter.testFailure("the callback did not fire") fRc = self.fCallbackSuccess # cleanup. oConsoleCallbacks.unregister() self.terminateVmBySession(oSession) # , fRc); else: fRc = False return fRc
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;
def actionExecute(self): # Testing PushHint/PopHint. reporter.testStart('Negative XML #1') oSubXmlFile = reporter.FileWrapperTestPipe() oSubXmlFile.write('<Test timestamp="%s" name="foobar3">\n\n\t\n\r\n' % (utils.getIsoTimestamp(), )) oSubXmlFile.write('<Test timestamp="%s" name="sub3">' % (utils.getIsoTimestamp(), )) oSubXmlFile.write('<Test timestamp="%s" name="subsub1">' % (utils.getIsoTimestamp(), )) oSubXmlFile.close() reporter.testDone() # Missing end, like we had with IRPT at one time. reporter.testStart('Negative XML #2 (IPRT)') oSubXmlFile = reporter.FileWrapperTestPipe() oSubXmlFile.write(""" <?xml version="1.0" encoding="UTF-8" ?> <Test timestamp="2013-05-29T08:59:05.930602000Z" name="tstRTGetOpt"> <Test timestamp="2013-05-29T08:59:05.930656000Z" name="Basics"> <Passed timestamp="2013-05-29T08:59:05.930756000Z"/> </Test> <Test timestamp="2013-05-29T08:59:05.930995000Z" name="RTGetOpt - IPv4"> <Passed timestamp="2013-05-29T08:59:05.931036000Z"/> </Test> <Test timestamp="2013-05-29T08:59:05.931161000Z" name="RTGetOpt - MAC Address"> <Passed timestamp="2013-05-29T08:59:05.931194000Z"/> </Test> <Test timestamp="2013-05-29T08:59:05.931313000Z" name="RTGetOpt - Option w/ Index"> <Passed timestamp="2013-05-29T08:59:05.931357000Z"/> </Test> <Test timestamp="2013-05-29T08:59:05.931475000Z" name="RTGetOptFetchValue"> <Passed timestamp="2013-05-29T08:59:05.931516000Z"/> </Test> <Test timestamp="2013-05-29T08:59:05.931640000Z" name="RTGetOpt - bool on/off"> <Passed timestamp="2013-05-29T08:59:05.931687000Z"/> </Test> <Test timestamp="2013-05-29T08:59:05.931807000Z" name="Standard options"> <Passed timestamp="2013-05-29T08:59:05.931843000Z"/> </Test> <Test timestamp="2013-05-29T08:59:05.931963000Z" name="Options first"> <Passed timestamp="2013-05-29T08:59:05.932035000Z"/> </Test> """) oSubXmlFile.close() oSubXmlFile = None reporter.testDone() # The use of testFailure. reporter.testStart('Using testFailure()') reporter.testValue('value-name3', 12345678, 'times') reporter.testFailure('failure detail message') reporter.testDone() return True
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.'); # # 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(); return fRc;
def test1OneCfg(self, oVM, cCpus, fHwVirt, fNestedPaging): """ Runs the specified VM thru test #1. Returns a success indicator on the general test execution. This is not the actual test result. """ # Reconfigure the VM fRc = True; oSession = self.openSession(oVM); 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.setupBootLogo(True, 2500); # Race avoidance fudge. fRc = fRc and oSession.saveSettings(); fRc = oSession.close() and fRc and True; # pychecker hack. oSession = None; else: fRc = False; # Zap the state (used by the callback). self.fCallbackFired = False; self.fCallbackSuccess = False; # Start up. if fRc is True: self.logVmInfo(oVM); oSession = self.startVm(oVM) if oSession is not None: # Set up a callback for catching the runtime error. !Races the guest bootup! oConsoleCallbacks = oSession.registerDerivedEventHandler(tdCpuPae1ConsoleCallbacks, {'oTstDrv':self,}) fRc = False; if oConsoleCallbacks is not None: # Wait for 30 seconds for something to finish. tsStart = base.timestampMilli(); while base.timestampMilli() - tsStart < 30000: oTask = self.waitForTasks(1000); if oTask is not None: break; if self.fCallbackFired: break; if not self.fCallbackFired: reporter.testFailure('the callback did not fire'); fRc = self.fCallbackSuccess; # cleanup. oConsoleCallbacks.unregister(); self.terminateVmBySession(oSession) #, fRc); else: fRc = False; return fRc;
def onRuntimeError(self, fFatal, sErrId, sMessage): """ Verify the error. """ reporter.log('onRuntimeError: fFatal=%s sErrId="%s" sMessage="%s"' % (fFatal, sErrId, sMessage)) if sErrId != "PAEmode": reporter.testFailure("sErrId=%s, expected PAEmode" % (sErrId,)) elif fFatal is not True: reporter.testFailure("fFatal=%s, expected True" % (fFatal,)) else: self.oTstDrv.fCallbackSuccess = True self.oTstDrv.fCallbackFired = True self.oVBoxMgr.interruptWaitEvents() return None
def actionExecute(self): # Testing PushHint/PopHint. reporter.testStart('Negative XML #1'); oSubXmlFile = reporter.FileWrapperTestPipe(); oSubXmlFile.write('<Test timestamp="%s" name="foobar3">\n\n\t\n\r\n' % (utils.getIsoTimestamp(),)); oSubXmlFile.write('<Test timestamp="%s" name="sub3">' % (utils.getIsoTimestamp(),)); oSubXmlFile.write('<Test timestamp="%s" name="subsub1">' % (utils.getIsoTimestamp(),)); oSubXmlFile.close(); reporter.testDone(); # Missing end, like we had with IRPT at one time. reporter.testStart('Negative XML #2 (IPRT)'); oSubXmlFile = reporter.FileWrapperTestPipe(); oSubXmlFile.write(""" <?xml version="1.0" encoding="UTF-8" ?> <Test timestamp="2013-05-29T08:59:05.930602000Z" name="tstRTGetOpt"> <Test timestamp="2013-05-29T08:59:05.930656000Z" name="Basics"> <Passed timestamp="2013-05-29T08:59:05.930756000Z"/> </Test> <Test timestamp="2013-05-29T08:59:05.930995000Z" name="RTGetOpt - IPv4"> <Passed timestamp="2013-05-29T08:59:05.931036000Z"/> </Test> <Test timestamp="2013-05-29T08:59:05.931161000Z" name="RTGetOpt - MAC Address"> <Passed timestamp="2013-05-29T08:59:05.931194000Z"/> </Test> <Test timestamp="2013-05-29T08:59:05.931313000Z" name="RTGetOpt - Option w/ Index"> <Passed timestamp="2013-05-29T08:59:05.931357000Z"/> </Test> <Test timestamp="2013-05-29T08:59:05.931475000Z" name="RTGetOptFetchValue"> <Passed timestamp="2013-05-29T08:59:05.931516000Z"/> </Test> <Test timestamp="2013-05-29T08:59:05.931640000Z" name="RTGetOpt - bool on/off"> <Passed timestamp="2013-05-29T08:59:05.931687000Z"/> </Test> <Test timestamp="2013-05-29T08:59:05.931807000Z" name="Standard options"> <Passed timestamp="2013-05-29T08:59:05.931843000Z"/> </Test> <Test timestamp="2013-05-29T08:59:05.931963000Z" name="Options first"> <Passed timestamp="2013-05-29T08:59:05.932035000Z"/> </Test> """); oSubXmlFile.close(); oSubXmlFile = None; reporter.testDone(); # The use of testFailure. reporter.testStart('Using testFailure()'); reporter.testValue('value-name3', 12345678, 'times'); reporter.testFailure('failure detail message'); reporter.testDone(); return True;
def onRuntimeError(self, fFatal, sErrId, sMessage): """ Verify the error. """ reporter.log('onRuntimeError: fFatal=%s sErrId="%s" sMessage="%s"' % (fFatal, sErrId, sMessage)); if sErrId != 'PAEmode': reporter.testFailure('sErrId=%s, expected PAEmode' % (sErrId,)); elif fFatal is not True: reporter.testFailure('fFatal=%s, expected True' % (fFatal,)); else: self.oTstDrv.fCallbackSuccess = True; self.oTstDrv.fCallbackFired = True; self.oVBoxMgr.interruptWaitEvents(); return None;
def test1Sub1DoTeleport(self, oSession, sHostname, uPort, sPassword, cMsMaxDowntime, hrcExpected, sTestName): """ Do a bad IConsole::teleport call and check the result.""" reporter.testStart(sTestName); fRc = False; try: oProgress = oSession.o.console.teleport(sHostname, uPort, sPassword, cMsMaxDowntime); except vbox.ComException, oXcpt: if vbox.ComError.equal(oXcpt, hrcExpected): fRc = True; else: reporter.testFailure('hresult %s, expected %s' \ % (vbox.ComError.toString(oXcpt.hresult), vbox.ComError.toString(hrcExpected)));
def __testScenario_6(self, oMachine, sNewLoc, sOldLoc): """ There is a floppy image (.img) attached to the VM. Prerequisites - there is Floppy Controller and there are no any images attached to it. """ fRc = True # Always clear before each scenario. dsReferenceFiles = defaultdict(set) # Create a new Session object. oSession = self.oTstDrv.openSession(oMachine) sFloppyLoc = self.asRsrcs[1] # '5.3/floppy/tdMoveVM1.img' sFloppyLoc = self.oTstDrv.getFullResourceName(sFloppyLoc) if not os.path.exists(sFloppyLoc): reporter.log('Floppy disk does not exist at "%s"' % (sFloppyLoc,)) fRc = False # Copy floppy image from the common resource folder into machine folder. shutil.copy(sFloppyLoc, sOldLoc) # Attach floppy image. if fRc is True: # Set actual floppy location. sFloppyImageName = 'tdMoveVM1.img' sFloppyLoc = sOldLoc + os.sep + sFloppyImageName sController=self.dsKeys['FloppyImage'] fRc = fRc and oSession.attachFloppy(sFloppyLoc, sController, 0, 0) dsReferenceFiles['FloppyImage'].add(os.path.normcase(os.path.join(os.path.join(sNewLoc, oMachine.name), sFloppyImageName))) if fRc is True: fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) if fRc is True: fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles) if fRc is False: reporter.testFailure('!!!!!!!!!!!!!!!!!! 6th scenario: Check locations failed... !!!!!!!!!!!!!!!!!!') else: reporter.testFailure('!!!!!!!!!!!!!!!!!! 6th scenario: Move VM failed... !!!!!!!!!!!!!!!!!!') else: reporter.testFailure('!!!!!!!!!!!!!!!!!! 6th scenario: Attach floppy image failed... !!!!!!!!!!!!!!!!!!') # Detach floppy image. fRes = oSession.detachHd(sController, 0, 0) if fRes is False: reporter.log('6th scenario: Couldn\'t detach image from the controller %s port %s device %s' % (sController, 0, 0)) fRes = oSession.saveSettings() if fRes is False: reporter.testFailure('6th scenario: Couldn\'t save machine settings') fRes = oSession.close() if fRes is False: reporter.log('6th scenario: Couldn\'t close machine session') return fRc
def test1Sub2SetEnabled(self, oSession, fEnabled): """ This should never fail.""" try: oSession.o.machine.teleporterEnabled = fEnabled; except: reporter.testFailureXcpt('machine.teleporterEnabled=%s' % (fEnabled,)); return False; try: fNew = oSession.o.machine.teleporterEnabled; except: reporter.testFailureXcpt(); return False; if fNew != fEnabled: reporter.testFailure('machine.teleporterEnabled=%s but afterwards it is actually %s' % (fEnabled, fNew)); return False; return True;
def test1Sub2SetPassword(self, oSession, sPassword): """ This should never fail.""" try: oSession.o.machine.teleporterPassword = sPassword; except: reporter.testFailureXcpt('machine.teleporterPassword=%s' % (sPassword,)); return False; try: sNew = oSession.o.machine.teleporterPassword; except: reporter.testFailureXcpt(); return False; if sNew != sPassword: reporter.testFailure('machine.teleporterPassword="******" but afterwards it is actually "%s"' % (sPassword, sNew)); return False; return True;
def test1Sub2SetAddress(self, oSession, sAddress): """ This should never fail.""" try: oSession.o.machine.teleporterAddress = sAddress; except: reporter.testFailureXcpt('machine.teleporterAddress=%s' % (sAddress,)); return False; try: sNew = oSession.o.machine.teleporterAddress; except: reporter.testFailureXcpt(); return False; if sNew != sAddress: reporter.testFailure('machine.teleporterAddress="%s" but afterwards it is actually "%s"' % (sAddress, sNew)); return False; return True;
def testUsbCompliance(self, oSession, oTxsSession, sUsbCtrl, sSpeed, sCaptureFile=None): """ Test VirtualBoxs USB stack in a VM. """ # Get configured USB test devices from hostname we are running on sGadgetHost, uGadgetPort = self.getGadgetParams( self.sHostname, sSpeed) oUsbGadget = usbgadget.UsbGadget() reporter.log('Connecting to UTS: ' + sGadgetHost) fRc = oUsbGadget.connectTo(30 * 1000, sGadgetHost, uPort=uGadgetPort) if fRc is True: reporter.log('Connect succeeded') self.oVBox.host.addUSBDeviceSource( 'USBIP', sGadgetHost, sGadgetHost + (':%s' % oUsbGadget.getUsbIpPort()), [], []) fSuperSpeed = False if sSpeed == 'Super': fSuperSpeed = True # Create test device gadget and a filter to attach the device automatically. fRc = oUsbGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest, fSuperSpeed) if fRc is True: iBusId, _ = oUsbGadget.getGadgetBusAndDevId() fRc = self.attachUsbDeviceToVm(oSession, '0525', 'a4a0', iBusId, sCaptureFile) if fRc is True: tupCmdLine = ('UsbTest', ) # Exclude a few tests which hang and cause a timeout, need investigation. lstTestsExclude = self.kdUsbTestsDisabled.get(sSpeed) for iTestExclude in lstTestsExclude: tupCmdLine = tupCmdLine + ('--exclude', str(iTestExclude)) fRc = self.txsRunTest(oTxsSession, 'UsbTest', 3600 * 1000, \ '${CDROM}/${OS/ARCH}/UsbTest${EXESUFF}', tupCmdLine) if not fRc: reporter.testFailure('Running USB test utility failed') else: reporter.testFailure('Failed to attach USB device to VM') oUsbGadget.disconnectFrom() else: reporter.testFailure('Failed to impersonate test device') self.oVBox.host.removeUSBDeviceSource(sGadgetHost) else: reporter.testFailure('Failed to connect to USB gadget') _ = sUsbCtrl return fRc
def __testScenario_6(self, oMachine, sNewLoc, sOldLoc): """ There is a floppy image (.img) attached to the VM. Prerequisites - there is Floppy Controller and there are no any images attached to it. """ fRc = True # Always clear before each scenario. dsReferenceFiles = defaultdict(set) # Create a new Session object. oSession = self.oTstDrv.openSession(oMachine) sFloppyLoc = self.asRsrcs[1] # '5.3/floppy/tdMoveVM1.img' sFloppyLoc = self.oTstDrv.getFullResourceName(sFloppyLoc) if not os.path.exists(sFloppyLoc): reporter.log('Floppy disk does not exist at "%s"' % (sFloppyLoc,)) fRc = False # Copy floppy image from the common resource folder into machine folder. shutil.copy(sFloppyLoc, sOldLoc) # Attach floppy image. if fRc is True: # Set actual floppy location. sFloppyImageName = 'tdMoveVM1.img' sFloppyLoc = sOldLoc + os.sep + sFloppyImageName sController=self.dsKeys['FloppyImage'] fRc = fRc and oSession.attachFloppy(sFloppyLoc, sController, 0, 0) dsReferenceFiles['FloppyImage'].add(os.path.join(os.path.join(sNewLoc, oMachine.name), sFloppyImageName)) if fRc is True: fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) if fRc is True: fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles) if fRc is False: reporter.testFailure('!!!!!!!!!!!!!!!!!! 6th scenario: Check locations failed... !!!!!!!!!!!!!!!!!!') else: reporter.testFailure('!!!!!!!!!!!!!!!!!! 6th scenario: Move VM failed... !!!!!!!!!!!!!!!!!!') else: reporter.testFailure('!!!!!!!!!!!!!!!!!! 6th scenario: Attach floppy image failed... !!!!!!!!!!!!!!!!!!') # Detach floppy image. fRes = oSession.detachHd(sController, 0, 0) if fRes is False: reporter.log('6th scenario: Couldn\'t detach image from the controller %s port %s device %s' % (sController, 0, 0)) fRes = oSession.saveSettings() if fRes is False: reporter.testFailure('6th scenario: Couldn\'t save machine settings') fRes = oSession.close() if fRes is False: reporter.log('6th scenario: Couldn\'t close machine session') return fRc
def testUsbReattach(self, oSession, oTxsSession, sUsbCtrl, sSpeed): # pylint: disable=W0613 """ Tests that rapid connect/disconnect cycles work. """ # Get configured USB test devices from hostname we are running on sGadgetHost, uGadgetPort = self.getGadgetParams( self.sHostname, sSpeed) oUsbGadget = usbgadget.UsbGadget() reporter.log('Connecting to UTS: ' + sGadgetHost) fRc = oUsbGadget.connectTo(30 * 1000, sGadgetHost, uPort=uGadgetPort) if fRc is True: self.oVBox.host.addUSBDeviceSource( 'USBIP', sGadgetHost, sGadgetHost + (':%s' % oUsbGadget.getUsbIpPort()), [], []) fSuperSpeed = False if sSpeed == 'Super': fSuperSpeed = True # Create test device gadget and a filter to attach the device automatically. fRc = oUsbGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest, fSuperSpeed) if fRc is True: iBusId, _ = oUsbGadget.getGadgetBusAndDevId() fRc = oSession.addUsbDeviceFilter('Compliance device', sVendorId = '0525', sProductId = 'a4a0', \ sPort = str(iBusId)) if fRc is True: # Wait a moment to let the USB device appear self.sleep(3) # Do a rapid disconnect reconnect cycle. Wait a second before disconnecting # again or it will happen so fast that the VM can't attach the new device. # @todo: Get rid of the constant wait and use an event to get notified when # the device was attached. for iCycle in xrange(0, self.cUsbReattachCycles): fRc = oUsbGadget.disconnectUsb() fRc = fRc and oUsbGadget.connectUsb() if not fRc: reporter.testFailure( 'Reattach cycle %s failed on the gadget device' % (iCycle)) break self.sleep(1) else: reporter.testFailure('Failed to impersonate test device') oUsbGadget.disconnectFrom() else: reporter.testFailure('Failed to connect to USB gadget') else: reporter.testFailure('Failed to create USB device filter') return fRc
def test1Sub4(self, oVM): """ Test that we can start and cancel a teleportation target. (No source VM trying to connect here.) xTracker: #4965 """ reporter.testStart('openRemoteSession cancel') for cSecsX2 in range(0, 10): if self.test1ResetVmConfig(oVM, fTeleporterEnabled=True): oSession, oProgress = self.startVmEx(oVM, fWait=False) if oSession is not None: self.sleep(cSecsX2 / 2) oProgress.cancel() oProgress.wait() self.terminateVmBySession(oSession, oProgress) else: reporter.testFailure('reconfig failed') return reporter.testDone()[1] == 0
def test1Sub4(self, oVM): """ Test that we can start and cancel a teleportation target. (No source VM trying to connect here.) xTracker: #4965 """ reporter.testStart('openRemoteSession cancel'); for cSecsX2 in range(0, 10): if self.test1ResetVmConfig(oVM, fTeleporterEnabled = True): oSession, oProgress = self.startVmEx(oVM, fWait = False); if oSession is not None: self.sleep(cSecsX2 / 2); oProgress.cancel(); oProgress.wait(); self.terminateVmBySession(oSession, oProgress); else: reporter.testFailure('reconfig failed'); return reporter.testDone()[1] == 0;
def __testScenario_2(self, oSession, oMachine, sNewLoc, sOldLoc): """ All disks attached to VM are located inside the VM's folder. There are no any snapshots and logs. """ sController = self.dsKeys['StandardImage'] aoMediumAttachments = oMachine.getMediumAttachmentsOfController( sController) oSubTstDrvMoveMedium1Instance = SubTstDrvMoveMedium1(self.oTstDrv) oSubTstDrvMoveMedium1Instance.moveTo(sOldLoc, aoMediumAttachments) del oSubTstDrvMoveMedium1Instance dsReferenceFiles = defaultdict(set) for s in self.asImagesNames: reporter.log('"%s"' % (s, )) dsReferenceFiles['StandardImage'].add( os.path.normcase(sNewLoc + os.sep + oMachine.name + os.sep + s)) sSettingFile = os.path.join( sNewLoc, os.path.join(oMachine.name, oMachine.name + '.vbox')) dsReferenceFiles['SettingsFile'].add(os.path.normcase(sSettingFile)) fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) if fRc is True: fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles) if fRc is False: reporter.testFailure( '!!!!!!!!!!!!!!!!!! 2nd scenario: Check locations failed... !!!!!!!!!!!!!!!!!!' ) else: reporter.testFailure( '!!!!!!!!!!!!!!!!!! 2nd scenario: Move VM failed... !!!!!!!!!!!!!!!!!!' ) fRes = oSession.saveSettings() if fRes is False: reporter.log('2nd scenario: Couldn\'t save machine settings') return fRc
def doTest(self, oSession): oConsole = oSession.console oGuest = oConsole.guest sOSTypeId = oGuest.OSTypeId.lower() if sOSTypeId.find("win") == -1 : reporter.log("Only Windows guests are currently supported") reporter.testDone() return True oGuestSession = oGuest.createSession("Administrator", "password", "", "Audio Validation Kit") guestSessionWaitResult = oGuestSession.waitFor(self.oVBoxMgr.constants.GuestSessionWaitResult_Start, 2000) reporter.log("guestSessionWaitResult = %d" % guestSessionWaitResult) for duration in range(3, 6): reporter.testStart("Checking for duration of " + str(duration) + " seconds") sPathToPlayer = "D:\\win\\" + ("amd64" if (sOSTypeId.find('_64') >= 0) else "x86") + "\\ntPlayToneWaveX.exe" oProcess = oGuestSession.processCreate(sPathToPlayer, ["xxx0", "--total-duration-in-secs", str(duration)], [], [], 0) processWaitResult = oProcess.waitFor(self.oVBoxMgr.constants.ProcessWaitForFlag_Start, 1000) reporter.log("Started: pid %d, waitResult %d" % (oProcess.PID, processWaitResult)) processWaitResult = oProcess.waitFor(self.oVBoxMgr.constants.ProcessWaitForFlag_Terminate, 2 * duration * 1000) reporter.log("Terminated: pid %d, waitResult %d" % (oProcess.PID, processWaitResult)) time.sleep(1) # Give audio backend sometime to save a stream to .wav file absFileName = self.seekLatestAudioFileName(oGuestSession, duration) if absFileName is None: reporter.testFailure("Unable to find audio file") continue reporter.log("Checking audio file '" + absFileName + "'") diff = self.checkGuestHostTimings(absFileName + ".timing") if diff is not None: if diff > 0.0: # Guest sends data quicker than a host can play if diff > 0.01: # 1% is probably good threshold here reporter.testFailure("Guest sends audio buffers too quickly") else: diff = -diff; # Much worse case: guest sends data very slow, host feels starvation if diff > 0.005: # 0.5% is probably good threshold here reporter.testFailure("Guest sends audio buffers too slowly") reporter.testDone() else: reporter.testFailure("Unable to parse a file with timings") oGuestSession.close() del oGuest del oConsole return True
def testUsbCompliance(self, oSession, oTxsSession, sUsbCtrl, sSpeed): """ Test VirtualBoxs USB stack in a VM. """ # Get configured USB test devices from hostname we are running on sGadgetHost, uGadgetPort = self.getGadgetParams(self.sHostname, sSpeed); oUsbGadget = usbgadget.UsbGadget(); reporter.log('Connecting to UTS: ' + sGadgetHost); fRc = oUsbGadget.connectTo(30 * 1000, sGadgetHost, uPort = uGadgetPort); if fRc is True: reporter.log('Connect succeeded'); self.oVBox.host.addUSBDeviceSource('USBIP', sGadgetHost, sGadgetHost + (':%s' % oUsbGadget.getUsbIpPort()), [], []); fSuperSpeed = False; if sSpeed == 'Super': fSuperSpeed = True; # Create test device gadget and a filter to attach the device automatically. fRc = oUsbGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest, fSuperSpeed); if fRc is True: iBusId, _ = oUsbGadget.getGadgetBusAndDevId(); fRc = oSession.addUsbDeviceFilter('Compliance device', sVendorId = '0525', sProductId = 'a4a0', \ sPort = format(iBusId, 'x')); if fRc is True: # Wait a moment to let the USB device appear self.sleep(3); tupCmdLine = ('UsbTest', ); # Exclude a few tests which hang and cause a timeout, need investigation. lstTestsExclude = self.kdUsbTestsDisabled.get(sSpeed); for iTestExclude in lstTestsExclude: tupCmdLine = tupCmdLine + ('--exclude', str(iTestExclude)); fRc = self.txsRunTest(oTxsSession, 'UsbTest', 3600 * 1000, \ '${CDROM}/${OS/ARCH}/UsbTest${EXESUFF}', tupCmdLine); if not fRc: reporter.testFailure('Running USB test utility failed'); else: reporter.testFailure('Failed to impersonate test device'); oUsbGadget.disconnectFrom(); else: reporter.testFailure('Failed to create USB device filter'); self.oVBox.host.removeUSBDeviceSource(sGadgetHost); else: reporter.testFailure('Failed to connect to USB gadget'); _ = sUsbCtrl; return fRc;
def test1Sub1(self, oVM): """ Test simple IConsole::teleport() failure paths. """ reporter.testStart('IConsole::teleport'); oSession = self.startVm(oVM); if oSession: self.test1Sub1DoTeleport(oSession, 'localhost', 65536, 'password', 10000, vbox.ComError.E_INVALIDARG, 'Bad port value 65536'); self.test1Sub1DoTeleport(oSession, 'localhost', 0, 'password', 10000, vbox.ComError.E_INVALIDARG, 'Bad port value 0'); self.test1Sub1DoTeleport(oSession, 'localhost', 5000, 'password', 0, vbox.ComError.E_INVALIDARG, 'Bad max downtime'); self.test1Sub1DoTeleport(oSession, '', 5000, 'password', 10000, vbox.ComError.E_INVALIDARG, 'No hostname'); self.test1Sub1DoTeleport(oSession, 'no.such.hostname.should.ever.exist.duh', 5000, 'password', 0, vbox.ComError.E_INVALIDARG, 'Non-existing host'); self.terminateVmBySession(oSession) else: reporter.testFailure('startVm'); return reporter.testDone()[1] == 0;
def testLinuxInstallAdditions(self, oSession, oTxsSession, oTestVm): # # The actual install. # Also tell the installer to produce the appropriate log files. # # Make sure to add "--nox11" to the makeself wrapper in order to not getting any blocking # xterm window spawned. fRc = self.txsRunTest(oTxsSession, 'VBoxLinuxAdditions.run', 30 * 60 * 1000, self.getGuestSystemShell(oTestVm), (self.getGuestSystemShell(oTestVm), '${CDROM}/%s/VBoxLinuxAdditions.run' % self.sGstPathGaPrefix, '--nox11')); if not fRc: iRc = self.getAdditionsInstallerResult(oTxsSession); # Check for rc == 0 just for completeness. if iRc in (0, 2): # Can happen if the GA installer has detected older VBox kernel modules running and needs a reboot. reporter.log('Guest has old(er) VBox kernel modules still running; requires a reboot'); fRc = True; if not fRc: reporter.error('Installing Linux Additions failed (isSuccess=%s, lastReply=%s, see log file for details)' % (oTxsSession.isSuccess(), oTxsSession.getLastReply())); # # Download log files. # Ignore errors as all files above might not be present for whatever reason. # self.txsDownloadFiles(oSession, oTxsSession, [('/var/log/vboxadd-install.log', 'vboxadd-install-%s.log' % oTestVm.sVmName), ], fIgnoreErrors = True); # Do the final reboot to get the just installed Guest Additions up and running. if fRc: reporter.testStart('Rebooting guest w/ updated Guest Additions active'); (fRc, oTxsSession) = self.txsRebootAndReconnectViaTcp(oSession, oTxsSession, cMsTimeout = 15 * 60 * 1000); if fRc: pass else: reporter.testFailure('Rebooting and reconnecting to TXS service failed'); reporter.testDone(); return (fRc, oTxsSession);
def testReadWrite(self, oSession, oTxsSession, oTestVm): """ Does a simple write test verifying the output. """ _ = oSession reporter.testStart('ReadWrite') tupCmdLine = ('SerialTest', '--tests', 'readwrite', '--txbytes', '1048576', '--device') if oTestVm.isWindows(): tupCmdLine += (r'\\.\COM1', ) elif oTestVm.isLinux(): tupCmdLine += (r'/dev/ttyS0', ) fRc = self.txsRunTest(oTxsSession, 'SerialTest', 600 * 1000, \ '${CDROM}/${OS/ARCH}/SerialTest${EXESUFF}', tupCmdLine) if not fRc: reporter.testFailure('Running serial test utility failed') reporter.testDone() return fRc
def test1(self): """ Executes test #1. """ fRc = True; oDiskCfg = self.kdStorageCfgs.get(socket.gethostname().lower()); # Test the host first if requested if oDiskCfg is not None: lstBinaryPaths = ['/bin', '/sbin', '/usr/bin', '/usr/sbin', \ '/opt/csw/bin', '/usr/ccs/bin', '/usr/sfw/bin']; oExecutor = remoteexecutor.RemoteExecutor(None, lstBinaryPaths, self.sScratchPath); self.oStorCfg = storagecfg.StorageCfg(oExecutor, utils.getHostOs(), oDiskCfg); if self.fTestHost: reporter.testStart('Host'); if self.fUseScratch: sMountPoint = self.sScratchPath; else: sMountPoint = self.prepareStorage(self.oStorCfg); if sMountPoint is not None: self.testBenchmarks(utils.getHostOs(), sMountPoint, oExecutor); self.cleanupStorage(self.oStorCfg); else: reporter.testFailure('Failed to prepare host storage'); fRc = False; reporter.testDone(); else: # Loop thru the test VMs. for sVM in self.asTestVMs: # run test on the VM. if not self.testBenchmarkOneVM(sVM): fRc = False; else: fRc = True; else: fRc = False; return fRc;
def testUsbCompliance(self, oSession, oTxsSession, sSpeed): """ Test VirtualBoxs USB stack in a VM. """ # Get configured USB test devices from hostname we are running on sGadgetHost, sGadgetType = self.getGadgetParams( self.sHostname, sSpeed) # Create device filter fRc = oSession.addUsbDeviceFilter('Compliance device', '0525', 'a4a0') if fRc is True: oUsbGadget = UsbGadget() fRc = oUsbGadget.connectTo(30 * 1000, sGadgetType, sGadgetHost) if fRc is True: fRc = oUsbGadget.impersonate('Test') if fRc is True: # Wait a moment to let the USB device appear self.sleep(3) fRc = self.txsRunTest(oTxsSession, 'Compliance', 3600 * 1000, \ '${CDROM}/${OS/ARCH}/UsbTest${EXESUFF}', ('UsbTest', )) else: reporter.testFailure('Failed to impersonate test device') oUsbGadget.disconnectFrom() else: reporter.testFailure('Failed to connect to USB gadget') else: reporter.testFailure('Failed to create USB device filter') return fRc
def testUsbCompliance(self, oSession, oTxsSession, sSpeed): """ Test VirtualBoxs USB stack in a VM. """ # Get configured USB test devices from hostname we are running on sGadgetHost, sGadgetType = self.getGadgetParams(self.sHostname, sSpeed); # Create device filter fRc = oSession.addUsbDeviceFilter('Compliance device', '0525', 'a4a0'); if fRc is True: oUsbGadget = UsbGadget(); fRc = oUsbGadget.connectTo(30 * 1000, sGadgetType, sGadgetHost); if fRc is True: fRc = oUsbGadget.impersonate('Test'); if fRc is True: # Wait a moment to let the USB device appear self.sleep(3); fRc = self.txsRunTest(oTxsSession, 'Compliance', 3600 * 1000, \ '${CDROM}/${OS/ARCH}/UsbTest${EXESUFF}', ('UsbTest', )); else: reporter.testFailure('Failed to impersonate test device'); oUsbGadget.disconnectFrom(); else: reporter.testFailure('Failed to connect to USB gadget'); else: reporter.testFailure('Failed to create USB device filter'); return fRc;
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 testUsbCompliance(self, oSession, oTxsSession, sSpeed): """ Test VirtualBoxs USB stack in a VM. """ # Get configured USB test devices from hostname we are running on sGadgetHost, sGadgetType = self.getGadgetParams(self.sHostname, sSpeed) # Create device filter fRc = oSession.addUsbDeviceFilter("Compliance device", "0525", "a4a0") if fRc is True: oUsbGadget = UsbGadget() fRc = oUsbGadget.connectTo(30 * 1000, sGadgetType, sGadgetHost) if fRc is True: fRc = oUsbGadget.impersonate("Test") if fRc is True: # Wait a moment to let the USB device appear self.sleep(3) fRc = self.txsRunTest( oTxsSession, "Compliance", 3600 * 1000, "${CDROM}/${OS/ARCH}/UsbTest${EXESUFF}", ("UsbTest",) ) else: reporter.testFailure("Failed to impersonate test device") oUsbGadget.disconnectFrom() else: reporter.testFailure("Failed to connect to USB gadget") else: reporter.testFailure("Failed to create USB device filter") return fRc
def testUsbCompliance(self, oSession, oTxsSession, sVmName): """ Test VirtualBoxs autostart feature in a VM. """ reporter.testStart('USB ' + sVmName) # Create device filter fRc = oSession.addUsbDeviceFilter('Compliance device', '0525', 'a4a0') if fRc is True: oUsbGadget = UsbGadget() fRc = oUsbGadget.connectTo(30 * 1000, '192.168.2.213') if fRc is True: fRc = oUsbGadget.impersonate('Test') if fRc is True: # Wait a moment to let the USB device appear self.sleep(2) reporter.testStart('USB Test') fRc = self.txsRunTest(oTxsSession, 'USB compliance test', 240 * 1000, \ '${CDROM}/${OS/ARCH}/UsbTest${EXESUFF}', ('UsbTest', )) reporter.testDone() else: reporter.testFailure('Failed to impersonate test device') oUsbGadget.disconnectFrom() else: reporter.testFailure('Failed to connect to USB gadget') else: reporter.testFailure('Failed to create USB device filter') reporter.testDone(not fRc) return fRc
def testUsbReattach(self, oSession, oTxsSession, sUsbCtrl, sSpeed): # pylint: disable=W0613 """ Tests that rapid connect/disconnect cycles work. """ # Get configured USB test devices from hostname we are running on sGadgetHost, uGadgetPort = self.getGadgetParams(self.sHostname, sSpeed); oUsbGadget = usbgadget.UsbGadget(); reporter.log('Connecting to UTS: ' + sGadgetHost); fRc = oUsbGadget.connectTo(30 * 1000, sGadgetHost, uPort = uGadgetPort); if fRc is True: self.oVBox.host.addUSBDeviceSource('USBIP', sGadgetHost, sGadgetHost + (':%s' % oUsbGadget.getUsbIpPort()), [], []); fSuperSpeed = False; if sSpeed == 'Super': fSuperSpeed = True; # Create test device gadget and a filter to attach the device automatically. fRc = oUsbGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest, fSuperSpeed); if fRc is True: iBusId, _ = oUsbGadget.getGadgetBusAndDevId(); fRc = oSession.addUsbDeviceFilter('Compliance device', sVendorId = '0525', sProductId = 'a4a0', \ sPort = str(iBusId)); if fRc is True: # Wait a moment to let the USB device appear self.sleep(3); # Do a rapid disconnect reconnect cycle. Wait a second before disconnecting # again or it will happen so fast that the VM can't attach the new device. # @todo: Get rid of the constant wait and use an event to get notified when # the device was attached. for iCycle in xrange (0, self.cUsbReattachCycles): fRc = oUsbGadget.disconnectUsb(); fRc = fRc and oUsbGadget.connectUsb(); if not fRc: reporter.testFailure('Reattach cycle %s failed on the gadget device' % (iCycle)); break; self.sleep(1); else: reporter.testFailure('Failed to impersonate test device'); oUsbGadget.disconnectFrom(); else: reporter.testFailure('Failed to connect to USB gadget'); else: reporter.testFailure('Failed to create USB device filter'); return fRc;
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 testReadWrite(self, oSession, oTxsSession, oTestVm): """ Does a simple write test verifying the output. """ _ = oSession; reporter.testStart('ReadWrite'); tupCmdLine = ('SerialTest', '--tests', 'readwrite', '--txbytes', '1048576'); if self.fVerboseTest: tupCmdLine += ('--verbose',); if oTestVm.isWindows(): tupCmdLine += ('--device', r'\\.\COM1',); elif oTestVm.isLinux(): tupCmdLine += ('--device', r'/dev/ttyS0',); fRc = self.txsRunTest(oTxsSession, 'SerialTest', 600 * 1000, \ '${CDROM}/${OS/ARCH}/SerialTest${EXESUFF}', tupCmdLine); if not fRc: reporter.testFailure('Running serial test utility failed'); reporter.testDone(); return fRc;
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(True) elif sHost == 'win': fRc = self._uninstallVBoxOnWindows(True) 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
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;
def test1Sub2SetPort(self, oSession, uPort, fInvalid=False): """ This can fail, thus fInvalid.""" if not fInvalid: uOld = uPort else: try: uOld = oSession.o.machine.teleporterPort except: return reporter.testFailureXcpt() try: oSession.o.machine.teleporterPort = uPort except Exception as oXcpt: if not fInvalid or vbox.ComError.notEqual( oXcpt, vbox.ComError.E_INVALIDARG): return reporter.testFailureXcpt('machine.teleporterPort=%u' % (uPort, )) else: if fInvalid: return reporter.testFailureXcpt( 'machine.teleporterPort=%u succeeded unexpectedly' % (uPort, )) try: uNew = oSession.o.machine.teleporterPort except: return reporter.testFailureXcpt() if uNew != uOld: if not fInvalid: reporter.testFailure( 'machine.teleporterPort=%u but afterwards it is actually %u' % (uPort, uNew)) else: reporter.testFailure( 'machine.teleporterPort is %u after failure, expected %u' % (uNew, uOld)) return False return True
def __testScenario_2(self, oSession, oMachine, sNewLoc, sOldLoc): """ All disks attached to VM are located inside the VM's folder. There are no any snapshots and logs. """ sController = self.dsKeys['StandardImage'] aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController) oSubTstDrvMoveMedium1Instance = SubTstDrvMoveMedium1(self.oTstDrv) oSubTstDrvMoveMedium1Instance.moveTo(sOldLoc, aoMediumAttachments) del oSubTstDrvMoveMedium1Instance dsReferenceFiles = defaultdict(set) for s in self.asImagesNames: reporter.log('"%s"' % (s,)) dsReferenceFiles['StandardImage'].add(sNewLoc + os.sep + oMachine.name + os.sep + s) sSettingFile = os.path.join(sNewLoc, os.path.join(oMachine.name, oMachine.name + '.vbox')) dsReferenceFiles['SettingsFile'].add(sSettingFile) fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) if fRc is True: fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles) if fRc is False: reporter.testFailure('!!!!!!!!!!!!!!!!!! 2nd scenario: Check locations failed... !!!!!!!!!!!!!!!!!!') else: reporter.testFailure('!!!!!!!!!!!!!!!!!! 2nd scenario: Move VM failed... !!!!!!!!!!!!!!!!!!') fRes = oSession.saveSettings() if fRes is False: reporter.log('2nd scenario: Couldn\'t save machine settings') return fRc
def testWrite(self, oSession, oTxsSession, oTestVm, sMode): """ Does a simple write test verifying the output. """ _ = oSession reporter.testStart('Write') tupCmdLine = ( 'SerialTest', '--tests', 'write', '--txbytes', '1048576', ) if self.fVerboseTest: tupCmdLine += ('--verbose') if oTestVm.isWindows(): tupCmdLine += ( '--device', r'\\.\COM1', ) elif oTestVm.isLinux(): tupCmdLine += ( '--device', r'/dev/ttyS0', ) fRc = self.txsRunTest(oTxsSession, 'SerialTest', 3600 * 1000, \ '${CDROM}/${OS/ARCH}/SerialTest${EXESUFF}', tupCmdLine) if not fRc: reporter.testFailure('Running serial test utility failed') elif sMode == 'RawFile': # Open serial port and verify cLast = 0 try: oFile = open(self.sLocation, 'rb') sFmt = '=I' cBytes = 4 for i in xrange(1048576 / 4): _ = i sData = oFile.read(cBytes) tupUnpacked = struct.unpack(sFmt, sData) cLast = cLast + 1 if tupUnpacked[0] != cLast: reporter.testFailure( 'Corruption detected, expected counter value %s, got %s' % (cLast + 1, tupUnpacked[0])) break oFile.close() except: reporter.logXcpt() reporter.testFailure('Verifying the written data failed') reporter.testDone() return fRc
def testUsbReattach(self, oSession, oTxsSession, sUsbCtrl, sSpeed): """ Tests that rapid connect/disconnect cycles work. """ # Get configured USB test devices from hostname we are running on sGadgetHost, sGadgetType = self.getGadgetParams(self.sHostname, sSpeed); # Create device filter fRc = oSession.addUsbDeviceFilter('Compliance device', '0525', 'a4a0'); if fRc is True: oUsbGadget = usbgadget.UsbGadget(); reporter.log('Connecting to gadget: ' + sGadgetType); fRc = oUsbGadget.connectTo(30 * 1000, sGadgetType, sGadgetHost); if fRc is True: reporter.log('Connect succeeded'); fRc = oUsbGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest); if fRc is True: self.sleep(1); # Do a rapid disconnect reconnect cycle. Wait a second before disconnecting # again or it will happen so fast that the VM can't attach the new device. # @todo: Get rid of the constant wait and use an event to get notified when # the device was attached. for iCycle in xrange (0, self.cUsbReattachCycles): fRc = oUsbGadget.disconnectUsb(); fRc = fRc and oUsbGadget.connectUsb(); if not fRc: reporter.testFailure('Reattach cycle %s failed on the gadget device' % (iCycle)); break; self.sleep(1); else: reporter.testFailure('Failed to impersonate test device'); oUsbGadget.disconnectFrom(); else: reporter.testFailure('Failed to connect to USB gadget'); else: reporter.testFailure('Failed to create USB device filter'); return fRc;
def __testScenario_3(self, oSession, oMachine, sNewLoc): """ There are snapshots """ # At moment, it's used only one snapshot due to the difficulty to get # all attachments of the machine (i.e. not only attached at moment) cSnap = 1 for counter in range(1, cSnap + 1): strSnapshot = 'Snapshot' + str(counter) fRc = oSession.takeSnapshot(strSnapshot) if fRc is False: reporter.testFailure( '3rd scenario: Can\'t take snapshot "%s"' % (strSnapshot, )) dsReferenceFiles = defaultdict(set) sController = self.dsKeys['StandardImage'] aoMediumAttachments = oMachine.getMediumAttachmentsOfController( sController) if fRc is True: for oAttachment in aoMediumAttachments: sRes = oAttachment.medium.location.rpartition(os.sep) dsReferenceFiles['SnapshotFile'].add( os.path.normcase(sNewLoc + os.sep + oMachine.name + os.sep + 'Snapshots' + os.sep + sRes[2])) sSettingFile = os.path.join( sNewLoc, os.path.join(oMachine.name, oMachine.name + '.vbox')) dsReferenceFiles['SettingsFile'].add( os.path.normcase(sSettingFile)) fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) if fRc is True: fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles) if fRc is False: reporter.testFailure( '!!!!!!!!!!!!!!!!!! 3rd scenario: Check locations failed... !!!!!!!!!!!!!!!!!!' ) else: reporter.testFailure( '!!!!!!!!!!!!!!!!!! 3rd scenario: Move VM failed... !!!!!!!!!!!!!!!!!!' ) fRes = oSession.saveSettings() if fRes is False: reporter.log('3rd scenario: Couldn\'t save machine settings') return fRc
def testUsbCompliance(self, oSession, oTxsSession, sUsbCtrl, sSpeed): """ Test VirtualBoxs USB stack in a VM. """ # Get configured USB test devices from hostname we are running on sGadgetHost, sGadgetType = self.getGadgetParams(self.sHostname, sSpeed); # Create device filter fRc = oSession.addUsbDeviceFilter('Compliance device', '0525', 'a4a0'); if fRc is True: oUsbGadget = usbgadget.UsbGadget(); reporter.log('Connecting to gadget: ' + sGadgetType); fRc = oUsbGadget.connectTo(30 * 1000, sGadgetType, sGadgetHost); if fRc is True: reporter.log('Connect succeeded'); fRc = oUsbGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest); if fRc is True: # Wait a moment to let the USB device appear self.sleep(3); tupCmdLine = ('UsbTest', ); # Exclude a few tests which hang and cause a timeout, need investigation. if sUsbCtrl is 'XHCI': tupCmdLine = tupCmdLine + ('--exclude', '10', '--exclude', '24'); fRc = self.txsRunTest(oTxsSession, 'UsbTest', 3600 * 1000, \ '${CDROM}/${OS/ARCH}/UsbTest${EXESUFF}', tupCmdLine); if not fRc: reporter.testFailure('Running USB test utility failed'); else: reporter.testFailure('Failed to impersonate test device'); oUsbGadget.disconnectFrom(); else: reporter.testFailure('Failed to connect to USB gadget'); else: reporter.testFailure('Failed to create USB device filter'); return fRc;
def testUsbReattach(self, oSession, oTxsSession, sUsbCtrl, sSpeed, sCaptureFile = None): # pylint: disable=unused-argument """ Tests that rapid connect/disconnect cycles work. """ # Get configured USB test devices from hostname we are running on sGadgetHost, uGadgetPort = self.getGadgetParams(self.sHostname, sSpeed); oUsbGadget = usbgadget.UsbGadget(); reporter.log('Connecting to UTS: ' + sGadgetHost); fRc = oUsbGadget.connectTo(30 * 1000, sGadgetHost, uPort = uGadgetPort, fTryConnect = True); if fRc is True: self.oVBox.host.addUSBDeviceSource('USBIP', sGadgetHost, sGadgetHost + (':%s' % oUsbGadget.getUsbIpPort()), [], []); fSuperSpeed = False; if sSpeed == 'Super': fSuperSpeed = True; # Create test device gadget and a filter to attach the device automatically. fRc = oUsbGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest, fSuperSpeed); if fRc is True: iBusId, _ = oUsbGadget.getGadgetBusAndDevId(); fRc = self.attachUsbDeviceToVm(oSession, '0525', 'a4a0', iBusId, sCaptureFile); if fRc is True: # Wait a moment to let the USB device appear self.sleep(3); # Do a rapid disconnect reconnect cycle. Wait a second before disconnecting # again or it will happen so fast that the VM can't attach the new device. # @todo: Get rid of the constant wait and use an event to get notified when # the device was attached. for iCycle in xrange (0, self.cUsbReattachCycles): fRc = oUsbGadget.disconnectUsb(); fRc = fRc and oUsbGadget.connectUsb(); if not fRc: reporter.testFailure('Reattach cycle %s failed on the gadget device' % (iCycle)); break; self.sleep(1); else: reporter.testFailure('Failed to create USB device filter'); oUsbGadget.disconnectFrom(); else: reporter.testFailure('Failed to impersonate test device'); else: reporter.log('warning: Failed to connect to USB gadget'); fRc = None return fRc;
def __testScenario_3(self, oSession, oMachine, sNewLoc): """ There are snapshots """ # At moment, it's used only one snapshot due to the difficulty to get # all attachments of the machine (i.e. not only attached at moment) cSnap = 1 for counter in range(1,cSnap+1): strSnapshot = 'Snapshot' + str(counter) fRc = oSession.takeSnapshot(strSnapshot) if fRc is False: reporter.testFailure('3rd scenario: Can\'t take snapshot "%s"' % (strSnapshot,)) dsReferenceFiles = defaultdict(set) sController = self.dsKeys['StandardImage'] aoMediumAttachments = oMachine.getMediumAttachmentsOfController(sController) if fRc is True: for oAttachment in aoMediumAttachments: sRes = oAttachment.medium.location.rpartition(os.sep) dsReferenceFiles['SnapshotFile'].add(sNewLoc + os.sep + oMachine.name + os.sep + 'Snapshots' + os.sep + sRes[2]) sSettingFile = os.path.join(sNewLoc, os.path.join(oMachine.name, oMachine.name + '.vbox')) dsReferenceFiles['SettingsFile'].add(sSettingFile) fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) if fRc is True: fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles) if fRc is False: reporter.testFailure('!!!!!!!!!!!!!!!!!! 3rd scenario: Check locations failed... !!!!!!!!!!!!!!!!!!') else: reporter.testFailure('!!!!!!!!!!!!!!!!!! 3rd scenario: Move VM failed... !!!!!!!!!!!!!!!!!!') fRes = oSession.saveSettings() if fRes is False: reporter.log('3d scenario: Couldn\'t save machine settings') return fRc
def test1Sub1DoTeleport(self, oSession, sHostname, uPort, sPassword, cMsMaxDowntime, hrcExpected, sTestName): """ Do a bad IConsole::teleport call and check the result.""" reporter.testStart(sTestName) fRc = False try: oProgress = oSession.o.console.teleport(sHostname, uPort, sPassword, cMsMaxDowntime) except vbox.ComException as oXcpt: if vbox.ComError.equal(oXcpt, hrcExpected): fRc = True else: reporter.testFailure('hresult %s, expected %s' \ % (vbox.ComError.toString(oXcpt.hresult), vbox.ComError.toString(hrcExpected))) except Exception as oXcpt: reporter.testFailure('Unexpected exception %s' % (oXcpt)) else: reporter.testFailure('Unpexected success') oProgress.cancel() oProgress.wait() reporter.testDone() return fRc
def testVMMove(self): """ Test machine moving. """ reporter.testStart('machine moving') if not self.oTstDrv.importVBoxApi(): return False isSupported = self.checkAPIVersion() if isSupported is False: reporter.log('API version is below "%s". Just skip this test.' % (self.oTstDrv.fpApiVer)) return reporter.testDone()[1] == 0 else: reporter.log('API version is "%s". Continuing the test.' % (self.oTstDrv.fpApiVer)) #Scenarios #1. All disks attached to VM are located outside the VM's folder. # There are no any snapshots and logs. # In this case only VM setting file should be moved (.vbox file) # #2. All disks attached to VM are located inside the VM's folder. # There are no any snapshots and logs. # #3. There are snapshots. # #4. There are one or more save state files in the snapshots folder # and some files in the logs folder. # #5. There is an ISO image (.iso) attached to the VM. # #6. There is a floppy image (.img) attached to the VM. # #7. There are shareable disk and immutable disk attached to the VM. try: #create test machine oMachine = self.createTestMachine() if oMachine is None: reporter.error('Failed to create test machine') #create temporary subdirectory in the current working directory sOrigLoc = self.oTstDrv.sScratchPath sBaseLoc = os.path.join(sOrigLoc, 'moveFolder') os.mkdir(sBaseLoc, 0o775) sController = 'SATA Controller' aoMediumAttachments = oMachine.getMediumAttachmentsOfController( sController) #lock machine #get session machine oSession = self.oTstDrv.openSession(oMachine) fRc = True sNewLoc = sBaseLoc + os.sep ############# 1 case. ########################################################################################## # All disks attached to VM are located outside the VM's folder. # There are no any snapshots and logs. # In this case only VM setting file should be moved (.vbox file) fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc fRc = fRc and oSession.saveSettings() if fRc is False: reporter.log( 'Couldn\'t save machine settings after 1t scenario') ############# 2 case. ########################################################################################## # All disks attached to VM are located inside the VM's folder. # There are no any snapshots and logs. sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep sNewLoc = os.path.join(sOrigLoc, 'moveFolder_2d_scenario') os.mkdir(sNewLoc, 0o775) aoMediumAttachments = oMachine.getMediumAttachmentsOfController( sController) oSubTstDrvMoveMedium1Instance = SubTstDrvMoveMedium1(self.oTstDrv) oSubTstDrvMoveMedium1Instance.setLocation(sOldLoc, aoMediumAttachments) del oSubTstDrvMoveMedium1Instance fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc fRc = fRc and oSession.saveSettings() if fRc is False: reporter.log( 'Couldn\'t save machine settings after 2nd scenario') ############# 3 case. ########################################################################################## # There are snapshots. sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep sNewLoc = os.path.join(sOrigLoc, 'moveFolder_3d_scenario') os.mkdir(sNewLoc, 0o775) cSnap = 2 for counter in range(1, cSnap + 1): strSnapshot = 'Snapshot' + str(counter) fRc = fRc and oSession.takeSnapshot(strSnapshot) if fRc is False: reporter.error('Error: Can\'t take snapshot "%s".' % (strSnapshot, )) reporter.testFailure('Error: Can\'t take snapshot "%s".' % (strSnapshot, )) aoMediumAttachments = oMachine.getMediumAttachmentsOfController( sController) if fRc is True: fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) and fRc fRc = fRc and oSession.saveSettings() if fRc is False: reporter.log( 'Couldn\'t save machine settings after 3d scenario') ############# 4 case. ########################################################################################## # There are one or more save state files in the snapshots folder # and some files in the logs folder. # Here we run VM, next stop it in the "save" state. # And next move VM sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep sNewLoc = os.path.join(sOrigLoc, 'moveFolder_4th_scenario') os.mkdir(sNewLoc, 0o775) #Close Session object because after starting VM we get new instance of session fRc = oSession.close() and fRc if fRc is False: reporter.log('Couldn\'t close machine session') del oSession self.__testScenario_4(oMachine, sNewLoc) ############## 5 case. ########################################################################################## #There is an ISO image (.iso) attached to the VM. #Prerequisites - there is IDE Controller and there are no any images attached to it. sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep sNewLoc = os.path.join(sOrigLoc, 'moveFolder_5th_scenario') os.mkdir(sNewLoc, 0o775) self.__testScenario_5(oMachine, sNewLoc, sOldLoc) ############# 6 case. ########################################################################################## #There is a floppy image (.img) attached to the VM. #Prerequisites - there is Floppy Controller and there are no any images attached to it. sOldLoc = sNewLoc + os.sep + oMachine.name + os.sep sNewLoc = os.path.join(sOrigLoc, 'moveFolder_6th_scenario') os.mkdir(sNewLoc, 0o775) self.__testScenario_6(oMachine, sNewLoc, sOldLoc) ############# 7 case. ########################################################################################## # # There are shareable disk and immutable disk attached to the VM. # # # # fRc = fRc and oSession.saveSettings() # if fRc is False: # reporter.log('Couldn\'t save machine settings') # assert fRc is True except: reporter.errorXcpt() return reporter.testDone()[1] == 0
def testVMMove(self): """ Test machine moving. """ if not self.oTstDrv.importVBoxApi(): return False fSupported = self.checkAPIVersion() reporter.log('ValidationKit folder is "%s"' % (g_ksValidationKitDir, )) if fSupported is False: reporter.log('API version %s is too old. Just skip this test.' % (self.oTstDrv.fpApiVer)) return None reporter.log('API version is "%s".' % (self.oTstDrv.fpApiVer)) # Scenarios # 1. All disks attached to VM are located outside the VM's folder. # There are no any snapshots and logs. # In this case only VM setting file should be moved (.vbox file) # # 2. All disks attached to VM are located inside the VM's folder. # There are no any snapshots and logs. # # 3. There are snapshots. # # 4. There are one or more save state files in the snapshots folder # and some files in the logs folder. # # 5. There is an ISO image (.iso) attached to the VM. # # 6. There is a floppy image (.img) attached to the VM. # # 7. There are shareable disk and immutable disk attached to the VM. try: ## @todo r=bird: Would be nice to use sub-tests here for each scenario, however ## this try/catch as well as lots of return points makes that very hard. ## Big try/catch stuff like this should be avoided. # Create test machine. oMachine = self.createTestMachine() if oMachine is None: reporter.error('Failed to create test machine') # Create temporary subdirectory in the current working directory. sOrigLoc = self.oTstDrv.sScratchPath sBaseLoc = os.path.join(sOrigLoc, 'moveFolder') os.mkdir(sBaseLoc, 0o775) # lock machine # get session machine oSession = self.oTstDrv.openSession(oMachine) fRc = True sNewLoc = sBaseLoc + os.sep dsReferenceFiles = defaultdict(set) # # 1. case: # # All disks attached to VM are located outside the VM's folder. # There are no any snapshots and logs. # In this case only VM setting file should be moved (.vbox file) # reporter.log("Scenario #1:") for s in self.asImagesNames: reporter.log('"%s"' % (s, )) dsReferenceFiles['StandardImage'].add( os.path.normcase(os.path.join(sOrigLoc, s))) sSettingFile = os.path.normcase( os.path.join( sNewLoc, os.path.join(oMachine.name, oMachine.name + '.vbox'))) dsReferenceFiles['SettingsFile'].add(sSettingFile) fRc = self.moveVMToLocation(sNewLoc, oSession.o.machine) if fRc is True: fRc = self.checkLocation(oSession.o.machine, dsReferenceFiles) if fRc is False: reporter.testFailure( '!!!!!!!!!!!!!!!!!! 1st scenario: Check locations failed... !!!!!!!!!!!!!!!!!!' ) return False else: reporter.testFailure( '!!!!!!!!!!!!!!!!!! 1st scenario: Move VM failed... !!!!!!!!!!!!!!!!!!' ) return False fRc = oSession.saveSettings() if fRc is False: reporter.testFailure( '1st scenario: Couldn\'t save machine settings') # # 2. case: # # All disks attached to VM are located inside the VM's folder. # There are no any snapshots and logs. # reporter.log("Scenario #2:") sOldLoc = sNewLoc + oMachine.name + os.sep sNewLoc = os.path.join(sOrigLoc, 'moveFolder_2nd_scenario') os.mkdir(sNewLoc, 0o775) fRc = self.__testScenario_2(oSession, oMachine, sNewLoc, sOldLoc) if fRc is False: return False # # 3. case: # # There are snapshots. # reporter.log("Scenario #3:") sOldLoc = sNewLoc + oMachine.name + os.sep sNewLoc = os.path.join(sOrigLoc, 'moveFolder_3rd_scenario') os.mkdir(sNewLoc, 0o775) fRc = self.__testScenario_3(oSession, oMachine, sNewLoc) if fRc is False: return False # # 4. case: # # There are one or more save state files in the snapshots folder # and some files in the logs folder. # Here we run VM, next stop it in the "save" state. # And next move VM # reporter.log("Scenario #4:") sOldLoc = sNewLoc + oMachine.name + os.sep sNewLoc = os.path.join(sOrigLoc, 'moveFolder_4th_scenario') os.mkdir(sNewLoc, 0o775) # Close Session object because after starting VM we get new instance of session fRc = oSession.close() and fRc if fRc is False: reporter.log('Couldn\'t close machine session') del oSession fRc = self.__testScenario_4(oMachine, sNewLoc) if fRc is False: return False # # 5. case: # # There is an ISO image (.iso) attached to the VM. # Prerequisites - there is IDE Controller and there are no any images attached to it. # reporter.log("Scenario #5:") sOldLoc = sNewLoc + os.sep + oMachine.name sNewLoc = os.path.join(sOrigLoc, 'moveFolder_5th_scenario') os.mkdir(sNewLoc, 0o775) fRc = self.__testScenario_5(oMachine, sNewLoc, sOldLoc) if fRc is False: return False # # 6. case: # # There is a floppy image (.img) attached to the VM. # Prerequisites - there is Floppy Controller and there are no any images attached to it. # reporter.log("Scenario #6:") sOldLoc = sNewLoc + os.sep + oMachine.name sNewLoc = os.path.join(sOrigLoc, 'moveFolder_6th_scenario') os.mkdir(sNewLoc, 0o775) fRc = self.__testScenario_6(oMachine, sNewLoc, sOldLoc) if fRc is False: return False # # # # 7. case: # # # # There are shareable disk and immutable disk attached to the VM. # # # reporter.log("Scenario #7:"); # fRc = fRc and oSession.saveSettings() # if fRc is False: # reporter.log('Couldn\'t save machine settings') # assert fRc is True except: reporter.errorXcpt() return fRc
def test1(self): """ Executes test #1. """ fRc = True oDiskCfg = self.kdStorageCfgs.get(socket.gethostname().lower()) # Test the host first if requested if oDiskCfg is not None or self.fUseScratch: lstBinaryPaths = ['/bin', '/sbin', '/usr/bin', '/usr/sbin', \ '/opt/csw/bin', '/usr/ccs/bin', '/usr/sfw/bin'] oExecutor = remoteexecutor.RemoteExecutor(None, lstBinaryPaths, self.sScratchPath) if not self.fUseScratch: self.oStorCfg = storagecfg.StorageCfg(oExecutor, utils.getHostOs(), oDiskCfg) # Try to cleanup any leftovers from a previous run first. fRc = self.oStorCfg.cleanupLeftovers() if not fRc: reporter.error( 'Failed to cleanup any leftovers from a previous run') if self.fTestHost: reporter.testStart('Host') if self.fUseScratch: sMountPoint = self.sScratchPath else: sMountPoint = self.prepareStorage(self.oStorCfg) if sMountPoint is not None: for sIoTest in self.asTests: reporter.testStart(sIoTest) for sTestSet in self.asTestSets: reporter.testStart(sTestSet) dTestSet = self.kdTestSets.get(sTestSet) self.testBenchmark(utils.getHostOs(), sIoTest, sMountPoint, oExecutor, dTestSet) reporter.testDone() reporter.testDone() self.cleanupStorage(self.oStorCfg) else: reporter.testFailure('Failed to prepare host storage') fRc = False reporter.testDone() else: # Create the storage space first if it is not done before every test. sMountPoint = None if self.fUseScratch: sMountPoint = self.sScratchPath elif not self.fRecreateStorCfg: reporter.testStart('Create host storage') sMountPoint = self.prepareStorage(self.oStorCfg) if sMountPoint is None: reporter.testFailure('Failed to prepare host storage') fRc = False self.oStorCfg.mkDirOnVolume(sMountPoint, 'test', 0777) sMountPoint = sMountPoint + '/test' reporter.testDone() if fRc: # Run the storage tests. if not self.testStorage(sMountPoint): fRc = False if not self.fRecreateStorCfg: self.cleanupStorage(self.oStorCfg) else: fRc = False return fRc
def testOneCfg( self, sVmName, eStorageController, sHostIoCache, sDiskFormat, # pylint: disable=R0913,R0915 sDiskVariant, sDiskPath, cCpus, sIoTest, sVirtMode, sTestSet): """ Runs the specified VM thru test #1. Returns a success indicator on the general test execution. This is not the actual test result. """ oVM = self.getVmByName(sVmName) dTestSet = self.kdTestSets.get(sTestSet) cbDisk = dTestSet.get('DiskSizeGb') * 1024 * 1024 * 1024 fHwVirt = sVirtMode != 'raw' fNestedPaging = sVirtMode == 'hwvirt-np' fRc = True if sDiskFormat == 'iSCSI': sDiskPath = self.asIscsiTargets[0] elif self.fUseScratch: sDiskPath = self.sScratchPath else: # If requested recreate the storage space to start with a clean config # for benchmarks if self.fRecreateStorCfg: sMountPoint = self.prepareStorage(self.oStorCfg) if sMountPoint is not None: # Create a directory where every normal user can write to. self.oStorCfg.mkDirOnVolume(sMountPoint, 'test', 0777) sDiskPath = sMountPoint + '/test' else: fRc = False reporter.testFailure('Failed to prepare storage for VM') if not fRc: return fRc lstDisks = [] # List of disks we have to delete afterwards. for iDiffLvl in range(self.cDiffLvls + 1): if iDiffLvl == 0: reporter.testStart('Base') else: reporter.testStart('Diff %u' % (iDiffLvl)) # Reconfigure the VM oSession = self.openSession(oVM) if oSession is not None: # Attach HD fRc = oSession.ensureControllerAttached( _ControllerTypeToName(eStorageController)) fRc = fRc and oSession.setStorageControllerType( eStorageController, _ControllerTypeToName(eStorageController)) if sHostIoCache == 'hostiocache': fRc = fRc and oSession.setStorageControllerHostIoCache( _ControllerTypeToName(eStorageController), True) elif sHostIoCache == 'no-hostiocache': fRc = fRc and oSession.setStorageControllerHostIoCache( _ControllerTypeToName(eStorageController), False) iDevice = 0 if eStorageController == vboxcon.StorageControllerType_PIIX3 or \ eStorageController == vboxcon.StorageControllerType_PIIX4: iDevice = 1 # Master is for the OS. oHdParent = None if iDiffLvl > 0: oHdParent = lstDisks[0] oHd = self.createHd(oSession, sDiskFormat, sDiskVariant, iDiffLvl, oHdParent, sDiskPath, cbDisk) if oHd is not None: lstDisks.insert(0, oHd) try: if oSession.fpApiVer >= 4.0: oSession.o.machine.attachDevice(_ControllerTypeToName(eStorageController), \ 0, iDevice, vboxcon.DeviceType_HardDisk, oHd) else: oSession.o.machine.attachDevice(_ControllerTypeToName(eStorageController), \ 0, iDevice, vboxcon.DeviceType_HardDisk, oHd.id) except: reporter.errorXcpt('attachDevice("%s",%s,%s,HardDisk,"%s") failed on "%s"' \ % (_ControllerTypeToName(eStorageController), 1, 0, oHd.id, oSession.sName) ) fRc = False else: reporter.log('attached "%s" to %s' % (sDiskPath, oSession.sName)) else: fRc = False fRc = fRc and oSession.enableVirtEx(fHwVirt) fRc = fRc and oSession.enableNestedPaging(fNestedPaging) fRc = fRc and oSession.setCpuCount(cCpus) 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=True) if oSession is not None: self.addTask(oSession) # Fudge factor - Allow the guest to finish starting up. self.sleep(5) # Prepare the storage on the guest lstBinaryPaths = [ '/bin', '/sbin', '/usr/bin', '/usr/sbin' ] oExecVm = remoteexecutor.RemoteExecutor( oTxsSession, lstBinaryPaths, '${SCRATCH}') oStorCfgVm = storagecfg.StorageCfg(oExecVm, 'linux', self.getGuestDisk(oSession, oTxsSession, \ eStorageController)) sMountPoint = self.prepareStorage(oStorCfgVm) if sMountPoint is not None: self.testBenchmark('linux', sIoTest, sMountPoint, oExecVm, dTestSet) self.cleanupStorage(oStorCfgVm) else: reporter.testFailure( 'Failed to prepare storage for the guest benchmark' ) # cleanup. self.removeTask(oTxsSession) self.terminateVmBySession(oSession) else: fRc = False # Remove disk oSession = self.openSession(oVM) if oSession is not None: try: oSession.o.machine.detachDevice( _ControllerTypeToName(eStorageController), 0, iDevice) # Remove storage controller if it is not an IDE controller. if eStorageController is not vboxcon.StorageControllerType_PIIX3 \ and eStorageController is not vboxcon.StorageControllerType_PIIX4: oSession.o.machine.removeStorageController( _ControllerTypeToName(eStorageController)) oSession.saveSettings() oSession.saveSettings() oSession.close() oSession = None except: reporter.errorXcpt( 'failed to detach/delete disk %s from storage controller' % (sDiskPath)) else: fRc = False reporter.testDone() # Delete all disks for oHd in lstDisks: self.oVBox.deleteHdByMedium(oHd) # Cleanup storage area if sDiskFormat != 'iSCSI' and not self.fUseScratch and self.fRecreateStorCfg: self.cleanupStorage(self.oStorCfg) return fRc