VirtualBox

Changeset 79292 in vbox for trunk/src/VBox/ValidationKit


Ignore:
Timestamp:
Jun 22, 2019 1:36:22 AM (6 years ago)
Author:
vboxsync
Message:

tdAddGuestCtrl.py: Rewriting the IGuestFile::write testcase. Use IGuestFile::setSize when availble (soon everywhere). bugref:9151 bugref:9320

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py

    r79280 r79292  
    3131
    3232# Standard Python imports.
    33 from array import array
    3433import errno
    3534import os
     
    412411        self.oOpenedFile    = None;
    413412
     413    def toString(self):
     414        """ Get a summary string. """
     415        return 'eAccessMode=%s eAction=%s sFile=%s' % (self.eAccessMode, self.eAction, self.sFile);
     416
    414417    def doOpenStep(self, fExpectSuccess):
    415418        """
     
    420423                                                             self.eSharing, self.fCreationMode, self.afOpenFlags);
    421424        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            reporter.maybeErrXcpt(fExpectSuccess, 'fileOpenEx(%s, %s, %s, %s, %s, %s)'
     426                                  % (self.sFile, self.eAccessMode, self.eAction, self.eSharing,
     427                                     self.fCreationMode, self.afOpenFlags,));
    425428            return False;
    426429        return True;
     
    462465        self.cbOpenExpected = cbOpenExpected;
    463466
     467    def toString(self):
     468        return 'cbOpenExpected=%s %s' % (self.cbOpenExpected, tdTestFileOpen.toString(self),);
     469
    464470    def doStepsOnOpenedFile(self, fExpectSuccess, fpApiVer):
    465471        #
     
    500506        return fRc;
    501507
    502 class tdTestFileReadWrite(tdTestGuestCtrlBase):
    503     """
    504     Tests reading from guest files.
    505     """
    506     def __init__(self, sFile = "", sUser = None, sPassword = None, sOpenMode = "r", # pylint: disable=too-many-arguments
    507                  sDisposition = "", sSharingMode = "", fCreationMode = 0, offFile = 0, cbToReadWrite = 0, abBuf = None):
    508         tdTestGuestCtrlBase.__init__(self);
    509         self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = None);
    510         self.sFile = sFile;
    511         self.sOpenMode = sOpenMode;
    512         self.sDisposition = sDisposition;
    513         self.sSharingMode = sSharingMode;
    514         self.fCreationMode = fCreationMode;
    515         self.offFile = offFile;
    516         self.cbToReadWrite = cbToReadWrite;
    517         self.abBuf = abBuf;
    518 
    519     def getOpenAction(self):
    520         """ Converts string disposition to open action enum. """
    521         if self.sDisposition == 'oe': return vboxcon.FileOpenAction_OpenExisting;
    522         if self.sDisposition == 'oc': return vboxcon.FileOpenAction_OpenOrCreate;
    523         if self.sDisposition == 'ce': return vboxcon.FileOpenAction_CreateNew;
    524         if self.sDisposition == 'ca': return vboxcon.FileOpenAction_CreateOrReplace;
    525         if self.sDisposition == 'ot': return vboxcon.FileOpenAction_OpenExistingTruncated;
    526         if self.sDisposition == 'oa': return vboxcon.FileOpenAction_AppendOrCreate;
    527         raise base.GenError(self.sDisposition);
    528 
    529     def getAccessMode(self):
    530         """ Converts open mode to access mode enum. """
    531         if self.sOpenMode == 'r':  return vboxcon.FileAccessMode_ReadOnly;
    532         if self.sOpenMode == 'w':  return vboxcon.FileAccessMode_WriteOnly;
    533         if self.sOpenMode == 'w+': return vboxcon.FileAccessMode_ReadWrite;
    534         if self.sOpenMode == 'r+': return vboxcon.FileAccessMode_ReadWrite;
    535         raise base.GenError(self.sOpenMode);
    536 
    537     def getSharingMode(self):
    538         """ Converts the sharing mode. """
    539         return vboxcon.FileSharingMode_All;
     508
     509class tdTestFileOpenAndWrite(tdTestFileOpen):
     510    """
     511    Opens the file and writes one or more chunks to it.
     512
     513    The chunks are a list of tuples(offset, bytes), where offset can be None
     514    if no seeking should be performed.
     515    """
     516    def __init__(self, sFile = "", eAccessMode = None, eAction = None, eSharing = None, # pylint: disable=too-many-arguments
     517                 fCreationMode = 0o660, atChunks = None, fUseAtApi = False, abContent = None, sUser = None, sPassword = None):
     518        tdTestFileOpen.__init__(self, sFile, eAccessMode if eAccessMode is not None else vboxcon.FileAccessMode_WriteOnly,
     519                                eAction, eSharing, fCreationMode, sUser, sPassword);
     520        assert atChunks is not None;
     521        self.atChunks  = atChunks   # type: list(tuple(int,bytearray))
     522        self.fUseAtApi = fUseAtApi;
     523        self.abContent = abContent  # type: bytearray
     524
     525    def toString(self):
     526        sChunks = ', '.join('%s LB %s' % (tChunk[0], len(tChunk[1]),) for tChunk in self.atChunks);
     527        sApi = 'writeAt' if self.fUseAtApi else 'write';
     528        return '%s [%s] %s' % (sApi, sChunks, tdTestFileOpen.toString(self),);
     529
     530    def doStepsOnOpenedFile(self, fExpectSuccess, fpApiVer):
     531        #
     532        # Call parent.
     533        #
     534        fRc = tdTestFileOpen.doStepsOnOpenedFile(self, fExpectSuccess, fpApiVer);
     535
     536        #
     537        # Do the writing.
     538        #
     539        for tChunk in self.atChunks:
     540            offFile, abBuf = tChunk;
     541            assert offFile is not None or not self.fUseAtApi;
     542            if self.fUseAtApi:
     543                reporter.log2('writeAt(%s, %s bytes)' % (offFile, len(abBuf),));
     544                try:
     545                    cbWritten = self.oOpenedFile.writeAt(offFile, abBuf, 30*1000);
     546                except:
     547                    return reporter.errorXcpt('writeAt(%s, %s bytes)' % (offFile, len(abBuf),));
     548            else:
     549                if offFile is not None:
     550                    try:
     551                        self.oOpenedFile.seek(offFile, vboxcon.FileSeekOrigin_Begin);
     552                    except:
     553                        return reporter.errorXcpt('seek(%s,Begin)' % (offFile, ));
     554                elif self.eAction != vboxcon.FileOpenAction_AppendOrCreate:
     555                    try:
     556                        offFile = self.oOpenedFile.seek(0, vboxcon.FileSeekOrigin_Current);
     557                    except:
     558                        return reporter.errorXcpt();
     559
     560                reporter.log2('write(%s bytes @ %s)' % (len(abBuf), offFile,));
     561                try:
     562                    cbWritten = self.oOpenedFile.write(abBuf, 30*1000);
     563                except:
     564                    return reporter.errorXcpt('write(%s bytes @ %s)' % (len(abBuf), offFile));
     565
     566            # Check how much was written, ASSUMING nothing we push thru here is too big:
     567            if cbWritten != len(abBuf):
     568                fRc = reporter.errorXcpt('Wrote less than expected: %s out of %s, expected all to be written'
     569                                         % (cbWritten, len(abBuf),));
     570
     571            #
     572            # Update the file content tracker if we've got one and can:
     573            #
     574            if self.abContent is not None:
     575                if cbWritten < len(abBuf):
     576                    abBuf = abBuf[:cbWritten];
     577
     578                # In append mode, the current file offset shall be disregarded and the
     579                # 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, ));
     584                    self.abContent.extend(abBuf);
     585                elif offFile is not None:
     586                    reporter.log('len(self.abContent)=%s + %s @ %s' % (len(self.abContent), cbWritten, offFile, ));
     587                    if offFile > len(self.abContent):
     588                        self.abContent.extend(bytearray(offFile - len(self.abContent)));
     589                    self.abContent[offFile:offFile + cbWritten] = abBuf;
     590                reporter.log('len(self.abContent)=%s' % (len(self.abContent),));
     591
     592        return fRc;
     593
     594
     595class tdTestFileOpenAndCheckContent(tdTestFileOpen):
     596    """
     597    Opens the file and checks the content using the read API.
     598    """
     599    def __init__(self, sFile = "", eSharing = None, abContent = None, cbContentExpected = None, sUser = None, sPassword = None):
     600        tdTestFileOpen.__init__(self, sFile = sFile, eSharing = eSharing, sUser = sUser, sPassword = sPassword);
     601        self.abContent = abContent  # type: bytearray
     602        self.cbContentExpected = cbContentExpected;
     603
     604    def toString(self):
     605        return 'check content %s (%s) %s' % (len(self.abContent), self.cbContentExpected, tdTestFileOpen.toString(self),);
     606
     607    def doStepsOnOpenedFile(self, fExpectSuccess, fpApiVer):
     608        #
     609        # Call parent.
     610        #
     611        fRc = tdTestFileOpen.doStepsOnOpenedFile(self, fExpectSuccess, fpApiVer);
     612
     613        #
     614        # Check the expected content size.
     615        #
     616        if self.cbContentExpected is not None:
     617            if len(self.abContent) != self.cbContentExpected:
     618                fRc = reporter.error('Incorrect abContent size: %s, expected %s'
     619                                     % (len(self.abContent), self.cbContentExpected,));
     620
     621        #
     622        # Read the file and compare it with the content.
     623        #
     624        offFile = 0;
     625        while True:
     626            try:
     627                abChunk = self.oOpenedFile.read(512*1024, 30*1000);
     628            except:
     629                return reporter.errorXcpt('read(512KB) @ %s' % (offFile,));
     630            cbChunk = len(abChunk);
     631            if cbChunk == 0:
     632                if offFile != len(self.abContent):
     633                    fRc = reporter.error('Unexpected EOF @ %s, len(abContent)=%s' % (offFile, len(self.abContent),));
     634                break;
     635            if offFile + cbChunk > len(self.abContent):
     636                fRc = reporter.error('File is larger than expected: at least %s bytes, expected %s bytes'
     637                                     % (offFile + cbChunk, len(self.abContent),));
     638            elif not utils.areBytesEqual(abChunk, self.abContent[offFile:(offFile + cbChunk)]):
     639                fRc = reporter.error('Mismatch in range %s LB %s!' % (offFile, cbChunk,));
     640            offFile += cbChunk;
     641
     642        return fRc;
    540643
    541644class tdTestSession(tdTestGuestCtrlBase):
     
    561664            return 0;
    562665        return len(aoSession);
     666
    563667
    564668class tdTestSessionEx(tdTestGuestCtrlBase):
     
    33783482            oTestVm.pathJoin(sTempDir, 'file-open-1'),
    33793483            oTestVm.pathJoin(sTempDir, 'file-open-2'),
     3484            oTestVm.pathJoin(sTempDir, 'file-open-3'),
     3485            oTestVm.pathJoin(sTempDir, 'file-open-4'),
    33803486        ];
    33813487        asNonEmptyFiles = [
     
    34433549            [ tdTestFileOpenCheckSize(sFile = asFiles[2], eAction = vboxcon.FileOpenAction_CreateOrReplace,
    34443550                                      eAccessMode = vboxcon.FileAccessMode_ReadWrite),                  tdTestResultSuccess() ],
     3551            # Create and append to file (weird stuff).
     3552            [ tdTestFileOpenCheckSize(sFile = asFiles[3], eAction = vboxcon.FileOpenAction_AppendOrCreate,
     3553                                      eAccessMode = vboxcon.FileAccessMode_ReadWrite),                  tdTestResultSuccess() ],
     3554            [ tdTestFileOpenCheckSize(sFile = asFiles[4], eAction = vboxcon.FileOpenAction_AppendOrCreate,
     3555                                      eAccessMode = vboxcon.FileAccessMode_WriteOnly),                  tdTestResultSuccess() ],
    34453556            # Open the non-empty files in non-destructive modes.
    34463557            [ tdTestFileOpenCheckSize(sFile = asNonEmptyFiles[0], cbOpenExpected = len(sContent)),      tdTestResultSuccess() ],
     
    35403651            fRc = reporter.errorXcpt('sBigName=%s' % (sBigPath,));
    35413652        else:
     3653            # Does setSize work now?
     3654            fUseFallback = True;
     3655            try:
     3656                oFile.setSize(0);
     3657                oFile.setSize(64);
     3658                fUseFallback = False;
     3659            except Exception as oXcpt:
     3660                reporter.logXcpt();
     3661
     3662            # Grow the file till we hit trouble, typical VERR_DISK_FULL, then
     3663            # reduce the file size if we have a working setSize.
    35423664            cbBigFile = 0;
    35433665            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;
     3666                if not fUseFallback:
     3667                    cbBigFile += 16*1024*1024;
     3668                    try:
     3669                        oFile.setSize(cbBigFile);
     3670                    except Exception as oXcpt:
     3671                        reporter.logXcpt('cbBigFile=%s' % (sBigPath,));
     3672                        try:
     3673                            cbBigFile -= 16*1024*1024;
     3674                            oFile.setSize(cbBigFile);
     3675                        except:
     3676                            reporter.logXcpt('cbBigFile=%s' % (sBigPath,));
     3677                        break;
     3678                else:
     3679                    cbBigFile += 32*1024*1024;
     3680                    try:
     3681                        oFile.seek(cbBigFile, vboxcon.FileSeekOrigin_Begin);
     3682                        oFile.write(bytearray(1), 60*1000);
     3683                    except:
     3684                        reporter.logXcpt('cbBigFile=%s' % (sBigPath,));
     3685                        break;
    35513686            try:
    35523687                cbBigFile = oFile.seek(0, vboxcon.FileSeekOrigin_End);
     
    35963731            for cbChunk in acbChunks:
    35973732                # Read the whole file straight thru:
    3598                 if oTestFile.cbContent >= 1024*1024: reporter.log2('... cbChunk=%s' % (cbChunk,));
     3733                #if oTestFile.cbContent >= 1024*1024: reporter.log2('... cbChunk=%s' % (cbChunk,));
    35993734                offFile = 0;
    36003735                cReads = 0;
     
    36373772                offFile  = self.oTestFiles.oRandom.randrange(0, oTestFile.cbContent + 1024);
    36383773                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,));
     3774                #if oTestFile.cbContent >= 1024*1024: reporter.log2('... %s LB %s' % (offFile, cbToRead,));
    36403775
    36413776                try:
     
    36843819                offFile  = self.oTestFiles.oRandom.randrange(0, oTestFile.cbContent + 1024);
    36853820                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,));
     3821                #if oTestFile.cbContent >= 1024*1024: reporter.log2('... %s LB %s (readAt)' % (offFile, cbToRead,));
    36873822
    36883823                try:
     
    38513986            return None;
    38523987
    3853         if oTestVm.isWindows():
    3854             sScratch = "C:\\Temp\\vboxtest\\testGuestCtrlFileWrite\\";
    3855         else:
    3856             sScratch = "/tmp/";
    3857 
    3858         if oTxsSession.syncMkDir('${SCRATCH}/testGuestCtrlFileWrite') is False:
    3859             reporter.error('Could not create scratch directory on guest');
    3860             return (False, oTxsSession);
    3861 
    3862         atTests = [];
    3863 
    3864         cbScratchBuf = random.randint(1, 4096);
    3865         abScratchBuf = os.urandom(cbScratchBuf);
    3866         atTests.extend([
    3867             # Write to a non-existing file.
    3868             [ tdTestFileReadWrite(sFile = sScratch + 'testGuestCtrlFileWrite.txt',
    3869                                   sOpenMode = 'w+', sDisposition = 'ce', cbToReadWrite = cbScratchBuf, abBuf = abScratchBuf),
    3870               tdTestResultFileReadWrite(fRc = True, abBuf = abScratchBuf, cbProcessed = cbScratchBuf, offFile = cbScratchBuf) ],
    3871         ]);
    3872 
    3873         aScratchBuf2 = os.urandom(cbScratchBuf);
    3874         atTests.extend([
    3875             # Append the same amount of data to the just created file.
    3876             [ tdTestFileReadWrite(sFile = sScratch + 'testGuestCtrlFileWrite.txt',
    3877                                   sOpenMode = 'w+', sDisposition = 'oa', cbToReadWrite = cbScratchBuf,
    3878                                   offFile = cbScratchBuf, abBuf = aScratchBuf2),
    3879               tdTestResultFileReadWrite(fRc = True, abBuf = aScratchBuf2, cbProcessed = cbScratchBuf,
    3880                                         offFile = cbScratchBuf * 2) ],
    3881         ]);
    3882 
    3883         fRc = True;
    3884         for (i, aTest) in enumerate(atTests):
    3885             oCurTest = aTest[0]; # tdTestFileReadWrite, use an index, later.
    3886             oCurRes  = aTest[1]; # tdTestResult
    3887             reporter.log('Testing #%d, sFile="%s", cbToReadWrite=%d, sOpenMode="%s", sDisposition="%s", offFile=%d ...'
    3888                          %  (i, oCurTest.sFile, oCurTest.cbToReadWrite, oCurTest.sOpenMode,
    3889                              oCurTest.sDisposition, oCurTest.offFile,));
     3988        #
     3989        # The test file and its content.
     3990        #
     3991        sFile     = oTestVm.pathJoin(self.getGuestTempDir(oTestVm), 'gctrl-write-1');
     3992        abContent = bytearray(0);
     3993
     3994        #
     3995        # The tests.
     3996        #
     3997        def randBytes(cbHowMany):
     3998            """ Returns an bytearray of random bytes. """
     3999            return bytearray(self.oTestFiles.oRandom.getrandbits(8) for _ in xrange(cbHowMany));
     4000
     4001        aoTests = [
     4002            # Write at end:
     4003            tdTestFileOpenAndWrite(sFile = sFile, eAction = vboxcon.FileOpenAction_CreateNew, abContent = abContent,
     4004                                   atChunks = [(None, randBytes(1)), (None, randBytes(77)), (None, randBytes(98)),]),
     4005            tdTestFileOpenAndCheckContent(sFile = sFile, abContent = abContent, cbContentExpected = 1+77+98), # 176
     4006            # Appending:
     4007            tdTestFileOpenAndWrite(sFile = sFile, eAction = vboxcon.FileOpenAction_AppendOrCreate, abContent = abContent,
     4008                                   atChunks = [(None, randBytes(255)), (None, randBytes(33)),]),
     4009            tdTestFileOpenAndCheckContent(sFile = sFile, abContent = abContent, cbContentExpected = 176 + 255+33), # 464
     4010            tdTestFileOpenAndWrite(sFile = sFile, eAction = vboxcon.FileOpenAction_AppendOrCreate, abContent = abContent,
     4011                                   atChunks = [(10, randBytes(44)),]),
     4012            tdTestFileOpenAndCheckContent(sFile = sFile, abContent = abContent, cbContentExpected = 464 + 44), # 508
     4013            # Write within existing:
     4014            tdTestFileOpenAndWrite(sFile = sFile, eAction = vboxcon.FileOpenAction_OpenExisting, abContent = abContent,
     4015                                   atChunks = [(0, randBytes(1)), (50, randBytes(77)), (255, randBytes(199)),]),
     4016            tdTestFileOpenAndCheckContent(sFile = sFile, abContent = abContent, cbContentExpected = 508),
     4017            # Writing around and over the end:
     4018            tdTestFileOpenAndWrite(sFile = sFile, abContent = abContent,
     4019                                   atChunks = [(500, randBytes(9)), (508, randBytes(15)), (512, randBytes(12)),]),
     4020            tdTestFileOpenAndCheckContent(sFile = sFile, abContent = abContent, cbContentExpected = 512+12),
     4021
     4022            # writeAt appending:
     4023            tdTestFileOpenAndWrite(sFile = sFile, abContent = abContent, fUseAtApi = True,
     4024                                   atChunks = [(0, randBytes(23)), (6, randBytes(1018)),]),
     4025            tdTestFileOpenAndCheckContent(sFile = sFile, abContent = abContent, cbContentExpected = 6+1018), # 1024
     4026            # writeAt within existing:
     4027            tdTestFileOpenAndWrite(sFile = sFile, abContent = abContent, fUseAtApi = True,
     4028                                   atChunks = [(1000, randBytes(23)), (1, randBytes(990)),]),
     4029            tdTestFileOpenAndCheckContent(sFile = sFile, abContent = abContent, cbContentExpected = 1024),
     4030            # writeAt around and over the end:
     4031            tdTestFileOpenAndWrite(sFile = sFile, abContent = abContent, fUseAtApi = True,
     4032                                   atChunks = [(1024, randBytes(63)), (1080, randBytes(968)),]),
     4033            tdTestFileOpenAndCheckContent(sFile = sFile, abContent = abContent, cbContentExpected = 1080+968), # 2048
     4034            # writeAt beyond the end:
     4035            tdTestFileOpenAndWrite(sFile = sFile, abContent = abContent, fUseAtApi = True, atChunks = [(3070, randBytes(2)),]),
     4036            tdTestFileOpenAndCheckContent(sFile = sFile, abContent = abContent, cbContentExpected = 3072),
     4037            # write beyond the end:
     4038            tdTestFileOpenAndWrite(sFile = sFile, abContent = abContent, atChunks = [(4090, randBytes(6)),]),
     4039            tdTestFileOpenAndCheckContent(sFile = sFile, abContent = abContent, cbContentExpected = 4096),
     4040        ];
     4041
     4042        for (i, oCurTest) in enumerate(aoTests):
     4043            reporter.log('Testing #%d: %s ...' % (i, oCurTest.toString(),));
     4044
    38904045            oCurTest.setEnvironment(oSession, oTxsSession, oTestVm);
    3891             fRc, oCurGuestSession = oCurTest.createSession('testGuestCtrlFileWrite: Test #%d' % (i,));
    3892             if fRc is False:
    3893                 reporter.error('Test #%d failed: Could not create session' % (i,));
     4046            fRc, _ = oCurTest.createSession('testGuestCtrlFileWrite: Test #%d' % (i,), True);
     4047            if fRc is not True:
     4048                fRc = reporter.error('Test #%d failed: Could not create session' % (i,));
    38944049                break;
    38954050
    3896             try:
    3897                 if oCurTest.offFile > 0: # The offset parameter is gone.
    3898                     curFile = oCurGuestSession.fileOpenEx(oCurTest.sFile, oCurTest.getAccessMode(), oCurTest.getOpenAction(),
    3899                                                          oCurTest.getSharingMode(), oCurTest.fCreationMode, []);
    3900                     curFile.seek(oCurTest.offFile, vboxcon.FileSeekOrigin_Begin);
    3901                     curOffset = long(curFile.offset);
    3902                     resOffset = long(oCurTest.offFile);
    3903                     if curOffset != resOffset:
    3904                         reporter.error('Test #%d failed: Initial offset on open does not match: Got %d, expected %d' \
    3905                                        % (i, curOffset, resOffset));
    3906                         fRc = False;
    3907                 else:
    3908                     curFile = oCurGuestSession.fileOpenEx(oCurTest.sFile, oCurTest.getAccessMode(), oCurTest.getOpenAction(),
    3909                                                          oCurTest.getSharingMode(), oCurTest.fCreationMode, []);
    3910                 if fRc and oCurTest.cbToReadWrite > 0:
    3911                     reporter.log("File '%s' opened" % oCurTest.sFile);
    3912                     ## @todo Split this up in 64K writes. Later.
    3913                     ## @todo Test timeouts.
    3914                     cBytesWritten = curFile.write(array('b', oCurTest.abBuf), 30 * 1000);
    3915                     if    oCurRes.cbProcessed > 0 \
    3916                       and oCurRes.cbProcessed != cBytesWritten:
    3917                         reporter.error('Test #%d failed: Written buffer length does not match: Got %d, expected %d' \
    3918                                        % (i, cBytesWritten, oCurRes.cbProcessed));
    3919                         fRc = False;
    3920                     if fRc:
    3921                         # Verify written content by seeking back to the initial offset and
    3922                         # re-read & compare the written data.
    3923                         try:
    3924                             if self.oTstDrv.fpApiVer >= 5.0:
    3925                                 curFile.seek(-(oCurTest.cbToReadWrite), vboxcon.FileSeekOrigin_Current);
    3926                             else:
    3927                                 curFile.seek(-(oCurTest.cbToReadWrite), vboxcon.FileSeekType_Current);
    3928                         except:
    3929                             reporter.logXcpt('Seeking back to initial write position failed:');
    3930                             fRc = False;
    3931                         if fRc and long(curFile.offset) != oCurTest.offFile:
    3932                             reporter.error('Test #%d failed: Initial write position does not match current position, ' \
    3933                                            'got %d, expected %d' % (i, long(curFile.offset), oCurTest.offFile));
    3934                             fRc = False;
    3935                     if fRc:
    3936                         aBufRead = curFile.read(oCurTest.cbToReadWrite, 30 * 1000);
    3937                         if len(aBufRead) != oCurTest.cbToReadWrite:
    3938                             reporter.error('Test #%d failed: Got buffer length %d, expected %d' \
    3939                                            % (i, len(aBufRead), oCurTest.cbToReadWrite));
    3940                             fRc = False;
    3941                         if     fRc \
    3942                            and oCurRes.abBuf is not None \
    3943                            and bytes(oCurRes.abBuf) != bytes(aBufRead):
    3944                             reporter.error('Test #%d failed: Read back buffer (%d bytes) does not match ' \
    3945                                            'written content (%d bytes)' % (i, len(aBufRead), len(aBufRead)));
    3946 
    3947                             curFile.close();
    3948 
    3949                             # Download written file from guest.
    3950                             aGstFiles = [];
    3951                             aGstFiles.append(oCurTest.sFile.replace('\\', '/'));
    3952                             self.oTstDrv.txsDownloadFiles(oSession, oTxsSession, aGstFiles, fIgnoreErrors = True);
    3953 
    3954                             # Create files with buffer contents and upload those for later (manual) inspection.
    3955                             oCurTest.uploadLogData(self.oTstDrv, oCurRes.abBuf, ('testGuestCtrlWriteTest%d-BufExcepted' % i),
    3956                                                                              ('Test #%d: Expected buffer' % i));
    3957                             oCurTest.uploadLogData(self.oTstDrv, aBufRead,    ('testGuestCtrlWriteTest%d-BufGot' % i),
    3958                                                                              ('Test #%d: Got buffer' % i));
    3959                             fRc = False;
    3960                 # Test final offset.
    3961                 curOffset = long(curFile.offset);
    3962                 resOffset = long(oCurRes.offFile);
    3963                 if curOffset != resOffset:
    3964                     reporter.error('Test #%d failed: Final offset does not match: Got %d, expected %d' \
    3965                                    % (i, curOffset, resOffset));
    3966                     fRc = False;
    3967                 if curFile.status == vboxcon.FileStatus_Open:
    3968                     curFile.close();
    3969                 reporter.log("File '%s' closed" % oCurTest.sFile);
    3970             except:
    3971                 reporter.logXcpt('Opening "%s" failed:' % (oCurTest.sFile,));
    3972                 fRc = False;
    3973 
    3974             oCurTest.closeSession();
    3975 
    3976             if fRc != oCurRes.fRc:
    3977                 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc, oCurRes.fRc));
    3978                 fRc = False;
    3979                 break;
     4051            fRc2 = oCurTest.doSteps(True, self.oTstDrv.fpApiVer);
     4052            if fRc2 is not True:
     4053                fRc = reporter.error('Test #%d failed!' % (i,));
     4054
     4055            fRc = oCurTest.closeSession(True) and fRc;
     4056
     4057        #
     4058        # Cleanup
     4059        #
     4060        if oTxsSession.syncRmFile(sFile) is not True:
     4061            fRc = reporter.error('Failed to remove write-test file: %s' % (sFile, ));
    39804062
    39814063        return (fRc, oTxsSession);
     
    41354217            # Copy to a Windows alternative data stream (ADS).
    41364218            atTests.extend([
    4137                 [ tdTestCopyToFile(sSrc = sBigFileHst,   sDst = os.path.join(sScratchGst, 'HostGABig.dat:ADS-Test')),
     4219                [ tdTestCopyToFile(sSrc = sBigFileHst,   sDst = oTestVm.pathJoin(sScratchGst, 'HostGABig.dat:ADS-Test')),
    41384220                  tdTestResultSuccess() ],
    4139                 [ tdTestCopyToFile(sSrc = sEmptyFileHst, sDst = os.path.join(sScratchGst, 'HostGABig.dat:ADS-Test')),
     4221                [ tdTestCopyToFile(sSrc = sEmptyFileHst, sDst = oTestVm.pathJoin(sScratchGst, 'HostGABig.dat:ADS-Test')),
    41404222                  tdTestResultSuccess() ],
    41414223            ]);
     
    41734255                atTests.extend([
    41744256                    [ tdTestCopyToDir(sSrc = sScratchNonEmptyDirHst, sDst = sScratchDstDir3Gst,
    4175                                       fFlags = [vboxcon.DirectoryCopyFlag_CopyIntoExisting]),       tdTestResultSuccess() ],
     4257                                      fFlags = [vboxcon.DirectoryCopyFlag_CopyIntoExisting]),   tdTestResultSuccess() ],
    41764258                ]);
    41774259            atTests.extend([
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