VirtualBox

Changeset 79159 in vbox


Ignore:
Timestamp:
Jun 16, 2019 3:27:39 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131328
Message:

tdAddGuestCtrl.py: Extended directory listing test to check names, sizes and types against the vboxtestfileset.TestFileSet object. bugref:9151 bugref:9320

Location:
trunk/src/VBox/ValidationKit
Files:
2 edited

Legend:

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

    r79158 r79159  
    4747
    4848
     49
     50class GstFsObj(object):
     51    """ A file system object we created in the guest for test purposes. """
     52    def __init__(self, oParent, sPath):
     53        self.oParent   = oParent    # type: GstDir
     54        self.sPath     = sPath      # type: str
     55        self.sName     = sPath      # type: str
     56        if oParent:
     57            assert sPath.startswith(oParent.sPath);
     58            self.sName = sPath[len(oParent.sPath) + 1:];
     59            # Add to parent.
     60            oParent.aoChildren.append(self);
     61            oParent.dChildrenUpper[self.sName.upper()] = self;
     62
     63class GstFile(GstFsObj):
     64    """ A file object in the guest. """
     65    def __init__(self, oParent, sPath, abContent):
     66        GstFsObj.__init__(self, oParent, sPath);
     67        self.abContent = abContent          # type: bytearray
     68        self.cbContent = len(abContent);
     69        self.off       = 0;
     70
     71    def read(self, cbToRead):
     72        assert self.off <= self.cbContent;
     73        cbLeft = self.cbContent - self.off;
     74        if cbLeft < cbToRead:
     75            cbToRead = cbLeft;
     76        abRet = self.abContent[self.off:(self.off + cbToRead)];
     77        assert len(abRet) == cbToRead;
     78        self.off += cbToRead;
     79        return abRet;
     80
     81class GstDir(GstFsObj):
     82    """ A file object in the guest. """
     83    def __init__(self, oParent, sPath):
     84        GstFsObj.__init__(self, oParent, sPath);
     85        self.aoChildren     = []  # type: list(GsFsObj)
     86        self.dChildrenUpper = {}  # type: dict(str,GsFsObj)
     87
     88    def contains(self, sName):
     89        """ Checks if the directory contains the given name. """
     90        return sName.upper() in self.dChildrenUpper
     91
     92
    4993class TestFileSet(object):
    5094    """
     
    5498    utility from the validation kit.
    5599    """
    56 
    57     class GstFsObj(object):
    58         """ A file system object we created in the guest for test purposes. """
    59         def __init__(self, oParent, sPath):
    60             self.oParent   = oParent    # type: GstDir
    61             self.sPath     = sPath      # type: str
    62             self.sName     = sPath      # type: str
    63             if oParent:
    64                 assert sPath.startswith(oParent.sPath);
    65                 self.sName = sPath[len(oParent.sPath) + 1:];
    66                 # Add to parent.
    67                 oParent.aoChildren.append(self);
    68                 oParent.dChildrenUpper[self.sName.upper()] = self;
    69 
    70     class GstFile(GstFsObj):
    71         """ A file object in the guest. """
    72         def __init__(self, oParent, sPath, abContent):
    73             TestFileSet.GstFsObj.__init__(self, oParent, sPath);
    74             self.abContent = abContent          # type: bytearray
    75             self.cbContent = len(abContent);
    76             self.off       = 0;
    77 
    78         def read(self, cbToRead):
    79             assert self.off <= self.cbContent;
    80             cbLeft = self.cbContent - self.off;
    81             if cbLeft < cbToRead:
    82                 cbToRead = cbLeft;
    83             abRet = self.abContent[self.off:(self.off + cbToRead)];
    84             assert len(abRet) == cbToRead;
    85             self.off += cbToRead;
    86             return abRet;
    87 
    88     class GstDir(GstFsObj):
    89         """ A file object in the guest. """
    90         def __init__(self, oParent, sPath):
    91             TestFileSet.GstFsObj.__init__(self, oParent, sPath);
    92             self.aoChildren     = []  # type: list(GsFsObj)
    93             self.dChildrenUpper = {}  # type: dict(str,GsFsObj)
    94 
    95         def contains(self, sName):
    96             """ Checks if the directory contains the given name. """
    97             return sName.upper() in self.dChildrenUpper
    98 
    99100
    100101    ksReservedWinOS2         = '/\\"*:<>?|\t\v\n\r\f\a\b';
     
    164165        ## Number of directories under oTreeDir.
    165166        self.cTreeDirs  = 0;
     167        ## Number of other file types under oTreeDir.
     168        self.cTreeOthers = 0;
    166169
    167170        ## All directories in creation order.
     
    242245        Creates a test directory.
    243246        """
    244         oDir = TestFileSet.GstDir(oParent, sDir);
     247        oDir = GstDir(oParent, sDir);
    245248        self.aoDirs.append(oDir);
    246249        self.dPaths[sDir] = oDir;
     
    254257        abContent = bytearray(self.oRandom.getrandbits(8) for _ in xrange(cbFile));
    255258
    256         oFile = TestFileSet.GstFile(oParent, sFile, abContent);
     259        oFile = GstFile(oParent, sFile, abContent);
    257260        self.aoFiles.append(oFile);
    258261        self.dPaths[sFile] = oFile;
     
    418421        return True;
    419422
    420 
  • trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py

    r79158 r79159  
    12981298
    12991299        return (fRc, cDirs, cFiles, cOthers);
     1300
     1301    def gctrlReadDirTree2(self, oGuestSession, oDir): # type: (vboxtestfileset.GstDir) -> bool
     1302        """
     1303        Helper function to recursively read a guest directory tree specified in the current test.
     1304        """
     1305
     1306        #
     1307        # Process the directory.
     1308        #
     1309
     1310        # Open the directory:
     1311        try:
     1312            oCurDir = oGuestSession.directoryOpen(oDir.sPath, '', None);
     1313        except:
     1314            return reporter.errorXcpt('sPath=%s' % (oDir.sPath,));
     1315
     1316        # Read the directory.
     1317        dLeftUpper = dict(oDir.dChildrenUpper);
     1318        cDot       = 0;
     1319        cDotDot    = 0;
     1320        fRc = True;
     1321        while True:
     1322            try:
     1323                oFsObjInfo = oCurDir.read();
     1324            except Exception as oXcpt:
     1325                if vbox.ComError.notEqual(oXcpt, vbox.ComError.VBOX_E_OBJECT_NOT_FOUND):
     1326                    fRc = reporter.errorXcpt('Error reading directory "%s":' % (oDir.sPath,));
     1327                break;
     1328
     1329            try:
     1330                sName  = oFsObjInfo.name;
     1331                eType  = oFsObjInfo.type;
     1332                cbFile = oFsObjInfo.objectSize;
     1333                ## @todo check further attributes.
     1334            except:
     1335                fRc = reporter.errorXcpt();
     1336                break;
     1337
     1338            # '.' and '..' entries are not present in oDir.aoChildren, so special treatment:
     1339            if sName in ('.', '..', ):
     1340                if eType != vboxcon.FsObjType_Directory:
     1341                    fRc = reporter.error('Wrong type for "%s": %d, expected %d (Directory)'
     1342                                         % (sName, eType, vboxcon.FsObjType_Directory));
     1343                if sName == '.': cDot    += 1;
     1344                else:            cDotDot += 1;
     1345            else:
     1346                # Find the child and remove it from the dictionary.
     1347                sNameUpper = sName.upper();
     1348                oFsObj = dLeftUpper.get(sNameUpper);
     1349                if oFsObj is None:
     1350                    fRc = reporter.error('Unknown object "%s" found in "%s" (type %s, size %s)!'
     1351                                         % (sName, oDir.sPath, eType, cbFile,));
     1352                else:
     1353                    del dLeftUpper[sNameUpper];
     1354
     1355                    # Check type
     1356                    if isinstance(oFsObj, vboxtestfileset.GstDir):
     1357                        if eType != vboxcon.FsObjType_Directory:
     1358                            fRc = reporter.error('%s: expected directory (%d), got eType=%d!'
     1359                                                 % (oFsObj.sPath, vboxcon.FsObjType_Directory, eType,));
     1360                    elif isinstance(oFsObj, vboxtestfileset.GstFile):
     1361                        if eType != vboxcon.FsObjType_File:
     1362                            fRc = reporter.error('%s: expected file (%d), got eType=%d!'
     1363                                                 % (oFsObj.sPath, vboxcon.FsObjType_File, eType,));
     1364                    else:
     1365                        fRc = reporter.error('%s: WTF? type=%s' % (oFsObj.sPath, type(oFsObj),));
     1366
     1367                    # Check the name.
     1368                    if oFsObj.sName != sName:
     1369                        fRc = reporter.error('%s: expected name "%s", got "%s" instead!' % (oFsObj.sPath, oFsObj.sName, sName,));
     1370
     1371                    # Check the size if a file.
     1372                    if isinstance(oFsObj, vboxtestfileset.GstFile) and cbFile != oFsObj.cbContent:
     1373                        fRc = reporter.error('%s: expected size %s, got %s instead!' % (oFsObj.sPath, oFsObj.cbContent, cbFile,));
     1374
     1375                    ## @todo check timestamps and attributes.
     1376
     1377        # Close the directory
     1378        try:
     1379            oCurDir.close();
     1380        except:
     1381            fRc = reporter.errorXcpt('oDir.sPath=%s' % (oDir.sPath,));
     1382
     1383        # Any files left over?
     1384        for sKey in dLeftUpper:
     1385            oFsObj = dLeftUpper[sKey];
     1386            fRc = reporter.error('%s: Was not returned! (%s)' % (oFsObj.sPath, type(oFsObj),));
     1387
     1388        # Check the dot and dot-dot counts.
     1389        if cDot != 1:
     1390            fRc = reporter.error('%s: Found %s "." entries, expected exactly 1!' % (oDir.sPath, cDot,));
     1391        if cDotDot != 1:
     1392            fRc = reporter.error('%s: Found %s ".." entries, expected exactly 1!' % (oDir.sPath, cDotDot,));
     1393
     1394        #
     1395        # Recurse into subdirectories using info from oDir.
     1396        #
     1397        for oFsObj in oDir.aoChildren:
     1398            if isinstance(oFsObj, vboxtestfileset.GstDir):
     1399                fRc = self.gctrlReadDirTree2(oGuestSession, oFsObj) and fRc;
     1400
     1401        return fRc;
    13001402
    13011403    def gctrlExecDoTest(self, i, oTest, oRes, oGuestSession):
     
    27492851        ## @todo trailing slash
    27502852
    2751         ## @todo this is very very inflexible.
    2752         ## Would be better to create a dir tree using TXS and make sure we get it back exactly as expected.
    2753         if oTestVm.sVmName.startswith('tst-xpsp2'):
    2754             atTests.extend([
    2755                 # Reading directories.
    2756                 [ tdTestDirRead(sDirectory = '../../Windows/Media'),
    2757                   tdTestResultDirRead(fRc = True, cFiles = 38) ],
    2758                 [ tdTestDirRead(sDirectory = 'C:\\Windows\\Help'),
    2759                   tdTestResultDirRead(fRc = True, cDirs = 13, cFiles = 574) ],
    2760                 [ tdTestDirRead(sDirectory = 'C:\\Windows\\Web'),
    2761                   tdTestResultDirRead(fRc = True, cDirs = 3, cFiles = 49) ]
    2762             ]);
     2853        # Read from the test file set.
     2854        atTests.extend([
     2855            [ tdTestDirRead(sDirectory = self.oTestFiles.oEmptyDir.sPath),
     2856              tdTestResultDirRead(fRc = True, cFiles = 0, cDirs = 0, cOthers = 0) ],
     2857            [ tdTestDirRead(sDirectory = self.oTestFiles.oManyDir.sPath),
     2858              tdTestResultDirRead(fRc = True, cFiles = len(self.oTestFiles.oManyDir.aoChildren), cDirs = 0, cOthers = 0) ],
     2859            [ tdTestDirRead(sDirectory = self.oTestFiles.oTreeDir.sPath),
     2860              tdTestResultDirRead(fRc = True, cFiles = self.oTestFiles.cTreeFiles, cDirs = self.oTestFiles.cTreeDirs,
     2861                                  cOthers = self.oTestFiles.cTreeOthers) ],
     2862        ]);
    27632863
    27642864
     
    27742874                break;
    27752875            (fRc2, cDirs, cFiles, cOthers) = self.gctrlReadDirTree(oCurTest, oCurGuestSession, oCurRes.fRc);
    2776             oCurTest.closeSession(True);
     2876            fRc = oCurTest.closeSession(True) and fRc;
    27772877
    27782878            reporter.log2('Test #%d: Returned %d directories, %d files total' % (i, cDirs, cFiles));
     
    28032903            else:
    28042904                fRc = reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, oCurRes.fRc));
     2905
     2906
     2907        #
     2908        # Go over a few directories in the test file set and compare names,
     2909        # types and sizes rather than just the counts like we did above.
     2910        #
     2911        if fRc is True:
     2912            oCurTest = tdTestDirRead();
     2913            oCurTest.setEnvironment(oSession, oTxsSession, oTestVm);
     2914            fRc, oCurGuestSession = oCurTest.createSession('testGuestCtrlDirRead: gctrlReadDirTree2', True);
     2915            if fRc is True:
     2916                for oDir in (self.oTestFiles.oEmptyDir, self.oTestFiles.oManyDir, self.oTestFiles.oTreeDir):
     2917                    reporter.log('Checking "%s" ...' % (oDir.sPath,));
     2918                    fRc = self.gctrlReadDirTree2(oCurGuestSession, oDir) and fRc;
     2919                fRc = oCurTest.closeSession(True) and fRc;
    28052920
    28062921        return (fRc, oTxsSession);
Note: See TracChangeset for help on using the changeset viewer.

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