Changeset 79255 in vbox for trunk/src/VBox/ValidationKit
- Timestamp:
- Jun 20, 2019 3:14:07 AM (6 years ago)
- Location:
- trunk/src/VBox/ValidationKit
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/testdriver/testfileset.py
r79208 r79255 131 131 132 132 return True; 133 134 @staticmethod 135 def hexFormatBytes(abBuf): 136 """ Formats a buffer/string/whatever as a string of hex bytes """ 137 if sys.version_info[0] >= 3: 138 if utils.isString(abBuf): 139 try: abBuf = bytes(abBuf, 'utf-8'); 140 except: pass; 141 else: 142 if utils.isString(abBuf): 143 try: abBuf = bytearray(abBuf, 'utf-8'); # pylint: disable=redefined-variable-type 144 except: pass; 145 sRet = ''; 146 off = 0; 147 for off, bByte in enumerate(abBuf): 148 if off > 0: 149 sRet += ' ' if off & 7 else '-'; 150 if isinstance(bByte, int): 151 sRet += '%02x' % (bByte,); 152 else: 153 sRet += '%02x' % (ord(bByte),); 154 return sRet; 155 156 def equalMemory(self, abBuf, offFile = 0): 157 """ 158 Compares the content of the given buffer with the file content at that 159 file offset. 160 161 Returns True if it matches, False + error logging if it does not match. 162 """ 163 if not abBuf: 164 return True; 165 if offFile >= self.cbContent: 166 return reporter.error('buffer @ %s LB %s is beyond the end of the file (%s bytes)!' 167 % (offFile, len(abBuf), self.cbContent,)); 168 if offFile + len(abBuf) > self.cbContent: 169 return reporter.error('buffer @ %s LB %s is partially beyond the end of the file (%s bytes)!' 170 % (offFile, len(abBuf), self.cbContent,)); 171 if utils.areBytesEqual(abBuf, self.abContent[offFile:(offFile + len(abBuf))]): 172 return True; 173 174 reporter.error('mismatch with buffer @ %s LB %s (cbContent=%s)!' % (offFile, len(abBuf), self.cbContent,)); 175 reporter.error(' type(abBuf): %s' % (type(abBuf),)); 176 #if isinstance(abBuf, memoryview): 177 # reporter.error(' nbytes=%s len=%s itemsize=%s type(obj)=%s' 178 # % (abBuf.nbytes, len(abBuf), abBuf.itemsize, type(abBuf.obj),)); 179 reporter.error('type(abContent): %s' % (type(self.abContent),)); 180 181 offBuf = 0; 182 cbLeft = len(abBuf); 183 while cbLeft > 0: 184 cbLine = min(16, cbLeft); 185 abBuf1 = abBuf[offBuf:(offBuf + cbLine)]; 186 abBuf2 = self.abContent[offFile:(offFile + cbLine)]; 187 if not utils.areBytesEqual(abBuf1, abBuf2): 188 try: sStr1 = self.hexFormatBytes(abBuf1); 189 except: sStr1 = 'oops'; 190 try: sStr2 = self.hexFormatBytes(abBuf2); 191 except: sStr2 = 'oops'; 192 reporter.log('%#10x: %s' % (offBuf, sStr1,)); 193 reporter.log('%#10x: %s' % (offFile, sStr2,)); 194 195 # Advance. 196 offBuf += 16; 197 offFile += 16; 198 cbLeft -= 16; 199 200 return False; 201 202 133 203 134 204 … … 516 586 self.assertTrue(isinstance(oSet.chooseRandomFile(), TestFile)); 517 587 588 def testHexFormatBytes(self): 589 self.assertEqual(TestFile.hexFormatBytes(bytearray([0,1,2,3,4,5,6,7,8,9])), 590 '00 01 02 03 04 05 06 07-08 09'); 591 self.assertEqual(TestFile.hexFormatBytes(memoryview(bytearray([0,1,2,3,4,5,6,7,8,9,10, 16]))), 592 '00 01 02 03 04 05 06 07-08 09 0a 10'); 593 518 594 519 595 if __name__ == '__main__': -
trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py
r79246 r79255 395 395 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = None); 396 396 self.sFile = sFile; 397 398 class tdTestFileOpen(tdTestGuestCtrlBase): 399 """ 400 Tests opening a guest files. 401 """ 402 def __init__(self, sFile = "", eAccessMode = None, eAction = None, eSharing = None, 403 fCreationMode = 0o660, sUser = None, sPassword = None): 404 tdTestGuestCtrlBase.__init__(self); 405 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = None); 406 self.sFile = sFile; 407 self.eAccessMode = eAccessMode if eAccessMode is not None else vboxcon.FileAccessMode_ReadOnly; 408 self.eAction = eAction if eAction is not None else vboxcon.FileOpenAction_OpenExisting; 409 self.eSharing = eSharing if eSharing is not None else vboxcon.FileSharingMode_All; 410 self.fCreationMode = fCreationMode; 411 self.afOpenFlags = []; 412 self.oOpenedFile = None; 413 414 def doOpenStep(self, fExpectSuccess): 415 """ 416 Does the open step, putting the resulting file in oOpenedFile. 417 """ 418 try: 419 self.oOpenedFile = self.oGuestSession.fileOpenEx(self.sFile, self.eAccessMode, self.eAction, 420 self.eSharing, self.fCreationMode, self.afOpenFlags); 421 except: 422 reporter.maybeErr(fExpectSuccess, 'fileOpenEx(%s, %s, %s, %s, %s, %s)' 423 % (self.sFile, self.eAccessMode, self.eAction, self.eSharing, 424 self.fCreationMode, self.afOpenFlags,)); 425 return False; 426 return True; 427 428 def doStepsOnOpenedFile(self, fExpectSuccess): 429 """ Overridden by children to do more testing. """ 430 _ = fExpectSuccess; 431 return True; 432 433 def doCloseStep(self): 434 """ Closes the file. """ 435 if self.oOpenedFile: 436 try: 437 self.oOpenedFile.close(); 438 except: 439 return reporter.errorXcpt('close([%s, %s, %s, %s, %s, %s])' 440 % (self.sFile, self.eAccessMode, self.eAction, self.eSharing, 441 self.fCreationMode, self.afOpenFlags,)); 442 self.oOpenedFile = None; 443 return True; 444 445 def doSteps(self, fExpectSuccess): 446 """ Do the tests. """ 447 fRc = self.doOpenStep(fExpectSuccess); 448 if fRc is True: 449 fRc = self.doStepsOnOpenedFile(fExpectSuccess); 450 if self.oOpenedFile: 451 fRc = self.doCloseStep() and fRc; 452 return fRc; 453 454 455 class tdTestFileOpenCheckSize(tdTestFileOpen): 456 """ 457 Opens a file and checks the size. 458 """ 459 def __init__(self, sFile = "", eAccessMode = None, eAction = None, eSharing = None, 460 fCreationMode = 0o660, cbOpenExpected = 0, sUser = None, sPassword = None): 461 tdTestFileOpen.__init__(self, sFile, eAccessMode, eAction, eSharing, fCreationMode, sUser, sPassword); 462 self.cbOpenExpected = cbOpenExpected; 463 464 def doStepsOnOpenedFile(self, fExpectSuccess): 465 # 466 # Call parent. 467 # 468 fRc = tdTestFileOpen.doStepsOnOpenedFile(self, fExpectSuccess); 469 470 # 471 # Check the size. 472 # 473 try: 474 oFsObjInfo = self.oOpenedFile.queryInfo(); 475 except: 476 return reporter.errorXcpt('queryInfo([%s, %s, %s, %s, %s, %s])' 477 % (self.sFile, self.eAccessMode, self.eAction, self.eSharing, 478 self.fCreationMode, self.afOpenFlags,)); 479 if oFsObjInfo is None: 480 return reporter.error('IGuestFile::queryInfo returned None'); 481 try: 482 cbFile = oFsObjInfo.objectSize; 483 except: 484 return reporter.errorXcpt(); 485 if cbFile != self.cbOpenExpected: 486 return reporter.error('Wrong file size after open (%d): %s, expected %s (file %s) (#1)' 487 % (self.eAction, cbFile, self.cbOpenExpected, self.sFile)); 488 489 try: 490 cbFile = self.oOpenedFile.querySize(); 491 except: 492 return reporter.errorXcpt('querySize([%s, %s, %s, %s, %s, %s])' 493 % (self.sFile, self.eAccessMode, self.eAction, self.eSharing, 494 self.fCreationMode, self.afOpenFlags,)); 495 if cbFile != self.cbOpenExpected: 496 return reporter.error('Wrong file size after open (%d): %s, expected %s (file %s) (#2)' 497 % (self.eAction, cbFile, self.cbOpenExpected, self.sFile)); 498 499 return fRc; 397 500 398 501 class tdTestFileReadWrite(tdTestGuestCtrlBase): … … 988 1091 'exec_basic', 'exec_timeout', 989 1092 'dir_create', 'dir_create_temp', 'dir_read', 990 'file_ remove', 'file_stat', 'file_read', 'file_write',1093 'file_open', 'file_remove', 'file_stat', 'file_read', 'file_write', 991 1094 'copy_to', 'copy_from', 992 1095 'update_additions' … … 1049 1152 ( False, self.testGuestCtrlCopyFrom, 'copy_from', 'Copy from guest',), 1050 1153 ( False, self.testGuestCtrlFileStat, 'file_stat', 'Querying file information (stat)',), 1154 ( False, self.testGuestCtrlFileOpen, 'file_open', 'File open',), 1051 1155 ( False, self.testGuestCtrlFileRead, 'file_read', 'File read',), 1052 1156 ( False, self.testGuestCtrlFileWrite, 'file_write', 'File write',), … … 3256 3360 return (fRc, oTxsSession); 3257 3361 3258 def testGuestCtrlFileRead(self, oSession, oTxsSession, oTestVm): # pylint: disable=too-many-locals 3362 def testGuestCtrlFileOpen(self, oSession, oTxsSession, oTestVm): # pylint: disable=too-many-locals 3363 """ 3364 Tests opening guest files. 3365 """ 3366 if self.oTstDrv.fpApiVer < 5.0: 3367 reporter.log('Skipping because of pre 5.0 API'); 3368 return None; 3369 3370 # 3371 # Paths. 3372 # 3373 sTempDir = self.getGuestTempDir(oTestVm); 3374 sFileForReading = self.getGuestSystemFileForReading(oTestVm); 3375 asFiles = [ 3376 oTestVm.pathJoin(sTempDir, 'file-open-0'), 3377 oTestVm.pathJoin(sTempDir, 'file-open-1'), 3378 oTestVm.pathJoin(sTempDir, 'file-open-2'), 3379 ]; 3380 asNonEmptyFiles = [ 3381 oTestVm.pathJoin(sTempDir, 'file-open-10'), 3382 oTestVm.pathJoin(sTempDir, 'file-open-11'), 3383 oTestVm.pathJoin(sTempDir, 'file-open-12'), 3384 oTestVm.pathJoin(sTempDir, 'file-open-13'), 3385 ]; 3386 sContent = 'abcdefghijklmnopqrstuvwxyz0123456789'; 3387 for sFile in asNonEmptyFiles: 3388 if oTxsSession.syncUploadString(sContent, sFile) is not True: 3389 return reporter.error('Failed to create "%s" via TXS' % (sFile,)); 3390 3391 # 3392 # The tests. 3393 # 3394 atTests = [ 3395 # Invalid stuff. 3396 [ tdTestFileOpen(sFile = ''), tdTestResultFailure() ], 3397 # Wrong open mode. 3398 [ tdTestFileOpen(sFile = sFileForReading, eAccessMode = -1), tdTestResultFailure() ], 3399 # Wrong disposition. 3400 [ tdTestFileOpen(sFile = sFileForReading, eAction = -1), tdTestResultFailure() ], 3401 # Non-existing file or path. 3402 [ tdTestFileOpen(sFile = oTestVm.pathJoin(sTempDir, 'no-such-file-or-dir')), tdTestResultFailure() ], 3403 [ tdTestFileOpen(sFile = oTestVm.pathJoin(sTempDir, 'no-such-file-or-dir'), 3404 eAction = vboxcon.FileOpenAction_OpenExistingTruncated), tdTestResultFailure() ], 3405 [ tdTestFileOpen(sFile = oTestVm.pathJoin(sTempDir, 'no-such-file-or-dir'), 3406 eAccessMode = vboxcon.FileAccessMode_WriteOnly, 3407 eAction = vboxcon.FileOpenAction_OpenExistingTruncated), tdTestResultFailure() ], 3408 [ tdTestFileOpen(sFile = oTestVm.pathJoin(sTempDir, 'no-such-file-or-dir'), 3409 eAccessMode = vboxcon.FileAccessMode_ReadWrite, 3410 eAction = vboxcon.FileOpenAction_OpenExistingTruncated), tdTestResultFailure() ], 3411 [ tdTestFileOpen(sFile = oTestVm.pathJoin(sTempDir, 'no-such-dir', 'no-such-file')), tdTestResultFailure() ], 3412 # Wrong type: 3413 [ tdTestFileOpen(sFile = self.getGuestTempDir(oTestVm)), tdTestResultFailure() ], 3414 [ tdTestFileOpen(sFile = self.getGuestSystemDir(oTestVm)), tdTestResultFailure() ], 3415 # O_EXCL and such: 3416 [ tdTestFileOpen(sFile = sFileForReading, eAction = vboxcon.FileOpenAction_CreateNew, 3417 eAccessMode = vboxcon.FileAccessMode_ReadWrite), tdTestResultFailure() ], 3418 [ tdTestFileOpen(sFile = sFileForReading, eAction = vboxcon.FileOpenAction_CreateNew), tdTestResultFailure() ], 3419 # Open a file. 3420 [ tdTestFileOpen(sFile = sFileForReading), tdTestResultSuccess() ], 3421 [ tdTestFileOpen(sFile = sFileForReading, 3422 eAction = vboxcon.FileOpenAction_OpenOrCreate), tdTestResultSuccess() ], 3423 # Create a new file. 3424 [ tdTestFileOpenCheckSize(sFile = asFiles[0], eAction = vboxcon.FileOpenAction_CreateNew, 3425 eAccessMode = vboxcon.FileAccessMode_ReadWrite), tdTestResultSuccess() ], 3426 [ tdTestFileOpenCheckSize(sFile = asFiles[0], eAction = vboxcon.FileOpenAction_CreateNew, 3427 eAccessMode = vboxcon.FileAccessMode_ReadWrite), tdTestResultFailure() ], 3428 [ tdTestFileOpenCheckSize(sFile = asFiles[0], eAction = vboxcon.FileOpenAction_OpenExisting, 3429 eAccessMode = vboxcon.FileAccessMode_ReadWrite), tdTestResultSuccess() ], 3430 [ tdTestFileOpenCheckSize(sFile = asFiles[0], eAction = vboxcon.FileOpenAction_CreateOrReplace, 3431 eAccessMode = vboxcon.FileAccessMode_ReadWrite), tdTestResultSuccess() ], 3432 [ tdTestFileOpenCheckSize(sFile = asFiles[0], eAction = vboxcon.FileOpenAction_OpenOrCreate, 3433 eAccessMode = vboxcon.FileAccessMode_ReadWrite), tdTestResultSuccess() ], 3434 [ tdTestFileOpenCheckSize(sFile = asFiles[0], eAction = vboxcon.FileOpenAction_OpenExistingTruncated, 3435 eAccessMode = vboxcon.FileAccessMode_ReadWrite), tdTestResultSuccess() ], 3436 [ tdTestFileOpenCheckSize(sFile = asFiles[0], eAction = vboxcon.FileOpenAction_AppendOrCreate, 3437 eAccessMode = vboxcon.FileAccessMode_ReadWrite), tdTestResultSuccess() ], 3438 # Open or create a new file. 3439 [ tdTestFileOpenCheckSize(sFile = asFiles[1], eAction = vboxcon.FileOpenAction_OpenOrCreate, 3440 eAccessMode = vboxcon.FileAccessMode_ReadWrite), tdTestResultSuccess() ], 3441 # Create or replace a new file. 3442 [ tdTestFileOpenCheckSize(sFile = asFiles[2], eAction = vboxcon.FileOpenAction_CreateOrReplace, 3443 eAccessMode = vboxcon.FileAccessMode_ReadWrite), tdTestResultSuccess() ], 3444 # Open the non-empty files in non-destructive modes. 3445 [ tdTestFileOpenCheckSize(sFile = asNonEmptyFiles[0], cbOpenExpected = len(sContent)), tdTestResultSuccess() ], 3446 [ tdTestFileOpenCheckSize(sFile = asNonEmptyFiles[1], cbOpenExpected = len(sContent), 3447 eAccessMode = vboxcon.FileAccessMode_ReadWrite), tdTestResultSuccess() ], 3448 [ tdTestFileOpenCheckSize(sFile = asNonEmptyFiles[2], cbOpenExpected = len(sContent), 3449 eAccessMode = vboxcon.FileAccessMode_WriteOnly), tdTestResultSuccess() ], 3450 3451 [ tdTestFileOpenCheckSize(sFile = asNonEmptyFiles[0], cbOpenExpected = len(sContent), 3452 eAction = vboxcon.FileOpenAction_OpenOrCreate, 3453 eAccessMode = vboxcon.FileAccessMode_ReadWrite), tdTestResultSuccess() ], 3454 [ tdTestFileOpenCheckSize(sFile = asNonEmptyFiles[1], cbOpenExpected = len(sContent), 3455 eAction = vboxcon.FileOpenAction_OpenOrCreate, 3456 eAccessMode = vboxcon.FileAccessMode_WriteOnly), tdTestResultSuccess() ], 3457 [ tdTestFileOpenCheckSize(sFile = asNonEmptyFiles[2], cbOpenExpected = len(sContent), 3458 eAction = vboxcon.FileOpenAction_OpenOrCreate, 3459 eAccessMode = vboxcon.FileAccessMode_WriteOnly), tdTestResultSuccess() ], 3460 3461 [ tdTestFileOpenCheckSize(sFile = asNonEmptyFiles[0], cbOpenExpected = len(sContent), 3462 eAction = vboxcon.FileOpenAction_AppendOrCreate, 3463 eAccessMode = vboxcon.FileAccessMode_ReadWrite), tdTestResultSuccess() ], 3464 [ tdTestFileOpenCheckSize(sFile = asNonEmptyFiles[1], cbOpenExpected = len(sContent), 3465 eAction = vboxcon.FileOpenAction_AppendOrCreate, 3466 eAccessMode = vboxcon.FileAccessMode_WriteOnly), tdTestResultSuccess() ], 3467 [ tdTestFileOpenCheckSize(sFile = asNonEmptyFiles[2], cbOpenExpected = len(sContent), 3468 eAction = vboxcon.FileOpenAction_AppendOrCreate, 3469 eAccessMode = vboxcon.FileAccessMode_WriteOnly), tdTestResultSuccess() ], 3470 3471 # Now the destructive stuff: 3472 [ tdTestFileOpenCheckSize(sFile = asNonEmptyFiles[0], eAccessMode = vboxcon.FileAccessMode_WriteOnly, 3473 eAction = vboxcon.FileOpenAction_OpenExistingTruncated), tdTestResultSuccess() ], 3474 [ tdTestFileOpenCheckSize(sFile = asNonEmptyFiles[1], eAccessMode = vboxcon.FileAccessMode_WriteOnly, 3475 eAction = vboxcon.FileOpenAction_CreateOrReplace), tdTestResultSuccess() ], 3476 [ tdTestFileOpenCheckSize(sFile = asNonEmptyFiles[2], eAction = vboxcon.FileOpenAction_CreateOrReplace, 3477 eAccessMode = vboxcon.FileAccessMode_WriteOnly), tdTestResultSuccess() ], 3478 ]; 3479 3480 # 3481 # Do the testing. 3482 # 3483 fRc = True; 3484 for (i, tTest) in enumerate(atTests): 3485 oCurTest = tTest[0] # type: tdTestFileOpen 3486 oCurRes = tTest[1] # type: tdTestResult 3487 3488 reporter.log('Testing #%d: %s - sFile="%s", eAccessMode=%d, eAction=%d, (%s, %s, %s) ...' 3489 % (i, oCurTest.__class__.__name__, oCurTest.sFile, oCurTest.eAccessMode, oCurTest.eAction, 3490 oCurTest.eSharing, oCurTest.fCreationMode, oCurTest.afOpenFlags,)); 3491 3492 oCurTest.setEnvironment(oSession, oTxsSession, oTestVm); 3493 fRc, _ = oCurTest.createSession('testGuestCtrlFileOpen: Test #%d' % (i,), True); 3494 if fRc is not True: 3495 fRc = reporter.error('Test #%d failed: Could not create session' % (i,)); 3496 break; 3497 3498 fRc2 = oCurTest.doSteps(oCurRes.fRc); 3499 if fRc2 != oCurRes.fRc: 3500 fRc = reporter.error('Test #%d result mismatch: Got %s, expected %s' % (i, fRc2, oCurRes.fRc,)); 3501 3502 fRc = oCurTest.closeSession(True) and fRc; 3503 3504 return (fRc, oTxsSession); 3505 3506 3507 def testGuestCtrlFileRead(self, oSession, oTxsSession, oTestVm): # pylint: disable=too-many-branches,too-many-statements 3259 3508 """ 3260 3509 Tests reading from guest files. 3261 3510 """ 3262 3263 if oTxsSession.syncMkDir('${SCRATCH}/testGuestCtrlFileRead') is False: 3264 reporter.error('Could not create scratch directory on guest'); 3511 if self.oTstDrv.fpApiVer < 5.0: 3512 reporter.log('Skipping because of pre 5.0 API'); 3513 return None; 3514 3515 # 3516 # Open and read all the files in the test file set. 3517 # 3518 3519 oTest = tdTestGuestCtrlBase(); 3520 oTest.setEnvironment(oSession, oTxsSession, oTestVm); 3521 fRc2, oGuestSession = oTest.createSession('FsStat on TestFileSet', True); 3522 if fRc2 is not True: 3265 3523 return (False, oTxsSession); 3266 3524 3267 atTests = [];3268 atTests.extend([3269 # Invalid stuff.3270 [ tdTestFileReadWrite(cbToReadWrite = 0), tdTestResultFileReadWrite() ],3271 [ tdTestFileReadWrite(sFile = ''), tdTestResultFileReadWrite() ],3272 [ tdTestFileReadWrite(sFile = 'non-existing.file'), tdTestResultFileReadWrite() ],3273 # Wrong open mode.3274 [ tdTestFileReadWrite(sFile = 'non-existing.file', sOpenMode = 'rt', sDisposition = 'oe'),3275 tdTestResultFileReadWrite() ],3276 [ tdTestFileReadWrite(sFile = '\\\\uncrulez\\non-existing.file', sOpenMode = 'tr', sDisposition = 'oe'),3277 tdTestResultFileReadWrite() ],3278 [ tdTestFileReadWrite(sFile = '../../non-existing.file', sOpenMode = 'wr', sDisposition = 'oe'),3279 tdTestResultFileReadWrite() ],3280 # Wrong disposition.3281 [ tdTestFileReadWrite(sFile = 'non-existing.file', sOpenMode = 'r', sDisposition = 'e'),3282 tdTestResultFileReadWrite() ],3283 [ tdTestFileReadWrite(sFile = '\\\\uncrulez\\non-existing.file', sOpenMode = 'r', sDisposition = 'o'),3284 tdTestResultFileReadWrite() ],3285 [ tdTestFileReadWrite(sFile = '../../non-existing.file', sOpenMode = 'r', sDisposition = 'c'),3286 tdTestResultFileReadWrite() ],3287 # Opening non-existing file when it should exist.3288 [ tdTestFileReadWrite(sFile = 'non-existing.file', sOpenMode = 'r', sDisposition = 'oe'),3289 tdTestResultFileReadWrite() ],3290 [ tdTestFileReadWrite(sFile = '\\\\uncrulez\\non-existing.file', sOpenMode = 'r', sDisposition = 'oe'),3291 tdTestResultFileReadWrite() ],3292 [ tdTestFileReadWrite(sFile = '../../non-existing.file', sOpenMode = 'r', sDisposition = 'oe'),3293 tdTestResultFileReadWrite() ]3294 ]);3295 3296 if oTestVm.isWindows():3297 atTests.extend([3298 # Create a file which must not exist (but it hopefully does).3299 [ tdTestFileReadWrite(sFile = 'C:\\Windows\\System32\\calc.exe', sOpenMode = 'w', sDisposition = 'ce'),3300 tdTestResultFileReadWrite() ],3301 # Open a file which must exist.3302 [ tdTestFileReadWrite(sFile = 'C:\\Windows\\System32\\kernel32.dll', sOpenMode = 'r', sDisposition = 'oe'),3303 tdTestResultFileReadWrite(fRc = True) ],3304 # Try truncating a file which already is opened with a different sharing mode (and thus should fail).3305 [ tdTestFileReadWrite(sFile = 'C:\\Windows\\System32\\kernel32.dll', sOpenMode = 'w', sDisposition = 'ot'),3306 tdTestResultFileReadWrite() ]3307 ]);3308 3309 # Note: tst-xppro has other contents in eula.txt.3310 if oTestVm.sVmName.startswith('tst-xpsp2'):3311 atTests.extend([3312 # Reading from beginning.3313 [ tdTestFileReadWrite(sFile = 'C:\\Windows\\System32\\eula.txt',3314 sOpenMode = 'r', sDisposition = 'oe', cbToReadWrite = 33),3315 tdTestResultFileReadWrite(fRc = True, abBuf = 'Microsoft(r) Windows(r) XP Profes',3316 cbProcessed = 33, offFile = 33) ],3317 # Reading from offset.3318 [ tdTestFileReadWrite(sFile = 'C:\\Windows\\System32\\eula.txt',3319 sOpenMode = 'r', sDisposition = 'oe', offFile = 17769, cbToReadWrite = 31),3320 tdTestResultFileReadWrite(fRc = True, abBuf = 'only with the HARDWARE. If\x0d\x0a ',3321 cbProcessed = 31, offFile = 17769 + 31) ]3322 ]);3323 elif oTestVm.isLinux():3324 atTests.extend([3325 # Create a file which must not exist (but it hopefully does).3326 [ tdTestFileReadWrite(sFile = '/etc/issue', sOpenMode = 'w', sDisposition = 'ce'),3327 tdTestResultFileReadWrite() ],3328 # Open a file which must exist.3329 [ tdTestFileReadWrite(sFile = '/etc/issue', sOpenMode = 'r', sDisposition = 'oe'),3330 tdTestResultFileReadWrite(fRc = True) ],3331 # Try truncating a file which already is opened with a different sharing mode (and thus should fail).3332 [ tdTestFileReadWrite(sFile = '/etc/issue', sOpenMode = 'w', sDisposition = 'ot'),3333 tdTestResultFileReadWrite() ]3334 ]);3335 3336 3525 fRc = True; 3337 for (i, aTest) in enumerate(atTests): 3338 oCurTest = aTest[0]; # tdTestFileReadWrite, use an index, later. 3339 oCurRes = aTest[1]; # tdTestResult 3340 reporter.log('Testing #%d, sFile="%s", cbToReadWrite=%d, sOpenMode="%s", sDisposition="%s", offFile=%d ...' 3341 % (i, oCurTest.sFile, oCurTest.cbToReadWrite, oCurTest.sOpenMode, 3342 oCurTest.sDisposition, oCurTest.offFile)); 3343 oCurTest.setEnvironment(oSession, oTxsSession, oTestVm); 3344 fRc, oCurGuestSession = oCurTest.createSession('testGuestCtrlFileRead: Test #%d' % (i,)); 3345 if fRc is False: 3346 reporter.error('Test #%d failed: Could not create session' % (i,)); 3347 break; 3526 for oTestFile in self.oTestFiles.aoFiles: # type: testfileset.TestFile 3527 reporter.log2('Test file: %s bytes, "%s" ...' % (oTestFile.cbContent, oTestFile.sPath,)); 3528 3529 # 3530 # Open it: 3531 # 3348 3532 try: 3349 fRc2 = True; 3350 if oCurTest.offFile > 0: # The offset parameter is gone. 3351 if self.oTstDrv.fpApiVer >= 5.0: 3352 curFile = oCurGuestSession.fileOpenEx(oCurTest.sFile, oCurTest.getAccessMode(), oCurTest.getOpenAction(), 3353 oCurTest.getSharingMode(), oCurTest.fCreationMode, []); 3354 curFile.seek(oCurTest.offFile, vboxcon.FileSeekOrigin_Begin); 3533 oFile = oGuestSession.fileOpenEx(oTestFile.sPath, vboxcon.FileAccessMode_ReadOnly, 3534 vboxcon.FileOpenAction_OpenExisting, vboxcon.FileSharingMode_All, 0, []); 3535 except: 3536 fRc = reporter.errorXcpt('sPath=%s' % (oTestFile.sPath, )); 3537 continue; 3538 3539 # 3540 # Read the file in different sized chunks: 3541 # 3542 if oTestFile.cbContent < 128: 3543 acbChunks = xrange(1,128); 3544 elif oTestFile.cbContent < 1024: 3545 acbChunks = (2048, 127, 63, 32, 29, 17, 16, 15, 9); 3546 else: 3547 acbChunks = (128 * 1024, 32 * 1024, 8192, 1024, 128); 3548 for cbChunk in acbChunks: 3549 # Read the whole file straight thru: 3550 #reporter.log2('... cbChunk=%s' % (cbChunk,)); 3551 offFile = 0; 3552 while offFile <= oTestFile.cbContent: 3553 try: 3554 abRead = oFile.read(cbChunk, 30*1000); 3555 except: 3556 fRc = reporter.errorXcpt('%s: offFile=%s cbChunk=%s cbContent=%s' 3557 % (oTestFile.sPath, offFile, cbChunk, oTestFile.cbContent)); 3558 break; 3559 cbRead = len(abRead); 3560 if cbRead == 0 and offFile == oTestFile.cbContent: 3561 break; 3562 if cbRead <= 0: 3563 fRc = reporter.error('%s @%s: cbRead=%s, cbContent=%s' 3564 % (oTestFile.sPath, offFile, cbRead, oTestFile.cbContent)); 3565 break; 3566 if not oTestFile.equalMemory(abRead, offFile): 3567 fRc = reporter.error('%s: read mismatch @ %s LB %s' % (oTestFile.sPath, offFile, cbRead)); 3568 break; 3569 offFile += cbRead; 3570 3571 # Seek to start of file. 3572 try: 3573 offFile = oFile.seek(0, vboxcon.FileSeekOrigin_Begin); 3574 except: 3575 fRc = reporter.errorXcpt('%s: error seeking to start of file' % (oTestFile.sPath,)); 3576 break; 3577 if offFile != 0: 3578 fRc = reporter.error('%s: seek to start of file returned %u, expected 0' % (oTestFile.sPath, offFile)); 3579 break; 3580 3581 # 3582 # Random reads. 3583 # 3584 for _ in xrange(16): 3585 offFile = self.oTestFiles.oRandom.randrange(0, oTestFile.cbContent + 1024); 3586 cbToRead = self.oTestFiles.oRandom.randrange(1, oTestFile.cbContent + 256); 3587 if cbToRead > 1024*1024: 3588 cbToRead = 1024*1024; 3589 #reporter.log2('... %s LB %s' % (offFile, cbToRead,)); 3590 3591 try: 3592 offActual = oFile.seek(offFile, vboxcon.FileSeekOrigin_Begin); 3593 except: 3594 fRc = reporter.errorXcpt('%s: error seeking to %s' % (oTestFile.sPath, offFile)); 3595 break; 3596 if offActual != offFile: 3597 fRc = reporter.error('%s: seek(%s,Begin) -> %s, expected %s' 3598 % (oTestFile.sPath, offFile, offActual, offFile)); 3599 break; 3600 3601 try: 3602 abRead = oFile.read(cbToRead, 30*1000); 3603 except: 3604 fRc = reporter.errorXcpt('%s: offFile=%s cbToRead=%s cbContent=%s' 3605 % (oTestFile.sPath, offFile, cbToRead, oTestFile.cbContent)); 3606 else: 3607 cbRead = len(abRead); 3608 if not oTestFile.equalMemory(abRead, offFile): 3609 fRc = reporter.error('%s: random read mismatch @ %s LB %s' % (oTestFile.sPath, offFile, cbRead,)); 3610 3611 try: 3612 offActual = oFile.offset; 3613 except: 3614 fRc = reporter.errorXcpt('%s: offFile=%s cbToRead=%s cbContent=%s (#1)' 3615 % (oTestFile.sPath, offFile, cbToRead, oTestFile.cbContent)); 3616 else: 3617 if offActual != offFile + cbRead: 3618 fRc = reporter.error('%s: IFile.offset is %s, expected %s (offFile=%s cbToRead=%s cbRead=%s) (#1)' 3619 % (oTestFile.sPath, offActual, offFile + cbRead, offFile, cbToRead, cbRead)); 3620 try: 3621 offActual = oFile.seek(0, vboxcon.FileSeekOrigin_Current); 3622 except: 3623 fRc = reporter.errorXcpt('%s: offFile=%s cbToRead=%s cbContent=%s (#1)' 3624 % (oTestFile.sPath, offFile, cbToRead, oTestFile.cbContent)); 3625 else: 3626 if offActual != offFile + cbRead: 3627 fRc = reporter.error('%s: seek(0,cur) -> %s, expected %s (offFile=%s cbToRead=%s cbRead=%s) (#1)' 3628 % (oTestFile.sPath, offActual, offFile + cbRead, offFile, cbToRead, cbRead)); 3629 3630 # 3631 # Random reads using readAt. 3632 # 3633 for _ in xrange(16): 3634 offFile = self.oTestFiles.oRandom.randrange(0, oTestFile.cbContent + 1024); 3635 cbToRead = self.oTestFiles.oRandom.randrange(1, oTestFile.cbContent + 256); 3636 if cbToRead > 1024*1024: 3637 cbToRead = 1024*1024; 3638 #reporter.log2('... %s LB %s (readAt)' % (offFile, cbToRead,)); 3639 3640 try: 3641 abRead = oFile.readAt(offFile, cbToRead, 30*1000); 3642 except: 3643 fRc = reporter.errorXcpt('%s: offFile=%s cbToRead=%s cbContent=%s' 3644 % (oTestFile.sPath, offFile, cbToRead, oTestFile.cbContent)); 3645 else: 3646 cbRead = len(abRead); 3647 if offFile >= oTestFile.cbContent or offFile + cbRead > oTestFile.cbContent: 3648 if cbRead != 0: 3649 fRc = reporter.error('%s: Read returned data beyond end of file: %s + %s = %s vs cbContent=%s (#2)' 3650 % (oTestFile.sPath, offFile, cbRead, offFile + cbRead, oTestFile.cbContent,)); 3651 if offFile + cbRead <= oTestFile.cbContent \ 3652 and not utils.areBytesEqual(abRead, oTestFile.abContent[offFile:(offFile + cbRead)]): 3653 fRc = reporter.error('%s: random readAt mismatch @ %s LB %s' % (oTestFile.sPath, offFile, cbRead,)); 3654 3655 if not self.fSkipKnownBugs: 3656 ## @todo See todo in GuestFile::getOffset() from r127065 (restored in r131439), but essentially 3657 ## the issue is that 'mCurOffset += cbActuallyRead' doesn't work for non-linear readAt calls. 3658 ## It should be 'mCurOffset = readAt.offsetParam + cbActuallyRead'. 3659 try: 3660 offActual = oFile.offset; 3661 except: 3662 fRc = reporter.errorXcpt('%s: offFile=%s cbToRead=%s cbContent=%s (#2)' 3663 % (oTestFile.sPath, offFile, cbToRead, oTestFile.cbContent)); 3355 3664 else: 3356 curFile = oCurGuestSession.fileOpenEx(oCurTest.sFile, oCurTest.sOpenMode, oCurTest.sDisposition, 3357 oCurTest.sSharingMode, oCurTest.fCreationMode, oCurTest.offFile); 3358 curOffset = long(curFile.offset); 3359 resOffset = long(oCurTest.offFile); 3360 if curOffset != resOffset: 3361 reporter.error('Test #%d failed: Initial offset on open does not match: Got %d, expected %d' 3362 % (i, curOffset, resOffset)); 3363 fRc2 = False; 3665 if offActual != offFile + cbRead: 3666 fRc = reporter.error('%s: IFile.offset is %s, expected %s (offFile=%s cbToRead=%s cbRead=%s) (#2)' 3667 % (oTestFile.sPath, offActual, offFile + cbRead, offFile, cbToRead, cbRead)); 3668 ## @todo The trouble here is that RTFileReadAt may or may not do the seeking depending on the OS (see docs). 3669 ## In addition, windows will not update the position if the offset is beyond EOF it seems. 3670 ## Fix is to always do a RTFileSeek after a successful RTFileReadAt call. 3671 try: 3672 offActual = oFile.seek(0, vboxcon.FileSeekOrigin_Current); 3673 except: 3674 fRc = reporter.errorXcpt('%s: offFile=%s cbToRead=%s cbContent=%s (#2)' 3675 % (oTestFile.sPath, offFile, cbToRead, oTestFile.cbContent)); 3676 else: 3677 if offActual != offFile + cbRead: 3678 fRc = reporter.error('%s: seek(0,cur) -> %s, expected %s (offFile=%s cbToRead=%s cbRead=%s) (#2)' 3679 % (oTestFile.sPath, offActual, offFile + cbRead, offFile, cbToRead, cbRead)); 3680 3681 # 3682 # A few negative things. 3683 # 3684 try: 3685 abRead = oFile.read(0, 30*1000); 3686 except Exception as oXcpt: 3687 if vbox.ComError.notEqual(oXcpt, vbox.ComError.E_INVALIDARG): 3688 reporter.errorXcpt('read(0,30s) did not raise E_INVALIDARG as expected!'); 3689 else: 3690 reporter.error('read(0,30s) did not fail!'); 3691 3692 try: 3693 abRead = oFile.readAt(0, 0, 30*1000); 3694 except Exception as oXcpt: 3695 if vbox.ComError.notEqual(oXcpt, vbox.ComError.E_INVALIDARG): 3696 reporter.errorXcpt('readAt(0,0,30s) did not raise E_INVALIDARG as expected!'); 3697 else: 3698 reporter.error('readAt(0,0,30s) did not fail!'); 3699 3700 if not self.fSkipKnownBugs: ## @todo Place a restriction on how much we permit being read in a single request. 3701 try: ## Document it in VirtualBox.xidl. 3702 abRead = oFile.read(1024*1024*1024, 30*1000); 3703 except Exception as oXcpt: 3704 if vbox.ComError.notEqual(oXcpt, vbox.ComError.E_INVALIDARG): 3705 reporter.errorXcpt('read(1GiB,30s) did not raise E_INVALIDARG as expected!'); 3364 3706 else: 3365 if self.oTstDrv.fpApiVer >= 5.0: 3366 curFile = oCurGuestSession.fileOpen(oCurTest.sFile, oCurTest.getAccessMode(), oCurTest.getOpenAction(), 3367 oCurTest.fCreationMode); 3707 reporter.error('read(1GiB,30s) did not fail! len(abRead)=%s' % (len(abRead), )); 3708 3709 try: 3710 abRead = oFile.readAt(0, 1024*1024*1024, 30*1000); 3711 except Exception as oXcpt: 3712 if vbox.ComError.notEqual(oXcpt, vbox.ComError.E_INVALIDARG): 3713 reporter.errorXcpt('readAt(0,1GiB,30s) did not raise E_INVALIDARG as expected!'); 3714 else: 3715 reporter.error('readAt(0,1GiB,30s) did not fail! len(abRead)=%s' % (len(abRead), )); 3716 3717 # 3718 # Check stat info on the file as well as querySize. 3719 # 3720 try: 3721 oFsObjInfo = oFile.queryInfo(); 3722 except: 3723 fRc = reporter.errorXcpt('%s: queryInfo()' % (oTestFile.sPath,)); 3724 else: 3725 if oFsObjInfo is None: 3726 fRc = reporter.error('IGuestFile::queryInfo returned None'); 3727 else: 3728 try: 3729 cbFile = oFsObjInfo.objectSize; 3730 except: 3731 fRc = reporter.errorXcpt(); 3368 3732 else: 3369 curFile = oCurGuestSession.fileOpen(oCurTest.sFile, oCurTest.sOpenMode, oCurTest.sDisposition, 3370 oCurTest.fCreationMode); 3371 if fRc2 and oCurTest.cbToReadWrite > 0: 3372 ## @todo Split this up in 64K reads. Later. 3373 ## @todo Test timeouts. 3374 aBufRead = curFile.read(oCurTest.cbToReadWrite, 30 * 1000); 3375 if oCurRes.cbProcessed > 0 \ 3376 and oCurRes.cbProcessed != len(aBufRead): 3377 reporter.error('Test #%d failed: Read buffer length does not match: Got %d, expected %d' 3378 % (i, len(aBufRead), oCurRes.cbProcessed)); 3379 fRc2 = False; 3380 if fRc2: 3381 if oCurRes.abBuf is not None \ 3382 and not utils.areBytesEqual(oCurRes.abBuf, aBufRead): 3383 reporter.error('Test #%d failed: Got buffer:\n"%s" (%d bytes, type %s)\n' 3384 'Expected buffer:\n"%s" (%d bytes, type %s)' 3385 % (i, map(hex, map(ord, aBufRead)), len(aBufRead), type(aBufRead), 3386 map(hex, map(ord, oCurRes.abBuf)), len(oCurRes.abBuf), type(oCurRes.abBuf),)); 3387 reporter.error('Test #%d failed: Got buffer:\n"%s"\nExpected buffer:\n"%s"' 3388 % (i, aBufRead, oCurRes.abBuf)); 3389 fRc2 = False; 3390 # Test final offset. 3391 curOffset = long(curFile.offset); 3392 resOffset = long(oCurRes.offFile); 3393 if curOffset != resOffset: 3394 reporter.error('Test #%d failed: Final offset does not match: Got %d, expected %d' \ 3395 % (i, curOffset, resOffset)); 3396 fRc2 = False; 3397 curFile.close(); 3398 3399 if fRc2 != oCurRes.fRc: 3400 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, oCurRes.fRc)); 3401 fRc = False; 3402 3733 if cbFile != oTestFile.cbContent: 3734 fRc = reporter.error('%s: queryInfo returned incorrect file size: %s, expected %s' 3735 % (oTestFile.sPath, cbFile, oTestFile.cbContent)); 3736 3737 try: 3738 cbFile = oFile.querySize(); 3403 3739 except: 3404 reporter.logXcpt('Opening "%s" failed:' % (oCurTest.sFile,)); 3405 fRc = False; 3406 3407 oCurTest.closeSession(); 3408 3740 fRc = reporter.errorXcpt('%s: querySize()' % (oTestFile.sPath,)); 3741 else: 3742 if cbFile != oTestFile.cbContent: 3743 fRc = reporter.error('%s: querySize returned incorrect file size: %s, expected %s' 3744 % (oTestFile.sPath, cbFile, oTestFile.cbContent)); 3745 3746 # 3747 # Close it and we're done with this file. 3748 # 3749 try: 3750 oFile.close(); 3751 except: 3752 fRc = reporter.errorXcpt('%s: error closing the file' % (oTestFile.sPath,)); 3753 3754 fRc = oTest.closeSession(True) and fRc; 3409 3755 return (fRc, oTxsSession); 3410 3756 3757 3411 3758 def testGuestCtrlFileWrite(self, oSession, oTxsSession, oTestVm): # pylint: disable=too-many-locals 3412 3759 """ 3413 3760 Tests writing to guest files. 3414 3761 """ 3762 if self.oTstDrv.fpApiVer < 5.0: 3763 reporter.log('Skipping because of pre 5.0 API'); 3764 return None; 3415 3765 3416 3766 if oTestVm.isWindows(): … … 3459 3809 try: 3460 3810 if oCurTest.offFile > 0: # The offset parameter is gone. 3461 if self.oTstDrv.fpApiVer >= 5.0: 3462 curFile = oCurGuestSession.fileOpenEx(oCurTest.sFile, oCurTest.getAccessMode(), oCurTest.getOpenAction(), 3463 oCurTest.getSharingMode(), oCurTest.fCreationMode, []); 3464 curFile.seek(oCurTest.offFile, vboxcon.FileSeekOrigin_Begin); 3465 else: 3466 curFile = oCurGuestSession.fileOpenEx(oCurTest.sFile, oCurTest.sOpenMode, oCurTest.sDisposition, 3467 oCurTest.sSharingMode, oCurTest.fCreationMode, oCurTest.offFile); 3811 curFile = oCurGuestSession.fileOpenEx(oCurTest.sFile, oCurTest.getAccessMode(), oCurTest.getOpenAction(), 3812 oCurTest.getSharingMode(), oCurTest.fCreationMode, []); 3813 curFile.seek(oCurTest.offFile, vboxcon.FileSeekOrigin_Begin); 3468 3814 curOffset = long(curFile.offset); 3469 3815 resOffset = long(oCurTest.offFile); … … 3473 3819 fRc = False; 3474 3820 else: 3475 if self.oTstDrv.fpApiVer >= 5.0: 3476 curFile = oCurGuestSession.fileOpenEx(oCurTest.sFile, oCurTest.getAccessMode(), oCurTest.getOpenAction(), 3477 oCurTest.getSharingMode(), oCurTest.fCreationMode, []); 3478 else: 3479 curFile = oCurGuestSession.fileOpen(oCurTest.sFile, oCurTest.sOpenMode, oCurTest.sDisposition, 3480 oCurTest.fCreationMode); 3821 curFile = oCurGuestSession.fileOpenEx(oCurTest.sFile, oCurTest.getAccessMode(), oCurTest.getOpenAction(), 3822 oCurTest.getSharingMode(), oCurTest.fCreationMode, []); 3481 3823 if fRc and oCurTest.cbToReadWrite > 0: 3482 3824 reporter.log("File '%s' opened" % oCurTest.sFile);
Note:
See TracChangeset
for help on using the changeset viewer.