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 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 test1OneCfg(self, sVmName, eStorageController, sDiskFormat): """ 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) # @ŧodo: Implement support for different formats. _ = sDiskFormat # Reconfigure the VM fRc = True oSession = self.openSession(oVM) if oSession is not None: # Attach HD fRc = oSession.ensureControllerAttached( _ControllerTypeToName(eStorageController)) fRc = fRc and oSession.setStorageControllerType( eStorageController, _ControllerTypeToName(eStorageController)) 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(oTxsSession) # Fudge factor - Allow the guest to finish starting up. self.sleep(5) # Do a snapshot first. oSession.takeSnapshot('Base snapshot') for i in range(0, 10): oSession.takeSnapshot('Snapshot ' + str(i)) self.test1UploadFile(oSession, oTxsSession) msNow = base.timestampMilli() oSnapshot = oSession.findSnapshot('Snapshot ' + str(i)) oSession.deleteSnapshot(oSnapshot.id, cMsTimeout=60 * 1000) msElapsed = base.timestampMilli() - msNow reporter.log('Deleting snapshot %d took %d ms' % (i, msElapsed)) # cleanup. self.removeTask(oTxsSession) self.terminateVmBySession(oSession) else: fRc = False return fRc
def test1OneCfg(self, sVmName, eStorageController, sDiskFormat): """ 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); # @ŧodo: Implement support for different formats. _ = sDiskFormat; # Reconfigure the VM fRc = True; oSession = self.openSession(oVM); if oSession is not None: # Attach HD fRc = oSession.ensureControllerAttached(_ControllerTypeToName(eStorageController)); fRc = fRc and oSession.setStorageControllerType(eStorageController, _ControllerTypeToName(eStorageController)); 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); # Do a snapshot first. oSession.takeSnapshot('Base snapshot'); for i in range(0, 10): oSession.takeSnapshot('Snapshot ' + str(i)); self.test1UploadFile(oSession, oTxsSession); msNow = base.timestampMilli(); oSnapshot = oSession.findSnapshot('Snapshot ' + str(i)); oSession.deleteSnapshot(oSnapshot.id, cMsTimeout = 60 * 1000); msElapsed = base.timestampMilli() - msNow; reporter.log('Deleting snapshot %d took %d ms' % (i, msElapsed)); # cleanup. self.removeTask(oTxsSession); self.terminateVmBySession(oSession) else: fRc = False; return fRc;
def mountShareEx(self, oSession, oTxsSession, sShareName, sHostPath, sGuestMountPoint, fMustSucceed): """ Automount a shared folder in the guest, extended version. Returns success status, based on fMustSucceed. """ reporter.testStart('Automounting "%s"' % (sShareName, )) reporter.log2('Creating shared folder "%s" at "%s" ...' % (sShareName, sGuestMountPoint)) try: oConsole = oSession.o.console oConsole.createSharedFolder(sShareName, sHostPath, True, True, sGuestMountPoint) except: if fMustSucceed: reporter.errorXcpt('createSharedFolder(%s,%s,True,True,%s)' % (sShareName, sHostPath, sGuestMountPoint)) else: reporter.log( 'createSharedFolder(%s,%s,True,True,%s) failed, good' % (sShareName, sHostPath, sGuestMountPoint)) reporter.testDone() return False is fMustSucceed # Check whether we can see the shared folder now. Retry for 30 seconds. msStart = base.timestampMilli() while True: fRc = oTxsSession.syncIsDir(sGuestMountPoint + self.sGuestSlash + 'candle.dir') reporter.log2('candle.dir check -> %s' % (fRc, )) if fRc is fMustSucceed: break if base.timestampMilli() - msStart > 30000: reporter.error('Shared folder mounting timed out!') break self.oTstDrv.sleep(1) reporter.testDone() return fRc == fMustSucceed
def unmountShareEx(self, oSession, oTxsSession, sShareName, sGuestMountPoint, fMustSucceed): """ Unmounts a shared folder in the guest. Returns success status, based on fMustSucceed. """ reporter.log2('Autounmount') try: oConsole = oSession.o.console oConsole.removeSharedFolder(sShareName) except: if fMustSucceed: reporter.errorXcpt('removeSharedFolder(%s)' % (sShareName, )) else: reporter.log('removeSharedFolder(%s)' % (sShareName, )) reporter.testDone() return False is fMustSucceed # Check whether the shared folder is gone on the guest now. Retry for 30 seconds. msStart = base.timestampMilli() while True: fRc = oTxsSession.syncIsDir(sGuestMountPoint + self.sGuestSlash + 'candle.dir') reporter.log2('candle.dir check -> %s' % (fRc, )) if fRc is not fMustSucceed: break if base.timestampMilli() - msStart > 30000: reporter.error('Shared folder unmounting timed out!') fRc = False break self.oTstDrv.sleep(1) reporter.testDone() return fRc is not fMustSucceed
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
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
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 testIt(self, oTestVm, oSession, oTxsSession): """ Executes the test. Returns fRc, oTxsSession. The latter may have changed. """ reporter.log("Active tests: %s" % (self.asTests, )) # # Skip the test if before 6.0 # if self.oTstDrv.fpApiVer < 6.0: reporter.log('Requires 6.0 or later (for now)') return (None, oTxsSession) # # Create the host directory to share. Empty except for a 'candle.dir' subdir # that we use to check that it mounted correctly. # sSharedFolder1 = os.path.join(self.oTstDrv.sScratchPath, 'shfl1') reporter.log2('Creating shared host folder "%s"...' % (sSharedFolder1, )) if os.path.exists(sSharedFolder1): try: shutil.rmtree(sSharedFolder1) except: return (reporter.errorXcpt('shutil.rmtree(%s)' % (sSharedFolder1, )), oTxsSession) try: os.mkdir(sSharedFolder1) except: return (reporter.errorXcpt('os.mkdir(%s)' % (sSharedFolder1, )), oTxsSession) try: os.mkdir(os.path.join(sSharedFolder1, 'candle.dir')) except: return (reporter.errorXcpt('os.mkdir(%s)' % (sSharedFolder1, )), oTxsSession) # Guess a free mount point inside the guest. if oTestVm.isWindows() or oTestVm.isOS2(): sMountPoint1 = 'V:' sGuestSlash = '\\' else: sMountPoint1 = '/mnt/shfl1' sGuestSlash = '/' # # Automount a shared folder in the guest. # reporter.testStart('Automount') reporter.log2('Creating shared folder shfl1...') try: oConsole = oSession.o.console oConsole.createSharedFolder('shfl1', sSharedFolder1, True, True, sMountPoint1) except: reporter.errorXcpt('createSharedFolder(shfl1,%s,True,True,%s)' % (sSharedFolder1, sMountPoint1)) reporter.testDone() return (False, oTxsSession) # Check whether we can see the shared folder now. Retry for 30 seconds. msStart = base.timestampMilli() while True: fRc = oTxsSession.syncIsDir(sMountPoint1 + sGuestSlash + 'candle.dir') reporter.log2('candle.dir check -> %s' % (fRc, )) if fRc is not False: break if base.timestampMilli() - msStart > 30000: reporter.error('Shared folder mounting timed out!') break self.oTstDrv.sleep(1) reporter.testDone() if fRc is not True: return (False, oTxsSession) # skip the remainder if we cannot auto mount the folder. # # Run FsPerf inside the guest. # fSkip = 'fsperf' not in self.asTests if fSkip is False: cMbFree = utils.getDiskUsage(sSharedFolder1) if cMbFree >= 16: reporter.log2('Free space: %u MBs' % (cMbFree, )) else: reporter.log('Skipping FsPerf because only %u MB free on %s' % ( cMbFree, sSharedFolder1, )) fSkip = True if fSkip is False: # Common arguments: asArgs = [ 'FsPerf', '-d', sMountPoint1 + sGuestSlash + 'fstestdir-1', '-s8' ] # Skip part of mmap on older windows systems without CcCoherencyFlushAndPurgeCache (>= w7). reporter.log2('oTestVm.sGuestOsType=%s' % (oTestVm.sGuestOsType, )) if oTestVm.getNonCanonicalGuestOsType() \ in [ 'WindowsNT3x', 'WindowsNT4', 'Windows2000', 'WindowsXP', 'WindowsXP_64', 'Windows2003', 'Windows2003_64', 'WindowsVista', 'WindowsVista_64', 'Windows2008', 'Windows2008_64']: asArgs.append('--no-mmap-coherency') # Configure I/O block sizes according to guest memory size: cbMbRam = 128 try: cbMbRam = oSession.o.machine.memorySize except: reporter.errorXcpt() reporter.log2('cbMbRam=%s' % (cbMbRam, )) asArgs.append('--set-block-size=1') asArgs.append('--add-block-size=512') asArgs.append('--add-block-size=4096') asArgs.append('--add-block-size=16384') asArgs.append('--add-block-size=65536') asArgs.append('--add-block-size=1048576') # 1 MiB if cbMbRam >= 512: asArgs.append('--add-block-size=33554432') # 32 MiB if cbMbRam >= 768: asArgs.append('--add-block-size=134217728') # 128 MiB # Putting lots (10000) of files in a single directory causes issues on OS X # (HFS+ presumably, though could be slow disks) and some linuxes (slow disks, # maybe ext2/3?). So, generally reduce the file count to 4096 everywhere # since we're not here to test the host file systems, and 3072 on macs. if utils.getHostOs() in [ 'darwin', ]: asArgs.append('--many-files=3072') elif utils.getHostOs() in [ 'linux', ]: asArgs.append('--many-files=4096') # Add the extra arguments from the command line and kick it off: asArgs.extend(self.asExtraArgs) # Run FsPerf: reporter.log2('Starting guest FsPerf (%s)...' % (asArgs, )) sFsPerfPath = self._locateGstFsPerf(oTxsSession) fRc = self.oTstDrv.txsRunTest(oTxsSession, 'FsPerf', 30 * 60 * 1000, sFsPerfPath, asArgs) reporter.log2('FsPerf -> %s' % (fRc, )) sTestDir = os.path.join(sSharedFolder1, 'fstestdir-1') if os.path.exists(sTestDir): fRc = reporter.errorXcpt('test directory lingers: %s' % (sTestDir, )) try: shutil.rmtree(sTestDir) except: fRc = reporter.errorXcpt('shutil.rmtree(%s)' % (sTestDir, )) else: reporter.testStart('FsPerf') reporter.testDone(fSkip or fRc is None) return (fRc, oTxsSession)