VirtualBox

Changeset 79132 in vbox


Ignore:
Timestamp:
Jun 13, 2019 3:13:12 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131297
Message:

tdAddGuestCtrl.py: More cleanups. Created pathutils.py for dealing with VM specific paths. bugref:9151 bugref:9320

Location:
trunk/src/VBox/ValidationKit
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/common/Makefile.kmk

    r76553 r79132  
    3939        utils.py \
    4040        netutils.py \
     41        pathutils.py \
    4142        webutils.py \
    4243        constants/__init__.py=>constants/__init__.py \
  • trunk/src/VBox/ValidationKit/common/__init__.py

    r76553 r79132  
    3333from common import utils;
    3434from common import netutils;
     35from common import pathutils;
    3536from common import webutils;
    3637
  • trunk/src/VBox/ValidationKit/testdriver/vboxtestvms.py

    r79087 r79132  
    4242from testdriver import reporter;
    4343from testdriver import vboxcon;
     44from common import pathutils;
    4445from common import utils;
    4546
     
    893894                fRc = oSession.close() and fRc;
    894895        return fRc;
     896
     897    def pathJoinEx(self, sBase, *asAppend):
     898        """ See common.pathutils.joinEx(). """
     899        return pathutils.joinEx(self.isWindows() or self.isOS2(), sBase, *asAppend);
    895900
    896901
     
    13611366        return 'password';
    13621367
     1368    def pathJoinEx(self, sBase, *asAppend):
     1369        """ See common.pathutils.joinEx(). """
     1370        return pathutils.joinEx(self.isWindows() or self.isOS2(), sBase, *asAppend);
     1371
    13631372
    13641373
  • trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py

    r79111 r79132  
    853853    Test result for reading guest directories.
    854854    """
    855     def __init__(self, fRc = False,
    856                  numFiles = 0, numDirs = 0):
     855    def __init__(self, fRc = False, cFiles = 0, cDirs = 0, cOthers = None):
    857856        tdTestResult.__init__(self, fRc = fRc);
    858         self.numFiles = numFiles;
    859         self.numDirs = numDirs;
     857        self.cFiles = cFiles;
     858        self.cDirs = cDirs;
     859        self.cOthers = cOthers;
    860860
    861861class tdTestResultExec(tdTestResult):
     
    864864    including the exit code, status + fFlags.
    865865    """
    866     def __init__(self, fRc = False, \
    867                  uExitStatus = 500, iExitCode = 0, \
    868                  sBuf = None, cbBuf = 0, \
    869                  cbStdOut = 0, cbStdErr = 0):
     866    def __init__(self, fRc = False, uExitStatus = 500, iExitCode = 0, sBuf = None, cbBuf = 0, cbStdOut = 0, cbStdErr = 0):
    870867        tdTestResult.__init__(self);
    871868        ## The overall test result.
     
    10831080
    10841081        return (fRc, oTxsSession);
     1082
     1083    @staticmethod
     1084    def getGuestSystemDir(oTestVm):
     1085        """
     1086        Helper for finding a system directory in the test VM that we can play around with.
     1087
     1088        On Windows this is always the System32 directory, so this function can be used as
     1089        basis for locating other files in or under that directory.
     1090        """
     1091        if oTestVm.isWindows():
     1092            if oTestVm.sKind in ['WindowsNT4', 'WindowsNT3x',]:
     1093                return 'C:\\Winnt\\System32';
     1094            return 'C:\\Windows\\System32';
     1095        if oTestVm.isOS2():
     1096            return 'C:\\OS2\\DLL';
     1097        return "/bin";
     1098
     1099    @staticmethod
     1100    def getGuestSystemShell(oTestVm):
     1101        """
     1102        Helper for finding the default system shell in the test VM.
     1103        """
     1104        if oTestVm.isWindows():
     1105            return SubTstDrvAddGuestCtrl.getGuestSystemDir(oTestVm) + '\\cmd.exe';
     1106        if oTestVm.isOS2():
     1107            return SubTstDrvAddGuestCtrl.getGuestSystemDir(oTestVm) + '\\..\\CMD.EXE';
     1108        return "/bin/sh";
     1109
     1110    @staticmethod
     1111    def getGuestSystemFileForReading(oTestVm):
     1112        """
     1113        Helper for finding a file in the test VM that we can read.
     1114        """
     1115        if oTestVm.isWindows():
     1116            return SubTstDrvAddGuestCtrl.getGuestSystemDir(oTestVm) + '\\ntdll.dll';
     1117        if oTestVm.isOS2():
     1118            return SubTstDrvAddGuestCtrl.getGuestSystemDir(oTestVm) + '\\DOSCALL1.DLL';
     1119        return "/bin/sh";
    10851120
    10861121    def gctrlCopyFileFrom(self, oGuestSession, sSrc, sDst, fFlags, fExpected):
     
    11851220        return fRc;
    11861221
    1187     def gctrlReadDir(self, oTest, oRes, oGuestSession, subDir = ''): # pylint: disable=too-many-locals
    1188         """
    1189         Helper function to read a guest directory specified in
    1190         the current test.
     1222
     1223    def gctrlReadDirTree(self, oTest, oGuestSession, fIsError, sSubDir = None):
     1224        """
     1225        Helper function to recursively read a guest directory tree specified in the current test.
    11911226        """
    11921227        sDir     = oTest.sDirectory;
    11931228        sFilter  = oTest.sFilter;
    11941229        fFlags   = oTest.fFlags;
    1195 
    1196         fRc = True; # Be optimistic.
    1197         cDirs = 0;  # Number of directories read.
    1198         cFiles = 0; # Number of files read.
    1199 
     1230        oTestVm  = oTest.oCreds.oTestVm;
     1231        sCurDir  = oTestVm.pathJoinEx(sDir, sSubDir) if sSubDir else sDir;
     1232
     1233        fRc      = True; # Be optimistic.
     1234        cDirs    = 0;    # Number of directories read.
     1235        cFiles   = 0;    # Number of files read.
     1236        cOthers  = 0;    # Other files.
     1237
     1238        #
     1239        # Open the directory:
     1240        #
     1241        # Note! Unlike fileOpen, directoryOpen will not fail if the directory does not exist.
     1242        #       Looks like it won't do nothing till you read from it.
     1243        #
     1244        #reporter.log2('Directory="%s", filter="%s", fFlags="%s"' % (sCurDir, sFilter, fFlags));
    12001245        try:
    1201             sCurDir = os.path.join(sDir, subDir);
    1202             #reporter.log2('Directory="%s", filter="%s", fFlags="%s"' % (sCurDir, sFilter, fFlags));
    12031246            oCurDir = oGuestSession.directoryOpen(sCurDir, sFilter, fFlags);
    1204             while fRc:
    1205                 try:
    1206                     oFsObjInfo = oCurDir.read();
    1207                     if     oFsObjInfo.name == "." \
    1208                         or oFsObjInfo.name == "..":
    1209                         #reporter.log2('\tSkipping "%s"' % oFsObjInfo.name);
    1210                         continue; # Skip "." and ".." entries.
    1211                     if oFsObjInfo.type is vboxcon.FsObjType_Directory:
    1212                         #reporter.log2('\tDirectory "%s"' % oFsObjInfo.name);
    1213                         cDirs += 1;
    1214                         sSubDir = oFsObjInfo.name;
    1215                         if subDir != "":
    1216                             sSubDir = os.path.join(subDir, oFsObjInfo.name);
    1217                         fRc, cSubDirs, cSubFiles = self.gctrlReadDir(oTest, oRes, oGuestSession, sSubDir);
    1218                         cDirs += cSubDirs;
    1219                         cFiles += cSubFiles;
    1220                     elif oFsObjInfo.type is vboxcon.FsObjType_File:
    1221                         #reporter.log2('\tFile "%s"' % oFsObjInfo.name);
    1222                         cFiles += 1;
    1223                     elif oFsObjInfo.type is vboxcon.FsObjType_Symlink:
    1224                         #reporter.log2('\tSymlink "%s" -- not tested yet' % oFsObjInfo.name);
    1225                         pass;
    1226                     else:
    1227                         reporter.error('\tDirectory "%s" contains invalid directory entry "%s" (type %d)' % \
    1228                                        (sCurDir, oFsObjInfo.name, oFsObjInfo.type));
    1229                         fRc = False;
    1230                 except Exception as oXcpt:
    1231                     # No necessarily an error -- could be VBOX_E_OBJECT_NOT_FOUND. See reference.
    1232                     if vbox.ComError.equal(oXcpt, vbox.ComError.VBOX_E_OBJECT_NOT_FOUND):
    1233                         #reporter.log2('\tNo more directory entries for "%s"' % (sCurDir,));
    1234                         break
    1235                     # Just log, don't assume an error here (will be done in the main loop then).
    1236                     reporter.logXcpt('\tDirectory open exception for directory="%s":' % (sCurDir,));
     1247        except:
     1248            reporter.maybeErrXcpt(fIsError, 'sCurDir=%s sFilter=%s fFlags=%s' % (sCurDir, sFilter, fFlags,))
     1249            return (False, 0, 0, 0);
     1250
     1251        # Read the directory.
     1252        while fRc is True:
     1253            try:
     1254                oFsObjInfo = oCurDir.read();
     1255            except Exception as oXcpt:
     1256                if vbox.ComError.notEqual(oXcpt, vbox.ComError.VBOX_E_OBJECT_NOT_FOUND):
     1257                    reporter.maybeErrXcpt(fIsError, 'Error reading directory "%s":' % (sCurDir,)); # See above why 'maybe'.
    12371258                    fRc = False;
    1238                     break;
     1259                #else: reporter.log2('\tNo more directory entries for "%s"' % (sCurDir,));
     1260                break;
     1261
     1262            try:
     1263                sName = oFsObjInfo.name;
     1264                eType = oFsObjInfo.type;
     1265            except:
     1266                fRc = reporter.errorXcpt();
     1267                break;
     1268
     1269            if sName in ('.', '..', ):
     1270                if eType != vboxcon.FsObjType_Directory:
     1271                    fRc = reporter.error('Wrong type for "%s": %d, expected %d (Directory)'
     1272                                         % (sName, eType, vboxcon.FsObjType_Directory));
     1273            elif eType == vboxcon.FsObjType_Directory:
     1274                #reporter.log2('  Directory "%s"' % oFsObjInfo.name);
     1275                aSubResult = self.gctrlReadDirTree(oTest, oGuestSession, fIsError,
     1276                                                   oTestVm.pathJoinEx(sSubDir, sName) if sSubDir else sName);
     1277                fRc      = aSubResult[0];
     1278                cDirs   += aSubResult[1] + 1;
     1279                cFiles  += aSubResult[2];
     1280                cOthers += aSubResult[3];
     1281            elif eType is vboxcon.FsObjType_File:
     1282                #reporter.log2('  File "%s"' % oFsObjInfo.name);
     1283                cFiles += 1;
     1284            elif eType is vboxcon.FsObjType_Symlink:
     1285                 #reporter.log2('  Symlink "%s" -- not tested yet' % oFsObjInfo.name);
     1286                cOthers += 1;
     1287            elif    oTestVm.isWindows() \
     1288                 or oTestVm.isOS2() \
     1289                 or eType not in (vboxcon.FsObjType_Fifo, vboxcon.FsObjType_DevChar, vboxcon.FsObjType_DevBlock,
     1290                                  vboxcon.FsObjType_Socket, vboxcon.FsObjType_WhiteOut):
     1291                fRc = reporter.error('Directory "%s" contains invalid directory entry "%s" (type %d)' %
     1292                                     (sCurDir, oFsObjInfo.name, oFsObjInfo.type,));
     1293            else:
     1294                cOthers += 1;
     1295
     1296        # Close the directory
     1297        try:
    12391298            oCurDir.close();
    12401299        except:
    1241             # Just log, don't assume an error here (will be done in the main loop then).
    1242             reporter.logXcpt('\tDirectory open exception for directory="%s":' % (sCurDir,));
    1243             fRc = False;
    1244 
    1245         return (fRc, cDirs, cFiles);
     1300            fRc = reporter.errorXcpt('sCurDir=%s' % (sCurDir));
     1301
     1302        return (fRc, cDirs, cFiles, cOthers);
    12461303
    12471304    def gctrlExecDoTest(self, i, oTest, oRes, oGuestSession):
     
    16011658        return (fRc, oTxsSession);
    16021659
    1603     def testGuestCtrlSessionFileRefs(self, oSession, oTxsSession, oTestVm): # pylint: disable=too-many-locals
     1660    def testGuestCtrlSessionFileRefs(self, oSession, oTxsSession, oTestVm):
    16041661        """
    16051662        Tests the guest session file reference handling.
     
    16071664
    16081665        # Find a file to play around with:
    1609         if oTestVm.isWindows():
    1610             sFile = "C:\\Windows\\System32\\ntdll.dll";
    1611             if oTestVm.sKind in ['WindowsNT4', 'WindowsNT3x',]:
    1612                 sFile = "C:\\Winnt\\System32\\ntdll.dll";
    1613         else:
    1614             sFile = "/bin/sh";
     1666        sFile = self.getGuestSystemFileForReading(oTestVm);
    16151667
    16161668        # Use credential defaults.
     
    16601712        else:
    16611713            if cFiles != cStaleFiles:
    1662                 fRc = reporter.error('Test failed: Got %d stale files, expected %d' % (cFiles, cStaleFiles));
     1714                fRc = reporter.error('Got %d stale files, expected %d' % (cFiles, cStaleFiles));
    16631715
    16641716        if fRc is True:
     
    16851737            else:
    16861738                if cFiles != cStaleFiles * 2:
    1687                     fRc = reporter.error('Test failed: Got %d total files, expected %d' % (cFiles, cStaleFiles * 2));
     1739                    fRc = reporter.error('Got %d total files, expected %d' % (cFiles, cStaleFiles * 2));
    16881740
    16891741            # Close them.
     
    17021754            # a reference in aoFiles[] for).
    17031755            if cFiles != cStaleFiles:
    1704                 fRc = reporter.error('Test failed: Got %d total files, expected %d' % (cFiles, cStaleFiles));
     1756                fRc = reporter.error('Got %d total files, expected %d' % (cFiles, cStaleFiles));
    17051757
    17061758            #
     
    17151767                else:
    17161768                    if eFileStatus != vboxcon.FileStatus_Closed:
    1717                         fRc = reporter.error('Test failed: Non-stale file #%d has status %d, expected %d'
     1769                        fRc = reporter.error('Non-stale file #%d has status %d, expected %d'
    17181770                                             % (i, eFileStatus, vboxcon.FileStatus_Closed));
    17191771
     
    17501802        """
    17511803
    1752         if oTestVm.isWindows():
    1753             sCmd = "C:\\windows\\system32\\cmd.exe";
    1754         elif oTestVm.isLinux():
    1755             sCmd = "/bin/sh";
     1804        sCmd = self.getGuestSystemShell(oTestVm);
    17561805        aArgs = [sCmd,];
    17571806
     
    17631812        cStaleProcs = 10;
    17641813
     1814        #
     1815        # Start a session.
     1816        #
     1817        aeWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];
     1818        try:
     1819            oGuest        = oSession.o.console.guest;
     1820            oGuestSession = oGuest.createSession(oCreds.sUser, oCreds.sPassword, oCreds.sDomain, "testGuestCtrlSessionFileRefs");
     1821            eWaitResult   = oGuestSession.waitForArray(aeWaitFor, 30 * 1000);
     1822        except:
     1823            return (reporter.errorXcpt(), oTxsSession);
     1824
     1825        # Be nice to Guest Additions < 4.3: They don't support session handling and therefore return WaitFlagNotSupported.
     1826        if eWaitResult not in (vboxcon.GuestSessionWaitResult_Start, vboxcon.GuestSessionWaitResult_WaitFlagNotSupported):
     1827            return (reporter.error('Session did not start successfully - wait error: %d' % (eWaitResult,)), oTxsSession);
     1828        reporter.log('Session successfully started');
     1829
     1830        #
     1831        # Fire off forever-running processes and "forget" them (stale entries).
     1832        # For them we don't have any references anymore intentionally.
     1833        #
     1834        reporter.log2('Starting stale processes...');
    17651835        fRc = True;
    1766         try:
    1767             oGuest = oSession.o.console.guest;
    1768             oGuestSession = oGuest.createSession(oCreds.sUser, oCreds.sPassword, oCreds.sDomain, "testGuestCtrlSessionProcRefs");
    1769             aeWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];
    1770             waitResult = oGuestSession.waitForArray(aeWaitFor, 30 * 1000);
     1836        for i in xrange(0, cStaleProcs):
     1837            try:
     1838                oGuestSession.processCreate(sCmd,
     1839                                            aArgs if self.oTstDrv.fpApiVer >= 5.0 else aArgs[1:], [],
     1840                                            [ vboxcon.ProcessCreateFlag_WaitForStdOut ], \
     1841                                            30 * 1000);
     1842                # Note: Use a timeout in the call above for not letting the stale processes
     1843                #       hanging around forever.  This can happen if the installed Guest Additions
     1844                #       do not support terminating guest processes.
     1845            except:
     1846                fRc = reporter.errorXcpt('Creating stale process #%d failed:' % (i,));
     1847                break;
     1848
     1849        try:    cProcesses = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'processes'));
     1850        except: fRc = reporter.errorXcpt();
     1851        else:
     1852            if cProcesses != cStaleProcs:
     1853                fRc = reporter.error('Got %d stale processes, expected %d' % (cProcesses, cStaleProcs));
     1854
     1855        if fRc is True:
    17711856            #
    1772             # Be nice to Guest Additions < 4.3: They don't support session handling and
    1773             # therefore return WaitFlagNotSupported.
     1857            # Fire off non-stale processes and wait for termination.
    17741858            #
    1775             if waitResult not in (vboxcon.GuestSessionWaitResult_Start, vboxcon.GuestSessionWaitResult_WaitFlagNotSupported):
    1776                 # Just log, don't assume an error here (will be done in the main loop then).
    1777                 reporter.log('Session did not start successfully, returned wait result: %d' \
    1778                               % (waitResult));
    1779                 return (False, oTxsSession);
    1780             reporter.log('Session successfully started');
    1781 
    1782             #
    1783             # Fire off forever-running processes and "forget" them (stale entries).
    1784             # For them we don't have any references anymore intentionally.
    1785             #
    1786             reporter.log2('Starting stale processes');
     1859            if oTestVm.isWindows() or oTestVm.isOS2():
     1860                aArgs = [ sCmd, '/C', 'dir', '/S', self.getGuestSystemDir(oTestVm), ];
     1861            else:
     1862                aArgs = [ sCmd, '-c', 'ls -la ' + self.getGuestSystemDir(oTestVm), ];
     1863            reporter.log2('Starting non-stale processes...');
     1864            aoProcesses = [];
    17871865            for i in xrange(0, cStaleProcs):
    17881866                try:
    1789                     oGuestSession.processCreate(sCmd,
    1790                                                 aArgs if self.oTstDrv.fpApiVer >= 5.0 else aArgs[1:], [],
    1791                                                 [ vboxcon.ProcessCreateFlag_WaitForStdOut ], \
    1792                                                 30 * 1000);
     1867                    oCurProc = oGuestSession.processCreate(sCmd, aArgs if self.oTstDrv.fpApiVer >= 5.0 else aArgs[1:],
     1868                                                           [], [], 0); # Infinite timeout.
     1869                    aoProcesses.append(oCurProc);
     1870                except:
     1871                    fRc = reporter.errorXcpt('Creating non-stale process #%d failed:' % (i,));
     1872                    break;
     1873
     1874            reporter.log2('Waiting for non-stale processes to terminate...');
     1875            for i, oProcess in enumerate(aoProcesses):
     1876                try:
     1877                    oProcess.waitForArray([ vboxcon.ProcessWaitForFlag_Terminate, ], 30 * 1000);
     1878                    eProcessStatus = oProcess.status;
     1879                except:
     1880                    fRc = reporter.errorXcpt('Waiting for non-stale process #%d failed:' % (i,));
     1881                else:
     1882                    if eProcessStatus != vboxcon.ProcessStatus_TerminatedNormally:
     1883                        fRc = reporter.error('Waiting for non-stale processes #%d resulted in status %d, expected %d'
     1884                                             % (i, eProcessStatus, vboxcon.ProcessStatus_TerminatedNormally));
     1885
     1886            try:    cProcesses = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'processes'));
     1887            except: fRc = reporter.errorXcpt();
     1888            else:
     1889                # Here we count the stale processes (that is, processes we don't have a reference
     1890                # anymore for) and the started + terminated non-stale processes (that we still keep
     1891                # a reference in aoProcesses[] for).
     1892                if cProcesses != (cStaleProcs * 2):
     1893                    fRc = reporter.error('Got %d total processes, expected %d' % (cProcesses, cStaleProcs));
     1894
     1895        if fRc is True:
     1896            reporter.log2('All non-stale processes terminated');
     1897
     1898            #
     1899            # Fire off non-stale blocking processes which are terminated via terminate().
     1900            #
     1901            if oTestVm.isWindows() or oTestVm.isOS2():
     1902                aArgs = [ sCmd, '/C', 'pause'];
     1903            else:
     1904                aArgs = [ sCmd ];
     1905            reporter.log2('Starting blocking processes...');
     1906            aoProcesses = [];
     1907            for i in xrange(0, cStaleProcs):
     1908                try:
     1909                    oCurProc = oGuestSession.processCreate(sCmd, aArgs if self.oTstDrv.fpApiVer >= 5.0 else aArgs[1:],
     1910                                                           [],  [], 30 * 1000);
    17931911                    # Note: Use a timeout in the call above for not letting the stale processes
    17941912                    #       hanging around forever.  This can happen if the installed Guest Additions
    17951913                    #       do not support terminating guest processes.
     1914                    aoProcesses.append(oCurProc);
    17961915                except:
    1797                     reporter.logXcpt('Creating stale process #%d failed:' % (i,));
    1798                     fRc = False;
     1916                    fRc = reporter.errorXcpt('Creating non-stale blocking process #%d failed:' % (i,));
    17991917                    break;
    18001918
    1801             if fRc:
    1802                 cProcs = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'processes'));
    1803                 if cProcs != cStaleProcs:
    1804                     reporter.error('Test failed: Got %d stale processes, expected %d' % (cProcs, cStaleProcs));
    1805                     fRc = False;
    1806 
    1807             if fRc:
    1808                 #
    1809                 # Fire off non-stale processes and wait for termination.
    1810                 #
    1811                 if oTestVm.isWindows():
    1812                     aArgs = [ sCmd, '/C', 'dir', '/S', 'C:\\Windows\\system'];
    1813                 else:
    1814                     aArgs = [ sCmd, '-c', 'date'];
    1815                 reporter.log2('Starting non-stale processes');
    1816                 aaProcs = [];
    1817                 for i in xrange(0, cStaleProcs):
    1818                     try:
    1819                         oCurProc = oGuestSession.processCreate(sCmd, aArgs if self.oTstDrv.fpApiVer >= 5.0 else aArgs[1:],
    1820                                                                [], [], 0); # Infinite timeout.
    1821                         aaProcs.append(oCurProc);
    1822                     except:
    1823                         reporter.logXcpt('Creating non-stale process #%d failed:' % (i,));
    1824                         fRc = False;
    1825                         break;
    1826             if fRc:
    1827                 reporter.log2('Waiting for non-stale processes to terminate');
    1828                 for i in xrange(0, cStaleProcs):
    1829                     try:
    1830                         aaProcs[i].waitForArray([ vboxcon.ProcessWaitForFlag_Terminate ], 30 * 1000);
    1831                         curProcStatus = aaProcs[i].status;
    1832                         if aaProcs[i].status != vboxcon.ProcessStatus_TerminatedNormally:
    1833                             reporter.error('Test failed: Waiting for non-stale processes #%d'
    1834                                            ' resulted in status %d, expected %d' \
    1835                                    % (i, curProcStatus, vboxcon.ProcessStatus_TerminatedNormally));
    1836                             fRc = False;
    1837                     except:
    1838                         reporter.logXcpt('Waiting for non-stale process #%d failed:' % (i,));
    1839                         fRc = False;
    1840                         break;
    1841                 cProcs = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'processes'));
    1842                 # Here we count the stale processes (that is, processes we don't have a reference
    1843                 # anymore for) and the started + terminated non-stale processes (that we still keep
    1844                 # a reference in aaProcs[] for).
    1845                 if cProcs != (cStaleProcs * 2):
    1846                     reporter.error('Test failed: Got %d total processes, expected %d' \
    1847                                    % (cProcs, cStaleProcs));
    1848                     fRc = False;
    1849                 if fRc:
    1850                     #
    1851                     # Check if all (referenced) non-stale processes now are in "terminated" state.
    1852                     #
    1853                     for i in xrange(0, cStaleProcs):
    1854                         curProcStatus = aaProcs[i].status;
    1855                         if aaProcs[i].status != vboxcon.ProcessStatus_TerminatedNormally:
    1856                             reporter.error('Test failed: Non-stale processes #%d has status %d, expected %d' \
    1857                                    % (i, curProcStatus, vboxcon.ProcessStatus_TerminatedNormally));
    1858                             fRc = False;
    1859             if fRc:
    1860                 reporter.log2('All non-stale processes terminated');
    1861 
    1862                 # Fire off blocking processes which are terminated via terminate().
    1863                 if oTestVm.isWindows():
    1864                     aArgs = [ sCmd, '/C', 'dir', '/S', 'C:\\Windows'];
    1865                 else:
    1866                     aArgs = [ sCmd ];
    1867                 reporter.log2('Starting blocking processes');
    1868                 aaProcs = [];
    1869                 for i in xrange(0, cStaleProcs):
    1870                     try:
    1871                         oCurProc = oGuestSession.processCreate(sCmd, aArgs if self.oTstDrv.fpApiVer >= 5.0 else aArgs[1:],
    1872                                                                [],  [], 30 * 1000);
    1873                         # Note: Use a timeout in the call above for not letting the stale processes
    1874                         #       hanging around forever.  This can happen if the installed Guest Additions
    1875                         #       do not support terminating guest processes.
    1876                         aaProcs.append(oCurProc);
    1877                     except:
    1878                         reporter.logXcpt('Creating blocking process failed:');
    1879                         fRc = False;
    1880                         break;
    1881             if fRc:
    1882                 reporter.log2('Terminating blocking processes');
    1883                 for i in xrange(0, cStaleProcs):
    1884                     try:
    1885                         aaProcs[i].terminate();
    1886                     except: # Termination might not be supported, just skip and log it.
    1887                         reporter.logXcpt('Termination of blocking process failed, skipped:');
    1888                 cProcs = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'processes'));
    1889                 if cProcs != (cStaleProcs * 2): # Still should be 20 processes because we terminated the 10 newest ones.
    1890                     reporter.error('Test failed: Got %d total processes, expected %d' % (cProcs, cStaleProcs * 2));
    1891                     fRc = False;
    1892             cProcs = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'processes'));
    1893             reporter.log2('Final guest session processes count: %d' % (cProcs,));
    1894             # Now try to close the session and see what happens.
    1895             reporter.log2('Closing guest session ...');
     1919            reporter.log2('Terminating blocking processes...');
     1920            for i, oProcess in enumerate(aoProcesses):
     1921                try:
     1922                    oProcess.terminate();
     1923                except: # Termination might not be supported, just skip and log it.
     1924                    reporter.logXcpt('Termination of blocking process #%d failed, skipped:' % (i,));
     1925
     1926            # There still should be 20 processes because we terminated the 10 newest ones.
     1927            try:    cProcesses = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'processes'));
     1928            except: fRc = reporter.errorXcpt();
     1929            else:
     1930                if cProcesses != (cStaleProcs * 2):
     1931                    fRc = reporter.error('Got %d total processes, expected %d' % (cProcesses, cStaleProcs));
     1932                reporter.log2('Final guest session processes count: %d' % (cProcesses,));
     1933
     1934        #
     1935        # Now try to close the session and see what happens.
     1936        #
     1937        reporter.log2('Closing guest session ...');
     1938        try:
    18961939            oGuestSession.close();
    18971940        except:
    1898             reporter.logXcpt('Testing for stale processes failed:');
    1899             fRc = False;
     1941            fRc = reporter.errorXcpt('Testing for stale processes failed:');
    19001942
    19011943        return (fRc, oTxsSession);
     
    19061948        """
    19071949
    1908         if oTestVm.isWindows():
    1909             sImageOut = "C:\\windows\\system32\\cmd.exe";
     1950        if oTestVm.isWindows() or oTestVm.isOS2():
     1951            sImageOut = self.getGuestSystemShell(oTestVm);
    19101952        else:
    19111953            sImageOut = "/bin/ls";
     
    19331975        if oTestVm.isWindows():
    19341976            sVBoxControl = "C:\\Program Files\\Oracle\\VirtualBox Guest Additions\\VBoxControl.exe";
     1977            sSystem32 = self.getGuestSystemDir(oTestVm);
    19351978            aaExec = [
    1936                 # Basic executon.
    1937                 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32' ]),
     1979                # Basic execution.
     1980                [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystem32 ]),
    19381981                  tdTestResultExec(fRc = True) ],
    1939                 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32\\kernel32.dll' ]),
     1982                [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystem32 + '\\kernel32.dll' ]),
    19401983                  tdTestResultExec(fRc = True) ],
    1941                 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32\\nonexist.dll' ]),
     1984                [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystem32 + '\\nonexist.dll' ]),
    19421985                  tdTestResultExec(fRc = True, iExitCode = 1) ],
    19431986                [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', '/wrongparam' ]),
     
    19481991                  tdTestResultExec(fRc = True) ],
    19491992                # StdOut.
    1950                 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32' ]),
     1993                [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystem32 ]),
    19511994                  tdTestResultExec(fRc = True) ],
    19521995                [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'stdout-non-existing' ]),
    19531996                  tdTestResultExec(fRc = True, iExitCode = 1) ],
    19541997                # StdErr.
    1955                 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32' ]),
     1998                [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystem32 ]),
    19561999                  tdTestResultExec(fRc = True) ],
    19572000                [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'stderr-non-existing' ]),
    19582001                  tdTestResultExec(fRc = True, iExitCode = 1) ],
    19592002                # StdOut + StdErr.
    1960                 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32' ]),
     2003                [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystem32 ]),
    19612004                  tdTestResultExec(fRc = True) ],
    19622005                [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'stdouterr-non-existing' ]),
     
    19842027            sVBoxControl = "/usr/bin/VBoxControl"; # Symlink
    19852028            aaExec = [
    1986                 # Basic executon.
     2029                # Basic execution.
    19872030                [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '-R', '/etc' ]),
    19882031                  tdTestResultExec(fRc = True, iExitCode = 1) ],
     
    21562199        """
    21572200
    2158         if oTestVm.isWindows():
    2159             sImage = "C:\\windows\\system32\\cmd.exe";
    2160         else:
    2161             sImage = "/bin/sh";
     2201        sImage = self.getGuestSystemShell(oTestVm);
    21622202
    21632203        # Use credential defaults.
     
    22322272        """
    22332273
    2234         if oTestVm.isWindows():
    2235             sImage = "C:\\windows\\system32\\cmd.exe";
    2236         else:
    2237             sImage = "/bin/sh";
     2274        sImage = self.getGuestSystemShell(oTestVm);
    22382275
    22392276        aaTests = [];
    22402277        if oTestVm.isWindows():
     2278            sSystem32 = self.getGuestSystemDir(oTestVm);
    22412279            aaTests.extend([
    22422280                # Simple.
     
    22512289                [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'set', 'ERRORLEVEL=0' ]),
    22522290                  tdTestResultExec(fRc = True, iExitCode = 0) ],
    2253                 [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32' ]),
     2291                [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', sSystem32 ]),
    22542292                  tdTestResultExec(fRc = True, iExitCode = 0) ],
    2255                 [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32\\kernel32.dll' ]),
     2293                [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', sSystem32 + '\\kernel32.dll' ]),
    22562294                  tdTestResultExec(fRc = True, iExitCode = 0) ],
    22572295                [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-file' ]),
     
    22612299                # FIXME: Failing tests.
    22622300                # With stdout.
    2263                 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32' ],
     2301                # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', sSystem32 ],
    22642302                #              fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut ]),
    22652303                #   tdTestResultExec(fRc = True, iExitCode = 0) ],
     
    22712309                #   tdTestResultExec(fRc = True, iExitCode = 1) ],
    22722310                # With stderr.
    2273                 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32' ],
     2311                # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', sSystem32],
    22742312                #              fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdErr ]),
    22752313                #   tdTestResultExec(fRc = True, iExitCode = 0) ],
     
    22812319                #   tdTestResultExec(fRc = True, iExitCode = 1) ],
    22822320                # With stdout/stderr.
    2283                 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32' ],
     2321                # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', sSystem32 ],
    22842322                #              fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),
    22852323                #   tdTestResultExec(fRc = True, iExitCode = 0) ],
     
    23342372        """
    23352373
    2336         if oTestVm.isWindows():
    2337             sImage = "C:\\windows\\system32\\cmd.exe";
    2338         else:
    2339             sImage = "/bin/sh";
     2374        sImage = self.getGuestSystemShell(oTestVm);
    23402375
    23412376        # Use credential defaults.
     
    26252660        return (fRc, oTxsSession);
    26262661
    2627     def testGuestCtrlDirRead(self, oSession, oTxsSession, oTestVm): # pylint: disable=too-many-locals
     2662    def testGuestCtrlDirRead(self, oSession, oTxsSession, oTestVm):
    26282663        """
    26292664        Tests opening and reading (enumerating) guest directories.
    26302665        """
    26312666
    2632         aaTests = [];
    2633         if oTestVm.isWindows():
    2634             aaTests.extend([
    2635                 # Invalid stuff.
    2636                 [ tdTestDirRead(sDirectory = ''), tdTestResultDirRead(fRc = False) ],
    2637                 [ tdTestDirRead(sDirectory = 'C:\\Windows', fFlags = [ 1234 ]), tdTestResultDirRead() ],
    2638                 [ tdTestDirRead(sDirectory = 'C:\\Windows', sFilter = '*.foo'), tdTestResultDirRead() ],
     2667        sSystemDir = self.getGuestSystemDir(oTestVm);
     2668        atTests = [
     2669            # Invalid stuff.
     2670            [ tdTestDirRead(sDirectory = ''), tdTestResultDirRead() ],
     2671            [ tdTestDirRead(sDirectory = sSystemDir, fFlags = [ 1234 ]), tdTestResultDirRead() ],
     2672            [ tdTestDirRead(sDirectory = sSystemDir, sFilter = '*.foo'), tdTestResultDirRead() ],
     2673            # Non-existing stuff.
     2674            [ tdTestDirRead(sDirectory = oTestVm.pathJoinEx(sSystemDir, 'really-no-such-subdir')), tdTestResultDirRead() ],
     2675            [ tdTestDirRead(sDirectory = oTestVm.pathJoinEx(sSystemDir, 'non', 'existing')), tdTestResultDirRead() ],
     2676        ];
     2677
     2678        if oTestVm.isWindows() or oTestVm.isOS2():
     2679            atTests.extend([
    26392680                # More unusual stuff.
    26402681                [ tdTestDirRead(sDirectory = 'z:\\'), tdTestResultDirRead() ],
    26412682                [ tdTestDirRead(sDirectory = '\\\\uncrulez\\foo'), tdTestResultDirRead() ],
    2642                 # Non-existing stuff.
    2643                 [ tdTestDirRead(sDirectory = 'c:\\Apps\\nonexisting'), tdTestResultDirRead() ],
    2644                 [ tdTestDirRead(sDirectory = 'c:\\Apps\\testDirRead'), tdTestResultDirRead() ]
    26452683            ]);
    2646 
    2647             if oTestVm.sVmName.startswith('tst-xpsp2'):
    2648                 aaTests.extend([
    2649                     # Reading directories.
    2650                     [ tdTestDirRead(sDirectory = '../../Windows/Media'),
    2651                       tdTestResultDirRead(fRc = True, numFiles = 38) ],
    2652                     [ tdTestDirRead(sDirectory = 'c:\\Windows\\Help'),
    2653                       tdTestResultDirRead(fRc = True, numDirs = 13, numFiles = 574) ],
    2654                     [ tdTestDirRead(sDirectory = 'c:\\Windows\\Web'),
    2655                       tdTestResultDirRead(fRc = True, numDirs = 3, numFiles = 49) ]
    2656                 ]);
    2657         elif oTestVm.isLinux():
    2658             aaTests.extend([
    2659                 # Invalid stuff.
    2660                 [ tdTestDirRead(sDirectory = ''), tdTestResultDirRead() ],
    2661                 [ tdTestDirRead(sDirectory = '/etc', fFlags = [ 1234 ]), tdTestResultDirRead() ],
    2662                 [ tdTestDirRead(sDirectory = '/etc', sFilter = '*.foo'), tdTestResultDirRead() ],
     2684        else:
     2685            atTests.extend([
    26632686                # More unusual stuff.
    26642687                [ tdTestDirRead(sDirectory = 'z:/'), tdTestResultDirRead() ],
    26652688                [ tdTestDirRead(sDirectory = '\\\\uncrulez\\foo'), tdTestResultDirRead() ],
    2666                 # Non-existing stuff.
    2667                 [ tdTestDirRead(sDirectory = '/etc/non/existing'), tdTestResultDirRead() ]
    26682689            ]);
     2690        # Read the system directory (ASSUMES at least 5 files in it):
     2691        atTests.append([ tdTestDirRead(sDirectory = sSystemDir), tdTestResultDirRead(fRc = True, cFiles = -5, cDirs = None) ]);
     2692        ## @todo trailing slash
     2693
     2694        ## @todo this is very very inflexible.
     2695        ## Would be better to create a dir tree using TXS and make sure we get it back exactly as expected.
     2696        if oTestVm.sVmName.startswith('tst-xpsp2'):
     2697            atTests.extend([
     2698                # Reading directories.
     2699                [ tdTestDirRead(sDirectory = '../../Windows/Media'),
     2700                  tdTestResultDirRead(fRc = True, cFiles = 38) ],
     2701                [ tdTestDirRead(sDirectory = 'C:\\Windows\\Help'),
     2702                  tdTestResultDirRead(fRc = True, cDirs = 13, cFiles = 574) ],
     2703                [ tdTestDirRead(sDirectory = 'C:\\Windows\\Web'),
     2704                  tdTestResultDirRead(fRc = True, cDirs = 3, cFiles = 49) ]
     2705            ]);
     2706
    26692707
    26702708        fRc = True;
    2671         for (i, aTest) in enumerate(aaTests):
    2672             oCurTest = aTest[0]; # tdTestExec, use an index, later.
    2673             oCurRes  = aTest[1]; # tdTestResult
     2709        for (i, tTest) in enumerate(atTests):
     2710            oCurTest = tTest[0]   # type: tdTestExec
     2711            oCurRes  = tTest[1]   # type: tdTestResultDirRead
     2712
    26742713            reporter.log('Testing #%d, dir="%s" ...' % (i, oCurTest.sDirectory));
    26752714            oCurTest.setEnvironment(oSession, oTxsSession, oTestVm);
    2676             fRc, oCurGuestSession = oCurTest.createSession('testGuestCtrlDirRead: Test #%d' % (i,));
    2677             if fRc is False:
    2678                 reporter.error('Test #%d failed: Could not create session' % (i,));
     2715            fRc, oCurGuestSession = oCurTest.createSession('testGuestCtrlDirRead: Test #%d' % (i,), True);
     2716            if fRc is not True:
    26792717                break;
    2680             (fRc2, cDirs, cFiles) = self.gctrlReadDir(oCurTest, oCurRes, oCurGuestSession);
    2681             oCurTest.closeSession();
     2718            (fRc2, cDirs, cFiles, cOthers) = self.gctrlReadDirTree(oCurTest, oCurGuestSession, oCurRes.fRc);
     2719            oCurTest.closeSession(True);
     2720
    26822721            reporter.log2('Test #%d: Returned %d directories, %d files total' % (i, cDirs, cFiles));
    26832722            if fRc2 is oCurRes.fRc:
    26842723                if fRc2 is True:
    2685                     if oCurRes.numFiles != cFiles:
    2686                         reporter.error('Test #%d failed: Got %d files, expected %d' % (i, cFiles, oCurRes.numFiles));
    2687                         fRc = False;
    2688                     if oCurRes.numDirs != cDirs:
    2689                         reporter.error('Test #%d failed: Got %d directories, expected %d' % (i, cDirs, oCurRes.numDirs));
    2690                         fRc = False;
     2724                    if oCurRes.cFiles is None:
     2725                        pass; # ignore
     2726                    elif oCurRes.cFiles >= 0 and cFiles != oCurRes.cFiles:
     2727                        fRc = reporter.error('Test #%d failed: Got %d files, expected %d' % (i, cFiles, oCurRes.cFiles));
     2728                    elif oCurRes.cFiles < 0 and cFiles < -oCurRes.cFiles:
     2729                        fRc = reporter.error('Test #%d failed: Got %d files, expected at least %d'
     2730                                             % (i, cFiles, -oCurRes.cFiles));
     2731                    if oCurRes.cDirs is None:
     2732                        pass; # ignore
     2733                    elif oCurRes.cDirs >= 0 and cDirs != oCurRes.cDirs:
     2734                        fRc = reporter.error('Test #%d failed: Got %d directories, expected %d' % (i, cDirs, oCurRes.cDirs));
     2735                    elif oCurRes.cDirs < 0 and cDirs < -oCurRes.cDirs:
     2736                        fRc = reporter.error('Test #%d failed: Got %d directories, expected at least %d'
     2737                                             % (i, cDirs, -oCurRes.cDirs));
     2738                    if oCurRes.cOthers is None:
     2739                        pass; # ignore
     2740                    elif oCurRes.cOthers >= 0 and cOthers != oCurRes.cOthers:
     2741                        fRc = reporter.error('Test #%d failed: Got %d other types, expected %d' % (i, cOthers, oCurRes.cOthers));
     2742                    elif oCurRes.cOthers < 0 and cOthers < -oCurRes.cOthers:
     2743                        fRc = reporter.error('Test #%d failed: Got %d other types, expected at least %d'
     2744                                             % (i, cOthers, -oCurRes.cOthers));
     2745
    26912746            else:
    2692                 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, oCurRes.fRc));
    2693                 fRc = False;
     2747                fRc = reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, oCurRes.fRc));
    26942748
    26952749        return (fRc, oTxsSession);
     
    36933747        _ = oGuestSession.waitForArray(aWaitFor, 30 * 1000);
    36943748
    3695         sCmd = 'c:\\windows\\system32\\cmd.exe';
     3749        sCmd = SubTstDrvAddGuestCtrl.getGuestSystemShell(oTestVm);
    36963750        aArgs = [ sCmd, '/C', 'dir', '/S', 'c:\\windows' ];
    36973751        aEnv = [];
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