Changeset 79111 in vbox for trunk/src/VBox/ValidationKit
- Timestamp:
- Jun 13, 2019 12:31:51 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py
r79087 r79111 30 30 __version__ = "$Revision$" 31 31 32 # Disable bitching about too many arguments per function.33 # pylint: disable=too-many-arguments34 35 ## @todo Convert map() usage to a cleaner alternative Python now offers.36 # pylint: disable=bad-builtin37 38 ## @todo Convert the context/test classes into named tuples. Not in the mood right now, so39 # disabling it.40 # pylint: disable=too-few-public-methods41 42 32 # Standard Python imports. 43 33 from array import array … … 45 35 import os 46 36 import random 47 import string # pylint: disable=deprecated-module37 import string 48 38 import struct 49 39 import sys … … 68 58 if sys.version_info[0] >= 3: 69 59 long = int # pylint: disable=redefined-builtin,invalid-name 60 xrange = range; # pylint: disable=redefined-builtin,invalid-name 70 61 71 62 … … 74 65 Class for handling a guest process input/output stream. 75 66 """ 76 def appendStream(self, stream, convertTo ='<b'):67 def appendStream(self, stream, convertTo = '<b'): 77 68 """ 78 69 Appends and converts a byte sequence to this object; … … 83 74 class tdCtxTest(object): 84 75 """ 85 Provides the actual test environment. Should be kept86 as generic as possible.76 Provides the actual test environment. 77 Should be kept as generic as possible. 87 78 """ 88 79 def __init__(self, oSession, oTxsSession, oTestVm): # pylint: disable=unused-argument … … 90 81 self.fRc = False; 91 82 ## IGuest reference. 92 self.oGuest = oSession.o.console.guest; 83 self.oGuest = oSession.o.console.guest; ## @todo may throw shit 93 84 self.oSesison = oSession; 94 85 self.oTxsSesison = oTxsSession; … … 125 116 """ 126 117 Base class for all guest control tests. 118 127 119 Note: This test ASSUMES that working Guest Additions 128 120 were installed and running on the guest to be tested. … … 150 142 sHstFileName = os.path.join(oTstDrv.sScratchPath, sFileName); 151 143 try: 152 oCurTestFile 144 oCurTestFile = open(sHstFileName, "wb"); 153 145 oCurTestFile.write(aData); 154 146 oCurTestFile.close(); 155 reporter.addLogFile(sHstFileName, 'misc/other', sDesc);156 147 except: 157 reporter.error('Unable to create temporary file for "%s"' % sDesc); 158 159 def createSession(self, sName): 148 return reporter.error('Unable to create temporary file for "%s"' % (sDesc,)); 149 return reporter.addLogFile(sHstFileName, 'misc/other', sDesc); 150 151 def createSession(self, sName, fIsError = False): 160 152 """ 161 153 Creates (opens) a guest session. … … 165 157 if sName is None: 166 158 sName = "<untitled>"; 159 160 reporter.log('Creating session "%s" ...' % (sName,)); 167 161 try: 168 reporter.log('Creating session "%s" ...' % (sName,));169 162 self.oGuestSession = self.oTest.oGuest.createSession(self.oCreds.sUser, 170 163 self.oCreds.sPassword, … … 173 166 except: 174 167 # Just log, don't assume an error here (will be done in the main loop then). 175 reporter. logXcpt('Creating a guest session "%s" failed; sUser="%s", pw="%s", sDomain="%s":'176 % (sName, self.oCreds.sUser, self.oCreds.sPassword, self.oCreds.sDomain));168 reporter.maybeErrXcpt(fIsError, 'Creating a guest session "%s" failed; sUser="%s", pw="%s", sDomain="%s":' 169 % (sName, self.oCreds.sUser, self.oCreds.sPassword, self.oCreds.sDomain)); 177 170 return (False, None); 178 171 172 reporter.log('Waiting for session "%s" to start within %dms...' % (sName, self.timeoutMS)); 173 aeWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start, ]; 179 174 try: 180 reporter.log('Waiting for session "%s" to start within %dms...' % (sName, self.timeoutMS)); 181 fWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ]; 182 waitResult = self.oGuestSession.waitForArray(fWaitFor, self.timeoutMS); 175 waitResult = self.oGuestSession.waitForArray(aeWaitFor, self.timeoutMS); 176 183 177 # 184 178 # Be nice to Guest Additions < 4.3: They don't support session handling and … … 187 181 if waitResult not in (vboxcon.GuestSessionWaitResult_Start, vboxcon.GuestSessionWaitResult_WaitFlagNotSupported): 188 182 # Just log, don't assume an error here (will be done in the main loop then). 189 reporter.log('Session did not start successfully, returned wait result: %d' \ 190 % (waitResult,)); 183 reporter.maybeErr(fIsError, 'Session did not start successfully, returned wait result: %d' % (waitResult,)); 191 184 return (False, None); 192 185 reporter.log('Session "%s" successfully started' % (sName,)); 193 186 except: 194 187 # Just log, don't assume an error here (will be done in the main loop then). 195 reporter. logXcpt('Waiting for guest session "%s" (usr=%s;pw=%s;dom=%s) to start failed:'196 % (sName, self.oCreds.sUser, self.oCreds.sPassword, self.oCreds.sDomain,));188 reporter.maybeErrXcpt(fIsError, 'Waiting for guest session "%s" (usr=%s;pw=%s;dom=%s) to start failed:' 189 % (sName, self.oCreds.sUser, self.oCreds.sPassword, self.oCreds.sDomain,)); 197 190 return (False, None); 198 191 else: … … 210 203 return self.oGuestSession; 211 204 212 def closeSession(self ):205 def closeSession(self, fIsError = False): 213 206 """ 214 207 Closes the guest session. 215 208 """ 216 209 if self.oGuestSession is not None: 217 sName = self.oGuestSession.name;218 210 try: 219 reporter.log('Closing session "%s" ...' % (sName,)); 211 sName = self.oGuestSession.name; 212 except: 213 return reporter.errorXcpt(); 214 215 reporter.log('Closing session "%s" ...' % (sName,)); 216 try: 220 217 self.oGuestSession.close(); 221 218 self.oGuestSession = None; 222 219 except: 223 220 # Just log, don't assume an error here (will be done in the main loop then). 224 reporter. logXcpt('Closing guest session "%s" failed:' % (sName,));221 reporter.maybeErrXcpt(fIsError, 'Closing guest session "%s" failed:' % (sName,)); 225 222 return False; 226 223 return True; … … 230 227 Test for copying files from the guest to the host. 231 228 """ 232 def __init__(self, sSrc = "", sDst = "", sUser = None, sPassword = None, aFlags = None):229 def __init__(self, sSrc = "", sDst = "", sUser = None, sPassword = None, fFlags = None): 233 230 tdTestGuestCtrlBase.__init__(self); 234 231 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = None); 235 232 self.sSrc = sSrc; 236 233 self.sDst = sDst; 237 self. aFlags = aFlags;234 self.fFlags = fFlags; 238 235 239 236 class tdTestCopyTo(tdTestGuestCtrlBase): … … 241 238 Test for copying files from the host to the guest. 242 239 """ 243 def __init__(self, sSrc = "", sDst = "", sUser = None, sPassword = None, aFlags = None):240 def __init__(self, sSrc = "", sDst = "", sUser = None, sPassword = None, fFlags = None): 244 241 tdTestGuestCtrlBase.__init__(self); 245 242 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = None); 246 243 self.sSrc = sSrc; 247 244 self.sDst = sDst; 248 self. aFlags = aFlags;245 self.fFlags = fFlags; 249 246 250 247 class tdTestDirCreate(tdTestGuestCtrlBase): … … 252 249 Test for directoryCreate call. 253 250 """ 254 def __init__(self, sDirectory = "", sUser = None, sPassword = None, fMode = 0, aFlags = None):251 def __init__(self, sDirectory = "", sUser = None, sPassword = None, fMode = 0, fFlags = None): 255 252 tdTestGuestCtrlBase.__init__(self); 256 253 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = None); 257 254 self.sDirectory = sDirectory; 258 255 self.fMode = fMode; 259 self. aFlags = aFlags;256 self.fFlags = fFlags; 260 257 261 258 class tdTestDirCreateTemp(tdTestGuestCtrlBase): … … 275 272 Test for the directoryOpen call. 276 273 """ 277 def __init__(self, sDirectory = "", sUser = None, sPassword = None, 278 sFilter = "", aFlags = None): 274 def __init__(self, sDirectory = "", sUser = None, sPassword = None, sFilter = "", fFlags = None): 279 275 tdTestGuestCtrlBase.__init__(self); 280 276 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = None); 281 277 self.sDirectory = sDirectory; 282 278 self.sFilter = sFilter; 283 self. aFlags = aFlags or [];279 self.fFlags = fFlags or []; 284 280 285 281 class tdTestDirRead(tdTestDirOpen): … … 288 284 """ 289 285 def __init__(self, sDirectory = "", sUser = None, sPassword = None, 290 sFilter = "", aFlags = None):291 tdTestDirOpen.__init__(self, sDirectory, sUser, sPassword, sFilter, aFlags);286 sFilter = "", fFlags = None): 287 tdTestDirOpen.__init__(self, sDirectory, sUser, sPassword, sFilter, fFlags); 292 288 293 289 class tdTestExec(tdTestGuestCtrlBase): … … 296 292 Has a default timeout of 5 minutes (for safety). 297 293 """ 298 def __init__(self, sCmd = "", aArgs = None, aEnv = None, \ 299 aFlags = None, timeoutMS = 5 * 60 * 1000, \ 300 sUser = None, sPassword = None, sDomain = None, \ 301 fWaitForExit = True): 294 def __init__(self, sCmd = "", aArgs = None, aEnv = None, fFlags = None, # pylint: disable=too-many-arguments 295 timeoutMS = 5 * 60 * 1000, sUser = None, sPassword = None, sDomain = None, fWaitForExit = True): 302 296 tdTestGuestCtrlBase.__init__(self); 303 297 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain); … … 305 299 self.aArgs = aArgs if aArgs is not None else [sCmd,]; 306 300 self.aEnv = aEnv; 307 self. aFlags = aFlags or [];301 self.fFlags = fFlags or []; 308 302 self.timeoutMS = timeoutMS; 309 303 self.fWaitForExit = fWaitForExit; … … 365 359 Tests reading from guest files. 366 360 """ 367 def __init__(self, sFile = "", sUser = None, sPassword = None, 368 sOpenMode = "r", sDisposition = "", 369 sSharingMode = "", 370 lCreationMode = 0, cbOffset = 0, cbToReadWrite = 0, 371 aBuf = None): 361 def __init__(self, sFile = "", sUser = None, sPassword = None, sOpenMode = "r", # pylint: disable=too-many-arguments 362 sDisposition = "", sSharingMode = "", fCreationMode = 0, offFile = 0, cbToReadWrite = 0, abBuf = None): 372 363 tdTestGuestCtrlBase.__init__(self); 373 364 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = None); … … 376 367 self.sDisposition = sDisposition; 377 368 self.sSharingMode = sSharingMode; 378 self.lCreationMode = lCreationMode; 379 self.cbOffset = cbOffset; ## r=bird: Wrong prefix. Just 'off' will suffice, alternatively 'offFile'. 380 ## 'cbOffset' looks like sizeof(offFile), which is probably 8 bytes these days. :-) 369 self.fCreationMode = fCreationMode; 370 self.offFile = offFile; 381 371 self.cbToReadWrite = cbToReadWrite; 382 self.a Buf = aBuf;372 self.abBuf = abBuf; 383 373 384 374 def getOpenAction(self): … … 411 401 tdTestGuestCtrlBase.__init__(self); 412 402 self.sSessionName = sSessionName; 413 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain);403 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain); 414 404 415 405 def getSessionCount(self, oVBoxMgr): … … 420 410 if self.oTest.oGuest is None: 421 411 return 0; 422 aoSession = oVBoxMgr.getArray(self.oTest.oGuest, 'sessions') 412 try: 413 aoSession = oVBoxMgr.getArray(self.oTest.oGuest, 'sessions') 414 except: 415 reporter.errorXcpt('sSessionName: %s' % (self.sSessionName,)); 416 return 0; 423 417 return len(aoSession); 424 418 … … 452 446 fRc = self.executeSteps(oTstDrv, oCurSession, sMsgPrefix); 453 447 except: 454 reporter.errorXcpt('%s: Unexpected exception executing test steps' % (sMsgPrefix,)); 455 fRc = False; 456 457 fRc2 = self.closeSession(); 448 fRc = reporter.errorXcpt('%s: Unexpected exception executing test steps' % (sMsgPrefix,)); 449 450 # 451 # Close the session. 452 # 453 fRc2 = self.closeSession(True); 458 454 if fRc2 is False: 459 reporter.error('%s: Session could not be closed' % (sMsgPrefix,)); 460 fRc = False; 455 fRc = reporter.error('%s: Session could not be closed' % (sMsgPrefix,)); 461 456 else: 462 reporter.error('%s: Session creation failed' % (sMsgPrefix,)); 463 fRc = False; 457 fRc = reporter.error('%s: Session creation failed' % (sMsgPrefix,)); 464 458 return fRc; 465 459 … … 475 469 pass; 476 470 elif fRc2 is None: 477 reporter.log(' skipping remaining %d steps' % (len(self.aoSteps) - i - 1,));471 reporter.log('%s: skipping remaining %d steps' % (sMsgPrefix, len(self.aoSteps) - i - 1,)); 478 472 break; 479 473 else: … … 489 483 for (i, oCurTest) in enumerate(aoTests): 490 484 try: 491 fRc2 = oCurTest.execute(oTstDrv, oVmSession, oTxsSession, oTestVm, '%s , test%#d' % (sMsgPrefix, i,));485 fRc2 = oCurTest.execute(oTstDrv, oVmSession, oTxsSession, oTestVm, '%s / %#d' % (sMsgPrefix, i,)); 492 486 if fRc2 is not True: 493 487 fRc = False; 494 488 except: 495 reporter.errorXcpt('Unexpected exception executing test #%d' % (i,)); 496 fRc = False; 489 fRc = reporter.errorXcpt('%s: Unexpected exception executing test #%d' % (sMsgPrefix, i ,)); 497 490 498 491 return (fRc, oTxsSession); … … 512 505 Returns None if to skip the remaining steps. 513 506 """ 514 reporter.error('%s: Missing execute implementation: %s' % (sMsgPrefix, self,));515 507 _ = oTstDrv; 516 508 _ = oGstCtrlSession; 517 return False;509 return reporter.error('%s: Missing execute implementation: %s' % (sMsgPrefix, self,)); 518 510 519 511 … … 563 555 if vbox.ComError.equal(oXcpt, self.hrcExpected): 564 556 return True; 565 reporter.errorXcpt('%s: Expected hrc=%#x (%s) got %#x (%s) instead (setenv %s=%s)' 566 % (sMsgPrefix, self.hrcExpected, vbox.ComError.toString(self.hrcExpected), 567 vbox.ComError.getXcptResult(oXcpt), 568 vbox.ComError.toString(vbox.ComError.getXcptResult(oXcpt)), 569 self.sVar, self.sValue,)); 570 return False; 557 return reporter.errorXcpt('%s: Expected hrc=%#x (%s) got %#x (%s) instead (setenv %s=%s)' 558 % (sMsgPrefix, self.hrcExpected, vbox.ComError.toString(self.hrcExpected), 559 vbox.ComError.getXcptResult(oXcpt), 560 vbox.ComError.toString(vbox.ComError.getXcptResult(oXcpt)), 561 self.sVar, self.sValue,)); 571 562 except: 572 reporter.errorXcpt('%s: Unexpected exception in tdStepSessionSetEnv::execute (%s=%s)' 573 % (sMsgPrefix, self.sVar, self.sValue,)); 574 return False; 563 return reporter.errorXcpt('%s: Unexpected exception in tdStepSessionSetEnv::execute (%s=%s)' 564 % (sMsgPrefix, self.sVar, self.sValue,)); 575 565 576 566 # Should we succeed? 577 567 if self.hrcExpected != 0: 578 reporter.error('%s: Expected hrcExpected=%#x, got S_OK (putenv %s=%s)' 579 % (sMsgPrefix, self.hrcExpected, self.sVar, self.sValue,)); 580 return False; 568 return reporter.error('%s: Expected hrcExpected=%#x, got S_OK (putenv %s=%s)' 569 % (sMsgPrefix, self.hrcExpected, self.sVar, self.sValue,)); 581 570 return True; 582 571 … … 604 593 if vbox.ComError.equal(oXcpt, self.hrcExpected): 605 594 return True; 606 reporter.errorXcpt('%s: Expected hrc=%#x (%s) got %#x (%s) instead (unsetenv %s)' 607 % (sMsgPrefix, self.hrcExpected, vbox.ComError.toString(self.hrcExpected), 608 vbox.ComError.getXcptResult(oXcpt), 609 vbox.ComError.toString(vbox.ComError.getXcptResult(oXcpt)), 610 self.sVar,)); 611 return False; 595 return reporter.errorXcpt('%s: Expected hrc=%#x (%s) got %#x (%s) instead (unsetenv %s)' 596 % (sMsgPrefix, self.hrcExpected, vbox.ComError.toString(self.hrcExpected), 597 vbox.ComError.getXcptResult(oXcpt), 598 vbox.ComError.toString(vbox.ComError.getXcptResult(oXcpt)), 599 self.sVar,)); 612 600 except: 613 reporter.errorXcpt('%s: Unexpected exception in tdStepSessionUnsetEnv::execute (%s)' 614 % (sMsgPrefix, self.sVar,)); 615 return False; 601 return reporter.errorXcpt('%s: Unexpected exception in tdStepSessionUnsetEnv::execute (%s)' 602 % (sMsgPrefix, self.sVar,)); 616 603 617 604 # Should we succeed? 618 605 if self.hrcExpected != 0: 619 reporter.error('%s: Expected hrcExpected=%#x, got S_OK (unsetenv %s)' 620 % (sMsgPrefix, self.hrcExpected, self.sVar,)); 621 return False; 606 return reporter.error('%s: Expected hrcExpected=%#x, got S_OK (unsetenv %s)' 607 % (sMsgPrefix, self.hrcExpected, self.sVar,)); 622 608 return True; 623 609 … … 645 631 if vbox.ComError.equal(oXcpt, self.hrcExpected): 646 632 return True; 647 reporter.errorXcpt('%s: Expected hrc=%#x (%s) got %#x (%s) instead (asEnv=%s)' 648 % (sMsgPrefix, self.hrcExpected, vbox.ComError.toString(self.hrcExpected), 649 vbox.ComError.getXcptResult(oXcpt), 650 vbox.ComError.toString(vbox.ComError.getXcptResult(oXcpt)), 651 self.asEnv,)); 652 return False; 633 return reporter.errorXcpt('%s: Expected hrc=%#x (%s) got %#x (%s) instead (asEnv=%s)' 634 % (sMsgPrefix, self.hrcExpected, vbox.ComError.toString(self.hrcExpected), 635 vbox.ComError.getXcptResult(oXcpt), 636 vbox.ComError.toString(vbox.ComError.getXcptResult(oXcpt)), 637 self.asEnv,)); 653 638 except: 654 reporter.errorXcpt('%s: Unexpected exception writing the environmentChanges property (asEnv=%s).' 655 % (sMsgPrefix, self.asEnv)); 656 return False; 639 return reporter.errorXcpt('%s: Unexpected exception writing the environmentChanges property (asEnv=%s).' 640 % (sMsgPrefix, self.asEnv)); 657 641 return True; 658 642 … … 688 672 asCurEnv = oTstDrv.oVBoxMgr.getArray(oGstCtrlSession, 'environment'); 689 673 except: 690 reporter.errorXcpt('%s: Unexpected exception reading the environmentChanges property.' % (sMsgPrefix,)); 691 return False; 674 return reporter.errorXcpt('%s: Unexpected exception reading the environmentChanges property.' % (sMsgPrefix,)); 692 675 693 676 # … … 701 684 asCopy.remove(sExpected); 702 685 except: 703 reporter.error('%s: Expected "%s" to be in the resulting environment' % (sMsgPrefix, sExpected,)); 704 fRc = False; 686 fRc = reporter.error('%s: Expected "%s" to be in the resulting environment' % (sMsgPrefix, sExpected,)); 705 687 for sUnexpected in asCopy: 706 reporter.error('%s: Unexpected "%s" in the resulting environment' % (sMsgPrefix, sUnexpected,)); 707 fRc = False; 688 fRc = reporter.error('%s: Unexpected "%s" in the resulting environment' % (sMsgPrefix, sUnexpected,)); 708 689 709 690 if fRc is not True: … … 852 833 Test updating the Guest Additions inside the guest. 853 834 """ 854 def __init__(self, sSrc = "", aArgs = None, aFlags = None,835 def __init__(self, sSrc = "", aArgs = None, fFlags = None, 855 836 sUser = None, sPassword = None, sDomain = None): 856 837 tdTestGuestCtrlBase.__init__(self); … … 858 839 self.sSrc = sSrc; 859 840 self.aArgs = aArgs; 860 self. aFlags = aFlags;841 self.fFlags = fFlags; 861 842 862 843 class tdTestResult(object): … … 881 862 """ 882 863 Holds a guest process execution test result, 883 including the exit code, status + aFlags.864 including the exit code, status + fFlags. 884 865 """ 885 866 def __init__(self, fRc = False, \ … … 916 897 """ 917 898 def __init__(self, fRc = False, 918 cbProcessed = 0, cbOffset = 0, aBuf = None):899 cbProcessed = 0, offFile = 0, abBuf = None): 919 900 tdTestResult.__init__(self, fRc = fRc); 920 901 self.cbProcessed = cbProcessed; 921 self. cbOffset = cbOffset;922 self.a Buf = aBuf;902 self.offFile = offFile; 903 self.abBuf = abBuf; 923 904 924 905 class tdTestResultSession(tdTestResult): … … 1103 1084 return (fRc, oTxsSession); 1104 1085 1105 def gctrlCopyFileFrom(self, oGuestSession, sSrc, sDst, aFlags):1086 def gctrlCopyFileFrom(self, oGuestSession, sSrc, sDst, fFlags, fExpected): 1106 1087 """ 1107 1088 Helper function to copy a single file from the guest to the host. 1089 """ 1090 reporter.log2('Copying guest file "%s" to host "%s"' % (sSrc, sDst)); 1091 try: 1092 if self.oTstDrv.fpApiVer >= 5.0: 1093 oCurProgress = oGuestSession.fileCopyFromGuest(sSrc, sDst, fFlags); 1094 else: 1095 oCurProgress = oGuestSession.copyFrom(sSrc, sDst, fFlags); 1096 except: 1097 reporter.maybeErrXcpt(fExpected, 'Copy from exception for sSrc="%s", sDst="%s":' % (sSrc, sDst,)); 1098 return False; 1099 if oCurProgress is None: 1100 return reporter.error('No progress object returned'); 1101 oProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, "gctrlFileCopyFrom"); 1102 oProgress.wait(); 1103 if not oProgress.isSuccess(): 1104 oProgress.logResult(fIgnoreErrors = not fExpected); 1105 return False; 1106 return True; 1107 1108 def gctrlCopyDirFrom(self, oGuestSession, sSrc, sDst, fFlags, fExpected): 1109 """ 1110 Helper function to copy a directory from the guest to the host. 1111 """ 1112 reporter.log2('Copying guest dir "%s" to host "%s"' % (sSrc, sDst)); 1113 try: 1114 oCurProgress = oGuestSession.directoryCopyFromGuest(sSrc, sDst, fFlags); 1115 except: 1116 reporter.maybeErrXcpt(fExpected, 'Copy dir from exception for sSrc="%s", sDst="%s":' % (sSrc, sDst,)); 1117 return False; 1118 if oCurProgress is None: 1119 return reporter.error('No progress object returned'); 1120 1121 oProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, "gctrlDirCopyFrom"); 1122 oProgress.wait(); 1123 if not oProgress.isSuccess(): 1124 oProgress.logResult(fIgnoreErrors = not fExpected); 1125 return False; 1126 return True; 1127 1128 def gctrlCopyFileTo(self, oGuestSession, sSrc, sDst, fFlags): 1129 """ 1130 Helper function to copy a single file from host to the guest. 1108 1131 """ 1109 1132 fRc = True; # Be optimistic. 1110 1133 try: 1111 reporter.log2('Copying guest file "%s" to host "%s"' % (sSrc, sDst));1134 reporter.log2('Copying host file "%s" to guest "%s" (flags %s)' % (sSrc, sDst, fFlags)); 1112 1135 if self.oTstDrv.fpApiVer >= 5.0: 1113 curProgress = oGuestSession.fileCopyFromGuest(sSrc, sDst, aFlags);1136 oCurProgress = oGuestSession.fileCopyToGuest(sSrc, sDst, fFlags); 1114 1137 else: 1115 curProgress = oGuestSession.copyFrom(sSrc, sDst, aFlags); 1116 if curProgress is not None: 1117 oProgress = vboxwrappers.ProgressWrapper(curProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, "gctrlFileCopyFrom"); 1118 try: 1119 oProgress.wait(); 1120 if not oProgress.isSuccess(): 1121 oProgress.logResult(fIgnoreErrors = True); 1122 fRc = False; 1123 except: 1124 reporter.logXcpt('Waiting exception for sSrc="%s", sDst="%s":' % (sSrc, sDst)); 1125 fRc = False; 1126 else: 1127 reporter.error('No progress object returned'); 1128 fRc = False; 1129 except: 1130 # Just log, don't assume an error here (will be done in the main loop then). 1131 reporter.logXcpt('Copy from exception for sSrc="%s", sDst="%s":' % (sSrc, sDst)); 1132 fRc = False; 1133 1134 return fRc; 1135 1136 def gctrlCopyFileTo(self, oGuestSession, sSrc, sDst, aFlags): 1137 """ 1138 Helper function to copy a single file from host to the guest. 1139 """ 1140 fRc = True; # Be optimistic. 1141 try: 1142 reporter.log2('Copying host file "%s" to guest "%s" (flags %s)' % (sSrc, sDst, aFlags)); 1143 if self.oTstDrv.fpApiVer >= 5.0: 1144 curProgress = oGuestSession.fileCopyToGuest(sSrc, sDst, aFlags); 1145 else: 1146 curProgress = oGuestSession.copyTo(sSrc, sDst, aFlags); 1147 if curProgress is not None: 1148 oProgress = vboxwrappers.ProgressWrapper(curProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, "gctrlCopyFileTo"); 1138 oCurProgress = oGuestSession.copyTo(sSrc, sDst, fFlags); 1139 if oCurProgress is not None: 1140 oProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, "gctrlCopyFileTo"); 1149 1141 try: 1150 1142 oProgress.wait(); … … 1175 1167 try: 1176 1168 oGuestSession.directoryCreate(oTest.sDirectory, \ 1177 oTest.fMode, oTest. aFlags);1169 oTest.fMode, oTest.fFlags); 1178 1170 if self.oTstDrv.fpApiVer >= 5.0: 1179 1171 fDirExists = oGuestSession.directoryExists(oTest.sDirectory, False); … … 1200 1192 sDir = oTest.sDirectory; 1201 1193 sFilter = oTest.sFilter; 1202 aFlags = oTest.aFlags;1194 fFlags = oTest.fFlags; 1203 1195 1204 1196 fRc = True; # Be optimistic. … … 1208 1200 try: 1209 1201 sCurDir = os.path.join(sDir, subDir); 1210 #reporter.log2('Directory="%s", filter="%s", aFlags="%s"' % (sCurDir, sFilter, aFlags));1211 oCurDir = oGuestSession.directoryOpen(sCurDir, sFilter, aFlags);1202 #reporter.log2('Directory="%s", filter="%s", fFlags="%s"' % (sCurDir, sFilter, fFlags)); 1203 oCurDir = oGuestSession.directoryOpen(sCurDir, sFilter, fFlags); 1212 1204 while fRc: 1213 1205 try: … … 1303 1295 #tsStart = base.timestampMilli(); 1304 1296 1305 reporter.log2('Using session user=%s, sDomain=%s, name=%s, timeout=%d' \ 1306 % (oGuestSession.user, oGuestSession.domain, \ 1307 oGuestSession.name, oGuestSession.timeout)); 1308 reporter.log2('Executing sCmd=%s, aFlags=%s, timeoutMS=%d, aArgs=%s, aEnv=%s' \ 1309 % (oTest.sCmd, oTest.aFlags, oTest.timeoutMS, \ 1310 oTest.aArgs, oTest.aEnv)); 1297 reporter.log2('Using session user=%s, sDomain=%s, name=%s, timeout=%d' 1298 % (oGuestSession.user, oGuestSession.domain, oGuestSession.name, oGuestSession.timeout)); 1299 reporter.log2('Executing sCmd=%s, fFlags=%s, timeoutMS=%d, aArgs=%s, aEnv=%s' 1300 % (oTest.sCmd, oTest.fFlags, oTest.timeoutMS, oTest.aArgs, oTest.aEnv)); 1311 1301 try: 1312 1302 curProc = oGuestSession.processCreate(oTest.sCmd, 1313 1303 oTest.aArgs if self.oTstDrv.fpApiVer >= 5.0 else oTest.aArgs[1:], 1314 oTest.aEnv, oTest. aFlags, oTest.timeoutMS);1304 oTest.aEnv, oTest.fFlags, oTest.timeoutMS); 1315 1305 if curProc is not None: 1316 1306 reporter.log2('Process start requested, waiting for start (%dms) ...' % (oTest.timeoutMS,)); 1317 fWaitFor = [ vboxcon.ProcessWaitForFlag_Start ];1318 waitResult = curProc.waitForArray( fWaitFor, oTest.timeoutMS);1307 aeWaitFor = [ vboxcon.ProcessWaitForFlag_Start ]; 1308 waitResult = curProc.waitForArray(aeWaitFor, oTest.timeoutMS); 1319 1309 reporter.log2('Wait result returned: %d, current process status is: %d' % (waitResult, curProc.status)); 1320 1310 1321 1311 if curProc.status == vboxcon.ProcessStatus_Started: 1322 fWaitFor = [ vboxcon.ProcessWaitForFlag_Terminate ];1323 if vboxcon.ProcessCreateFlag_WaitForStdOut in oTest. aFlags:1324 fWaitFor.append(vboxcon.ProcessWaitForFlag_StdOut);1325 if vboxcon.ProcessCreateFlag_WaitForStdErr in oTest. aFlags:1326 fWaitFor.append(vboxcon.ProcessWaitForFlag_StdErr);1312 aeWaitFor = [ vboxcon.ProcessWaitForFlag_Terminate ]; 1313 if vboxcon.ProcessCreateFlag_WaitForStdOut in oTest.fFlags: 1314 aeWaitFor.append(vboxcon.ProcessWaitForFlag_StdOut); 1315 if vboxcon.ProcessCreateFlag_WaitForStdErr in oTest.fFlags: 1316 aeWaitFor.append(vboxcon.ProcessWaitForFlag_StdErr); 1327 1317 ## @todo Add vboxcon.ProcessWaitForFlag_StdIn. 1328 reporter.log2('Process (PID %d) started, waiting for termination (%dms), waitFlags=%s ...' \1329 % (curProc.PID, oTest.timeoutMS, fWaitFor));1318 reporter.log2('Process (PID %d) started, waiting for termination (%dms), waitFlags=%s ...' 1319 % (curProc.PID, oTest.timeoutMS, aeWaitFor)); 1330 1320 while True: 1331 waitResult = curProc.waitForArray( fWaitFor, oTest.timeoutMS);1321 waitResult = curProc.waitForArray(aeWaitFor, oTest.timeoutMS); 1332 1322 reporter.log2('Wait returned: %d' % (waitResult,)); 1333 1323 try: … … 1355 1345 vboxcon.ProcessWaitResult_Error, 1356 1346 vboxcon.ProcessWaitResult_Timeout,): 1357 reporter.log2('Process (PID %d) reported terminate/error/timeout: %d, status: %d' \1347 reporter.log2('Process (PID %d) reported terminate/error/timeout: %d, status: %d' 1358 1348 % (curProc.PID, waitResult, curProc.status)); 1359 1349 break; … … 1479 1469 return tdTestSessionEx.executeListTestSessions(aoTests, self.oTstDrv, oSession, oTxsSession, oTestVm, 'SessionEnv'); 1480 1470 1481 def testGuestCtrlSession(self, oSession, oTxsSession, oTestVm): # pylint: disable=too-many-locals1471 def testGuestCtrlSession(self, oSession, oTxsSession, oTestVm): 1482 1472 """ 1483 1473 Tests the guest session handling. 1484 1474 """ 1485 1475 1486 aaTests = [ 1476 # 1477 # Parameters. 1478 # 1479 atTests = [ 1487 1480 # Invalid parameters. 1488 1481 [ tdTestSession(sUser = ''), tdTestResultSession() ], … … 1498 1491 [ tdTestSession(sUser = 'foo', sPassword = 'bar', sDomain = 'boo'), tdTestResultSession() ], 1499 1492 # Correct credentials. 1500 [ tdTestSession(), 1501 tdTestResultSession(fRc = True, cNumSessions = 1) ] 1493 [ tdTestSession(), tdTestResultSession(fRc = True, cNumSessions = 1) ] 1502 1494 ]; 1503 1495 1504 # Parameters.1505 1496 fRc = True; 1506 for (i, aTest) in enumerate(aaTests): 1507 curTest = aTest[0]; # tdTestSession, use an index, later. 1508 curRes = aTest[1]; # tdTestResult 1509 curTest.setEnvironment(oSession, oTxsSession, oTestVm); 1510 reporter.log('Testing #%d, user="%s", sPassword="%s", sDomain="%s" ...' \ 1511 % (i, curTest.oCreds.sUser, curTest.oCreds.sPassword, curTest.oCreds.sDomain)); 1512 curGuestSessionName = 'testGuestCtrlSession: Test #%d' % (i); 1513 fRc2, curGuestSession = curTest.createSession(curGuestSessionName); 1497 for (i, tTest) in enumerate(atTests): 1498 oCurTest = tTest[0] # type: tdTestSession 1499 oCurRes = tTest[1] # type: tdTestResult 1500 1501 oCurTest.setEnvironment(oSession, oTxsSession, oTestVm); 1502 reporter.log('Testing #%d, user="%s", sPassword="%s", sDomain="%s" ...' 1503 % (i, oCurTest.oCreds.sUser, oCurTest.oCreds.sPassword, oCurTest.oCreds.sDomain)); 1504 sCurGuestSessionName = 'testGuestCtrlSession: Test #%d' % (i,); 1505 fRc2, oCurGuestSession = oCurTest.createSession(sCurGuestSessionName, fIsError = oCurRes.fRc); 1506 1514 1507 # See note about < 4.3 Guest Additions above. 1515 if curGuestSession is not None \ 1516 and curGuestSession.protocolVersion >= 2 \ 1517 and fRc2 is not curRes.fRc: 1518 reporter.error('Test #%d failed: Session creation failed: Got %s, expected %s' \ 1519 % (i, fRc2, curRes.fRc)); 1520 fRc = False; 1508 uProtocolVersion = 2; 1509 if oCurGuestSession is not None: 1510 try: 1511 uProtocolVersion = oCurGuestSession.protocolVersion; 1512 except: 1513 fRc = reporter.errorXcpt('Test #%d' % (i,)); 1514 1515 if uProtocolVersion >= 2 and fRc2 is not oCurRes.fRc: 1516 fRc = reporter.error('Test #%d failed: Session creation failed: Got %s, expected %s' % (i, fRc2, oCurRes.fRc,)); 1517 1518 if fRc2 and oCurGuestSession is None: 1519 fRc = reporter.error('Test #%d failed: no session object' % (i,)); 1520 fRc2 = False; 1521 1521 1522 if fRc2: 1522 # On Guest Additions < 4.3 getSessionCount() always will return 1, so skip the 1523 # check then. 1524 if curGuestSession.protocolVersion >= 2: 1525 curSessionCount = curTest.getSessionCount(self.oTstDrv.oVBoxMgr); 1526 if curSessionCount is not curRes.cNumSessions: 1527 reporter.error('Test #%d failed: Session count does not match: Got %d, expected %d' \ 1528 % (i, curSessionCount, curRes.cNumSessions)); 1529 fRc = False; 1530 break; 1531 if curGuestSession is not None \ 1532 and curGuestSession.name != curGuestSessionName: 1533 reporter.error('Test #%d failed: Session name does not match: Got "%s", expected "%s"' \ 1534 % (i, curGuestSession.name, curGuestSessionName)); 1535 fRc = False; 1536 break; 1537 fRc2 = curTest.closeSession(); 1523 if uProtocolVersion >= 2: # For Guest Additions < 4.3 getSessionCount() always will return 1. 1524 cCurSessions = oCurTest.getSessionCount(self.oTstDrv.oVBoxMgr); 1525 if cCurSessions != oCurRes.cNumSessions: 1526 fRc = reporter.error('Test #%d failed: Session count does not match: Got %d, expected %d' 1527 % (i, cCurSessions, oCurRes.cNumSessions)); 1528 try: 1529 sObjName = oCurGuestSession.name; 1530 except: 1531 fRc = reporter.errorXcpt('Test #%d' % (i,)); 1532 else: 1533 if sObjName != sCurGuestSessionName: 1534 fRc = reporter.error('Test #%d failed: Session name does not match: Got "%s", expected "%s"' 1535 % (i, sObjName, sCurGuestSessionName)); 1536 fRc2 = oCurTest.closeSession(True); 1538 1537 if fRc2 is False: 1539 reporter.error('Test #%d failed: Session could not be closed' % (i,)); 1540 fRc = False; 1541 break; 1538 fRc = reporter.error('Test #%d failed: Session could not be closed' % (i,)); 1542 1539 1543 1540 if fRc is False: 1544 1541 return (False, oTxsSession); 1545 1542 1543 # 1546 1544 # Multiple sessions. 1547 iMaxGuestSessions = 31; # Maximum number of concurrent guest session allowed. 1545 # 1546 cMaxGuestSessions = 31; # Maximum number of concurrent guest session allowed. 1548 1547 # Actually, this is 32, but we don't test session 0. 1549 multiSession= {};1548 aoMultiSessions = {}; 1550 1549 reporter.log2('Opening multiple guest tsessions at once ...'); 1551 for i in range(iMaxGuestSessions + 1): 1552 multiSession[i] = tdTestSession(sSessionName = 'MultiSession #%d' % (i,)); 1553 multiSession[i].setEnvironment(oSession, oTxsSession, oTestVm); 1554 curSessionCount = multiSession[i].getSessionCount(self.oTstDrv.oVBoxMgr); 1555 reporter.log2('MultiSession test #%d count is %d' % (i, curSessionCount)); 1556 if curSessionCount is not i: 1557 reporter.error('MultiSession count #%d must be %d, got %d' % (i, i, curSessionCount)); 1558 fRc = False; 1550 for i in xrange(cMaxGuestSessions + 1): 1551 aoMultiSessions[i] = tdTestSession(sSessionName = 'MultiSession #%d' % (i,)); 1552 aoMultiSessions[i].setEnvironment(oSession, oTxsSession, oTestVm); 1553 1554 cCurSessions = aoMultiSessions[i].getSessionCount(self.oTstDrv.oVBoxMgr); 1555 reporter.log2('MultiSession test #%d count is %d' % (i, cCurSessions)); 1556 if cCurSessions != i: 1557 return (reporter.error('MultiSession count is %d, expected %d' % (cCurSessions, i)), oTxsSession); 1558 fRc2, _ = aoMultiSessions[i].createSession('MultiSession #%d' % (i,), i < cMaxGuestSessions); 1559 if fRc2 is not True: 1560 if i < cMaxGuestSessions: 1561 return (reporter.error('MultiSession #%d test failed' % (i,)), oTxsSession); 1562 reporter.log('MultiSession #%d exceeded concurrent guest session count, good' % (i,)); 1559 1563 break; 1560 fRc2, _ = multiSession[i].createSession('MultiSession #%d' % (i,)); 1561 if fRc2 is not True: 1562 if i < iMaxGuestSessions: 1563 reporter.error('MultiSession #%d test failed' % (i,)); 1564 fRc = False; 1565 else: 1566 reporter.log('MultiSession #%d exceeded concurrent guest session count, good' % (i,)); 1567 break; 1568 1569 curSessionCount = multiSession[i].getSessionCount(self.oTstDrv.oVBoxMgr); 1570 if curSessionCount is not iMaxGuestSessions: 1571 reporter.error('Final MultiSession count must be %d, got %d' 1572 % (iMaxGuestSessions, curSessionCount)); 1573 return (False, oTxsSession); 1564 1565 cCurSessions = aoMultiSessions[i].getSessionCount(self.oTstDrv.oVBoxMgr); 1566 if cCurSessions is not cMaxGuestSessions: 1567 return (reporter.error('Final session count %d, expected %d ' % (cCurSessions, cMaxGuestSessions,)), oTxsSession); 1574 1568 1575 1569 reporter.log2('Closing MultiSessions ...'); 1576 iLastSession = iMaxGuestSessions - 1; 1577 for i in range(iLastSession): # Close all but the last opened session. 1578 fRc2 = multiSession[i].closeSession(); 1579 reporter.log2('MultiSession #%d count is %d' % (i, multiSession[i].getSessionCount(self.oTstDrv.oVBoxMgr),)); 1570 for i in xrange(cMaxGuestSessions): 1571 # Close this session: 1572 oClosedGuestSession = aoMultiSessions[i].oGuestSession; 1573 fRc2 = aoMultiSessions[i].closeSession(True); 1574 cCurSessions = aoMultiSessions[i].getSessionCount(self.oTstDrv.oVBoxMgr) 1575 reporter.log2('MultiSession #%d count is %d' % (i, cCurSessions,)); 1580 1576 if fRc2 is False: 1581 reporter.error('Closing MultiSession #%d failed' % (i,)); 1582 fRc = False; 1583 break; 1584 curSessionCount = multiSession[i].getSessionCount(self.oTstDrv.oVBoxMgr); 1585 if curSessionCount != 1: 1586 reporter.error('Final MultiSession count #2 must be 1, got %d' % (curSessionCount,)); 1587 fRc = False; 1588 1589 try: 1590 # r=bird: multiSession[0].oGuestSession is None! Why don't you just use 'assert' or 'if' to check 1591 # the functioning of the __testcase__? 1592 1593 # Make sure that accessing the first opened guest session does not work anymore because we just removed (closed) it. 1594 curSessionName = multiSession[0].oGuestSession.name; 1595 reporter.error('Accessing first removed MultiSession should not be possible, got name="%s"' % (curSessionName,)); 1596 fRc = False; 1597 except: 1598 reporter.logXcpt('Could not access first removed MultiSession object, good:'); 1599 1600 try: 1601 # Try Accessing last opened session which did not get removed yet. 1602 curSessionName = multiSession[iLastSession].oGuestSession.name; 1603 reporter.log('Accessing last standing MultiSession worked, got name="%s"' % (curSessionName,)); 1604 multiSession[iLastSession].closeSession(); 1605 curSessionCount = multiSession[i].getSessionCount(self.oTstDrv.oVBoxMgr); 1606 if curSessionCount != 0: 1607 reporter.error('Final MultiSession count #3 must be 0, got %d' % (curSessionCount,)); 1608 fRc = False; 1609 except: 1610 reporter.logXcpt('Could not access last standing MultiSession object:'); 1611 fRc = False; 1577 fRc = reporter.error('Closing MultiSession #%d failed' % (i,)); 1578 elif cCurSessions != cMaxGuestSessions - (i + 1): 1579 fRc = reporter.error('Expected %d session after closing #%d, got %d instead' 1580 % (cMaxGuestSessions - (i + 1), cCurSessions, i,)); 1581 assert aoMultiSessions[i].oGuestSession is None or not fRc2; 1582 ## @todo any way to check that the session is closed other than the 'sessions' attribute? 1583 1584 # Try check that none of the remaining sessions got closed. 1585 try: 1586 aoGuestSessions = self.oTstDrv.oVBoxMgr.getArray(atTests[0][0].oTest.oGuest, 'sessions'); 1587 except: 1588 return (reporter.errorXcpt('i=%d/%d' % (i, cMaxGuestSessions,)), oTxsSession); 1589 if oClosedGuestSession in aoGuestSessions: 1590 fRc = reporter.error('i=%d/%d: %s should not be in %s' 1591 % (i, cMaxGuestSessions, oClosedGuestSession, aoGuestSessions)); 1592 if i + 1 < cMaxGuestSessions: # Not sure what xrange(2,2) does... 1593 for j in xrange(i + 1, cMaxGuestSessions): 1594 if aoMultiSessions[j].oGuestSession not in aoGuestSessions: 1595 fRc = reporter.error('i=%d/j=%d/%d: %s should be in %s' 1596 % (i, j, cMaxGuestSessions, aoMultiSessions[j].oGuestSession, aoGuestSessions)); 1597 ## @todo any way to check that they work? 1612 1598 1613 1599 ## @todo Test session timeouts. … … 1620 1606 """ 1621 1607 1608 # Find a file to play around with: 1622 1609 if oTestVm.isWindows(): 1623 sFile = "C:\\windows\\system32\\kernel32.dll"; 1624 elif oTestVm.isLinux(): 1610 sFile = "C:\\Windows\\System32\\ntdll.dll"; 1611 if oTestVm.sKind in ['WindowsNT4', 'WindowsNT3x',]: 1612 sFile = "C:\\Winnt\\System32\\ntdll.dll"; 1613 else: 1625 1614 sFile = "/bin/sh"; 1626 1615 … … 1632 1621 cStaleFiles = 10; 1633 1622 1623 # 1624 # Start a session. 1625 # 1626 aeWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ]; 1627 try: 1628 oGuest = oSession.o.console.guest; 1629 oGuestSession = oGuest.createSession(oCreds.sUser, oCreds.sPassword, oCreds.sDomain, "testGuestCtrlSessionFileRefs"); 1630 eWaitResult = oGuestSession.waitForArray(aeWaitFor, 30 * 1000); 1631 except: 1632 return (reporter.errorXcpt(), oTxsSession); 1633 1634 # Be nice to Guest Additions < 4.3: They don't support session handling and therefore return WaitFlagNotSupported. 1635 if eWaitResult not in (vboxcon.GuestSessionWaitResult_Start, vboxcon.GuestSessionWaitResult_WaitFlagNotSupported): 1636 return (reporter.error('Session did not start successfully - wait error: %d' % (eWaitResult,)), oTxsSession); 1637 reporter.log('Session successfully started'); 1638 1639 # 1640 # Open guest files and "forget" them (stale entries). 1641 # For them we don't have any references anymore intentionally. 1642 # 1643 reporter.log2('Opening stale files'); 1644 fRc = True; 1645 for i in xrange(0, cStaleFiles): 1646 try: 1647 if self.oTstDrv.fpApiVer >= 5.0: 1648 oGuestSession.fileOpen(sFile, vboxcon.FileAccessMode_ReadOnly, vboxcon.FileOpenAction_OpenExisting, 0); 1649 else: 1650 oGuestSession.fileOpen(sFile, "r", "oe", 0); 1651 # Note: Use a timeout in the call above for not letting the stale processes 1652 # hanging around forever. This can happen if the installed Guest Additions 1653 # do not support terminating guest processes. 1654 except: 1655 fRc = reporter.errorXcpt('Opening stale file #%d failed:' % (i,)); 1656 break; 1657 1658 try: cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files')); 1659 except: fRc = reporter.errorXcpt(); 1660 else: 1661 if cFiles != cStaleFiles: 1662 fRc = reporter.error('Test failed: Got %d stale files, expected %d' % (cFiles, cStaleFiles)); 1663 1664 if fRc is True: 1665 # 1666 # Open non-stale files and close them again. 1667 # 1668 reporter.log2('Opening non-stale files'); 1669 aoFiles = []; 1670 for i in xrange(0, cStaleFiles): 1671 try: 1672 if self.oTstDrv.fpApiVer >= 5.0: 1673 oCurFile = oGuestSession.fileOpen(sFile, vboxcon.FileAccessMode_ReadOnly, 1674 vboxcon.FileOpenAction_OpenExisting, 0); 1675 else: 1676 oCurFile = oGuestSession.fileOpen(sFile, "r", "oe", 0); 1677 aoFiles.append(oCurFile); 1678 except: 1679 fRc = reporter.errorXcpt('Opening non-stale file #%d failed:' % (i,)); 1680 break; 1681 1682 # Check the count. 1683 try: cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files')); 1684 except: fRc = reporter.errorXcpt(); 1685 else: 1686 if cFiles != cStaleFiles * 2: 1687 fRc = reporter.error('Test failed: Got %d total files, expected %d' % (cFiles, cStaleFiles * 2)); 1688 1689 # Close them. 1690 reporter.log2('Closing all non-stale files again ...'); 1691 for i, oFile in enumerate(aoFiles): 1692 try: 1693 oFile.close(); 1694 except: 1695 fRc = reporter.errorXcpt('Closing non-stale file #%d failed:' % (i,)); 1696 1697 # Check the count again. 1698 try: cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files')); 1699 except: fRc = reporter.errorXcpt(); 1700 # Here we count the stale files (that is, files we don't have a reference 1701 # anymore for) and the opened and then closed non-stale files (that we still keep 1702 # a reference in aoFiles[] for). 1703 if cFiles != cStaleFiles: 1704 fRc = reporter.error('Test failed: Got %d total files, expected %d' % (cFiles, cStaleFiles)); 1705 1706 # 1707 # Check that all (referenced) non-stale files are now in the "closed" state. 1708 # 1709 reporter.log2('Checking statuses of all non-stale files ...'); 1710 for i, oFile in enumerate(aoFiles): 1711 try: 1712 eFileStatus = aoFiles[i].status; 1713 except: 1714 fRc = reporter.errorXcpt('Checking status of file #%d failed:' % (i,)); 1715 else: 1716 if eFileStatus != vboxcon.FileStatus_Closed: 1717 fRc = reporter.error('Test failed: Non-stale file #%d has status %d, expected %d' 1718 % (i, eFileStatus, vboxcon.FileStatus_Closed)); 1719 1720 if fRc is True: 1721 reporter.log2('All non-stale files closed'); 1722 1723 try: cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files')); 1724 except: fRc = reporter.errorXcpt(); 1725 else: reporter.log2('Final guest session file count: %d' % (cFiles,)); 1726 1727 # 1728 # Now try to close the session and see what happens. 1729 # Note! Session closing is why we've been doing all the 'if fRc is True' stuff above rather than returning. 1730 # 1731 reporter.log2('Closing guest session ...'); 1732 try: 1733 oGuestSession.close(); 1734 except: 1735 fRc = reporter.errorXcpt('Testing for stale processes failed:'); 1736 1737 return (fRc, oTxsSession); 1738 1739 #def testGuestCtrlSessionDirRefs(self, oSession, oTxsSession, oTestVm): 1740 # """ 1741 # Tests the guest session directory reference handling. 1742 # """ 1743 1744 # fRc = True; 1745 # return (fRc, oTxsSession); 1746 1747 def testGuestCtrlSessionProcRefs(self, oSession, oTxsSession, oTestVm): # pylint: disable=too-many-locals 1748 """ 1749 Tests the guest session process reference handling. 1750 """ 1751 1752 if oTestVm.isWindows(): 1753 sCmd = "C:\\windows\\system32\\cmd.exe"; 1754 elif oTestVm.isLinux(): 1755 sCmd = "/bin/sh"; 1756 aArgs = [sCmd,]; 1757 1758 # Use credential defaults. 1759 oCreds = tdCtxCreds(); 1760 oCreds.applyDefaultsIfNotSet(oTestVm); 1761 1762 # Number of stale guest processes to create. 1763 cStaleProcs = 10; 1764 1634 1765 fRc = True; 1635 1766 try: 1636 1767 oGuest = oSession.o.console.guest; 1637 oGuestSession = oGuest.createSession(oCreds.sUser, oCreds.sPassword, oCreds.sDomain, "testGuestCtrlSession FileRefs");1638 fWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];1639 waitResult = oGuestSession.waitForArray( fWaitFor, 30 * 1000);1768 oGuestSession = oGuest.createSession(oCreds.sUser, oCreds.sPassword, oCreds.sDomain, "testGuestCtrlSessionProcRefs"); 1769 aeWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ]; 1770 waitResult = oGuestSession.waitForArray(aeWaitFor, 30 * 1000); 1640 1771 # 1641 1772 # Be nice to Guest Additions < 4.3: They don't support session handling and … … 1650 1781 1651 1782 # 1652 # Open guest files and "forget" them (stale entries).1653 # For them we don't have any references anymore intentionally.1654 #1655 reporter.log2('Opening stale files');1656 for i in range(0, cStaleFiles):1657 try:1658 if self.oTstDrv.fpApiVer >= 5.0:1659 oGuestSession.fileOpen(sFile, vboxcon.FileAccessMode_ReadOnly, vboxcon.FileOpenAction_OpenExisting, 0);1660 else:1661 oGuestSession.fileOpen(sFile, "r", "oe", 0);1662 # Note: Use a timeout in the call above for not letting the stale processes1663 # hanging around forever. This can happen if the installed Guest Additions1664 # do not support terminating guest processes.1665 except:1666 reporter.errorXcpt('Opening stale file #%d failed:' % (i,));1667 fRc = False;1668 break;1669 1670 if fRc:1671 cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files'));1672 if cFiles != cStaleFiles:1673 reporter.error('Test failed: Got %d stale files, expected %d' % (cFiles, cStaleFiles));1674 fRc = False;1675 1676 if fRc:1677 #1678 # Open non-stale files and close them again.1679 #1680 reporter.log2('Opening non-stale files');1681 aaFiles = [];1682 for i in range(0, cStaleFiles):1683 try:1684 if self.oTstDrv.fpApiVer >= 5.0:1685 oCurFile = oGuestSession.fileOpen(sFile, vboxcon.FileAccessMode_ReadOnly,1686 vboxcon.FileOpenAction_OpenExisting, 0);1687 else:1688 oCurFile = oGuestSession.fileOpen(sFile, "r", "oe", 0);1689 aaFiles.append(oCurFile);1690 except:1691 reporter.errorXcpt('Opening non-stale file #%d failed:' % (i,));1692 fRc = False;1693 break;1694 if fRc:1695 cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files'));1696 if cFiles != cStaleFiles * 2:1697 reporter.error('Test failed: Got %d total files, expected %d' % (cFiles, cStaleFiles * 2));1698 fRc = False;1699 if fRc:1700 reporter.log2('Closing all non-stale files again ...');1701 for i in range(0, cStaleFiles):1702 try:1703 aaFiles[i].close();1704 except:1705 reporter.errorXcpt('Waiting for non-stale file #%d failed:' % (i,));1706 fRc = False;1707 break;1708 cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files'));1709 # Here we count the stale files (that is, files we don't have a reference1710 # anymore for) and the opened and then closed non-stale files (that we still keep1711 # a reference in aaFiles[] for).1712 if cFiles != cStaleFiles:1713 reporter.error('Test failed: Got %d total files, expected %d' \1714 % (cFiles, cStaleFiles));1715 fRc = False;1716 if fRc:1717 #1718 # Check if all (referenced) non-stale files now are in "closed" state.1719 #1720 reporter.log2('Checking statuses of all non-stale files ...');1721 for i in range(0, cStaleFiles):1722 try:1723 curFilesStatus = aaFiles[i].status;1724 if curFilesStatus != vboxcon.FileStatus_Closed:1725 reporter.error('Test failed: Non-stale file #%d has status %d, expected %d' \1726 % (i, curFilesStatus, vboxcon.FileStatus_Closed));1727 fRc = False;1728 except:1729 reporter.errorXcpt('Checking status of file #%d failed:' % (i,));1730 fRc = False;1731 break;1732 if fRc:1733 reporter.log2('All non-stale files closed');1734 cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files'));1735 reporter.log2('Final guest session file count: %d' % (cFiles,));1736 # Now try to close the session and see what happens.1737 reporter.log2('Closing guest session ...');1738 oGuestSession.close();1739 except:1740 reporter.errorXcpt('Testing for stale processes failed:');1741 fRc = False;1742 1743 return (fRc, oTxsSession);1744 1745 #def testGuestCtrlSessionDirRefs(self, oSession, oTxsSession, oTestVm):1746 # """1747 # Tests the guest session directory reference handling.1748 # """1749 1750 # fRc = True;1751 # return (fRc, oTxsSession);1752 1753 def testGuestCtrlSessionProcRefs(self, oSession, oTxsSession, oTestVm): # pylint: disable=too-many-locals1754 """1755 Tests the guest session process reference handling.1756 """1757 1758 if oTestVm.isWindows():1759 sCmd = "C:\\windows\\system32\\cmd.exe";1760 elif oTestVm.isLinux():1761 sCmd = "/bin/sh";1762 aArgs = [sCmd,];1763 1764 # Use credential defaults.1765 oCreds = tdCtxCreds();1766 oCreds.applyDefaultsIfNotSet(oTestVm);1767 1768 # Number of stale guest processes to create.1769 cStaleProcs = 10;1770 1771 fRc = True;1772 try:1773 oGuest = oSession.o.console.guest;1774 oGuestSession = oGuest.createSession(oCreds.sUser, oCreds.sPassword, oCreds.sDomain, "testGuestCtrlSessionProcRefs");1775 fWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];1776 waitResult = oGuestSession.waitForArray(fWaitFor, 30 * 1000);1777 #1778 # Be nice to Guest Additions < 4.3: They don't support session handling and1779 # therefore return WaitFlagNotSupported.1780 #1781 if waitResult not in (vboxcon.GuestSessionWaitResult_Start, vboxcon.GuestSessionWaitResult_WaitFlagNotSupported):1782 # Just log, don't assume an error here (will be done in the main loop then).1783 reporter.log('Session did not start successfully, returned wait result: %d' \1784 % (waitResult));1785 return (False, oTxsSession);1786 reporter.log('Session successfully started');1787 1788 #1789 1783 # Fire off forever-running processes and "forget" them (stale entries). 1790 1784 # For them we don't have any references anymore intentionally. 1791 1785 # 1792 1786 reporter.log2('Starting stale processes'); 1793 for i in range(0, cStaleProcs):1787 for i in xrange(0, cStaleProcs): 1794 1788 try: 1795 1789 oGuestSession.processCreate(sCmd, … … 1821 1815 reporter.log2('Starting non-stale processes'); 1822 1816 aaProcs = []; 1823 for i in range(0, cStaleProcs):1817 for i in xrange(0, cStaleProcs): 1824 1818 try: 1825 1819 oCurProc = oGuestSession.processCreate(sCmd, aArgs if self.oTstDrv.fpApiVer >= 5.0 else aArgs[1:], … … 1832 1826 if fRc: 1833 1827 reporter.log2('Waiting for non-stale processes to terminate'); 1834 for i in range(0, cStaleProcs):1828 for i in xrange(0, cStaleProcs): 1835 1829 try: 1836 1830 aaProcs[i].waitForArray([ vboxcon.ProcessWaitForFlag_Terminate ], 30 * 1000); … … 1857 1851 # Check if all (referenced) non-stale processes now are in "terminated" state. 1858 1852 # 1859 for i in range(0, cStaleProcs):1853 for i in xrange(0, cStaleProcs): 1860 1854 curProcStatus = aaProcs[i].status; 1861 1855 if aaProcs[i].status != vboxcon.ProcessStatus_TerminatedNormally: … … 1873 1867 reporter.log2('Starting blocking processes'); 1874 1868 aaProcs = []; 1875 for i in range(0, cStaleProcs):1869 for i in xrange(0, cStaleProcs): 1876 1870 try: 1877 1871 oCurProc = oGuestSession.processCreate(sCmd, aArgs if self.oTstDrv.fpApiVer >= 5.0 else aArgs[1:], … … 1887 1881 if fRc: 1888 1882 reporter.log2('Terminating blocking processes'); 1889 for i in range(0, cStaleProcs):1883 for i in xrange(0, cStaleProcs): 1890 1884 try: 1891 1885 aaProcs[i].terminate(); … … 1973 1967 # tdTestResultExec(fRc = True, iExitCode = 1) ] 1974 1968 # [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'set', 'windir' ], 1975 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),1969 # fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]), 1976 1970 # tdTestResultExec(fRc = True, sBuf = 'windir=C:\\WINDOWS\r\n') ], 1977 1971 # [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'set', 'TEST_FOO' ], 1978 1972 # aEnv = [ 'TEST_FOO=BAR' ], 1979 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),1973 # fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]), 1980 1974 # tdTestResultExec(fRc = True, sBuf = 'TEST_FOO=BAR\r\n') ], 1981 1975 # [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'set', 'TEST_FOO' ], 1982 1976 # aEnv = [ 'TEST_FOO=BAR', 'TEST_BAZ=BAR' ], 1983 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),1977 # fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]), 1984 1978 # tdTestResultExec(fRc = True, sBuf = 'TEST_FOO=BAR\r\n') ] 1985 1979 … … 2024 2018 # [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'set', 'windir' ], 2025 2019 # 2026 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),2020 # fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]), 2027 2021 # tdTestResultExec(fRc = True, sBuf = 'windir=C:\\WINDOWS\r\n') ], 2028 2022 # [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'set', 'TEST_FOO' ], 2029 2023 # aEnv = [ 'TEST_FOO=BAR' ], 2030 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),2024 # fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]), 2031 2025 # tdTestResultExec(fRc = True, sBuf = 'TEST_FOO=BAR\r\n') ], 2032 2026 # [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'set', 'TEST_FOO' ], 2033 2027 # aEnv = [ 'TEST_FOO=BAR', 'TEST_BAZ=BAR' ], 2034 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),2028 # fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]), 2035 2029 # tdTestResultExec(fRc = True, sBuf = 'TEST_FOO=BAR\r\n') ] 2036 2030 … … 2054 2048 reporter.log('One session per guest process ...'); 2055 2049 for (i, aTest) in enumerate(aaTests): 2056 curTest = aTest[0]; # tdTestExec, use an index, later.2057 curRes = aTest[1]; # tdTestResultExec2058 curTest.setEnvironment(oSession, oTxsSession, oTestVm);2059 fRc, curGuestSession = curTest.createSession('testGuestCtrlExec: Test #%d' % (i,));2050 oCurTest = aTest[0]; # tdTestExec, use an index, later. 2051 oCurRes = aTest[1]; # tdTestResultExec 2052 oCurTest.setEnvironment(oSession, oTxsSession, oTestVm); 2053 fRc, oCurGuestSession = oCurTest.createSession('testGuestCtrlExec: Test #%d' % (i,)); 2060 2054 if fRc is False: 2061 2055 reporter.error('Test #%d failed: Could not create session' % (i,)); 2062 2056 break; 2063 fRc = self.gctrlExecDoTest(i, curTest, curRes, curGuestSession);2057 fRc = self.gctrlExecDoTest(i, oCurTest, oCurRes, oCurGuestSession); 2064 2058 if fRc is False: 2065 2059 break; 2066 fRc = curTest.closeSession();2060 fRc = oCurTest.closeSession(); 2067 2061 if fRc is False: 2068 2062 break; … … 2091 2085 try: 2092 2086 reporter.log('Creating session for all tests ...'); 2093 curGuestSession = oGuest.createSession(oCreds.sUser, oCreds.sPassword, oCreds.sDomain,2087 oCurGuestSession = oGuest.createSession(oCreds.sUser, oCreds.sPassword, oCreds.sDomain, 2094 2088 'testGuestCtrlExec: One session for all tests'); 2095 2089 try: 2096 fWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];2097 waitResult = curGuestSession.waitForArray(fWaitFor, 30 * 1000);2090 aeWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ]; 2091 waitResult = oCurGuestSession.waitForArray(aeWaitFor, 30 * 1000); 2098 2092 if waitResult not in (vboxcon.GuestSessionWaitResult_Start, vboxcon.GuestSessionWaitResult_WaitFlagNotSupported): 2099 2093 reporter.error('Session did not start successfully, returned wait result: %d' \ … … 2109 2103 # call then. 2110 2104 for (i, aTest) in enumerate(aaTests): 2111 curTest = aTest[0]; # tdTestExec, use an index, later.2112 curRes = aTest[1]; # tdTestResultExec2113 curTest.setEnvironment(oSession, oTxsSession, oTestVm);2114 fRc = self.gctrlExecDoTest(i, curTest, curRes, curGuestSession);2105 oCurTest = aTest[0]; # tdTestExec, use an index, later. 2106 oCurRes = aTest[1]; # tdTestResultExec 2107 oCurTest.setEnvironment(oSession, oTxsSession, oTestVm); 2108 fRc = self.gctrlExecDoTest(i, oCurTest, oCurRes, oCurGuestSession); 2115 2109 if fRc is False: 2116 2110 break; 2117 2111 try: 2118 2112 reporter.log2('Closing guest session ...'); 2119 curGuestSession.close();2120 curGuestSession = None;2113 oCurGuestSession.close(); 2114 oCurGuestSession = None; 2121 2115 except: 2122 2116 # Just log, don't assume an error here (will be done in the main loop then). … … 2178 2172 oGuestSession = oGuest.createSession(oCreds.sUser, oCreds.sPassword, oCreds.sDomain, 'testGuestCtrlExecReboot'); 2179 2173 try: 2180 fWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];2181 waitResult = oGuestSession.waitForArray( fWaitFor, 30 * 1000);2174 aeWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ]; 2175 waitResult = oGuestSession.waitForArray(aeWaitFor, 30 * 1000); 2182 2176 if waitResult not in (vboxcon.GuestSessionWaitResult_Start, vboxcon.GuestSessionWaitResult_WaitFlagNotSupported): 2183 2177 reporter.error('Session did not start successfully, returned wait result: %d' \ … … 2193 2187 aArgs = [ sImage ]; 2194 2188 aEnv = []; 2195 aFlags = [];2189 fFlags = []; 2196 2190 oGuestProcess = oGuestSession.processCreate(sImage, 2197 aArgs if self.oTstDrv.fpApiVer >= 5.0 else aArgs[1:], aEnv, aFlags,2191 aArgs if self.oTstDrv.fpApiVer >= 5.0 else aArgs[1:], aEnv, fFlags, 2198 2192 30 * 1000); 2199 2193 waitResult = oGuestProcess.waitForArray([ vboxcon.ProcessWaitForFlag_Start ], 30 * 1000); … … 2268 2262 # With stdout. 2269 2263 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32' ], 2270 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut ]),2264 # fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut ]), 2271 2265 # tdTestResultExec(fRc = True, iExitCode = 0) ], 2272 2266 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-file' ], 2273 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut ]),2267 # fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut ]), 2274 2268 # tdTestResultExec(fRc = True, iExitCode = 1) ], 2275 2269 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-dir\\' ], 2276 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut ]),2270 # fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut ]), 2277 2271 # tdTestResultExec(fRc = True, iExitCode = 1) ], 2278 2272 # With stderr. 2279 2273 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32' ], 2280 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdErr ]),2274 # fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdErr ]), 2281 2275 # tdTestResultExec(fRc = True, iExitCode = 0) ], 2282 2276 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-file' ], 2283 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdErr ]),2277 # fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdErr ]), 2284 2278 # tdTestResultExec(fRc = True, iExitCode = 1) ], 2285 2279 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-dir\\' ], 2286 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdErr ]),2280 # fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdErr ]), 2287 2281 # tdTestResultExec(fRc = True, iExitCode = 1) ], 2288 2282 # With stdout/stderr. 2289 2283 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32' ], 2290 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),2284 # fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]), 2291 2285 # tdTestResultExec(fRc = True, iExitCode = 0) ], 2292 2286 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-file' ], 2293 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),2287 # fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]), 2294 2288 # tdTestResultExec(fRc = True, iExitCode = 1) ], 2295 2289 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-dir\\' ], 2296 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),2290 # fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]), 2297 2291 # tdTestResultExec(fRc = True, iExitCode = 1) ] 2298 2292 ## @todo Test stdin! … … 2321 2315 fRc = True; 2322 2316 for (i, aTest) in enumerate(aaTests): 2323 curTest = aTest[0]; # tdTestExec, use an index, later.2324 curRes = aTest[1]; # tdTestResult2325 curTest.setEnvironment(oSession, oTxsSession, oTestVm);2326 fRc, curGuestSession = curTest.createSession('testGuestCtrlExecErrorLevel: Test #%d' % (i,));2317 oCurTest = aTest[0]; # tdTestExec, use an index, later. 2318 oCurRes = aTest[1]; # tdTestResult 2319 oCurTest.setEnvironment(oSession, oTxsSession, oTestVm); 2320 fRc, oCurGuestSession = oCurTest.createSession('testGuestCtrlExecErrorLevel: Test #%d' % (i,)); 2327 2321 if fRc is False: 2328 2322 reporter.error('Test #%d failed: Could not create session' % (i,)); 2329 2323 break; 2330 fRc = self.gctrlExecDoTest(i, curTest, curRes, curGuestSession);2331 curTest.closeSession();2324 fRc = self.gctrlExecDoTest(i, oCurTest, oCurRes, oCurGuestSession); 2325 oCurTest.closeSession(); 2332 2326 if fRc is False: 2333 2327 break; … … 2443 2437 [ tdTestDirCreate(sDirectory = sScratch ), tdTestResult() ], 2444 2438 [ tdTestDirCreate(sDirectory = os.path.join(sScratch, 'foo\\bar\\baz'), 2445 aFlags = [ vboxcon.DirectoryCreateFlag_Parents ] ),2439 fFlags = [ vboxcon.DirectoryCreateFlag_Parents ] ), 2446 2440 tdTestResult(fRc = True) ], 2447 2441 [ tdTestDirCreate(sDirectory = os.path.join(sScratch, 'foo\\bar\\baz'), 2448 aFlags = [ vboxcon.DirectoryCreateFlag_Parents ] ),2442 fFlags = [ vboxcon.DirectoryCreateFlag_Parents ] ), 2449 2443 tdTestResult(fRc = True) ], 2450 2444 # Long (+ random) stuff. 2451 2445 [ tdTestDirCreate(sDirectory = os.path.join(sScratch, 2452 "".join(random.choice(string.ascii_lowercase) for i in range(32))) ),2446 "".join(random.choice(string.ascii_lowercase) for i in xrange(32))) ), 2453 2447 tdTestResult(fRc = True) ], 2454 2448 [ tdTestDirCreate(sDirectory = os.path.join(sScratch, 2455 "".join(random.choice(string.ascii_lowercase) for i in range(128))) ),2449 "".join(random.choice(string.ascii_lowercase) for i in xrange(128))) ), 2456 2450 tdTestResult(fRc = True) ], 2457 2451 # Following two should fail on Windows (paths too long). Both should timeout. 2458 2452 [ tdTestDirCreate(sDirectory = os.path.join(sScratch, 2459 "".join(random.choice(string.ascii_lowercase) for i in range(255))) ),2453 "".join(random.choice(string.ascii_lowercase) for i in xrange(255))) ), 2460 2454 tdTestResult(fRc = not oTestVm.isWindows()) ], 2461 2455 [ tdTestDirCreate(sDirectory = os.path.join(sScratch, 2462 "".join(random.choice(string.ascii_lowercase) for i in range(255))) ),2456 "".join(random.choice(string.ascii_lowercase) for i in xrange(255))) ), 2463 2457 tdTestResult(fRc = not oTestVm.isWindows()) ] 2464 2458 ]); … … 2466 2460 fRc = True; 2467 2461 for (i, aTest) in enumerate(aaTests): 2468 curTest = aTest[0]; # tdTestExec, use an index, later.2469 curRes = aTest[1]; # tdTestResult2470 reporter.log('Testing #%d, sDirectory="%s" ...' % (i, curTest.sDirectory));2471 curTest.setEnvironment(oSession, oTxsSession, oTestVm);2472 fRc, curGuestSession = curTest.createSession('testGuestCtrlDirCreate: Test #%d' % (i,));2462 oCurTest = aTest[0]; # tdTestExec, use an index, later. 2463 oCurRes = aTest[1]; # tdTestResult 2464 reporter.log('Testing #%d, sDirectory="%s" ...' % (i, oCurTest.sDirectory)); 2465 oCurTest.setEnvironment(oSession, oTxsSession, oTestVm); 2466 fRc, oCurGuestSession = oCurTest.createSession('testGuestCtrlDirCreate: Test #%d' % (i,)); 2473 2467 if fRc is False: 2474 2468 reporter.error('Test #%d failed: Could not create session' % (i,)); 2475 2469 break; 2476 fRc = self.gctrlCreateDir( curTest, curRes, curGuestSession);2477 curTest.closeSession();2470 fRc = self.gctrlCreateDir(oCurTest, oCurRes, oCurGuestSession); 2471 oCurTest.closeSession(); 2478 2472 if fRc is False: 2479 2473 reporter.error('Test #%d failed' % (i,)); … … 2582 2576 # Random stuff. 2583 2577 # [ tdTestDirCreateTemp( 2584 # sTemplate = "XXX-".join(random.choice(string.ascii_lowercase) for i in range(32)),2578 # sTemplate = "XXX-".join(random.choice(string.ascii_lowercase) for i in xrange(32)), 2585 2579 # sDirectory = sScratch, 2586 2580 # fSecure = True, fMode = 0o755), 2587 2581 # tdTestResult(fRc = True) ], 2588 # [ tdTestDirCreateTemp(sTemplate = "".join('X' for i in range(32)),2582 # [ tdTestDirCreateTemp(sTemplate = "".join('X' for i in xrange(32)), 2589 2583 # sDirectory = sScratch, 2590 2584 # fSecure = True, fMode = 0o755), 2591 2585 # tdTestResult(fRc = True) ], 2592 # [ tdTestDirCreateTemp(sTemplate = "".join('X' for i in range(128)),2586 # [ tdTestDirCreateTemp(sTemplate = "".join('X' for i in xrange(128)), 2593 2587 # sDirectory = sScratch, 2594 2588 # fSecure = True, fMode = 0o755), … … 2598 2592 fRc = True; 2599 2593 for (i, aTest) in enumerate(aaTests): 2600 curTest = aTest[0]; # tdTestExec, use an index, later.2601 curRes = aTest[1]; # tdTestResult2594 oCurTest = aTest[0]; # tdTestExec, use an index, later. 2595 oCurRes = aTest[1]; # tdTestResult 2602 2596 reporter.log('Testing #%d, sTemplate="%s", fMode=%#o, path="%s", secure="%s" ...' % 2603 (i, curTest.sTemplate, curTest.fMode, curTest.sDirectory, curTest.fSecure));2604 curTest.setEnvironment(oSession, oTxsSession, oTestVm);2605 fRc, curGuestSession = curTest.createSession('testGuestCtrlDirCreateTemp: Test #%d' % (i,));2597 (i, oCurTest.sTemplate, oCurTest.fMode, oCurTest.sDirectory, oCurTest.fSecure)); 2598 oCurTest.setEnvironment(oSession, oTxsSession, oTestVm); 2599 fRc, oCurGuestSession = oCurTest.createSession('testGuestCtrlDirCreateTemp: Test #%d' % (i,)); 2606 2600 if fRc is False: 2607 2601 reporter.error('Test #%d failed: Could not create session' % (i,)); … … 2609 2603 sDirTemp = ""; 2610 2604 try: 2611 sDirTemp = curGuestSession.directoryCreateTemp(curTest.sTemplate, curTest.fMode,2612 curTest.sDirectory, curTest.fSecure);2605 sDirTemp = oCurGuestSession.directoryCreateTemp(oCurTest.sTemplate, oCurTest.fMode, 2606 oCurTest.sDirectory, oCurTest.fSecure); 2613 2607 except: 2614 if curRes.fRc is True:2615 reporter.errorXcpt('Creating temp directory "%s" failed:' % ( curTest.sDirectory,));2608 if oCurRes.fRc is True: 2609 reporter.errorXcpt('Creating temp directory "%s" failed:' % (oCurTest.sDirectory,)); 2616 2610 fRc = False; 2617 2611 break; 2618 2612 else: 2619 reporter.logXcpt('Creating temp directory "%s" failed expectedly, skipping:' % ( curTest.sDirectory,));2620 curTest.closeSession();2613 reporter.logXcpt('Creating temp directory "%s" failed expectedly, skipping:' % (oCurTest.sDirectory,)); 2614 oCurTest.closeSession(); 2621 2615 if sDirTemp != "": 2622 2616 reporter.log2('Temporary directory is: %s' % (sDirTemp,)); 2623 2617 if self.oTstDrv.fpApiVer >= 5.0: 2624 fExists = curGuestSession.directoryExists(sDirTemp, False);2618 fExists = oCurGuestSession.directoryExists(sDirTemp, False); 2625 2619 else: 2626 fExists = curGuestSession.directoryExists(sDirTemp);2620 fExists = oCurGuestSession.directoryExists(sDirTemp); 2627 2621 if fExists is False: 2628 2622 reporter.error('Test #%d failed: Temporary directory "%s" does not exists' % (i, sDirTemp)); … … 2641 2635 # Invalid stuff. 2642 2636 [ tdTestDirRead(sDirectory = ''), tdTestResultDirRead(fRc = False) ], 2643 [ tdTestDirRead(sDirectory = 'C:\\Windows', aFlags = [ 1234 ]), tdTestResultDirRead() ],2637 [ tdTestDirRead(sDirectory = 'C:\\Windows', fFlags = [ 1234 ]), tdTestResultDirRead() ], 2644 2638 [ tdTestDirRead(sDirectory = 'C:\\Windows', sFilter = '*.foo'), tdTestResultDirRead() ], 2645 2639 # More unusual stuff. … … 2665 2659 # Invalid stuff. 2666 2660 [ tdTestDirRead(sDirectory = ''), tdTestResultDirRead() ], 2667 [ tdTestDirRead(sDirectory = '/etc', aFlags = [ 1234 ]), tdTestResultDirRead() ],2661 [ tdTestDirRead(sDirectory = '/etc', fFlags = [ 1234 ]), tdTestResultDirRead() ], 2668 2662 [ tdTestDirRead(sDirectory = '/etc', sFilter = '*.foo'), tdTestResultDirRead() ], 2669 2663 # More unusual stuff. … … 2676 2670 fRc = True; 2677 2671 for (i, aTest) in enumerate(aaTests): 2678 curTest = aTest[0]; # tdTestExec, use an index, later.2679 curRes = aTest[1]; # tdTestResult2680 reporter.log('Testing #%d, dir="%s" ...' % (i, curTest.sDirectory));2681 curTest.setEnvironment(oSession, oTxsSession, oTestVm);2682 fRc, curGuestSession = curTest.createSession('testGuestCtrlDirRead: Test #%d' % (i,));2672 oCurTest = aTest[0]; # tdTestExec, use an index, later. 2673 oCurRes = aTest[1]; # tdTestResult 2674 reporter.log('Testing #%d, dir="%s" ...' % (i, oCurTest.sDirectory)); 2675 oCurTest.setEnvironment(oSession, oTxsSession, oTestVm); 2676 fRc, oCurGuestSession = oCurTest.createSession('testGuestCtrlDirRead: Test #%d' % (i,)); 2683 2677 if fRc is False: 2684 2678 reporter.error('Test #%d failed: Could not create session' % (i,)); 2685 2679 break; 2686 (fRc2, cDirs, cFiles) = self.gctrlReadDir( curTest, curRes, curGuestSession);2687 curTest.closeSession();2680 (fRc2, cDirs, cFiles) = self.gctrlReadDir(oCurTest, oCurRes, oCurGuestSession); 2681 oCurTest.closeSession(); 2688 2682 reporter.log2('Test #%d: Returned %d directories, %d files total' % (i, cDirs, cFiles)); 2689 if fRc2 is curRes.fRc:2683 if fRc2 is oCurRes.fRc: 2690 2684 if fRc2 is True: 2691 if curRes.numFiles != cFiles:2692 reporter.error('Test #%d failed: Got %d files, expected %d' % (i, cFiles, curRes.numFiles));2685 if oCurRes.numFiles != cFiles: 2686 reporter.error('Test #%d failed: Got %d files, expected %d' % (i, cFiles, oCurRes.numFiles)); 2693 2687 fRc = False; 2694 if curRes.numDirs != cDirs:2695 reporter.error('Test #%d failed: Got %d directories, expected %d' % (i, cDirs, curRes.numDirs));2688 if oCurRes.numDirs != cDirs: 2689 reporter.error('Test #%d failed: Got %d directories, expected %d' % (i, cDirs, oCurRes.numDirs)); 2696 2690 fRc = False; 2697 2691 else: 2698 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, curRes.fRc));2692 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, oCurRes.fRc)); 2699 2693 fRc = False; 2700 2694 … … 2760 2754 fRc = True; 2761 2755 for (i, aTest) in enumerate(aaTests): 2762 curTest = aTest[0]; # tdTestExec, use an index, later.2763 curRes = aTest[1]; # tdTestResult2764 reporter.log('Testing #%d, file="%s" ...' % (i, curTest.sFile));2765 curTest.setEnvironment(oSession, oTxsSession, oTestVm);2766 fRc, curGuestSession = curTest.createSession('testGuestCtrlFileRemove: Test #%d' % (i,));2756 oCurTest = aTest[0]; # tdTestExec, use an index, later. 2757 oCurRes = aTest[1]; # tdTestResult 2758 reporter.log('Testing #%d, file="%s" ...' % (i, oCurTest.sFile)); 2759 oCurTest.setEnvironment(oSession, oTxsSession, oTestVm); 2760 fRc, oCurGuestSession = oCurTest.createSession('testGuestCtrlFileRemove: Test #%d' % (i,)); 2767 2761 if fRc is False: 2768 2762 reporter.error('Test #%d failed: Could not create session' % (i,)); … … 2770 2764 try: 2771 2765 if self.oTstDrv.fpApiVer >= 5.0: 2772 curGuestSession.fsObjRemove(curTest.sFile);2766 oCurGuestSession.fsObjRemove(oCurTest.sFile); 2773 2767 else: 2774 curGuestSession.fileRemove(curTest.sFile);2768 oCurGuestSession.fileRemove(oCurTest.sFile); 2775 2769 except: 2776 if curRes.fRc is True:2777 reporter.errorXcpt('Removing file "%s" failed:' % ( curTest.sFile,));2770 if oCurRes.fRc is True: 2771 reporter.errorXcpt('Removing file "%s" failed:' % (oCurTest.sFile,)); 2778 2772 fRc = False; 2779 2773 break; 2780 2774 else: 2781 reporter.logXcpt('Removing file "%s" failed expectedly, skipping:' % ( curTest.sFile,));2782 curTest.closeSession();2775 reporter.logXcpt('Removing file "%s" failed expectedly, skipping:' % (oCurTest.sFile,)); 2776 oCurTest.closeSession(); 2783 2777 return (fRc, oTxsSession); 2784 2778 … … 2925 2919 [ tdTestFileReadWrite(sFile = 'C:\\Windows\\System32\\eula.txt', 2926 2920 sOpenMode = 'r', sDisposition = 'oe', cbToReadWrite = 33), 2927 tdTestResultFileReadWrite(fRc = True, a Buf = 'Microsoft(r) Windows(r) XP Profes',2928 cbProcessed = 33, cbOffset= 33) ],2921 tdTestResultFileReadWrite(fRc = True, abBuf = 'Microsoft(r) Windows(r) XP Profes', 2922 cbProcessed = 33, offFile = 33) ], 2929 2923 # Reading from offset. 2930 2924 [ tdTestFileReadWrite(sFile = 'C:\\Windows\\System32\\eula.txt', 2931 sOpenMode = 'r', sDisposition = 'oe', cbOffset= 17769, cbToReadWrite = 31),2932 tdTestResultFileReadWrite(fRc = True, a Buf = 'only with the HARDWARE. If\x0d\x0a ',2933 cbProcessed = 31, cbOffset= 17769 + 31) ]2925 sOpenMode = 'r', sDisposition = 'oe', offFile = 17769, cbToReadWrite = 31), 2926 tdTestResultFileReadWrite(fRc = True, abBuf = 'only with the HARDWARE. If\x0d\x0a ', 2927 cbProcessed = 31, offFile = 17769 + 31) ] 2934 2928 ]); 2935 2929 elif oTestVm.isLinux(): … … 2948 2942 fRc = True; 2949 2943 for (i, aTest) in enumerate(aaTests): 2950 curTest = aTest[0]; # tdTestFileReadWrite, use an index, later. 2951 curRes = aTest[1]; # tdTestResult 2952 reporter.log('Testing #%d, sFile="%s", cbToReadWrite=%d, sOpenMode="%s", sDisposition="%s", cbOffset=%d ...' % \ 2953 (i, curTest.sFile, curTest.cbToReadWrite, curTest.sOpenMode, curTest.sDisposition, curTest.cbOffset)); 2954 curTest.setEnvironment(oSession, oTxsSession, oTestVm); 2955 fRc, curGuestSession = curTest.createSession('testGuestCtrlFileRead: Test #%d' % (i,)); 2944 oCurTest = aTest[0]; # tdTestFileReadWrite, use an index, later. 2945 oCurRes = aTest[1]; # tdTestResult 2946 reporter.log('Testing #%d, sFile="%s", cbToReadWrite=%d, sOpenMode="%s", sDisposition="%s", offFile=%d ...' 2947 % (i, oCurTest.sFile, oCurTest.cbToReadWrite, oCurTest.sOpenMode, 2948 oCurTest.sDisposition, oCurTest.offFile)); 2949 oCurTest.setEnvironment(oSession, oTxsSession, oTestVm); 2950 fRc, oCurGuestSession = oCurTest.createSession('testGuestCtrlFileRead: Test #%d' % (i,)); 2956 2951 if fRc is False: 2957 2952 reporter.error('Test #%d failed: Could not create session' % (i,)); … … 2959 2954 try: 2960 2955 fRc2 = True; 2961 if curTest.cbOffset> 0: # The offset parameter is gone.2956 if oCurTest.offFile > 0: # The offset parameter is gone. 2962 2957 if self.oTstDrv.fpApiVer >= 5.0: 2963 curFile = curGuestSession.fileOpenEx(curTest.sFile, curTest.getAccessMode(), curTest.getOpenAction(),2964 curTest.getSharingMode(), curTest.lCreationMode, []);2965 curFile.seek( curTest.cbOffset, vboxcon.FileSeekOrigin_Begin);2958 curFile = oCurGuestSession.fileOpenEx(oCurTest.sFile, oCurTest.getAccessMode(), oCurTest.getOpenAction(), 2959 oCurTest.getSharingMode(), oCurTest.fCreationMode, []); 2960 curFile.seek(oCurTest.offFile, vboxcon.FileSeekOrigin_Begin); 2966 2961 else: 2967 curFile = curGuestSession.fileOpenEx(curTest.sFile, curTest.sOpenMode, curTest.sDisposition, \2968 curTest.sSharingMode, curTest.lCreationMode, curTest.cbOffset);2962 curFile = oCurGuestSession.fileOpenEx(oCurTest.sFile, oCurTest.sOpenMode, oCurTest.sDisposition, 2963 oCurTest.sSharingMode, oCurTest.fCreationMode, oCurTest.offFile); 2969 2964 curOffset = long(curFile.offset); 2970 resOffset = long( curTest.cbOffset);2965 resOffset = long(oCurTest.offFile); 2971 2966 if curOffset != resOffset: 2972 reporter.error('Test #%d failed: Initial offset on open does not match: Got %d, expected %d' \2967 reporter.error('Test #%d failed: Initial offset on open does not match: Got %d, expected %d' 2973 2968 % (i, curOffset, resOffset)); 2974 2969 fRc2 = False; 2975 2970 else: 2976 2971 if self.oTstDrv.fpApiVer >= 5.0: 2977 curFile = curGuestSession.fileOpen(curTest.sFile, curTest.getAccessMode(), curTest.getOpenAction(),2978 curTest.lCreationMode);2972 curFile = oCurGuestSession.fileOpen(oCurTest.sFile, oCurTest.getAccessMode(), oCurTest.getOpenAction(), 2973 oCurTest.fCreationMode); 2979 2974 else: 2980 curFile = curGuestSession.fileOpen(curTest.sFile, curTest.sOpenMode, curTest.sDisposition, \ 2981 curTest.lCreationMode); 2982 if fRc2 \ 2983 and curTest.cbToReadWrite > 0: 2975 curFile = oCurGuestSession.fileOpen(oCurTest.sFile, oCurTest.sOpenMode, oCurTest.sDisposition, 2976 oCurTest.fCreationMode); 2977 if fRc2 and oCurTest.cbToReadWrite > 0: 2984 2978 ## @todo Split this up in 64K reads. Later. 2985 2979 ## @todo Test timeouts. 2986 aBufRead = curFile.read( curTest.cbToReadWrite, 30 * 1000);2987 if curRes.cbProcessed > 0 \2988 and curRes.cbProcessed != len(aBufRead):2980 aBufRead = curFile.read(oCurTest.cbToReadWrite, 30 * 1000); 2981 if oCurRes.cbProcessed > 0 \ 2982 and oCurRes.cbProcessed != len(aBufRead): 2989 2983 reporter.error('Test #%d failed: Read buffer length does not match: Got %d, expected %d' 2990 % (i, len(aBufRead), curRes.cbProcessed));2984 % (i, len(aBufRead), oCurRes.cbProcessed)); 2991 2985 fRc2 = False; 2992 2986 if fRc2: 2993 if curRes.aBuf is not None \2994 and not utils.areBytesEqual( curRes.aBuf, aBufRead):2987 if oCurRes.abBuf is not None \ 2988 and not utils.areBytesEqual(oCurRes.abBuf, aBufRead): 2995 2989 reporter.error('Test #%d failed: Got buffer:\n"%s" (%d bytes, type %s)\n' 2996 2990 'Expected buffer:\n"%s" (%d bytes, type %s)' 2997 2991 % (i, map(hex, map(ord, aBufRead)), len(aBufRead), type(aBufRead), 2998 map(hex, map(ord, curRes.aBuf)), len(curRes.aBuf), type(curRes.aBuf),));2992 map(hex, map(ord, oCurRes.abBuf)), len(oCurRes.abBuf), type(oCurRes.abBuf),)); 2999 2993 reporter.error('Test #%d failed: Got buffer:\n"%s"\nExpected buffer:\n"%s"' 3000 % (i, aBufRead, curRes.aBuf));2994 % (i, aBufRead, oCurRes.abBuf)); 3001 2995 fRc2 = False; 3002 2996 # Test final offset. 3003 2997 curOffset = long(curFile.offset); 3004 resOffset = long( curRes.cbOffset);2998 resOffset = long(oCurRes.offFile); 3005 2999 if curOffset != resOffset: 3006 3000 reporter.error('Test #%d failed: Final offset does not match: Got %d, expected %d' \ … … 3009 3003 curFile.close(); 3010 3004 3011 if fRc2 != curRes.fRc:3012 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, curRes.fRc));3005 if fRc2 != oCurRes.fRc: 3006 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, oCurRes.fRc)); 3013 3007 fRc = False; 3014 3008 3015 3009 except: 3016 reporter.logXcpt('Opening "%s" failed:' % ( curTest.sFile,));3010 reporter.logXcpt('Opening "%s" failed:' % (oCurTest.sFile,)); 3017 3011 fRc = False; 3018 3012 3019 curTest.closeSession();3013 oCurTest.closeSession(); 3020 3014 3021 3015 return (fRc, oTxsSession); … … 3037 3031 aaTests = []; 3038 3032 3039 c ScratchBuf = random.randint(1, 4096);3040 a ScratchBuf = os.urandom(cScratchBuf);3033 cbScratchBuf = random.randint(1, 4096); 3034 abScratchBuf = os.urandom(cbScratchBuf); 3041 3035 aaTests.extend([ 3042 3036 # Write to a non-existing file. 3043 3037 [ tdTestFileReadWrite(sFile = sScratch + 'testGuestCtrlFileWrite.txt', 3044 sOpenMode = 'w+', sDisposition = 'ce', cbToReadWrite = cScratchBuf, 3045 aBuf = aScratchBuf), 3046 tdTestResultFileReadWrite(fRc = True, aBuf = aScratchBuf, \ 3047 cbProcessed = cScratchBuf, cbOffset = cScratchBuf) ] 3038 sOpenMode = 'w+', sDisposition = 'ce', cbToReadWrite = cbScratchBuf, abBuf = abScratchBuf), 3039 tdTestResultFileReadWrite(fRc = True, abBuf = abScratchBuf, cbProcessed = cbScratchBuf, offFile = cbScratchBuf) ], 3048 3040 ]); 3049 3041 3050 aScratchBuf2 = os.urandom(c ScratchBuf);3042 aScratchBuf2 = os.urandom(cbScratchBuf); 3051 3043 aaTests.extend([ 3052 3044 # Append the same amount of data to the just created file. 3053 3045 [ tdTestFileReadWrite(sFile = sScratch + 'testGuestCtrlFileWrite.txt', 3054 sOpenMode = 'w+', sDisposition = 'oa', cbToReadWrite = c ScratchBuf,3055 cbOffset = cScratchBuf, aBuf = aScratchBuf2),3056 tdTestResultFileReadWrite(fRc = True, a Buf = aScratchBuf2, \3057 cbProcessed = cScratchBuf, cbOffset = cScratchBuf * 2) ],3046 sOpenMode = 'w+', sDisposition = 'oa', cbToReadWrite = cbScratchBuf, 3047 offFile = cbScratchBuf, abBuf = aScratchBuf2), 3048 tdTestResultFileReadWrite(fRc = True, abBuf = aScratchBuf2, cbProcessed = cbScratchBuf, 3049 offFile = cbScratchBuf * 2) ], 3058 3050 ]); 3059 3051 3060 3052 fRc = True; 3061 3053 for (i, aTest) in enumerate(aaTests): 3062 curTest = aTest[0]; # tdTestFileReadWrite, use an index, later. 3063 curRes = aTest[1]; # tdTestResult 3064 reporter.log('Testing #%d, sFile="%s", cbToReadWrite=%d, sOpenMode="%s", sDisposition="%s", cbOffset=%d ...' % \ 3065 (i, curTest.sFile, curTest.cbToReadWrite, curTest.sOpenMode, curTest.sDisposition, curTest.cbOffset)); 3066 curTest.setEnvironment(oSession, oTxsSession, oTestVm); 3067 fRc, curGuestSession = curTest.createSession('testGuestCtrlFileWrite: Test #%d' % (i,)); 3054 oCurTest = aTest[0]; # tdTestFileReadWrite, use an index, later. 3055 oCurRes = aTest[1]; # tdTestResult 3056 reporter.log('Testing #%d, sFile="%s", cbToReadWrite=%d, sOpenMode="%s", sDisposition="%s", offFile=%d ...' 3057 % (i, oCurTest.sFile, oCurTest.cbToReadWrite, oCurTest.sOpenMode, 3058 oCurTest.sDisposition, oCurTest.offFile,)); 3059 oCurTest.setEnvironment(oSession, oTxsSession, oTestVm); 3060 fRc, oCurGuestSession = oCurTest.createSession('testGuestCtrlFileWrite: Test #%d' % (i,)); 3068 3061 if fRc is False: 3069 3062 reporter.error('Test #%d failed: Could not create session' % (i,)); … … 3071 3064 3072 3065 try: 3073 if curTest.cbOffset> 0: # The offset parameter is gone.3066 if oCurTest.offFile > 0: # The offset parameter is gone. 3074 3067 if self.oTstDrv.fpApiVer >= 5.0: 3075 curFile = curGuestSession.fileOpenEx(curTest.sFile, curTest.getAccessMode(), curTest.getOpenAction(),3076 curTest.getSharingMode(), curTest.lCreationMode, []);3077 curFile.seek( curTest.cbOffset, vboxcon.FileSeekOrigin_Begin);3068 curFile = oCurGuestSession.fileOpenEx(oCurTest.sFile, oCurTest.getAccessMode(), oCurTest.getOpenAction(), 3069 oCurTest.getSharingMode(), oCurTest.fCreationMode, []); 3070 curFile.seek(oCurTest.offFile, vboxcon.FileSeekOrigin_Begin); 3078 3071 else: 3079 curFile = curGuestSession.fileOpenEx(curTest.sFile, curTest.sOpenMode, curTest.sDisposition,3080 curTest.sSharingMode, curTest.lCreationMode, curTest.cbOffset);3072 curFile = oCurGuestSession.fileOpenEx(oCurTest.sFile, oCurTest.sOpenMode, oCurTest.sDisposition, 3073 oCurTest.sSharingMode, oCurTest.fCreationMode, oCurTest.offFile); 3081 3074 curOffset = long(curFile.offset); 3082 resOffset = long( curTest.cbOffset);3075 resOffset = long(oCurTest.offFile); 3083 3076 if curOffset != resOffset: 3084 3077 reporter.error('Test #%d failed: Initial offset on open does not match: Got %d, expected %d' \ … … 3087 3080 else: 3088 3081 if self.oTstDrv.fpApiVer >= 5.0: 3089 curFile = curGuestSession.fileOpenEx(curTest.sFile, curTest.getAccessMode(), curTest.getOpenAction(),3090 curTest.getSharingMode(), curTest.lCreationMode, []);3082 curFile = oCurGuestSession.fileOpenEx(oCurTest.sFile, oCurTest.getAccessMode(), oCurTest.getOpenAction(), 3083 oCurTest.getSharingMode(), oCurTest.fCreationMode, []); 3091 3084 else: 3092 curFile = curGuestSession.fileOpen(curTest.sFile, curTest.sOpenMode, curTest.sDisposition,3093 curTest.lCreationMode);3094 if fRc and curTest.cbToReadWrite > 0:3095 reporter.log("File '%s' opened" % curTest.sFile);3085 curFile = oCurGuestSession.fileOpen(oCurTest.sFile, oCurTest.sOpenMode, oCurTest.sDisposition, 3086 oCurTest.fCreationMode); 3087 if fRc and oCurTest.cbToReadWrite > 0: 3088 reporter.log("File '%s' opened" % oCurTest.sFile); 3096 3089 ## @todo Split this up in 64K writes. Later. 3097 3090 ## @todo Test timeouts. 3098 cBytesWritten = curFile.write(array('b', curTest.aBuf), 30 * 1000);3099 if curRes.cbProcessed > 0 \3100 and curRes.cbProcessed != cBytesWritten:3091 cBytesWritten = curFile.write(array('b', oCurTest.abBuf), 30 * 1000); 3092 if oCurRes.cbProcessed > 0 \ 3093 and oCurRes.cbProcessed != cBytesWritten: 3101 3094 reporter.error('Test #%d failed: Written buffer length does not match: Got %d, expected %d' \ 3102 % (i, cBytesWritten, curRes.cbProcessed));3095 % (i, cBytesWritten, oCurRes.cbProcessed)); 3103 3096 fRc = False; 3104 3097 if fRc: … … 3107 3100 try: 3108 3101 if self.oTstDrv.fpApiVer >= 5.0: 3109 curFile.seek(-( curTest.cbToReadWrite), vboxcon.FileSeekOrigin_Current);3102 curFile.seek(-(oCurTest.cbToReadWrite), vboxcon.FileSeekOrigin_Current); 3110 3103 else: 3111 curFile.seek(-( curTest.cbToReadWrite), vboxcon.FileSeekType_Current);3104 curFile.seek(-(oCurTest.cbToReadWrite), vboxcon.FileSeekType_Current); 3112 3105 except: 3113 3106 reporter.logXcpt('Seeking back to initial write position failed:'); 3114 3107 fRc = False; 3115 if fRc and long(curFile.offset) != curTest.cbOffset:3108 if fRc and long(curFile.offset) != oCurTest.offFile: 3116 3109 reporter.error('Test #%d failed: Initial write position does not match current position, ' \ 3117 'got %d, expected %d' % (i, long(curFile.offset), curTest.cbOffset));3110 'got %d, expected %d' % (i, long(curFile.offset), oCurTest.offFile)); 3118 3111 fRc = False; 3119 3112 if fRc: 3120 aBufRead = curFile.read( curTest.cbToReadWrite, 30 * 1000);3121 if len(aBufRead) != curTest.cbToReadWrite:3113 aBufRead = curFile.read(oCurTest.cbToReadWrite, 30 * 1000); 3114 if len(aBufRead) != oCurTest.cbToReadWrite: 3122 3115 reporter.error('Test #%d failed: Got buffer length %d, expected %d' \ 3123 % (i, len(aBufRead), curTest.cbToReadWrite));3116 % (i, len(aBufRead), oCurTest.cbToReadWrite)); 3124 3117 fRc = False; 3125 3118 if fRc \ 3126 and curRes.aBuf is not None \3127 and bytes( curRes.aBuf) != bytes(aBufRead):3119 and oCurRes.abBuf is not None \ 3120 and bytes(oCurRes.abBuf) != bytes(aBufRead): 3128 3121 reporter.error('Test #%d failed: Read back buffer (%d bytes) does not match ' \ 3129 3122 'written content (%d bytes)' % (i, len(aBufRead), len(aBufRead))); … … 3133 3126 # Download written file from guest. 3134 3127 aGstFiles = []; 3135 aGstFiles.append( curTest.sFile.replace('\\', '/'));3128 aGstFiles.append(oCurTest.sFile.replace('\\', '/')); 3136 3129 self.oTstDrv.txsDownloadFiles(oSession, oTxsSession, aGstFiles, fIgnoreErrors = True); 3137 3130 3138 3131 # Create files with buffer contents and upload those for later (manual) inspection. 3139 curTest.uploadLogData(self.oTstDrv, curRes.aBuf, ('testGuestCtrlWriteTest%d-BufExcepted' % i),3132 oCurTest.uploadLogData(self.oTstDrv, oCurRes.abBuf, ('testGuestCtrlWriteTest%d-BufExcepted' % i), 3140 3133 ('Test #%d: Expected buffer' % i)); 3141 curTest.uploadLogData(self.oTstDrv, aBufRead, ('testGuestCtrlWriteTest%d-BufGot' % i),3134 oCurTest.uploadLogData(self.oTstDrv, aBufRead, ('testGuestCtrlWriteTest%d-BufGot' % i), 3142 3135 ('Test #%d: Got buffer' % i)); 3143 3136 fRc = False; 3144 3137 # Test final offset. 3145 3138 curOffset = long(curFile.offset); 3146 resOffset = long( curRes.cbOffset);3139 resOffset = long(oCurRes.offFile); 3147 3140 if curOffset != resOffset: 3148 3141 reporter.error('Test #%d failed: Final offset does not match: Got %d, expected %d' \ … … 3151 3144 if curFile.status == vboxcon.FileStatus_Open: 3152 3145 curFile.close(); 3153 reporter.log("File '%s' closed" % curTest.sFile);3146 reporter.log("File '%s' closed" % oCurTest.sFile); 3154 3147 except: 3155 reporter.logXcpt('Opening "%s" failed:' % ( curTest.sFile,));3148 reporter.logXcpt('Opening "%s" failed:' % (oCurTest.sFile,)); 3156 3149 fRc = False; 3157 3150 3158 curTest.closeSession();3159 3160 if fRc != curRes.fRc:3161 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc, curRes.fRc));3151 oCurTest.closeSession(); 3152 3153 if fRc != oCurRes.fRc: 3154 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc, oCurRes.fRc)); 3162 3155 fRc = False; 3163 3156 break; … … 3201 3194 # Destination missing. 3202 3195 [ tdTestCopyTo(sSrc = ''), tdTestResult() ], 3203 [ tdTestCopyTo(sSrc = '/placeholder', aFlags = [ 80 ] ), tdTestResult() ],3196 [ tdTestCopyTo(sSrc = '/placeholder', fFlags = [ 80 ] ), tdTestResult() ], 3204 3197 # Source missing. 3205 3198 [ tdTestCopyTo(sDst = ''), tdTestResult() ], 3206 [ tdTestCopyTo(sDst = '/placeholder', aFlags = [ 80 ] ), tdTestResult() ],3199 [ tdTestCopyTo(sDst = '/placeholder', fFlags = [ 80 ] ), tdTestResult() ], 3207 3200 # Testing DirectoryCopyFlag flags. 3208 [ tdTestCopyTo(sSrc = sTestFileBig, sDst = sScratchGstInvalid, aFlags = [ 80 ] ), tdTestResult() ],3201 [ tdTestCopyTo(sSrc = sTestFileBig, sDst = sScratchGstInvalid, fFlags = [ 80 ] ), tdTestResult() ], 3209 3202 # Testing FileCopyFlag flags. 3210 [ tdTestCopyTo(sSrc = sTestFileBig, sDst = sScratchGstInvalid, aFlags = [ 80 ] ), tdTestResult() ],3203 [ tdTestCopyTo(sSrc = sTestFileBig, sDst = sScratchGstInvalid, fFlags = [ 80 ] ), tdTestResult() ], 3211 3204 # Nothing to copy (source and/or destination is empty). 3212 3205 [ tdTestCopyTo(sSrc = 'z:\\'), tdTestResult() ], … … 3259 3252 ## the old ones like XP with a "proper" administrator. 3260 3253 #[ tdTestCopyTo(sSrc = os.path.join(sSystemRoot, 'security'), 3261 # sDst = sScratchGst, aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),3254 # sDst = sScratchGst, fFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]), 3262 3255 # 3263 3256 # Copying directories with regular files. 3264 3257 [ tdTestCopyTo(sSrc = os.path.join(sSystemRoot, 'Help'), 3265 sDst = sScratchGst, aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),3258 sDst = sScratchGst, fFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]), 3266 3259 tdTestResult(fRc = True) ] 3267 3260 ]); … … 3269 3262 fRc = True; 3270 3263 for (i, aTest) in enumerate(aaTests): 3271 curTest = aTest[0]; # tdTestExec, use an index, later.3272 curRes = aTest[1]; # tdTestResult3273 reporter.log('Testing #%d, sSrc=%s, sDst=%s, aFlags=%s ...' % \3274 (i, curTest.sSrc, curTest.sDst, curTest.aFlags));3275 curTest.setEnvironment(oSession, oTxsSession, oTestVm);3276 fRc, curGuestSession = curTest.createSession('testGuestCtrlCopyTo: Test #%d' % (i,));3264 oCurTest = aTest[0]; # tdTestExec, use an index, later. 3265 oCurRes = aTest[1]; # tdTestResult 3266 reporter.log('Testing #%d, sSrc=%s, sDst=%s, fFlags=%s ...' % \ 3267 (i, oCurTest.sSrc, oCurTest.sDst, oCurTest.fFlags)); 3268 oCurTest.setEnvironment(oSession, oTxsSession, oTestVm); 3269 fRc, oCurGuestSession = oCurTest.createSession('testGuestCtrlCopyTo: Test #%d' % (i,)); 3277 3270 if fRc is False: 3278 3271 reporter.error('Test #%d failed: Could not create session' % (i,)); … … 3280 3273 3281 3274 fRc2 = False; 3282 if os.path.isdir( curTest.sSrc):3275 if os.path.isdir(oCurTest.sSrc): 3283 3276 try: 3284 curProgress = curGuestSession.directoryCopyToGuest(curTest.sSrc, curTest.sDst, curTest.aFlags);3285 if curProgress is not None:3286 oProgress = vboxwrappers.ProgressWrapper( curProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, \3277 oCurProgress = oCurGuestSession.directoryCopyToGuest(oCurTest.sSrc, oCurTest.sDst, oCurTest.fFlags); 3278 if oCurProgress is not None: 3279 oProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, \ 3287 3280 "gctrlDirCopyTo"); 3288 3281 try: … … 3293 3286 oProgress.logResult(fIgnoreErrors = True); 3294 3287 except: 3295 reporter.logXcpt('Waiting exception for sSrc="%s", sDst="%s":' % ( curTest.sSrc, curTest.sDst));3288 reporter.logXcpt('Waiting exception for sSrc="%s", sDst="%s":' % (oCurTest.sSrc, oCurTest.sDst)); 3296 3289 else: 3297 3290 reporter.error('No progress object returned'); 3298 3291 except: 3299 reporter.logXcpt('directoryCopyToGuest exception for sSrc="%s", sDst="%s":' % ( curTest.sSrc, curTest.sDst));3292 reporter.logXcpt('directoryCopyToGuest exception for sSrc="%s", sDst="%s":' % (oCurTest.sSrc, oCurTest.sDst)); 3300 3293 else: 3301 fRc2 = self.gctrlCopyFileTo( curGuestSession, curTest.sSrc, curTest.sDst, curTest.aFlags);3302 3303 curTest.closeSession();3304 3305 if fRc2 is curRes.fRc:3294 fRc2 = self.gctrlCopyFileTo(oCurGuestSession, oCurTest.sSrc, oCurTest.sDst, oCurTest.fFlags); 3295 3296 oCurTest.closeSession(); 3297 3298 if fRc2 is oCurRes.fRc: 3306 3299 ## @todo Verify the copied results (size, checksum?). 3307 3300 pass; 3308 3301 else: 3309 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, curRes.fRc));3302 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, oCurRes.fRc)); 3310 3303 fRc = False; 3311 3304 break; … … 3350 3343 # Destination missing. 3351 3344 [ tdTestCopyFrom(sSrc = ''), tdTestResult() ], 3352 [ tdTestCopyFrom(sSrc = 'Something', aFlags = [ 80 ] ), tdTestResult() ],3345 [ tdTestCopyFrom(sSrc = 'Something', fFlags = [ 80 ] ), tdTestResult() ], 3353 3346 # Source missing. 3354 3347 [ tdTestCopyFrom(sDst = ''), tdTestResult() ], 3355 [ tdTestCopyFrom(sDst = 'Something', aFlags = [ 80 ] ), tdTestResult() ],3348 [ tdTestCopyFrom(sDst = 'Something', fFlags = [ 80 ] ), tdTestResult() ], 3356 3349 # Testing DirectoryCopyFlag flags. 3357 [ tdTestCopyFrom(sSrc = sSrcDirExisting, sDst = sScratchHstInvalid, aFlags = [ 80 ] ), tdTestResult() ],3350 [ tdTestCopyFrom(sSrc = sSrcDirExisting, sDst = sScratchHstInvalid, fFlags = [ 80 ] ), tdTestResult() ], 3358 3351 # Testing FileCopyFlag flags. 3359 [ tdTestCopyFrom(sSrc = sSrcFileExisting, sDst = sScratchHstInvalid, aFlags = [ 80 ] ), tdTestResult() ],3352 [ tdTestCopyFrom(sSrc = sSrcFileExisting, sDst = sScratchHstInvalid, fFlags = [ 80 ] ), tdTestResult() ], 3360 3353 # Nothing to copy (sDst is empty / unreachable). 3361 3354 [ tdTestCopyFrom(sSrc = 'z:\\'), tdTestResult() ], … … 3407 3400 # Next try with the DirectoryCopyFlag_CopyIntoExisting flag being set. 3408 3401 [ tdTestCopyFrom(sSrc = sSrcDirExisting, sDst = sScratchHst, 3409 aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ] ),3402 fFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ] ), 3410 3403 tdTestResult(fRc = True) ], 3411 3404 # Ditto, with trailing slash. 3412 3405 [ tdTestCopyFrom(sSrc = sSrcDirExisting, 3413 sDst = sScratchHst + "/", aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),3406 sDst = sScratchHst + "/", fFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]), 3414 3407 tdTestResult(fRc = True) ], 3415 3408 # Copying contents of directories into a non-existing directory chain on the host which fail. 3416 3409 [ tdTestCopyFrom(sSrc = sSrcDirExisting + sPathSep, sDst = sScratchHstNotExistChain, 3417 aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]), tdTestResult() ],3410 fFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]), tdTestResult() ], 3418 3411 # Copying contents of directories into a non-existing directory on the host, which should succeed. 3419 3412 [ tdTestCopyFrom(sSrc = sSrcDirExisting + sPathSep, sDst = sScratchHstNotExist, 3420 aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ] ),3413 fFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ] ), 3421 3414 tdTestResult(fRc = True) ] 3422 3415 ]); … … 3424 3417 fRc = True; 3425 3418 for (i, aTest) in enumerate(aaTests): 3426 curTest = aTest[0]; # tdTestExec, use an index, later. 3427 curRes = aTest[1]; # tdTestResult 3428 reporter.log('Testing #%d, sSrc="%s", sDst="%s", aFlags="%s" ...' % \ 3429 (i, curTest.sSrc, curTest.sDst, curTest.aFlags)); 3430 curTest.setEnvironment(oSession, oTxsSession, oTestVm); 3431 fRc, curGuestSession = curTest.createSession('testGuestCtrlCopyFrom: Test #%d' % (i,)); 3432 if fRc is False: 3433 reporter.error('Test #%d failed: Could not create session' % (i,)); 3419 oCurTest = aTest[0]; # tdTestExec, use an index, later. 3420 oCurRes = aTest[1]; # tdTestResult 3421 reporter.log('Testing #%d, sSrc="%s", sDst="%s", fFlags="%s" ...' 3422 % (i, oCurTest.sSrc, oCurTest.sDst, oCurTest.fFlags,)); 3423 3424 oCurTest.setEnvironment(oSession, oTxsSession, oTestVm); 3425 fRc2, oCurGuestSession = oCurTest.createSession('testGuestCtrlCopyFrom: Test #%d' % (i,)); 3426 if fRc2 is not True: 3427 fRc = reporter.error('Test #%d failed: Could not create session' % (i,)); 3434 3428 break; 3435 3436 fRc2 = True;3437 3429 3438 3430 try: 3439 3431 if self.oTstDrv.fpApiVer >= 5.0: 3440 oFsInfo = curGuestSession.fsObjQueryInfo(curTest.sSrc, True); # fFollowSymlinks3432 oFsInfo = oCurGuestSession.fsObjQueryInfo(oCurTest.sSrc, True); # fFollowSymlinks 3441 3433 else: 3442 oFsInfo = curGuestSession.fileQueryInfo(curTest.sSrc); 3443 3444 if oFsInfo.type is vboxcon.FsObjType_Directory: 3445 curProgress = curGuestSession.directoryCopyFromGuest(curTest.sSrc, curTest.sDst, curTest.aFlags); 3446 if curProgress is not None: 3447 oProgress = vboxwrappers.ProgressWrapper(curProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, \ 3448 "gctrlDirCopyFrom"); 3449 try: 3450 oProgress.wait(); 3451 if not oProgress.isSuccess(): 3452 oProgress.logResult(fIgnoreErrors = True); 3453 fRc2 = False; 3454 except: 3455 reporter.logXcpt('Waiting exception for sSrc="%s", sDst="%s":' % (curTest.sSrc, curTest.sDst)); 3456 fRc2 = False; 3457 else: 3458 reporter.error('No progress object returned'); 3459 fRc2 = False; 3460 elif oFsInfo.type is vboxcon.FsObjType_File: 3461 fRc2 = self.gctrlCopyFileFrom(curGuestSession, curTest.sSrc, curTest.sDst, curTest.aFlags); 3434 oFsInfo = oCurGuestSession.fileQueryInfo(oCurTest.sSrc); 3435 eFsObjType = oFsInfo.type; 3436 except: 3437 if oCurRes.fRc: 3438 reporter.errorXcpt('Query information exception for sSrc="%s", sDst="%s":' % (oCurTest.sSrc, oCurTest.sDst,)); 3439 else: 3440 reporter.logXcpt( 'Query information exception for sSrc="%s", sDst="%s":' % (oCurTest.sSrc, oCurTest.sDst,)); 3441 fRc2 = False; 3442 else: 3443 if eFsObjType == vboxcon.FsObjType_Directory: 3444 fRc2 = self.gctrlCopyDirFrom(oCurGuestSession, oCurTest.sSrc, oCurTest.sDst, oCurTest.fFlags, oCurRes.fRc); 3445 elif eFsObjType == vboxcon.FsObjType_File: 3446 fRc2 = self.gctrlCopyFileFrom(oCurGuestSession, oCurTest.sSrc, oCurTest.sDst, oCurTest.fFlags, oCurRes.fRc); 3462 3447 else: 3463 3448 reporter.log2('Element "%s" not handled (yet), skipping' % oFsInfo.name); 3464 3449 3465 except: 3466 reporter.logXcpt('Query information exception for sSrc="%s", sDst="%s":' % (curTest.sSrc, curTest.sDst)); 3467 fRc2 = False; 3468 3469 curTest.closeSession(); 3470 if fRc2 is curRes.fRc: 3471 ## @todo Verify the copied results (size, checksum?). 3472 pass; 3450 oCurTest.closeSession(); 3451 if fRc2 == oCurRes.fRc: 3452 pass; ## @todo Verify the copied results (size, checksum?). 3473 3453 else: 3474 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, curRes.fRc)); 3475 fRc = False; 3476 break; 3454 fRc = reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, oCurRes.fRc)); 3477 3455 3478 3456 return (fRc, oTxsSession); … … 3489 3467 if not os.path.isfile(sVBoxValidationKitISO): 3490 3468 sCur = os.getcwd(); 3491 for i in range(0, 10):3469 for i in xrange(0, 10): 3492 3470 sVBoxValidationKitISO = os.path.join(sCur, 'validationkit/VBoxValidationKit.iso'); 3493 3471 if os.path.isfile(sVBoxValidationKitISO): … … 3518 3496 [ tdTestUpdateAdditions(sSrc = ''), tdTestResult() ], 3519 3497 3520 # Wrong aFlags.3498 # Wrong fFlags. 3521 3499 [ tdTestUpdateAdditions(sSrc = self.oTstDrv.getGuestAdditionsIso(), 3522 aFlags = [ 1234 ]), tdTestResult() ],3500 fFlags = [ 1234 ]), tdTestResult() ], 3523 3501 3524 3502 # Non-existing .ISO. … … 3546 3524 fRc = True; 3547 3525 for (i, aTest) in enumerate(aaTests): 3548 curTest = aTest[0]; # tdTestExec, use an index, later.3549 curRes = aTest[1]; # tdTestResult3550 reporter.log('Testing #%d, sSrc="%s", aFlags="%s" ...' % \3551 (i, curTest.sSrc, curTest.aFlags));3552 curTest.setEnvironment(oSession, oTxsSession, oTestVm);3553 fRc, _ = curTest.createSession('Test #%d' % (i,));3526 oCurTest = aTest[0]; # tdTestExec, use an index, later. 3527 oCurRes = aTest[1]; # tdTestResult 3528 reporter.log('Testing #%d, sSrc="%s", fFlags="%s" ...' % \ 3529 (i, oCurTest.sSrc, oCurTest.fFlags)); 3530 oCurTest.setEnvironment(oSession, oTxsSession, oTestVm); 3531 fRc, _ = oCurTest.createSession('Test #%d' % (i,)); 3554 3532 if fRc is False: 3555 3533 reporter.error('Test #%d failed: Could not create session' % (i,)); 3556 3534 break; 3557 3535 try: 3558 curProgress = curTest.oTest.oGuest.updateGuestAdditions(curTest.sSrc, curTest.aArgs, curTest.aFlags);3559 if curProgress is not None:3560 oProgress = vboxwrappers.ProgressWrapper( curProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, "gctrlUpGA");3536 oCurProgress = oCurTest.oTest.oGuest.updateGuestAdditions(oCurTest.sSrc, oCurTest.aArgs, oCurTest.fFlags); 3537 if oCurProgress is not None: 3538 oProgress = vboxwrappers.ProgressWrapper(oCurProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, "gctrlUpGA"); 3561 3539 try: 3562 3540 oProgress.wait(); … … 3572 3550 except: 3573 3551 # Just log, don't assume an error here (will be done in the main loop then). 3574 reporter.logXcpt('Updating Guest Additions exception for sSrc="%s", aFlags="%s":' \3575 % ( curTest.sSrc, curTest.aFlags));3552 reporter.logXcpt('Updating Guest Additions exception for sSrc="%s", fFlags="%s":' \ 3553 % (oCurTest.sSrc, oCurTest.fFlags)); 3576 3554 fRc = False; 3577 curTest.closeSession();3578 if fRc is curRes.fRc:3555 oCurTest.closeSession(); 3556 if fRc is oCurRes.fRc: 3579 3557 if fRc: 3580 3558 ## @todo Verify if Guest Additions were really updated (build, revision, ...). 3581 3559 pass; 3582 3560 else: 3583 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc, curRes.fRc));3561 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc, oCurRes.fRc)); 3584 3562 fRc = False; 3585 3563 break; … … 3718 3696 aArgs = [ sCmd, '/C', 'dir', '/S', 'c:\\windows' ]; 3719 3697 aEnv = []; 3720 aFlags = [];3721 3722 for _ in range(100):3698 fFlags = []; 3699 3700 for _ in xrange(100): 3723 3701 oProc = oGuestSession.processCreate(sCmd, aArgs if self.fpApiVer >= 5.0 else aArgs[1:], 3724 aEnv, aFlags, 30 * 1000);3702 aEnv, fFlags, 30 * 1000); 3725 3703 3726 3704 aWaitFor = [ vboxcon.ProcessWaitForFlag_Terminate ];
Note:
See TracChangeset
for help on using the changeset viewer.