Changeset 54938 in vbox for trunk/src/VBox
- Timestamp:
- Mar 25, 2015 1:04:20 PM (10 years ago)
- Location:
- trunk/src/VBox/ValidationKit
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/testdriver/vboxwrappers.py
r54432 r54938 1647 1647 return fRc; 1648 1648 1649 def attachHd(self, sHd, sController = "IDE Controller", iPort = 0, iDevice = 0, fImmutable = True ):1649 def attachHd(self, sHd, sController = "IDE Controller", iPort = 0, iDevice = 0, fImmutable = True, fForceResource = True): 1650 1650 """ 1651 1651 Attaches a HD to a VM. … … 1653 1653 """ 1654 1654 # Input validation. 1655 if not self.oTstDrv.isResourceFile(sHd):1655 if fForceResource and not self.oTstDrv.isResourceFile(sHd): 1656 1656 reporter.fatal('"%s" is not in the resource set' % (sHd,)); 1657 1657 return None; … … 1661 1661 1662 1662 # Find the HD, registering it if necessary (as immutable). 1663 sFullName = self.oTstDrv.getFullResourceName(sHd); 1663 if fForceResource: 1664 sFullName = self.oTstDrv.getFullResourceName(sHd); 1665 else: 1666 sFullName = sHd; 1664 1667 try: 1665 1668 oHd = self.oVBox.findHardDisk(sFullName); … … 1703 1706 return fRc; 1704 1707 1708 def createBaseHd(self, sHd, sFmt = "VDI", cb = 10*1024*1024*1024): 1709 """ 1710 Creates a base HD. 1711 Returns Medium object on success and None on failure. Error information is logged. 1712 """ 1713 try: 1714 if self.fpApiVer >= 4.4: 1715 oHd = self.oVBox.createMedium(sFmt, sHd, vboxcon.AccessMode_ReadWrite, vboxcon.DeviceType_HardDisk); 1716 else: 1717 oHd = self.oVBox.createHardDisk(sFmt, sHd); 1718 oProgressXpcom = oHd.createBaseStorage(cb, (vboxcon.MediumVariant_Standard, )) 1719 oProgress = ProgressWrapper(oProgressXpcom, self.oVBoxMgr, self.oTstDrv, 'create base disk %s' % (sHd)); 1720 oProgress.wait(); 1721 oProgress.logResult(); 1722 except: 1723 reporter.errorXcpt('failed to create base hd "%s"' % (sHd)); 1724 oHd = None 1725 1726 return oHd; 1727 1728 def createDiffHd(self, oParentHd, sHd, sFmt = "VDI"): 1729 """ 1730 Creates a differencing HD. 1731 Returns Medium object on success and None on failure. Error information is logged. 1732 """ 1733 try: 1734 if self.fpApiVer >= 4.4: 1735 oHd = self.oVBox.createMedium(sFmt, sHd, vboxcon.AccessMode_ReadWrite, vboxcon.DeviceType_HardDisk); 1736 else: 1737 oHd = self.oVBox.createHardDisk(sFmt, sHd); 1738 oProgressXpcom = oParentHd.createDiffStorage(oHd, (vboxcon.MediumVariant_Standard, )) 1739 oProgress = ProgressWrapper(oProgressXpcom, self.oVBoxMgr, self.oTstDrv, 'create diff disk %s' % (sHd)); 1740 oProgress.wait(); 1741 oProgress.logResult(); 1742 except: 1743 reporter.errorXcpt('failed to create diff hd "%s"' % (sHd)); 1744 oHd = None 1745 1746 return oHd; 1747 1705 1748 def createAndAttachHd(self, sHd, sFmt = "VDI", sController = "IDE Controller", cb = 10*1024*1024*1024, \ 1706 1749 iPort = 0, iDevice = 0, fImmutable = True): … … 1712 1755 return False; 1713 1756 1714 try: 1715 if self.fpApiVer >= 4.4: 1716 oHd = self.oVBox.createMedium(sFmt, sHd, vboxcon.AccessMode_ReadWrite, vboxcon.DeviceType_HardDisk); 1717 else: 1718 oHd = self.oVBox.createHardDisk(sFmt, sHd); 1719 oProgressXpcom = oHd.createBaseStorage(cb, (vboxcon.MediumVariant_Standard, )) 1720 oProgress = ProgressWrapper(oProgressXpcom, self.oVBoxMgr, self.oTstDrv, 'create disk %s' % (sHd)); 1721 oProgress.wait(); 1722 oProgress.logResult(); 1723 except: 1724 reporter.errorXcpt('failed to create hd "%s"' % (sHd)); 1757 oHd = self.createBaseHd(sHd, sFmt, cb) 1758 if oHd is None: 1725 1759 return False; 1726 1760 -
trunk/src/VBox/ValidationKit/tests/api/Makefile.kmk
r52776 r54938 5 5 6 6 # 7 # Copyright (C) 2006-201 4Oracle Corporation7 # Copyright (C) 2006-2015 Oracle Corporation 8 8 # 9 9 # This file is part of VirtualBox Open Source Edition (OSE), as … … 33 33 ValidationKitTestsApi_INST = $(INST_VALIDATIONKIT)tests/api/ 34 34 ValidationKitTestsApi_EXEC_SOURCES := \ 35 $(PATH_SUB_CURRENT)/tdPython1.py 35 $(PATH_SUB_CURRENT)/tdPython1.py \ 36 $(PATH_SUB_CURRENT)/tdTreeDepth1.py 36 37 37 38 VBOX_VALIDATIONKIT_PYTHON_SOURCES += $(ValidationKitTestsApi_EXEC_SOURCES) -
trunk/src/VBox/ValidationKit/tests/api/tdTreeDepth1.py
r54788 r54938 4 4 5 5 """ 6 VirtualBox Validation Kit - Python BindingsTest #16 VirtualBox Validation Kit - Medium and Snapshot Tree Depth Test #1 7 7 """ 8 8 9 9 __copyright__ = \ 10 10 """ 11 Copyright (C) 2010-201 4Oracle Corporation11 Copyright (C) 2010-2015 Oracle Corporation 12 12 13 13 This file is part of VirtualBox Open Source Edition (OSE), as … … 40 40 # Only the main script needs to modify the path. 41 41 try: __file__ 42 except: __file__ = sys.argv[0] ;43 g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) ;44 sys.path.append(g_ksValidationKitDir) ;42 except: __file__ = sys.argv[0] 43 g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 44 sys.path.append(g_ksValidationKitDir) 45 45 46 46 # Validation Kit imports. 47 from testdriver import reporter; 48 from testdriver import base; 49 from testdriver import vbox; 47 from testdriver import reporter 48 from testdriver import base 49 from testdriver import vbox 50 from testdriver import vboxcon 50 51 51 52 52 class td Python1(vbox.TestDriver):53 class tdTreeDepth1(vbox.TestDriver): 53 54 """ 54 Python BindingsTest #1.55 Medium and Snapshot Tree Depth Test #1. 55 56 """ 56 57 57 58 def __init__(self): 58 vbox.TestDriver.__init__(self) ;59 self.asRsrcs = None ;59 vbox.TestDriver.__init__(self) 60 self.asRsrcs = None 60 61 61 62 … … 69 70 """ 70 71 if not self.importVBoxApi(): 71 return False ;72 return True ;72 return False 73 return True 73 74 74 75 def actionExecute(self): … … 76 77 Execute the testcase. 77 78 """ 78 return self.test EventQueueWaiting() \79 and self.test EventQueueInterrupt();79 return self.testMediumTreeDepth() \ 80 and self.testSnapshotTreeDepth() 80 81 81 82 # … … 83 84 # 84 85 85 def testEventQueueWaitingThreadProc(self): 86 """ Thread procedure for checking that waitForEvents fails when not called by the main thread. """ 86 def testMediumTreeDepth(self): 87 """ 88 Test medium tree depth. 89 """ 90 reporter.testStart('mediumTreeDepth') 91 87 92 try: 88 rc2 = self.oVBoxMgr.waitForEvents(0); 93 oVM = self.createTestVM('test-medium', 1, None, 4) 94 assert oVM is not None 95 96 # create chain with 300 disk images (medium tree depth limit) 97 fRc = True 98 oSession = self.openSession(oVM) 99 for i in range(1, 301): 100 sHddPath = os.path.join(self.sScratchPath, 'Test' + str(i) + '.vdi') 101 if i is 1: 102 oHd = oSession.createBaseHd(sHddPath, cb=1024*1024) 103 else: 104 oHd = oSession.createDiffHd(oHd, sHddPath) 105 if oHd is None: 106 fRc = False 107 break 108 109 # modify the VM config, attach HDD 110 fRc = fRc and oSession.attachHd(sHddPath, sController='SATA Controller', fImmutable=False, fForceResource=False) 111 fRc = fRc and oSession.saveSettings() 112 fRc = oSession.close() and fRc 113 114 # unregister and re-register to test loading of settings 115 sSettingsFile = oVM.settingsFilePath 116 reporter.log('unregistering VM') 117 oVM.unregister(vboxcon.CleanupMode_DetachAllReturnNone) 118 oVBox = self.oVBoxMgr.getVirtualBox() 119 reporter.log('opening VM %s, testing config reading' % (sSettingsFile)) 120 oVM = oVBox.openMachine(sSettingsFile) 121 122 assert fRc is True 89 123 except: 90 return True; 91 reporter.error('waitForEvents() returned "%s" when called on a worker thread, expected exception.' % (rc2,)); 92 return False; 124 reporter.errorXcpt() 93 125 94 def testEventQueueWaiting(self): 126 return reporter.testDone()[1] == 0 127 128 def testSnapshotTreeDepth(self): 95 129 """ 96 Test event queue waiting.130 Test snapshot tree depth. 97 131 """ 98 reporter.testStart(' waitForEvents');132 reporter.testStart('snapshotTreeDepth') 99 133 100 # Check return values and such. 101 for cMsTimeout in (0, 1, 2, 3, 256, 1000, 0): 102 iLoop = 0; 103 while True: 104 try: 105 rc = self.oVBoxMgr.waitForEvents(cMsTimeout); 106 except: 107 reporter.errorXcpt(); 108 break; 109 if not isinstance(rc, types.IntType): 110 reporter.error('waitForEvents returns non-integer type'); 111 break; 112 if rc == 1: 113 break; 114 if rc != 0: 115 reporter.error('waitForEvents returns "%s", expected 0 or 1' % (rc,)); 116 break; 117 iLoop += 1; 118 if iLoop > 10240: 119 reporter.error('waitForEvents returns 0 (success) %u times. ' 120 'Expected 1 (timeout/interrupt) after a call or two.' 121 % (iLoop,)); 122 break; 123 if reporter.testErrorCount() != 0: 124 break; 134 try: 135 oVM = self.createTestVM('test-snap', 1, None, 4) 136 assert oVM is not None 125 137 126 # Check that we get an exception when trying to call the method from 127 # a different thread. 128 reporter.log('If running a debug build, you will see an ignored assertion now. Please ignore it.') 129 sVBoxAssertSaved = os.environ.get('VBOX_ASSERT', 'breakpoint'); 130 os.environ['VBOX_ASSERT'] = 'ignore'; 131 oThread = threading.Thread(target=self.testEventQueueWaitingThreadProc); 132 oThread.start(); 133 oThread.join(); 134 os.environ['VBOX_ASSERT'] = sVBoxAssertSaved; 138 # modify the VM config, create and attach empty HDD 139 oSession = self.openSession(oVM) 140 sHddPath = os.path.join(self.sScratchPath, 'TestSnapEmpty.vdi') 141 fRc = True 142 fRc = fRc and oSession.createAndAttachHd(sHddPath, cb=1024*1024, sController='SATA Controller', fImmutable=False) 143 fRc = fRc and oSession.saveSettings() 135 144 136 return reporter.testDone()[1] == 0; 145 # take 250 snapshots (snapshot tree depth limit) 146 for i in range(1, 251): 147 fRc = fRc and oSession.takeSnapshot('Snapshot ' + str(i)) 148 fRc = oSession.close() and fRc 137 149 138 def interruptWaitEventsThreadProc(self): 139 """ Thread procedure that's used for waking up the main thread. """ 140 time.sleep(2); 141 try: 142 rc2 = self.oVBoxMgr.interruptWaitEvents(); 150 # unregister and re-register to test loading of settings 151 sSettingsFile = oVM.settingsFilePath 152 reporter.log('unregistering VM') 153 oVM.unregister(vboxcon.CleanupMode_DetachAllReturnNone) 154 oVBox = self.oVBoxMgr.getVirtualBox() 155 reporter.log('opening VM %s, testing config reading' % (sSettingsFile)) 156 oVM = oVBox.openMachine(sSettingsFile) 157 158 assert fRc is True 143 159 except: 144 reporter.errorXcpt(); 145 else: 146 if rc2 is True: 147 return True; 148 reporter.error('interruptWaitEvents returned "%s" when called from other thread, expected True' % (rc2,)); 149 return False; 160 reporter.errorXcpt() 150 161 151 def testEventQueueInterrupt(self): 152 """ 153 Test interrupting an event queue wait. 154 """ 155 reporter.testStart('interruptWait'); 156 157 # interrupt ourselves first and check the return value. 158 for i in range(0, 10): 159 try: 160 rc = self.oVBoxMgr.interruptWaitEvents(); 161 except: 162 reporter.errorXcpt(); 163 break; 164 if rc is not True: 165 reporter.error('interruptWaitEvents returned "%s" expected True' % (rc,)); 166 break 167 168 if reporter.testErrorCount() == 0: 169 # 170 # Interrupt a waitForEvents call. 171 # 172 # This test ASSUMES that no other events are posted to the thread's 173 # event queue once we've drained it. Also ASSUMES the box is 174 # relatively fast and not too busy because we're timing sensitive. 175 # 176 for i in range(0, 4): 177 # Try quiesce the event queue. 178 for _ in range(1, 100): 179 self.oVBoxMgr.waitForEvents(0); 180 181 # Create a thread that will interrupt us in 2 seconds. 182 try: 183 oThread = threading.Thread(target=self.interruptWaitEventsThreadProc); 184 oThread.setDaemon(False); 185 except: 186 reporter.errorXcpt(); 187 break; 188 189 cMsTimeout = 20000; 190 if i == 2: 191 cMsTimeout = -1; 192 elif i == 3: 193 cMsTimeout = -999999; 194 195 # Do the wait. 196 oThread.start(); 197 msNow = base.timestampMilli(); 198 try: 199 rc = self.oVBoxMgr.waitForEvents(cMsTimeout); 200 except: 201 reporter.errorXcpt(); 202 else: 203 msElapsed = base.timestampMilli() - msNow; 204 205 # Check the return code and elapsed time. 206 if not isinstance(rc, types.IntType): 207 reporter.error('waitForEvents returns non-integer type after %u ms, expected 1' % (msElapsed,)); 208 elif rc != 1: 209 reporter.error('waitForEvents returned "%s" after %u ms, expected 1' % (rc, msElapsed)); 210 if msElapsed > 15000: 211 reporter.error('waitForEvents after %u ms, expected just above 2-3 seconds' % (msElapsed,)); 212 elif msElapsed < 100: 213 reporter.error('waitForEvents after %u ms, expected more than 100 ms.' % (msElapsed,)); 214 215 oThread.join(); 216 oThread = None; 217 if reporter.testErrorCount() != 0: 218 break; 219 reporter.log('Iteration %u was successful...' % (i + 1,)); 220 return reporter.testDone()[1] == 0; 162 return reporter.testDone()[1] == 0 221 163 222 164 223 165 if __name__ == '__main__': 224 sys.exit(td Python1().main(sys.argv));166 sys.exit(tdTreeDepth1().main(sys.argv)) 225 167
Note:
See TracChangeset
for help on using the changeset viewer.