VirtualBox

Ignore:
Timestamp:
Jun 21, 2019 2:26:11 PM (5 years ago)
Author:
vboxsync
Message:

tdAddGuestCtrl.py: Crudely create a large file in the guest so we can better test read and readAt buffer handling. Adjusted read tests so they don't take so long. bugref:9151 bugref:9320

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/testdriver/testfileset.py

    r79255 r79280  
    154154        return sRet;
    155155
     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
    156166    def equalMemory(self, abBuf, offFile = 0):
    157167        """
     
    163173        if not abBuf:
    164174            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;
    173185
    174186        reporter.error('mismatch with buffer @ %s LB %s (cbContent=%s)!' % (offFile, len(abBuf), self.cbContent,));
     
    201213
    202214
     215class 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;
    203265
    204266
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette