Changeset 79136 in vbox for trunk/src/VBox/ValidationKit
- Timestamp:
- Jun 13, 2019 8:12:56 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py
r79135 r79136 864 864 including the exit code, status + fFlags. 865 865 """ 866 def __init__(self, fRc = False, uExitStatus = 500, iExitCode = 0, sBuf = None, cbBuf = 0, cbStdOut = 0, cbStdErr = 0):866 def __init__(self, fRc = False, uExitStatus = 500, iExitCode = 0, sBuf = None, cbBuf = 0, cbStdOut = None, cbStdErr = None): 867 867 tdTestResult.__init__(self); 868 868 ## The overall test result. … … 1312 1312 """ 1313 1313 reporter.log('Testing #%d, cmd="%s" ...' % (i, oTest.sCmd)); 1314 fRc = self.gctrlExecute(oTest, oGuestSession); 1315 if fRc is oRes.fRc: 1316 if fRc is True: 1314 fRcExec = self.gctrlExecute(oTest, oGuestSession, oRes.fRc); 1315 if fRcExec == oRes.fRc: 1316 fRc = True; 1317 if fRcExec is True: 1317 1318 # Compare exit status / code on successful process execution. 1318 1319 if oTest.uExitStatus != oRes.uExitStatus \ 1319 1320 or oTest.iExitCode != oRes.iExitCode: 1320 reporter.error('Test #%dfailed: Got exit status + code %d,%d, expected %d,%d'1321 % (i, oTest.uExitStatus, oTest.iExitCode, oRes.uExitStatus, oRes.iExitCode));1322 return False;1323 if fRc is True: 1321 fRc = reporter.error('Test #%d (%s) failed: Got exit status + code %d,%d, expected %d,%d' 1322 % (i, oTest.aArgs, oTest.uExitStatus, oTest.iExitCode, 1323 oRes.uExitStatus, oRes.iExitCode)); 1324 1324 1325 # Compare test / result buffers on successful process execution. 1325 if oTest.sBuf is not None \ 1326 and oRes.sBuf is not None: 1327 if bytes(oTest.sBuf) != bytes(oRes.sBuf): 1328 reporter.error('Test #%d failed: Got buffer\n%s (%d bytes), expected\n%s (%d bytes)' 1329 % (i, map(hex, map(ord, oTest.sBuf)), len(oTest.sBuf), \ 1330 map(hex, map(ord, oRes.sBuf)), len(oRes.sBuf))); 1331 return False; 1326 if oTest.sBuf is not None and oRes.sBuf is not None: 1327 if not utils.areBytesEqual(oTest.sBuf, oRes.sBuf): 1328 fRc = reporter.error('Test #%d (%s) failed: Got buffer\n%s (%d bytes), expected\n%s (%d bytes)' 1329 % (i, oTest.aArgs, 1330 map(hex, map(ord, oTest.sBuf)), len(oTest.sBuf), 1331 map(hex, map(ord, oRes.sBuf)), len(oRes.sBuf))); 1332 1332 reporter.log2('Test #%d passed: Buffers match (%d bytes)' % (i, len(oRes.sBuf))); 1333 elif oRes.sBuf is not None \1334 and oRes.sBuf:1335 reporter.error('Test #%d failed: Got no buffer data, expected\n%s (%dbytes)' %1336 (i, map(hex, map(ord, oRes.sBuf)), len(oRes.sBuf))); 1337 return False;1338 elif oRes.cbStdOut > 0 \1339 and oRes.cbStdOut != oTest.cbStdOut:1340 reporter.error('Test #%d failed: Got %d stdout data, expected %d'1341 % (i, oTest.cbStdOut, oRes.cbStdOut));1342 return False;1333 elif oRes.sBuf and not oTest.sBuf: 1334 fRc = reporter.error('Test #%d (%s) failed: Got no buffer data, expected\n%s (%dbytes)' % 1335 (i, oTest.aArgs, map(hex, map(ord, oRes.sBuf)), len(oRes.sBuf),)); 1336 1337 if oRes.cbStdOut is not None and oRes.cbStdOut != oTest.cbStdOut: 1338 fRc = reporter.error('Test #%d (%s) failed: Got %d bytes of stdout data, expected %d' 1339 % (i, oTest.aArgs, oTest.cbStdOut, oRes.cbStdOut)); 1340 if oRes.cbStdErr is not None and oRes.cbStdErr != oTest.cbStdErr: 1341 fRc = reporter.error('Test #%d (%s) failed: Got %d bytes of stderr data, expected %d' 1342 % (i, oTest.aArgs, oTest.cbStdErr, oRes.cbStdErr)); 1343 1343 else: 1344 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc, oRes.fRc));1345 return False;1346 return True; 1347 1348 def gctrlExecute(self, oTest, oGuestSession):1349 """1350 Helper function to execute a program on a guest, specified in 1351 the current test.1344 fRc = reporter.error('Test #%d (%s) failed: Got %s, expected %s' % (i, oTest.aArgs, fRcExec, oRes.fRc)); 1345 return fRc; 1346 1347 def gctrlExecute(self, oTest, oGuestSession, fIsError): 1348 """ 1349 Helper function to execute a program on a guest, specified in the current test. 1350 1351 Note! This weirdo returns results (process exitcode and status) in oTest. 1352 1352 """ 1353 1353 fRc = True; # Be optimistic. 1354 1355 # Reset the weird result stuff: 1356 oTest.cbStdOut = 0; 1357 oTest.cbStdErr = 0; 1358 oTest.sBuf = ''; 1359 oTest.uExitStatus = 0; 1360 oTest.iExitCode = 0; 1354 1361 1355 1362 ## @todo Compare execution timeouts! 1356 1363 #tsStart = base.timestampMilli(); 1357 1364 1358 reporter.log2('Using session user=%s, sDomain=%s, name=%s, timeout=%d'1359 % (oGuestSession.user, oGuestSession.domain, oGuestSession.name, oGuestSession.timeout));1360 reporter.log2('Executing sCmd=%s, fFlags=%s, timeoutMS=%d, aArgs=%s, aEnv=%s'1361 % (oTest.sCmd, oTest.fFlags, oTest.timeoutMS, oTest.aArgs, oTest.aEnv));1362 1365 try: 1363 curProc = oGuestSession.processCreate(oTest.sCmd, 1364 oTest.aArgs if self.oTstDrv.fpApiVer >= 5.0 else oTest.aArgs[1:], 1365 oTest.aEnv, oTest.fFlags, oTest.timeoutMS); 1366 if curProc is not None: 1367 reporter.log2('Process start requested, waiting for start (%dms) ...' % (oTest.timeoutMS,)); 1368 aeWaitFor = [ vboxcon.ProcessWaitForFlag_Start ]; 1369 waitResult = curProc.waitForArray(aeWaitFor, oTest.timeoutMS); 1370 reporter.log2('Wait result returned: %d, current process status is: %d' % (waitResult, curProc.status)); 1371 1372 if curProc.status == vboxcon.ProcessStatus_Started: 1373 aeWaitFor = [ vboxcon.ProcessWaitForFlag_Terminate ]; 1366 reporter.log2('Using session user=%s, sDomain=%s, name=%s, timeout=%d' 1367 % (oGuestSession.user, oGuestSession.domain, oGuestSession.name, oGuestSession.timeout,)); 1368 except: 1369 return reporter.errorXcpt(); 1370 1371 # 1372 # Start the process: 1373 # 1374 reporter.log2('Executing sCmd=%s, fFlags=%s, timeoutMS=%d, asArgs=%s, asEnv=%s' 1375 % (oTest.sCmd, oTest.fFlags, oTest.timeoutMS, oTest.aArgs, oTest.aEnv,)); 1376 try: 1377 oProcess = oGuestSession.processCreate(oTest.sCmd, 1378 oTest.aArgs if self.oTstDrv.fpApiVer >= 5.0 else oTest.aArgs[1:], 1379 oTest.aEnv, oTest.fFlags, oTest.timeoutMS); 1380 except: 1381 reporter.maybeErrXcpt(fIsError, 'asArgs=%s' % (oTest.aArgs,)); 1382 return False; 1383 if oProcess is None: 1384 return reporter.error('oProcess is None! (%s)' % (oTest.aArgs,)); 1385 1386 #time.sleep(5); # try this if you want to see races here. 1387 1388 # Wait for the process to start properly: 1389 reporter.log2('Process start requested, waiting for start (%dms) ...' % (oTest.timeoutMS,)); 1390 iPid = -1; 1391 aeWaitFor = [ vboxcon.ProcessWaitForFlag_Start, ]; 1392 try: 1393 eWaitResult = oProcess.waitForArray(aeWaitFor, oTest.timeoutMS); 1394 except: 1395 reporter.maybeErrXcpt(fIsError, 'waitforArray failed for asArgs=%s' % (oTest.aArgs,)); 1396 fRc = False; 1397 else: 1398 try: 1399 eStatus = oProcess.status; 1400 iPid = oProcess.PID; 1401 except: 1402 fRc = reporter.errorXcpt('asArgs=%s' % (oTest.aArgs,)); 1403 else: 1404 reporter.log2('Wait result returned: %d, current process status is: %d' % (eWaitResult, eStatus,)); 1405 1406 # 1407 # Wait for the process to run to completion if necessary. 1408 # 1409 # Note! The above eWaitResult return value can be ignored as it will 1410 # (mostly) reflect the process status anyway. 1411 # 1412 if eStatus == vboxcon.ProcessStatus_Started: 1413 1414 # What to wait for: 1415 aeWaitFor = [ vboxcon.ProcessWaitForFlag_Terminate, ]; 1374 1416 if vboxcon.ProcessCreateFlag_WaitForStdOut in oTest.fFlags: 1375 1417 aeWaitFor.append(vboxcon.ProcessWaitForFlag_StdOut); … … 1377 1419 aeWaitFor.append(vboxcon.ProcessWaitForFlag_StdErr); 1378 1420 ## @todo Add vboxcon.ProcessWaitForFlag_StdIn. 1379 reporter.log2('Process (PID %d) started, waiting for termination (%dms), waitFlags=%s ...' 1380 % (curProc.PID, oTest.timeoutMS, aeWaitFor)); 1421 1422 reporter.log2('Process (PID %d) started, waiting for termination (%dms), aeWaitFor=%s ...' 1423 % (iPid, oTest.timeoutMS, aeWaitFor)); 1424 acbFdOut = [0,0,0]; 1381 1425 while True: 1382 waitResult = curProc.waitForArray(aeWaitFor, oTest.timeoutMS);1383 reporter.log2('Wait returned: %d' % (waitResult,));1384 1426 try: 1385 # Try stdout. 1386 if waitResult in (vboxcon.ProcessWaitResult_StdOut, vboxcon.ProcessWaitResult_WaitFlagNotSupported): 1387 reporter.log2('Reading stdout ...'); 1388 abBuf = curProc.Read(1, 64 * 1024, oTest.timeoutMS); 1389 if abBuf: 1390 reporter.log2('Process (PID %d) got %d bytes of stdout data' % (curProc.PID, len(abBuf))); 1391 oTest.cbStdOut += len(abBuf); 1392 oTest.sBuf = abBuf; # Appending does *not* work atm, so just assign it. No time now. 1393 # Try stderr. 1394 if waitResult in (vboxcon.ProcessWaitResult_StdErr, vboxcon.ProcessWaitResult_WaitFlagNotSupported): 1395 reporter.log2('Reading stderr ...'); 1396 abBuf = curProc.Read(2, 64 * 1024, oTest.timeoutMS); 1397 if abBuf: 1398 reporter.log2('Process (PID %d) got %d bytes of stderr data' % (curProc.PID, len(abBuf))); 1399 oTest.cbStdErr += len(abBuf); 1400 oTest.sBuf = abBuf; # Appending does *not* work atm, so just assign it. No time now. 1401 # Use stdin. 1402 if waitResult in (vboxcon.ProcessWaitResult_StdIn, vboxcon.ProcessWaitResult_WaitFlagNotSupported): 1403 pass; #reporter.log2('Process (PID %d) needs stdin data' % (curProc.pid,)); 1404 # Termination or error? 1405 if waitResult in (vboxcon.ProcessWaitResult_Terminate, 1406 vboxcon.ProcessWaitResult_Error, 1407 vboxcon.ProcessWaitResult_Timeout,): 1408 reporter.log2('Process (PID %d) reported terminate/error/timeout: %d, status: %d' 1409 % (curProc.PID, waitResult, curProc.status)); 1410 break; 1427 eWaitResult = oProcess.waitForArray(aeWaitFor, oTest.timeoutMS); 1428 except KeyboardInterrupt: # Not sure how helpful this is, but whatever. 1429 reporter.error('Process (PID %d) execution interrupted' % (iPid,)); 1430 try: oProcess.close(); 1431 except: pass; 1432 break; 1411 1433 except: 1412 # Just skip reads which returned nothing. 1413 pass; 1414 reporter.log2('Final process status (PID %d) is: %d' % (curProc.PID, curProc.status)); 1415 reporter.log2('Process (PID %d) %d stdout, %d stderr' % (curProc.PID, oTest.cbStdOut, oTest.cbStdErr)); 1416 oTest.uExitStatus = curProc.status; 1417 oTest.iExitCode = curProc.exitCode; 1418 reporter.log2('Process (PID %d) has exit code: %d' % (curProc.PID, oTest.iExitCode)); 1419 except KeyboardInterrupt: 1420 reporter.error('Process (PID %d) execution interrupted' % (curProc.PID,)); 1421 if curProc is not None: 1422 curProc.close(); 1434 fRc = reporter.errorXcpt('asArgs=%s' % (oTest.aArgs,)); 1435 break; 1436 reporter.log2('Wait returned: %d' % (eWaitResult,)); 1437 1438 # Process output: 1439 for eFdResult, iFd, sFdNm in [ (vboxcon.ProcessWaitResult_StdOut, 1, 'stdout'), 1440 (vboxcon.ProcessWaitResult_StdErr, 2, 'stderr'), ]: 1441 if eWaitResult in (eFdResult, vboxcon.ProcessWaitResult_WaitFlagNotSupported): 1442 reporter.log2('Reading %s ...' % (sFdNm,)); 1443 try: 1444 abBuf = oProcess.Read(1, 64 * 1024, oTest.timeoutMS); 1445 except KeyboardInterrupt: # Not sure how helpful this is, but whatever. 1446 reporter.error('Process (PID %d) execution interrupted' % (iPid,)); 1447 try: oProcess.close(); 1448 except: pass; 1449 except: 1450 pass; ## @todo test for timeouts and fail on anything else! 1451 else: 1452 if abBuf: 1453 reporter.log2('Process (PID %d) got %d bytes of %s data' % (iPid, len(abBuf), sFdNm,)); 1454 acbFdOut[iFd] += len(abBuf); 1455 oTest.sBuf = abBuf; ## @todo Figure out how to uniform + append! 1456 1457 ## Process input (todo): 1458 #if eWaitResult in (vboxcon.ProcessWaitResult_StdIn, vboxcon.ProcessWaitResult_WaitFlagNotSupported): 1459 # reporter.log2('Process (PID %d) needs stdin data' % (iPid,)); 1460 1461 # Termination or error? 1462 if eWaitResult in (vboxcon.ProcessWaitResult_Terminate, 1463 vboxcon.ProcessWaitResult_Error, 1464 vboxcon.ProcessWaitResult_Timeout,): 1465 try: eStatus = oProcess.status; 1466 except: fRc = reporter.errorXcpt('asArgs=%s' % (oTest.aArgs,)); 1467 reporter.log2('Process (PID %d) reported terminate/error/timeout: %d, status: %d' 1468 % (iPid, eWaitResult, eStatus,)); 1469 break; 1470 1471 # End of the wait loop. 1472 _, oTest.cbStdOut, oTest.cbStdErr = acbFdOut; 1473 1474 try: eStatus = oProcess.status; 1475 except: fRc = reporter.errorXcpt('asArgs=%s' % (oTest.aArgs,)); 1476 reporter.log2('Final process status (PID %d) is: %d' % (iPid, eStatus)); 1477 reporter.log2('Process (PID %d) %d stdout, %d stderr' % (iPid, oTest.cbStdOut, oTest.cbStdErr)); 1478 1479 # 1480 # Get the final status and exit code of the process. 1481 # 1482 try: 1483 oTest.uExitStatus = oProcess.status; 1484 oTest.iExitCode = oProcess.exitCode; 1423 1485 except: 1424 # Just log, don't assume an error here (will be done in the main loop then). 1425 reporter.logXcpt('Execution exception for command "%s":' % (oTest.sCmd,)); 1426 fRc = False; 1427 1486 fRc = reporter.errorXcpt('asArgs=%s' % (oTest.aArgs,)); 1487 reporter.log2('Process (PID %d) has exit code: %d; status: %d ' % (iPid, oTest.iExitCode, oTest.uExitStatus)); 1428 1488 return fRc; 1429 1489 … … 1952 2012 """ 1953 2013 2014 # Paths: 2015 sVBoxControl = None; ## @todo Get path of installed Guest Additions. Later. 2016 sSystemDir = self.getGuestSystemDir(oTestVm); 2017 sFileForReading = self.getGuestSystemFileForReading(oTestVm); 1954 2018 if oTestVm.isWindows() or oTestVm.isOS2(): 1955 2019 sImageOut = self.getGuestSystemShell(oTestVm); 2020 if oTestVm.isWindows(): 2021 sVBoxControl = "C:\\Program Files\\Oracle\\VirtualBox Guest Additions\\VBoxControl.exe"; 1956 2022 else: 1957 2023 sImageOut = "/bin/ls"; 2024 if oTestVm.isLinux(): ## @todo check solaris and darwin. 2025 sVBoxControl = "/usr/bin/VBoxControl"; # Symlink 1958 2026 1959 2027 # Use credential defaults. … … 1961 2029 oCreds.applyDefaultsIfNotSet(oTestVm); 1962 2030 1963 a aInvalid = [2031 atInvalid = [ 1964 2032 # Invalid parameters. 1965 2033 [ tdTestExec(), tdTestResultExec() ], … … 1977 2045 ]; 1978 2046 1979 if oTestVm.isWindows(): 1980 sVBoxControl = "C:\\Program Files\\Oracle\\VirtualBox Guest Additions\\VBoxControl.exe"; 1981 sSystem32 = self.getGuestSystemDir(oTestVm); 1982 aaExec = [ 2047 if oTestVm.isWindows() or oTestVm.isOS2(): 2048 atExec = [ 1983 2049 # Basic execution. 1984 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystem 32]),2050 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystemDir ]), 1985 2051 tdTestResultExec(fRc = True) ], 1986 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', s System32 + '\\kernel32.dll']),2052 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sFileForReading ]), 1987 2053 tdTestResultExec(fRc = True) ], 1988 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystem 32+ '\\nonexist.dll' ]),2054 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystemDir + '\\nonexist.dll' ]), 1989 2055 tdTestResultExec(fRc = True, iExitCode = 1) ], 1990 2056 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', '/wrongparam' ]), 1991 2057 tdTestResultExec(fRc = True, iExitCode = 1) ], 1992 # Paths with spaces.1993 ## @todo Get path of installed Guest Additions. Later.1994 [ tdTestExec(sCmd = sVBoxControl, aArgs = [ sVBoxControl, 'version' ]),1995 tdTestResultExec(fRc = True) ],1996 2058 # StdOut. 1997 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystem 32]),2059 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystemDir ]), 1998 2060 tdTestResultExec(fRc = True) ], 1999 2061 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'stdout-non-existing' ]), 2000 2062 tdTestResultExec(fRc = True, iExitCode = 1) ], 2001 2063 # StdErr. 2002 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystem 32]),2064 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystemDir ]), 2003 2065 tdTestResultExec(fRc = True) ], 2004 2066 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'stderr-non-existing' ]), 2005 2067 tdTestResultExec(fRc = True, iExitCode = 1) ], 2006 2068 # StdOut + StdErr. 2007 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystem 32]),2069 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', sSystemDir ]), 2008 2070 tdTestResultExec(fRc = True) ], 2009 2071 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'stdouterr-non-existing' ]), 2010 tdTestResultExec(fRc = True, iExitCode = 1) ] 2072 tdTestResultExec(fRc = True, iExitCode = 1) ], 2073 ]; 2074 # atExec.extend([ 2011 2075 # FIXME: Failing tests. 2012 2076 # Environment variables. … … 2027 2091 ## @todo Create some files (or get files) we know the output size of to validate output length! 2028 2092 ## @todo Add task which gets killed at some random time while letting the guest output something. 2029 ]; 2030 elif oTestVm.isLinux(): 2031 sVBoxControl = "/usr/bin/VBoxControl"; # Symlink 2032 aaExec = [ 2093 #]; 2094 else: 2095 atExec = [ 2033 2096 # Basic execution. 2034 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '-R', '/etc']),2097 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '-R', sSystemDir ]), 2035 2098 tdTestResultExec(fRc = True, iExitCode = 1) ], 2036 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/bin/sh']),2099 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, sFileForReading ]), 2037 2100 tdTestResultExec(fRc = True) ], 2038 2101 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '--wrong-parameter' ]), … … 2040 2103 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/non/existent' ]), 2041 2104 tdTestResultExec(fRc = True, iExitCode = 2) ], 2042 # Paths with spaces.2043 ## @todo Get path of installed Guest Additions. Later.2044 [ tdTestExec(sCmd = sVBoxControl, aArgs = [ sVBoxControl, 'version' ]),2045 tdTestResultExec(fRc = True) ],2046 2105 # StdOut. 2047 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/etc']),2106 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, sSystemDir ]), 2048 2107 tdTestResultExec(fRc = True) ], 2049 2108 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, 'stdout-non-existing' ]), 2050 2109 tdTestResultExec(fRc = True, iExitCode = 2) ], 2051 2110 # StdErr. 2052 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/etc']),2111 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, sSystemDir ]), 2053 2112 tdTestResultExec(fRc = True) ], 2054 2113 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, 'stderr-non-existing' ]), 2055 2114 tdTestResultExec(fRc = True, iExitCode = 2) ], 2056 2115 # StdOut + StdErr. 2057 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/etc']),2116 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, sSystemDir ]), 2058 2117 tdTestResultExec(fRc = True) ], 2059 2118 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, 'stdouterr-non-existing' ]), 2060 tdTestResultExec(fRc = True, iExitCode = 2) ] 2119 tdTestResultExec(fRc = True, iExitCode = 2) ], 2120 ]; 2121 # atExec.extend([ 2061 2122 # FIXME: Failing tests. 2062 2123 # Environment variables. … … 2078 2139 ## @todo Create some files (or get files) we know the output size of to validate output length! 2079 2140 ## @todo Add task which gets killed at some random time while letting the guest output something. 2080 ]; 2141 #]; 2142 2143 if sVBoxControl: 2144 # Paths with spaces on windows. 2145 atExec.append([ tdTestExec(sCmd = sVBoxControl, aArgs = [ sVBoxControl, 'version' ]), 2146 tdTestResultExec(fRc = True) ]); 2147 2081 2148 2082 2149 # Build up the final test array for the first batch. 2083 aaTests = []; 2084 aaTests.extend(aaInvalid); 2085 if aaExec is not None: 2086 aaTests.extend(aaExec); 2150 atTests = atInvalid + atExec; 2151 2152 # 2153 # First batch: One session per guest process. 2154 # 2155 reporter.log('One session per guest process ...'); 2087 2156 fRc = True; 2088 2089 if fRc is False: 2090 return (fRc, oTxsSession); 2091 2092 # 2093 # First batch: One session per guest process. 2094 # 2095 reporter.log('One session per guest process ...'); 2096 for (i, aTest) in enumerate(aaTests): 2097 oCurTest = aTest[0]; # tdTestExec, use an index, later. 2098 oCurRes = aTest[1]; # tdTestResultExec 2157 for (i, tTest) in enumerate(atTests): 2158 oCurTest = tTest[0] # type: tdTestExec 2159 oCurRes = tTest[1] # type: tdTestResultExec 2099 2160 oCurTest.setEnvironment(oSession, oTxsSession, oTestVm); 2100 fRc, oCurGuestSession = oCurTest.createSession('testGuestCtrlExec: Test #%d' % (i,) );2101 if fRc is False:2161 fRc, oCurGuestSession = oCurTest.createSession('testGuestCtrlExec: Test #%d' % (i,), True); 2162 if fRc is not True: 2102 2163 reporter.error('Test #%d failed: Could not create session' % (i,)); 2103 2164 break; 2104 2165 fRc = self.gctrlExecDoTest(i, oCurTest, oCurRes, oCurGuestSession); 2105 if fRc is False:2166 if fRc is not True: 2106 2167 break; 2107 fRc = oCurTest.closeSession( );2108 if fRc is False:2168 fRc = oCurTest.closeSession(True); 2169 if fRc is not True: 2109 2170 break; 2110 2171 … … 2112 2173 2113 2174 # No sessions left? 2114 if fRc is True:2175 try: 2115 2176 aSessions = self.oTstDrv.oVBoxMgr.getArray(oSession.o.console.guest, 'sessions'); 2116 cSessions = len(aSessions); 2177 except: 2178 fRc = reporter.errorXcpt(); 2179 else: 2180 cSessions = len(aSessions); 2117 2181 if cSessions != 0: 2118 reporter.error('Found %d stale session(s), expected 0:' % (cSessions,));2182 fRc = reporter.error('Found %d stale session(s), expected 0:' % (cSessions,)); 2119 2183 for (i, aSession) in enumerate(aSessions): 2120 reporter.log('\tStale session #%d ("%s")' % (aSession.id, aSession.name));2121 fRc = False;2122 2123 if fRc is False:2184 try: reporter.log(' Stale session #%d ("%s")' % (aSession.id, aSession.name)); 2185 except: reporter.errorXcpt(); 2186 2187 if fRc is not True: 2124 2188 return (fRc, oTxsSession); 2125 2189 … … 2129 2193 # Second batch: One session for *all* guest processes. 2130 2194 # 2131 oGuest = oSession.o.console.guest; 2195 2196 # Create session. 2197 reporter.log('Creating session for all tests ...'); 2198 aeWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start, ]; 2132 2199 try: 2133 reporter.log('Creating session for all tests ...');2200 oGuest = oSession.o.console.guest; 2134 2201 oCurGuestSession = oGuest.createSession(oCreds.sUser, oCreds.sPassword, oCreds.sDomain, 2135 2202 'testGuestCtrlExec: One session for all tests'); 2203 except: 2204 return (reporter.errorXcpt(), oTxsSession); 2205 2206 try: 2207 eWaitResult = oCurGuestSession.waitForArray(aeWaitFor, 30 * 1000); 2208 except: 2209 fRc = reporter.errorXcpt('Waiting for guest session to start failed:'); 2210 else: 2211 if eWaitResult not in (vboxcon.GuestSessionWaitResult_Start, vboxcon.GuestSessionWaitResult_WaitFlagNotSupported): 2212 fRc = reporter.error('Session did not start successfully, returned wait result: %d' % (eWaitResult,)); 2213 else: 2214 reporter.log('Session successfully started'); 2215 2216 # Do the tests within this session. 2217 for (i, tTest) in enumerate(atTests): 2218 oCurTest = tTest[0] # type: tdTestExec 2219 oCurRes = tTest[1] # type: tdTestResultExec 2220 2221 oCurTest.setEnvironment(oSession, oTxsSession, oTestVm); 2222 fRc = self.gctrlExecDoTest(i, oCurTest, oCurRes, oCurGuestSession); 2223 if fRc is False: 2224 break; 2225 2226 # Close the session. 2227 reporter.log2('Closing guest session ...'); 2136 2228 try: 2137 aeWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];2138 waitResult = oCurGuestSession.waitForArray(aeWaitFor, 30 * 1000);2139 if waitResult not in (vboxcon.GuestSessionWaitResult_Start, vboxcon.GuestSessionWaitResult_WaitFlagNotSupported):2140 reporter.error('Session did not start successfully, returned wait result: %d' \2141 % (waitResult));2142 return (False, oTxsSession);2143 reporter.log('Session successfully started');2144 except:2145 # Just log, don't assume an error here (will be done in the main loop then).2146 reporter.logXcpt('Waiting for guest session to start failed:');2147 return (False, oTxsSession);2148 # Note: Not waiting for the guest session to start here2149 # is intentional. This must be handled by the process execution2150 # call then.2151 for (i, aTest) in enumerate(aaTests):2152 oCurTest = aTest[0]; # tdTestExec, use an index, later.2153 oCurRes = aTest[1]; # tdTestResultExec2154 oCurTest.setEnvironment(oSession, oTxsSession, oTestVm);2155 fRc = self.gctrlExecDoTest(i, oCurTest, oCurRes, oCurGuestSession);2156 if fRc is False:2157 break;2158 try:2159 reporter.log2('Closing guest session ...');2160 2229 oCurGuestSession.close(); 2161 2230 oCurGuestSession = None; 2162 2231 except: 2163 # Just log, don't assume an error here (will be done in the main loop then). 2164 reporter.logXcpt('Closing guest session failed:'); 2165 fRc = False; 2166 except: 2167 reporter.logXcpt('Could not create one session:'); 2168 2169 reporter.log('Execution of all tests done, checking for stale sessions again'); 2170 2171 # No sessions left? 2172 if fRc is True: 2173 cSessions = len(self.oTstDrv.oVBoxMgr.getArray(oSession.o.console.guest, 'sessions')); 2174 if cSessions != 0: 2175 reporter.error('Found %d stale session(s), expected 0' % (cSessions,)); 2176 fRc = False; 2177 2232 fRc = reporter.errorXcpt('Closing guest session failed:'); 2233 2234 # No sessions left? 2235 reporter.log('Execution of all tests done, checking for stale sessions again'); 2236 try: cSessions = len(self.oTstDrv.oVBoxMgr.getArray(oSession.o.console.guest, 'sessions')); 2237 except: fRc = reporter.errorXcpt(); 2238 else: 2239 if cSessions != 0: 2240 fRc = reporter.error('Found %d stale session(s), expected 0' % (cSessions,)); 2178 2241 return (fRc, oTxsSession); 2179 2242
Note:
See TracChangeset
for help on using the changeset viewer.