VirtualBox

Changeset 84563 in vbox


Ignore:
Timestamp:
May 27, 2020 2:06:44 PM (4 years ago)
Author:
vboxsync
Message:

Validation Kit/tdAddGuestCtrl.py: Implemented limitString() for limiting string output length; especially useful for logging very long (random) test data.

File:
1 edited

Legend:

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

    r84544 r84563  
    6060    xrange = range; # pylint: disable=redefined-builtin,invalid-name
    6161
     62def limitString(sString, cLimit = 32):
     63    """
     64    Returns a string with ellipsis ("...") when exceeding the specified limit.
     65    Useful for toning down logging. By default strings will be shortened at 32 characters.
     66    """
     67    if not isinstance(sString, str):
     68        return "";
     69    cLen = len(sString);
     70    return (sString[:cLimit] + '...[%d more]' % (cLen - cLimit)) if cLen > cLimit else sString;
    6271
    6372class GuestStream(bytearray):
     
    386395
    387396    def execute(self, oSubTstDrv):
    388         reporter.log2('Deleting file "%s" ...' % (self.sPath,));
     397        reporter.log2('Deleting file "%s" ...' % (limitString(self.sPath),));
    389398        try:
    390399            if oSubTstDrv.oTstDrv.fpApiVer >= 5.0:
     
    409418    def execute(self, oSubTstDrv):
    410419        _ = oSubTstDrv;
    411         reporter.log2('Deleting directory "%s" ...' % (self.sPath,));
     420        reporter.log2('Deleting directory "%s" ...' % (limitString(self.sPath),));
    412421        try:
    413422            self.oGuestSession.directoryRemove(self.sPath);
     
    430439
    431440    def execute(self, oSubTstDrv):
    432         reporter.log2('Deleting tree "%s" ...' % (self.sPath,));
     441        reporter.log2('Deleting tree "%s" ...' % (limitString(self.sPath),));
    433442        try:
    434443            oProgress = self.oGuestSession.directoryRemoveRecursive(self.sPath, self.afFlags);
     
    11211130        """
    11221131        reporter.log2('tdStepStat: sPath=%s enmType=%s hrcExpected=%s fFound=%s fFollowLinks=%s'
    1123                       % (self.sPath, self.enmType, self.hrcExpected, self.fFound, self.fFollowLinks,));
     1132                      % (limitString(self.sPath), self.enmType, self.hrcExpected, self.fFound, self.fFollowLinks,));
    11241133
    11251134        # Don't execute non-file tests on older VBox version.
     
    16711680        # Do the copying.
    16721681        #
    1673         reporter.log2('Copying guest file "%s" to host "%s"' % (oTest.sSrc, oTest.sDst));
     1682        reporter.log2('Copying guest file "%s" to host "%s"' % (limitString(oTest.sSrc), limitString(oTest.sDst)));
    16741683        try:
    16751684            if self.oTstDrv.fpApiVer >= 5.0:
     
    17671776        # Do the copying.
    17681777        #
    1769         reporter.log2('Copying guest dir "%s" to host "%s"' % (oTest.sSrc, oTest.sDst));
     1778        reporter.log2('Copying guest dir "%s" to host "%s"' % (limitString(oTest.sSrc), limitString(oTest.sDst)));
    17701779        try:
    17711780            oCurProgress = oGuestSession.directoryCopyFromGuest(oTest.sSrc, oTest.sDst, oTest.afFlags);
     
    18001809        Helper function to copy a single file from the host to the guest.
    18011810        """
    1802         reporter.log2('Copying host file "%s" to guest "%s" (flags %s)' % (sSrc, sDst, afFlags));
     1811        reporter.log2('Copying host file "%s" to guest "%s" (flags %s)' % (limitString(sSrc), limitString(sDst), afFlags));
    18031812        try:
    18041813            if self.oTstDrv.fpApiVer >= 5.0:
     
    18281837        Helper function to copy a directory tree from the host to the guest.
    18291838        """
    1830         reporter.log2('Copying host directory "%s" to guest "%s" (flags %s)' % (sSrc, sDst, afFlags));
     1839        reporter.log2('Copying host directory "%s" to guest "%s" (flags %s)' % (limitString(sSrc), limitString(sDst), afFlags));
    18311840        try:
    18321841            oCurProgress = oGuestSession.directoryCopyToGuest(sSrc, sDst, afFlags);
     
    18531862        Helper function to create a guest directory specified in the current test.
    18541863        """
    1855         reporter.log2('Creating directory "%s"' % (oTest.sDirectory,));
     1864        reporter.log2('Creating directory "%s"' % (limitString(oTest.sDirectory),));
    18561865        try:
    18571866            oGuestSession.directoryCreate(oTest.sDirectory, oTest.fMode, oTest.afFlags);
     
    18921901
    18931902        # Open the directory:
    1894         reporter.log2('Directory="%s", filter="%s", afFlags="%s"' % (sCurDir, sFilter, afFlags));
     1903        reporter.log2('Directory="%s", filter="%s", afFlags="%s"' % (limitString(sCurDir), sFilter, afFlags));
    18951904        try:
    18961905            oCurDir = oGuestSession.directoryOpen(sCurDir, sFilter, afFlags);
     
    19121921                    fRc = False;
    19131922                else:
    1914                     reporter.log2('\tNo more directory entries for "%s"' % (sCurDir,));
     1923                    reporter.log2('\tNo more directory entries for "%s"' % (limitString(sCurDir),));
    19151924                break;
    19161925
     
    19271936                                         % (sName, eType, vboxcon.FsObjType_Directory));
    19281937            elif eType == vboxcon.FsObjType_Directory:
    1929                 reporter.log2('  Directory "%s"' % oFsObjInfo.name);
     1938                reporter.log2('  Directory "%s"' % limitString(oFsObjInfo.name));
    19301939                aSubResult = self.gctrlReadDirTree(oTest, oGuestSession, fIsError,
    19311940                                                   oTestVm.pathJoin(sSubDir, sName) if sSubDir else sName);
     
    21252134        # Start the process:
    21262135        #
    2127         reporter.log2('Executing sCmd=%s, afFlags=%s, timeoutMS=%d, asEnv=%s'
    2128                       % (oTest.sCmd, oTest.afFlags, oTest.timeoutMS, oTest.aEnv,));
    2129 
    2130         # Don't be too noisy by default when testing reeeeeeally long arguments.
    2131         if len(oTest.asArgs) <= 64:
    2132             reporter.log2('asArgs=%s' % (oTest.asArgs,));
    2133         else:
    2134             reporter.log4('asArgs=%s' % (oTest.asArgs,));
    2135 
     2136        reporter.log2('Executing sCmd=%s, afFlags=%s, timeoutMS=%d, asArgs=%s, asEnv=%s'
     2137                      % (oTest.sCmd, oTest.afFlags, oTest.timeoutMS, limitString(oTest.asArgs), limitString(oTest.aEnv),));
    21362138        try:
    21372139            oProcess = oGuestSession.processCreate(oTest.sCmd,
     
    34503452                    reporter.logXcpt('Creating temp directory "%s" failed expectedly, skipping:' % (oCurTest.sDirectory,));
    34513453            else:
    3452                 reporter.log2('Temporary directory is: "%s"' % (sDirTemp,));
     3454                reporter.log2('Temporary directory is: "%s"' % (limitString(sDirTemp),));
    34533455                if not sDirTemp:
    34543456                    fRc = reporter.error('Resulting directory is empty!');
     
    34723474                        fRc = reporter.errorXcpt('sDirTemp="%s"' % (sDirTemp,));
    34733475                    else:
    3474                         reporter.log2('%s: eType=%s (dir=%d)' % (sDirTemp, eType, vboxcon.FsObjType_Directory,));
     3476                        reporter.log2('%s: eType=%s (dir=%d)' % (limitString(sDirTemp), eType, vboxcon.FsObjType_Directory,));
    34753477                        if eType != vboxcon.FsObjType_Directory:
    34763478                            fRc = reporter.error('Temporary directory "%s" not created as a directory: eType=%d'
     
    36813683                reporter.log('Deleting the file in "%s" ...' % (self.oTestFiles.oManyDir.sPath,));
    36823684                for oFile in self.oTestFiles.oManyDir.aoChildren:
    3683                     reporter.log2('"%s"' % (oFile.sPath,));
     3685                    reporter.log2('"%s"' % (limitString(oFile.sPath),));
    36843686                    try:
    36853687                        if self.oTstDrv.fpApiVer >= 5.0:
     
    37953797            oFsObj = self.oTestFiles.dPaths[sPath];
    37963798            reporter.log2('testGuestCtrlFileStat: %s sPath=%s'
    3797                           % ('file' if isinstance(oFsObj, testfileset.TestFile) else 'dir ', oFsObj.sPath,));
     3799                          % ('file' if isinstance(oFsObj, testfileset.TestFile) else 'dir ', limitString(oFsObj.sPath),));
    37983800
    37993801            # Query the information:
     
    41004102        #
    41014103        for oTestFile in aoExtraFiles + self.oTestFiles.aoFiles: # type: testfileset.TestFile
    4102             reporter.log2('Test file: %s bytes, "%s" ...' % (oTestFile.cbContent, oTestFile.sPath,));
     4104            reporter.log2('Test file: %s bytes, "%s" ...' % (oTestFile.cbContent, limitString(oTestFile.sPath),));
    41034105
    41044106            #
     
    46564658            oCurTest = tTest[0]; # tdTestCopyTo
    46574659            oCurRes  = tTest[1]; # tdTestResult
    4658             reporter.log('Testing #%d, sSrc=%s, sDst=%s, afFlags=%s ...' % (i, oCurTest.sSrc, oCurTest.sDst, oCurTest.afFlags));
     4660            reporter.log('Testing #%d, sSrc=%s, sDst=%s, afFlags=%s ...'
     4661                         % (i, limitString(oCurTest.sSrc), limitString(oCurTest.sDst), oCurTest.afFlags));
    46594662
    46604663            oCurTest.setEnvironment(oSession, oTxsSession, oTestVm);
     
    48314834                reporter.log('Testing #%d, %s: sSrc="%s", sDst="%s", afFlags="%s" ...'
    48324835                             % (i, "directory" if isinstance(oCurTest, tdTestCopyFromDir) else "file",
    4833                                 oCurTest.sSrc, oCurTest.sDst, oCurTest.afFlags,));
     4836                                limitString(oCurTest.sSrc), limitString(oCurTest.sDst), oCurTest.afFlags,));
    48344837            else:
    48354838                reporter.log('Testing #%d, tdTestRemoveHostDir "%s"  ...' % (i, oCurTest.sDir,));
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