Changeset 79280 in vbox
- Timestamp:
- Jun 21, 2019 2:26:11 PM (6 years ago)
- Location:
- trunk/src/VBox/ValidationKit
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/testdriver/testfileset.py
r79255 r79280 154 154 return sRet; 155 155 156 def checkRange(self, cbRange, offFile = 0): 157 """ Check if the specified range is entirely within the file or not. """ 158 if offFile >= self.cbContent: 159 return reporter.error('buffer @ %s LB %s is beyond the end of the file (%s bytes)!' 160 % (offFile, cbRange, self.cbContent,)); 161 if offFile + cbRange > self.cbContent: 162 return reporter.error('buffer @ %s LB %s is partially beyond the end of the file (%s bytes)!' 163 % (offFile, cbRange, self.cbContent,)); 164 return True; 165 156 166 def equalMemory(self, abBuf, offFile = 0): 157 167 """ … … 163 173 if not abBuf: 164 174 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; 175 176 if not self.checkRange(len(abBuf), offFile): 177 return False; 178 179 if sys.version_info[0] >= 3: 180 if utils.areBytesEqual(abBuf, self.abContent[offFile:(offFile + len(abBuf))]): 181 return True; 182 else: 183 if utils.areBytesEqual(abBuf, buffer(self.abContent, offFile, len(abBuf))): # pylint: disable=undefined-variable 184 return True; 173 185 174 186 reporter.error('mismatch with buffer @ %s LB %s (cbContent=%s)!' % (offFile, len(abBuf), self.cbContent,)); … … 201 213 202 214 215 class TestFileZeroFilled(TestFile): 216 """ 217 Zero filled test file. 218 """ 219 220 def __init__(self, oParent, sPath, cbContent): 221 TestFile.__init__(self, oParent, sPath, bytearray(1)); 222 self.cbContent = cbContent; 223 224 def read(self, cbToRead): 225 """ read() emulation. """ 226 assert self.off <= self.cbContent; 227 cbLeft = self.cbContent - self.off; 228 if cbLeft < cbToRead: 229 cbToRead = cbLeft; 230 abRet = bytearray(cbToRead); 231 assert len(abRet) == cbToRead; 232 self.off += cbToRead; 233 if sys.version_info[0] < 3: 234 return bytes(abRet); 235 return abRet; 236 237 def equalFile(self, oFile): 238 _ = oFile; 239 assert False, "not implemented"; 240 return False; 241 242 def equalMemory(self, abBuf, offFile = 0): 243 if not abBuf: 244 return True; 245 246 if not self.checkRange(len(abBuf), offFile): 247 return False; 248 249 if utils.areBytesEqual(abBuf, bytearray(len(abBuf))): 250 return True; 251 252 cErrors = 0; 253 offBuf = 0 254 while offBuf < len(abBuf): 255 bByte = abBuf[offBuf]; 256 if not isinstance(bByte, int): 257 bByte = ord(bByte); 258 if bByte != 0: 259 reporter.error('Mismatch @ %s/%s: %#x, expected 0!' % (offFile, offBuf, bByte,)); 260 cErrors += 1; 261 if cErrors > 32: 262 return False; 263 offBuf += 1; 264 return cErrors == 0; 203 265 204 266 -
trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py
r79262 r79280 3515 3515 3516 3516 # 3517 # Open and read all the files in the test file set. 3518 # 3519 3517 # Do everything in one session. 3518 # 3520 3519 oTest = tdTestGuestCtrlBase(); 3521 3520 oTest.setEnvironment(oSession, oTxsSession, oTestVm); … … 3524 3523 return (False, oTxsSession); 3525 3524 3525 # 3526 # Create a really big zero filled, up to 1 GiB, adding it to the list of 3527 # files from the set. 3528 # 3529 # Note! This code sucks a bit because we don't have a working setSize nor 3530 # any way to figure out how much free space there is in the guest. 3531 # 3532 aoExtraFiles = []; 3533 sBigName = self.oTestFiles.generateFilenameEx(); 3534 sBigPath = oTestVm.pathJoin(self.oTestFiles.oRoot.sPath, sBigName); 3526 3535 fRc = True; 3527 for oTestFile in self.oTestFiles.aoFiles: # type: testfileset.TestFile 3536 try: 3537 oFile = oGuestSession.fileOpenEx(sBigPath, vboxcon.FileAccessMode_ReadWrite, vboxcon.FileOpenAction_CreateOrReplace, 3538 vboxcon.FileSharingMode_All, 0, []); 3539 except: 3540 fRc = reporter.errorXcpt('sBigName=%s' % (sBigPath,)); 3541 else: 3542 cbBigFile = 0; 3543 while cbBigFile < (1024 + 32)*1024*1024: 3544 cbBigFile += 32*1024*1024; 3545 try: 3546 oFile.seek(cbBigFile, vboxcon.FileSeekOrigin_Begin); 3547 oFile.write(bytearray(1), 60*1000); 3548 except: 3549 reporter.logXcpt('cbBigFile=%s' % (sBigPath,)); 3550 break; 3551 try: 3552 cbBigFile = oFile.seek(0, vboxcon.FileSeekOrigin_End); 3553 except: 3554 fRc = reporter.errorXcpt('sBigName=%s' % (sBigPath,)); 3555 try: 3556 oFile.close(); 3557 except: 3558 fRc = reporter.errorXcpt('sBigName=%s' % (sBigPath,)); 3559 if fRc is True: 3560 reporter.log('Big file: %s bytes: %s' % (cbBigFile, sBigPath,)); 3561 aoExtraFiles.append(testfileset.TestFileZeroFilled(None, sBigPath, cbBigFile)); 3562 else: 3563 try: 3564 oGuestSession.fsObjRemove(sBigPath); 3565 except: 3566 reporter.errorXcpt('fsObjRemove(sBigName=%s)' % (sBigPath,)); 3567 3568 # 3569 # Open and read all the files in the test file set. 3570 # 3571 for oTestFile in aoExtraFiles + self.oTestFiles.aoFiles: # type: testfileset.TestFile 3528 3572 reporter.log2('Test file: %s bytes, "%s" ...' % (oTestFile.cbContent, oTestFile.sPath,)); 3529 3573 … … 3545 3589 elif oTestFile.cbContent < 1024: 3546 3590 acbChunks = (2048, 127, 63, 32, 29, 17, 16, 15, 9); 3591 elif oTestFile.cbContent < 8*1024*1024: 3592 acbChunks = (128*1024, 32*1024, 8191, 255); 3547 3593 else: 3548 acbChunks = (128 * 1024, 32 * 1024, 8192, 1024, 128); 3594 acbChunks = (768*1024, 128*1024); 3595 3549 3596 for cbChunk in acbChunks: 3550 3597 # Read the whole file straight thru: 3551 #reporter.log2('... cbChunk=%s' % (cbChunk,));3598 if oTestFile.cbContent >= 1024*1024: reporter.log2('... cbChunk=%s' % (cbChunk,)); 3552 3599 offFile = 0; 3600 cReads = 0; 3553 3601 while offFile <= oTestFile.cbContent: 3554 3602 try: … … 3569 3617 break; 3570 3618 offFile += cbRead; 3619 cReads += 1; 3620 if cReads > 8192: 3621 break; 3571 3622 3572 3623 # Seek to start of file. … … 3583 3634 # Random reads. 3584 3635 # 3585 for _ in xrange( 16):3636 for _ in xrange(8): 3586 3637 offFile = self.oTestFiles.oRandom.randrange(0, oTestFile.cbContent + 1024); 3587 cbToRead = self.oTestFiles.oRandom.randrange(1, oTestFile.cbContent + 256); 3588 if cbToRead > 1024*1024: 3589 cbToRead = 1024*1024; 3590 #reporter.log2('... %s LB %s' % (offFile, cbToRead,)); 3638 cbToRead = self.oTestFiles.oRandom.randrange(1, min(oTestFile.cbContent + 256, 768*1024)); 3639 if oTestFile.cbContent >= 1024*1024: reporter.log2('... %s LB %s' % (offFile, cbToRead,)); 3591 3640 3592 3641 try: … … 3632 3681 # Random reads using readAt. 3633 3682 # 3634 for _ in xrange(1 6):3683 for _ in xrange(12): 3635 3684 offFile = self.oTestFiles.oRandom.randrange(0, oTestFile.cbContent + 1024); 3636 cbToRead = self.oTestFiles.oRandom.randrange(1, oTestFile.cbContent + 256); 3637 if cbToRead > 1024*1024: 3638 cbToRead = 1024*1024; 3639 #reporter.log2('... %s LB %s (readAt)' % (offFile, cbToRead,)); 3685 cbToRead = self.oTestFiles.oRandom.randrange(1, min(oTestFile.cbContent + 256, 768*1024)); 3686 if oTestFile.cbContent >= 1024*1024: reporter.log2('... %s LB %s (readAt)' % (offFile, cbToRead,)); 3640 3687 3641 3688 try: … … 3646 3693 else: 3647 3694 cbRead = len(abRead); 3648 if offFile >= oTestFile.cbContent or offFile + cbRead > oTestFile.cbContent: 3649 if cbRead != 0: 3650 fRc = reporter.error('%s: Read returned data beyond end of file: %s + %s = %s vs cbContent=%s (#2)' 3651 % (oTestFile.sPath, offFile, cbRead, offFile + cbRead, oTestFile.cbContent,)); 3652 if offFile + cbRead <= oTestFile.cbContent \ 3653 and not utils.areBytesEqual(abRead, oTestFile.abContent[offFile:(offFile + cbRead)]): 3695 if not oTestFile.equalMemory(abRead, offFile): 3654 3696 fRc = reporter.error('%s: random readAt mismatch @ %s LB %s' % (oTestFile.sPath, offFile, cbRead,)); 3655 3697 … … 3683 3725 # A few negative things. 3684 3726 # 3727 3728 # Zero byte reads -> E_INVALIDARG. 3685 3729 try: 3686 3730 abRead = oFile.read(0, 30*1000); 3687 3731 except Exception as oXcpt: 3688 3732 if vbox.ComError.notEqual(oXcpt, vbox.ComError.E_INVALIDARG): 3689 reporter.errorXcpt('read(0,30s) did not raise E_INVALIDARG as expected!');3733 fRc = reporter.errorXcpt('read(0,30s) did not raise E_INVALIDARG as expected!'); 3690 3734 else: 3691 reporter.error('read(0,30s) did not fail!');3735 fRc = reporter.error('read(0,30s) did not fail!'); 3692 3736 3693 3737 try: … … 3695 3739 except Exception as oXcpt: 3696 3740 if vbox.ComError.notEqual(oXcpt, vbox.ComError.E_INVALIDARG): 3697 reporter.errorXcpt('readAt(0,0,30s) did not raise E_INVALIDARG as expected!');3741 fRc = reporter.errorXcpt('readAt(0,0,30s) did not raise E_INVALIDARG as expected!'); 3698 3742 else: 3699 reporter.error('readAt(0,0,30s) did not fail!'); 3700 3701 if not self.fSkipKnownBugs: ## @todo Place a restriction on how much we permit being read in a single request. 3702 try: ## Document it in VirtualBox.xidl. 3703 abRead = oFile.read(1024*1024*1024, 30*1000); 3704 except Exception as oXcpt: 3705 if vbox.ComError.notEqual(oXcpt, vbox.ComError.E_INVALIDARG): 3706 reporter.errorXcpt('read(1GiB,30s) did not raise E_INVALIDARG as expected!'); 3707 else: 3708 reporter.error('read(1GiB,30s) did not fail! len(abRead)=%s' % (len(abRead), )); 3709 3710 try: 3711 abRead = oFile.readAt(0, 1024*1024*1024, 30*1000); 3712 except Exception as oXcpt: 3713 if vbox.ComError.notEqual(oXcpt, vbox.ComError.E_INVALIDARG): 3714 reporter.errorXcpt('readAt(0,1GiB,30s) did not raise E_INVALIDARG as expected!'); 3715 else: 3716 reporter.error('readAt(0,1GiB,30s) did not fail! len(abRead)=%s' % (len(abRead), )); 3743 fRc = reporter.error('readAt(0,0,30s) did not fail!'); 3744 3745 # See what happens when we read 1GiB. We should get a max of 1MiB back. 3746 ## @todo Document this behaviour in VirtualBox.xidl. 3747 try: 3748 oFile.seek(0, vboxcon.FileSeekOrigin_Begin); 3749 except: 3750 fRc = reporter.error('seek(0)'); 3751 try: 3752 abRead = oFile.read(1024*1024*1024, 30*1000); 3753 except: 3754 fRc = reporter.errorXcpt('read(1GiB,30s)'); 3755 else: 3756 if len(abRead) != min(oTestFile.cbContent, 1024*1024): 3757 fRc = reporter.error('Expected read(1GiB,30s) to return %s bytes, got %s bytes instead' 3758 % (min(oTestFile.cbContent, 1024*1024), len(abRead),)); 3759 3760 try: 3761 abRead = oFile.readAt(0, 1024*1024*1024, 30*1000); 3762 except: 3763 fRc = reporter.errorXcpt('readAt(0,1GiB,30s)'); 3764 else: 3765 if len(abRead) != min(oTestFile.cbContent, 1024*1024): 3766 reporter.error('Expected readAt(0, 1GiB,30s) to return %s bytes, got %s bytes instead' 3767 % (min(oTestFile.cbContent, 1024*1024), len(abRead),)); 3717 3768 3718 3769 # … … 3758 3809 % (oTestFile.sPath, cbFile, oTestFile.cbContent)); 3759 3810 if oTestFile.cbContent > 0: 3760 for _ in xrange( 12):3811 for _ in xrange(5): 3761 3812 offSeek = self.oTestFiles.oRandom.randrange(oTestFile.cbContent + 1); 3762 3813 try: … … 3778 3829 fRc = reporter.errorXcpt('%s: error closing the file' % (oTestFile.sPath,)); 3779 3830 3831 # 3832 # Clean up. 3833 # 3834 for oTestFile in aoExtraFiles: 3835 try: 3836 oGuestSession.fsObjRemove(sBigPath); 3837 except: 3838 fRc = reporter.errorXcpt('fsObjRemove(%s)' % (sBigPath,)); 3839 3780 3840 fRc = oTest.closeSession(True) and fRc; 3841 3781 3842 return (fRc, oTxsSession); 3782 3843
Note:
See TracChangeset
for help on using the changeset viewer.