Changeset 72734 in vbox for trunk/src/VBox
- Timestamp:
- Jun 29, 2018 6:59:56 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/tests/api/tdPython1.py
r70816 r72734 39 39 # Only the main script needs to modify the path. 40 40 try: __file__ 41 except: __file__ = sys.argv[0] 42 g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 43 sys.path.append(g_ksValidationKitDir) 41 except: __file__ = sys.argv[0]; 42 g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))); 43 sys.path.append(g_ksValidationKitDir); 44 44 45 45 # Validation Kit imports. 46 from testdriver import base 47 from testdriver import reporter 46 from testdriver import base; 47 from testdriver import reporter; 48 48 49 49 … … 61 61 """ 62 62 return self.testEventQueueWaiting() \ 63 and self.testEventQueueInterrupt() 63 and self.testEventQueueInterrupt(); 64 64 65 65 # … … 70 70 """ Thread procedure for checking that waitForEvents fails when not called by the main thread. """ 71 71 try: 72 rc2 = self.oTstDrv.oVBoxMgr.waitForEvents(0) 72 rc2 = self.oTstDrv.oVBoxMgr.waitForEvents(0); 73 73 except: 74 return True 75 reporter.error('waitForEvents() returned "%s" when called on a worker thread, expected exception.' % (rc2,)) 76 return False 74 return True; 75 reporter.error('waitForEvents() returned "%s" when called on a worker thread, expected exception.' % (rc2,)); 76 return False; 77 77 78 78 def testEventQueueWaiting(self): … … 80 80 Test event queue waiting. 81 81 """ 82 reporter.testStart('waitForEvents') 82 reporter.testStart('waitForEvents'); 83 83 84 84 # Check return values and such. 85 85 for cMsTimeout in (0, 1, 2, 3, 256, 1000, 0): 86 iLoop = 0 86 iLoop = 0; 87 87 while True: 88 88 try: 89 rc = self.oTstDrv.oVBoxMgr.waitForEvents(cMsTimeout) 89 rc = self.oTstDrv.oVBoxMgr.waitForEvents(cMsTimeout); 90 90 except: 91 reporter.errorXcpt() 92 break 91 reporter.errorXcpt(); 92 break; 93 93 if not isinstance(rc, int): 94 reporter.error('waitForEvents returns non-integer type') 95 break 94 reporter.error('waitForEvents returns non-integer type'); 95 break; 96 96 if rc == 1: 97 break 97 break; 98 98 if rc != 0: 99 reporter.error('waitForEvents returns "%s", expected 0 or 1' % (rc,)) 100 break 101 iLoop += 1 99 reporter.error('waitForEvents returns "%s", expected 0 or 1' % (rc,)); 100 break; 101 iLoop += 1; 102 102 if iLoop > 10240: 103 103 reporter.error('waitForEvents returns 0 (success) %u times. ' 104 104 'Expected 1 (timeout/interrupt) after a call or two.' 105 % (iLoop,)) 106 break 105 % (iLoop,)); 106 break; 107 107 if reporter.testErrorCount() != 0: 108 break 108 break; 109 109 110 110 # Check that we get an exception when trying to call the method from 111 111 # a different thread. 112 112 reporter.log('If running a debug build, you will see an ignored assertion now. Please ignore it.') 113 sVBoxAssertSaved = os.environ.get('VBOX_ASSERT', 'breakpoint') 114 os.environ['VBOX_ASSERT'] = 'ignore' 115 oThread = threading.Thread(target=self.testEventQueueWaitingThreadProc) 116 oThread.start() 117 oThread.join() 118 os.environ['VBOX_ASSERT'] = sVBoxAssertSaved 119 120 return reporter.testDone()[1] == 0 113 sVBoxAssertSaved = os.environ.get('VBOX_ASSERT', 'breakpoint'); 114 os.environ['VBOX_ASSERT'] = 'ignore'; 115 oThread = threading.Thread(target=self.testEventQueueWaitingThreadProc); 116 oThread.start(); 117 oThread.join(); 118 os.environ['VBOX_ASSERT'] = sVBoxAssertSaved; 119 120 return reporter.testDone()[1] == 0; 121 121 122 122 def interruptWaitEventsThreadProc(self): 123 123 """ Thread procedure that's used for waking up the main thread. """ 124 time.sleep(2) 124 time.sleep(2); 125 125 try: 126 rc2 = self.oTstDrv.oVBoxMgr.interruptWaitEvents() 126 rc2 = self.oTstDrv.oVBoxMgr.interruptWaitEvents(); 127 127 except: 128 reporter.errorXcpt() 128 reporter.errorXcpt(); 129 129 else: 130 130 if rc2 is True: 131 return True 132 reporter.error('interruptWaitEvents returned "%s" when called from other thread, expected True' % (rc2,)) 133 return False 131 return True; 132 reporter.error('interruptWaitEvents returned "%s" when called from other thread, expected True' % (rc2,)); 133 return False; 134 134 135 135 def testEventQueueInterrupt(self): … … 137 137 Test interrupting an event queue wait. 138 138 """ 139 reporter.testStart('interruptWait') 139 reporter.testStart('interruptWait'); 140 140 141 141 # interrupt ourselves first and check the return value. 142 142 for i in range(0, 10): 143 143 try: 144 rc = self.oTstDrv.oVBoxMgr.interruptWaitEvents() 144 rc = self.oTstDrv.oVBoxMgr.interruptWaitEvents(); 145 145 except: 146 reporter.errorXcpt() 147 break 146 reporter.errorXcpt(); 147 break; 148 148 if rc is not True: 149 reporter.error('interruptWaitEvents returned "%s" expected True' % (rc,)) 149 reporter.error('interruptWaitEvents returned "%s" expected True' % (rc,)); 150 150 break 151 151 … … 161 161 # Try quiesce the event queue. 162 162 for _ in range(1, 100): 163 self.oTstDrv.oVBoxMgr.waitForEvents(0) 163 self.oTstDrv.oVBoxMgr.waitForEvents(0); 164 164 165 165 # Create a thread that will interrupt us in 2 seconds. 166 166 try: 167 oThread = threading.Thread(target=self.interruptWaitEventsThreadProc) 168 oThread.setDaemon(False) 167 oThread = threading.Thread(target=self.interruptWaitEventsThreadProc); 168 oThread.setDaemon(False); 169 169 except: 170 reporter.errorXcpt() 171 break 172 173 cMsTimeout = 20000 170 reporter.errorXcpt(); 171 break; 172 173 cMsTimeout = 20000; 174 174 if i == 2: 175 cMsTimeout = -1 175 cMsTimeout = -1; 176 176 elif i == 3: 177 cMsTimeout = -999999 177 cMsTimeout = -999999; 178 178 179 179 # Do the wait. 180 oThread.start() 181 msNow = base.timestampMilli() 180 oThread.start(); 181 msNow = base.timestampMilli(); 182 182 try: 183 rc = self.oTstDrv.oVBoxMgr.waitForEvents(cMsTimeout) 183 rc = self.oTstDrv.oVBoxMgr.waitForEvents(cMsTimeout); 184 184 except: 185 reporter.errorXcpt() 185 reporter.errorXcpt(); 186 186 else: 187 msElapsed = base.timestampMilli() - msNow 187 msElapsed = base.timestampMilli() - msNow; 188 188 189 189 # Check the return code and elapsed time. 190 190 if not isinstance(rc, int): 191 reporter.error('waitForEvents returns non-integer type after %u ms, expected 1' % (msElapsed,)) 191 reporter.error('waitForEvents returns non-integer type after %u ms, expected 1' % (msElapsed,)); 192 192 elif rc != 1: 193 reporter.error('waitForEvents returned "%s" after %u ms, expected 1' % (rc, msElapsed)) 193 reporter.error('waitForEvents returned "%s" after %u ms, expected 1' % (rc, msElapsed)); 194 194 if msElapsed > 15000: 195 reporter.error('waitForEvents after %u ms, expected just above 2-3 seconds' % (msElapsed,)) 195 reporter.error('waitForEvents after %u ms, expected just above 2-3 seconds' % (msElapsed,)); 196 196 elif msElapsed < 100: 197 reporter.error('waitForEvents after %u ms, expected more than 100 ms.' % (msElapsed,)) 198 199 oThread.join() 200 oThread = None 197 reporter.error('waitForEvents after %u ms, expected more than 100 ms.' % (msElapsed,)); 198 199 oThread.join(); 200 oThread = None; 201 201 if reporter.testErrorCount() != 0: 202 break 203 reporter.log('Iteration %u was successful...' % (i + 1,)) 204 return reporter.testDone()[1] == 0 202 break; 203 reporter.log('Iteration %u was successful...' % (i + 1,)); 204 return reporter.testDone()[1] == 0; 205 205 206 206 207 207 if __name__ == '__main__': 208 sys.path.append(os.path.dirname(os.path.abspath(__file__))) 209 from tdApi1 import tdApi1 210 sys.exit(tdApi1([SubTstDrvPython1]).main(sys.argv)) 211 208 sys.path.append(os.path.dirname(os.path.abspath(__file__))); 209 from tdApi1 import tdApi1; 210 sys.exit(tdApi1([SubTstDrvPython1]).main(sys.argv)); 211
Note:
See TracChangeset
for help on using the changeset viewer.