Changeset 79132 in vbox
- Timestamp:
- Jun 13, 2019 3:13:12 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 131297
- Location:
- trunk/src/VBox/ValidationKit
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/common/Makefile.kmk
r76553 r79132 39 39 utils.py \ 40 40 netutils.py \ 41 pathutils.py \ 41 42 webutils.py \ 42 43 constants/__init__.py=>constants/__init__.py \ -
trunk/src/VBox/ValidationKit/common/__init__.py
r76553 r79132 33 33 from common import utils; 34 34 from common import netutils; 35 from common import pathutils; 35 36 from common import webutils; 36 37 -
trunk/src/VBox/ValidationKit/testdriver/vboxtestvms.py
r79087 r79132 42 42 from testdriver import reporter; 43 43 from testdriver import vboxcon; 44 from common import pathutils; 44 45 from common import utils; 45 46 … … 893 894 fRc = oSession.close() and fRc; 894 895 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); 895 900 896 901 … … 1361 1366 return 'password'; 1362 1367 1368 def pathJoinEx(self, sBase, *asAppend): 1369 """ See common.pathutils.joinEx(). """ 1370 return pathutils.joinEx(self.isWindows() or self.isOS2(), sBase, *asAppend); 1371 1363 1372 1364 1373 -
trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py
r79111 r79132 853 853 Test result for reading guest directories. 854 854 """ 855 def __init__(self, fRc = False, 856 numFiles = 0, numDirs = 0): 855 def __init__(self, fRc = False, cFiles = 0, cDirs = 0, cOthers = None): 857 856 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; 860 860 861 861 class tdTestResultExec(tdTestResult): … … 864 864 including the exit code, status + fFlags. 865 865 """ 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): 870 867 tdTestResult.__init__(self); 871 868 ## The overall test result. … … 1083 1080 1084 1081 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"; 1085 1120 1086 1121 def gctrlCopyFileFrom(self, oGuestSession, sSrc, sDst, fFlags, fExpected): … … 1185 1220 return fRc; 1186 1221 1187 def gctrlReadDir(self, oTest, oRes, oGuestSession, subDir = ''): # pylint: disable=too-many-locals 1188 """1189 Helper function to read a guest directory specified in1190 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. 1191 1226 """ 1192 1227 sDir = oTest.sDirectory; 1193 1228 sFilter = oTest.sFilter; 1194 1229 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)); 1200 1245 try: 1201 sCurDir = os.path.join(sDir, subDir);1202 #reporter.log2('Directory="%s", filter="%s", fFlags="%s"' % (sCurDir, sFilter, fFlags));1203 1246 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'. 1237 1258 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: 1239 1298 oCurDir.close(); 1240 1299 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); 1246 1303 1247 1304 def gctrlExecDoTest(self, i, oTest, oRes, oGuestSession): … … 1601 1658 return (fRc, oTxsSession); 1602 1659 1603 def testGuestCtrlSessionFileRefs(self, oSession, oTxsSession, oTestVm): # pylint: disable=too-many-locals1660 def testGuestCtrlSessionFileRefs(self, oSession, oTxsSession, oTestVm): 1604 1661 """ 1605 1662 Tests the guest session file reference handling. … … 1607 1664 1608 1665 # 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); 1615 1667 1616 1668 # Use credential defaults. … … 1660 1712 else: 1661 1713 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)); 1663 1715 1664 1716 if fRc is True: … … 1685 1737 else: 1686 1738 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)); 1688 1740 1689 1741 # Close them. … … 1702 1754 # a reference in aoFiles[] for). 1703 1755 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)); 1705 1757 1706 1758 # … … 1715 1767 else: 1716 1768 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' 1718 1770 % (i, eFileStatus, vboxcon.FileStatus_Closed)); 1719 1771 … … 1750 1802 """ 1751 1803 1752 if oTestVm.isWindows(): 1753 sCmd = "C:\\windows\\system32\\cmd.exe"; 1754 elif oTestVm.isLinux(): 1755 sCmd = "/bin/sh"; 1804 sCmd = self.getGuestSystemShell(oTestVm); 1756 1805 aArgs = [sCmd,]; 1757 1806 … … 1763 1812 cStaleProcs = 10; 1764 1813 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...'); 1765 1835 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: 1771 1856 # 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. 1774 1858 # 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 = []; 1787 1865 for i in xrange(0, cStaleProcs): 1788 1866 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); 1793 1911 # Note: Use a timeout in the call above for not letting the stale processes 1794 1912 # hanging around forever. This can happen if the installed Guest Additions 1795 1913 # do not support terminating guest processes. 1914 aoProcesses.append(oCurProc); 1796 1915 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,)); 1799 1917 break; 1800 1918 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: 1896 1939 oGuestSession.close(); 1897 1940 except: 1898 reporter.logXcpt('Testing for stale processes failed:'); 1899 fRc = False; 1941 fRc = reporter.errorXcpt('Testing for stale processes failed:'); 1900 1942 1901 1943 return (fRc, oTxsSession); … … 1906 1948 """ 1907 1949 1908 if oTestVm.isWindows() :1909 sImageOut = "C:\\windows\\system32\\cmd.exe";1950 if oTestVm.isWindows() or oTestVm.isOS2(): 1951 sImageOut = self.getGuestSystemShell(oTestVm); 1910 1952 else: 1911 1953 sImageOut = "/bin/ls"; … … 1933 1975 if oTestVm.isWindows(): 1934 1976 sVBoxControl = "C:\\Program Files\\Oracle\\VirtualBox Guest Additions\\VBoxControl.exe"; 1977 sSystem32 = self.getGuestSystemDir(oTestVm); 1935 1978 aaExec = [ 1936 # Basic execut on.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 ]), 1938 1981 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' ]), 1940 1983 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' ]), 1942 1985 tdTestResultExec(fRc = True, iExitCode = 1) ], 1943 1986 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', '/wrongparam' ]), … … 1948 1991 tdTestResultExec(fRc = True) ], 1949 1992 # StdOut. 1950 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32']),1993 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystem32 ]), 1951 1994 tdTestResultExec(fRc = True) ], 1952 1995 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'stdout-non-existing' ]), 1953 1996 tdTestResultExec(fRc = True, iExitCode = 1) ], 1954 1997 # StdErr. 1955 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32']),1998 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystem32 ]), 1956 1999 tdTestResultExec(fRc = True) ], 1957 2000 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'stderr-non-existing' ]), 1958 2001 tdTestResultExec(fRc = True, iExitCode = 1) ], 1959 2002 # StdOut + StdErr. 1960 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32']),2003 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystem32 ]), 1961 2004 tdTestResultExec(fRc = True) ], 1962 2005 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'stdouterr-non-existing' ]), … … 1984 2027 sVBoxControl = "/usr/bin/VBoxControl"; # Symlink 1985 2028 aaExec = [ 1986 # Basic execut on.2029 # Basic execution. 1987 2030 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '-R', '/etc' ]), 1988 2031 tdTestResultExec(fRc = True, iExitCode = 1) ], … … 2156 2199 """ 2157 2200 2158 if oTestVm.isWindows(): 2159 sImage = "C:\\windows\\system32\\cmd.exe"; 2160 else: 2161 sImage = "/bin/sh"; 2201 sImage = self.getGuestSystemShell(oTestVm); 2162 2202 2163 2203 # Use credential defaults. … … 2232 2272 """ 2233 2273 2234 if oTestVm.isWindows(): 2235 sImage = "C:\\windows\\system32\\cmd.exe"; 2236 else: 2237 sImage = "/bin/sh"; 2274 sImage = self.getGuestSystemShell(oTestVm); 2238 2275 2239 2276 aaTests = []; 2240 2277 if oTestVm.isWindows(): 2278 sSystem32 = self.getGuestSystemDir(oTestVm); 2241 2279 aaTests.extend([ 2242 2280 # Simple. … … 2251 2289 [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'set', 'ERRORLEVEL=0' ]), 2252 2290 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 ]), 2254 2292 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' ]), 2256 2294 tdTestResultExec(fRc = True, iExitCode = 0) ], 2257 2295 [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-file' ]), … … 2261 2299 # FIXME: Failing tests. 2262 2300 # With stdout. 2263 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32'],2301 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', sSystem32 ], 2264 2302 # fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut ]), 2265 2303 # tdTestResultExec(fRc = True, iExitCode = 0) ], … … 2271 2309 # tdTestResultExec(fRc = True, iExitCode = 1) ], 2272 2310 # With stderr. 2273 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32'],2311 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', sSystem32], 2274 2312 # fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdErr ]), 2275 2313 # tdTestResultExec(fRc = True, iExitCode = 0) ], … … 2281 2319 # tdTestResultExec(fRc = True, iExitCode = 1) ], 2282 2320 # With stdout/stderr. 2283 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32'],2321 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', sSystem32 ], 2284 2322 # fFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]), 2285 2323 # tdTestResultExec(fRc = True, iExitCode = 0) ], … … 2334 2372 """ 2335 2373 2336 if oTestVm.isWindows(): 2337 sImage = "C:\\windows\\system32\\cmd.exe"; 2338 else: 2339 sImage = "/bin/sh"; 2374 sImage = self.getGuestSystemShell(oTestVm); 2340 2375 2341 2376 # Use credential defaults. … … 2625 2660 return (fRc, oTxsSession); 2626 2661 2627 def testGuestCtrlDirRead(self, oSession, oTxsSession, oTestVm): # pylint: disable=too-many-locals2662 def testGuestCtrlDirRead(self, oSession, oTxsSession, oTestVm): 2628 2663 """ 2629 2664 Tests opening and reading (enumerating) guest directories. 2630 2665 """ 2631 2666 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([ 2639 2680 # More unusual stuff. 2640 2681 [ tdTestDirRead(sDirectory = 'z:\\'), tdTestResultDirRead() ], 2641 2682 [ tdTestDirRead(sDirectory = '\\\\uncrulez\\foo'), tdTestResultDirRead() ], 2642 # Non-existing stuff.2643 [ tdTestDirRead(sDirectory = 'c:\\Apps\\nonexisting'), tdTestResultDirRead() ],2644 [ tdTestDirRead(sDirectory = 'c:\\Apps\\testDirRead'), tdTestResultDirRead() ]2645 2683 ]); 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([ 2663 2686 # More unusual stuff. 2664 2687 [ tdTestDirRead(sDirectory = 'z:/'), tdTestResultDirRead() ], 2665 2688 [ tdTestDirRead(sDirectory = '\\\\uncrulez\\foo'), tdTestResultDirRead() ], 2666 # Non-existing stuff.2667 [ tdTestDirRead(sDirectory = '/etc/non/existing'), tdTestResultDirRead() ]2668 2689 ]); 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 2669 2707 2670 2708 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 2674 2713 reporter.log('Testing #%d, dir="%s" ...' % (i, oCurTest.sDirectory)); 2675 2714 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: 2679 2717 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 2682 2721 reporter.log2('Test #%d: Returned %d directories, %d files total' % (i, cDirs, cFiles)); 2683 2722 if fRc2 is oCurRes.fRc: 2684 2723 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 2691 2746 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)); 2694 2748 2695 2749 return (fRc, oTxsSession); … … 3693 3747 _ = oGuestSession.waitForArray(aWaitFor, 30 * 1000); 3694 3748 3695 sCmd = 'c:\\windows\\system32\\cmd.exe';3749 sCmd = SubTstDrvAddGuestCtrl.getGuestSystemShell(oTestVm); 3696 3750 aArgs = [ sCmd, '/C', 'dir', '/S', 'c:\\windows' ]; 3697 3751 aEnv = [];
Note:
See TracChangeset
for help on using the changeset viewer.