Changeset 79303 in vbox for trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py
- Timestamp:
- Jun 24, 2019 11:00:02 AM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 131520
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py
r79292 r79303 429 429 return True; 430 430 431 def doStepsOnOpenedFile(self, fExpectSuccess, fpApiVer):431 def doStepsOnOpenedFile(self, fExpectSuccess, oSubTst): 432 432 """ Overridden by children to do more testing. """ 433 _ = fExpectSuccess; _ = fpApiVer;433 _ = fExpectSuccess; _ = oSubTst; 434 434 return True; 435 435 … … 446 446 return True; 447 447 448 def doSteps(self, fExpectSuccess, fpApiVer):448 def doSteps(self, fExpectSuccess, oSubTst): 449 449 """ Do the tests. """ 450 450 fRc = self.doOpenStep(fExpectSuccess); 451 451 if fRc is True: 452 fRc = self.doStepsOnOpenedFile(fExpectSuccess, fpApiVer);452 fRc = self.doStepsOnOpenedFile(fExpectSuccess, oSubTst); 453 453 if self.oOpenedFile: 454 454 fRc = self.doCloseStep() and fRc; … … 468 468 return 'cbOpenExpected=%s %s' % (self.cbOpenExpected, tdTestFileOpen.toString(self),); 469 469 470 def doStepsOnOpenedFile(self, fExpectSuccess, fpApiVer):470 def doStepsOnOpenedFile(self, fExpectSuccess, oSubTst): 471 471 # 472 472 # Call parent. 473 473 # 474 fRc = tdTestFileOpen.doStepsOnOpenedFile(self, fExpectSuccess, fpApiVer);474 fRc = tdTestFileOpen.doStepsOnOpenedFile(self, fExpectSuccess, oSubTst); 475 475 476 476 # 477 477 # Check the size. Requires 6.0 or later (E_NOTIMPL in 5.2). 478 478 # 479 if fpApiVer >= 6.0:479 if oSubTst.oTstDrv.fpApiVer >= 6.0: 480 480 try: 481 481 oFsObjInfo = self.oOpenedFile.queryInfo(); … … 521 521 self.atChunks = atChunks # type: list(tuple(int,bytearray)) 522 522 self.fUseAtApi = fUseAtApi; 523 self.fAppend = ( eAccessMode in (vboxcon.FileAccessMode_AppendOnly, vboxcon.FileAccessMode_AppendRead) 524 or eAction == vboxcon.FileOpenAction_AppendOrCreate); 523 525 self.abContent = abContent # type: bytearray 524 526 … … 528 530 return '%s [%s] %s' % (sApi, sChunks, tdTestFileOpen.toString(self),); 529 531 530 def doStepsOnOpenedFile(self, fExpectSuccess, fpApiVer):532 def doStepsOnOpenedFile(self, fExpectSuccess, oSubTst): 531 533 # 532 534 # Call parent. 533 535 # 534 fRc = tdTestFileOpen.doStepsOnOpenedFile(self, fExpectSuccess, fpApiVer);536 fRc = tdTestFileOpen.doStepsOnOpenedFile(self, fExpectSuccess, oSubTst); 535 537 536 538 # 537 539 # Do the writing. 538 540 # 539 for tChunk in self.atChunks: 540 offFile, abBuf = tChunk; 541 assert offFile is not None or not self.fUseAtApi; 541 for offFile, abBuf in self.atChunks: 542 542 if self.fUseAtApi: 543 # 544 # writeAt: 545 # 546 assert offFile is not None; 543 547 reporter.log2('writeAt(%s, %s bytes)' % (offFile, len(abBuf),)); 548 if self.fAppend: 549 if self.abContent is not None: # Try avoid seek as it updates the cached offset in GuestFileImpl. 550 offExpectAfter = len(self.abContent); 551 else: 552 try: 553 offSave = self.oOpenedFile.seek(0, vboxcon.FileSeekOrigin_Current); 554 offExpectAfter = self.oOpenedFile.seek(0, vboxcon.FileSeekOrigin_End); 555 self.oOpenedFile.seek(offSave, vboxcon.FileSeekOrigin_Begin); 556 except: 557 return reporter.errorXcpt(); 558 offExpectAfter += len(abBuf); 559 else: 560 offExpectAfter = offFile + len(abBuf); 561 544 562 try: 545 563 cbWritten = self.oOpenedFile.writeAt(offFile, abBuf, 30*1000); 546 564 except: 547 565 return reporter.errorXcpt('writeAt(%s, %s bytes)' % (offFile, len(abBuf),)); 566 548 567 else: 568 # 569 # write: 570 # 571 if self.fAppend: 572 if self.abContent is not None: # Try avoid seek as it updates the cached offset in GuestFileImpl. 573 offExpectAfter = len(self.abContent); 574 else: 575 try: 576 offSave = self.oOpenedFile.seek(0, vboxcon.FileSeekOrigin_Current); 577 offExpectAfter = self.oOpenedFile.seek(0, vboxcon.FileSeekOrigin_End); 578 self.oOpenedFile.seek(offSave, vboxcon.FileSeekOrigin_Begin); 579 except: 580 return reporter.errorXcpt('seek(0,End)'); 549 581 if offFile is not None: 550 582 try: 551 583 self.oOpenedFile.seek(offFile, vboxcon.FileSeekOrigin_Begin); 552 584 except: 553 return reporter.errorXcpt('seek(%s,Begin)' % (offFile, 554 el if self.eAction != vboxcon.FileOpenAction_AppendOrCreate:585 return reporter.errorXcpt('seek(%s,Begin)' % (offFile,)); 586 else: 555 587 try: 556 588 offFile = self.oOpenedFile.seek(0, vboxcon.FileSeekOrigin_Current); 557 589 except: 558 590 return reporter.errorXcpt(); 591 if not self.fAppend: 592 offExpectAfter = offFile; 593 offExpectAfter += len(abBuf); 559 594 560 595 reporter.log2('write(%s bytes @ %s)' % (len(abBuf), offFile,)); … … 564 599 return reporter.errorXcpt('write(%s bytes @ %s)' % (len(abBuf), offFile)); 565 600 601 # 566 602 # Check how much was written, ASSUMING nothing we push thru here is too big: 603 # 567 604 if cbWritten != len(abBuf): 568 605 fRc = reporter.errorXcpt('Wrote less than expected: %s out of %s, expected all to be written' 569 606 % (cbWritten, len(abBuf),)); 607 if not self.fAppend: 608 offExpectAfter -= len(abBuf) - cbWritten; 570 609 571 610 # … … 576 615 abBuf = abBuf[:cbWritten]; 577 616 617 # 578 618 # In append mode, the current file offset shall be disregarded and the 579 619 # write always goes to the end of the file, regardless of writeAt or write. 580 # Note that RTFileWriteAt only naturally behaves this way on linux, so 581 # VBoxService makes the linux behaviour general across all OSes. 582 if self.eAction == vboxcon.FileOpenAction_AppendOrCreate: 583 reporter.log('len(self.abContent)=%s + %s' % (len(self.abContent), cbWritten, )); 620 # Note that RTFileWriteAt only naturally behaves this way on linux and 621 # (probably) windows, so VBoxService makes that behaviour generic across 622 # all OSes. 623 # 624 if self.fAppend: 625 reporter.log2('len(self.abContent)=%s + %s' % (len(self.abContent), cbWritten, )); 584 626 self.abContent.extend(abBuf); 585 elif offFile is not None: 586 reporter.log('len(self.abContent)=%s + %s @ %s' % (len(self.abContent), cbWritten, offFile, )); 627 else: 628 if offFile is None: 629 offFile = offExpectAfter - cbWritten; 630 reporter.log2('len(self.abContent)=%s + %s @ %s' % (len(self.abContent), cbWritten, offFile, )); 587 631 if offFile > len(self.abContent): 588 632 self.abContent.extend(bytearray(offFile - len(self.abContent))); 589 633 self.abContent[offFile:offFile + cbWritten] = abBuf; 590 reporter.log('len(self.abContent)=%s' % (len(self.abContent),)); 591 634 reporter.log2('len(self.abContent)=%s' % (len(self.abContent),)); 635 636 # 637 # Check the resulting file offset with IGuestFile::offset. 638 # 639 try: 640 offApi = self.oOpenedFile.offset; # Must be gotten first! 641 offSeek = self.oOpenedFile.seek(0, vboxcon.FileSeekOrigin_Current); 642 except: 643 fRc = reporter.errorXcpt(); 644 else: 645 reporter.log2('offApi=%s offSeek=%s offExpectAfter=%s' % (offApi, offSeek, offExpectAfter,)); 646 if offSeek != offExpectAfter: 647 fRc = reporter.error('Seek offset is %s, expected %s after %s bytes write @ %s (offApi=%s)' 648 % (offSeek, offExpectAfter, len(abBuf), offFile, offApi,)); 649 if offApi != offExpectAfter: 650 fRc = reporter.error('IGuestFile::offset is %s, expected %s after %s bytes write @ %s (offSeek=%s)' 651 % (offApi, offExpectAfter, len(abBuf), offFile, offSeek,)); 652 # for each chunk - end 592 653 return fRc; 593 654 … … 605 666 return 'check content %s (%s) %s' % (len(self.abContent), self.cbContentExpected, tdTestFileOpen.toString(self),); 606 667 607 def doStepsOnOpenedFile(self, fExpectSuccess, fpApiVer):668 def doStepsOnOpenedFile(self, fExpectSuccess, oSubTst): 608 669 # 609 670 # Call parent. 610 671 # 611 fRc = tdTestFileOpen.doStepsOnOpenedFile(self, fExpectSuccess, fpApiVer);672 fRc = tdTestFileOpen.doStepsOnOpenedFile(self, fExpectSuccess, oSubTst); 612 673 613 674 # … … 3608 3669 break; 3609 3670 3610 fRc2 = oCurTest.doSteps(oCurRes.fRc, self .oTstDrv.fpApiVer);3671 fRc2 = oCurTest.doSteps(oCurRes.fRc, self); 3611 3672 if fRc2 != oCurRes.fRc: 3612 3673 fRc = reporter.error('Test #%d result mismatch: Got %s, expected %s' % (i, fRc2, oCurRes.fRc,)); … … 4032 4093 atChunks = [(1024, randBytes(63)), (1080, randBytes(968)),]), 4033 4094 tdTestFileOpenAndCheckContent(sFile = sFile, abContent = abContent, cbContentExpected = 1080+968), # 2048 4034 # writeAt beyond the end: 4095 4096 # writeAt beyond the end (gap is filled with zeros): 4035 4097 tdTestFileOpenAndWrite(sFile = sFile, abContent = abContent, fUseAtApi = True, atChunks = [(3070, randBytes(2)),]), 4036 4098 tdTestFileOpenAndCheckContent(sFile = sFile, abContent = abContent, cbContentExpected = 3072), 4037 # write beyond the end :4099 # write beyond the end (gap is filled with zeros): 4038 4100 tdTestFileOpenAndWrite(sFile = sFile, abContent = abContent, atChunks = [(4090, randBytes(6)),]), 4039 4101 tdTestFileOpenAndCheckContent(sFile = sFile, abContent = abContent, cbContentExpected = 4096), … … 4049 4111 break; 4050 4112 4051 fRc2 = oCurTest.doSteps(True, self .oTstDrv.fpApiVer);4113 fRc2 = oCurTest.doSteps(True, self); 4052 4114 if fRc2 is not True: 4053 4115 fRc = reporter.error('Test #%d failed!' % (i,));
Note:
See TracChangeset
for help on using the changeset viewer.