Changeset 103200 in vbox for trunk/src/VBox/ValidationKit/tests
- Timestamp:
- Feb 5, 2024 11:32:33 AM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py
r103079 r103200 1426 1426 '3d' 1427 1427 ]; 1428 1429 # Possible paths for the Guest Control Helper binary. 1430 self.asGstCtlHelperPaths = [ 1431 # Debugging stuff (SCP'd over to the guest). 1432 '/tmp/VBoxGuestControlHelper', 1433 'C:\\Temp\\VBoxGuestControlHelper', 1434 # Validation Kit .ISO. 1435 '${CDROM}/vboxvalidationkit/${OS/ARCH}/VBoxGuestControlHelper${EXESUFF}', 1436 '${CDROM}/${OS/ARCH}/VBoxGuestControlHelper${EXESUFF}', 1437 # Test VMs. 1438 '/opt/apps/VBoxGuestControlHelper', 1439 '/opt/apps/VBoxGuestControlHelper', 1440 '/apps/VBoxGuestControlHelper', 1441 'C:\\Apps\\VBoxGuestControlHelper${EXESUFF}' 1442 ]; 1443 # Full path to the Guest Control Helper binary we're going to use. Only gets resolved once. 1444 self.sGstCtlHelperExe = ''; 1445 1428 1446 self.asTests = self.asTestsDef; 1429 1447 self.fSkipKnownBugs = False; … … 1599 1617 1600 1618 return True; 1619 1620 def locateGstBinary(self, oSession, oTxsSession, asPaths): 1621 """ 1622 Locates a guest binary on the guest by checking the paths in \a asPaths. 1623 1624 Returns a tuple (success, path). 1625 """ 1626 for sCurPath in asPaths: 1627 reporter.log2('Checking for \"%s\" ...' % (sCurPath)); 1628 if self.txsIsFile(oSession, oTxsSession, sCurPath, fIgnoreErrors = True): 1629 return (True, sCurPath); 1630 reporter.error('Unable to find guest binary in any of these places:\n%s' % ('\n'.join(asPaths),)); 1631 return (False, ""); 1601 1632 1602 1633 # … … 2339 2370 return oProcess; 2340 2371 2341 def gctrlExecute(self, oTest, oGuestSession, fIsError): # pylint: disable=too-many-statements 2342 """ 2343 Helper function to execute a program on a guest, specified in the current test. 2344 2345 Note! This weirdo returns results (process exitcode and status) in oTest. 2346 """ 2347 fRc = True; # Be optimistic. 2348 2349 # Reset the weird result stuff: 2350 oTest.cbStdOut = 0; 2351 oTest.cbStdErr = 0; 2352 oTest.sBuf = ''; 2353 oTest.uExitStatus = 0; 2354 oTest.iExitCode = 0; 2355 2356 ## @todo Compare execution timeouts! 2357 #tsStart = base.timestampMilli(); 2358 2372 def processExecute(self, oGuestSession, sCmd, asArgs, sCwd, aEnv, afFlags, timeoutMS, fIsError = True): 2373 """ 2374 Executes a process on the guest and deals with input/output + waiting flags. 2375 2376 Returns tuple (success, exit status, exit code, stdout len, stderr len, stdout / stderr output). 2377 """ 2378 2379 # 2380 # Start the process: 2381 # 2359 2382 try: 2360 reporter.log2('Using session user=%s, sDomain=%s, name=%s, timeout=%d' 2361 % (oGuestSession.user, oGuestSession.domain, oGuestSession.name, oGuestSession.timeout,)); 2383 oProcess = self.processCreateWrapper(oGuestSession, sCmd, asArgs, sCwd, aEnv, afFlags, timeoutMS); 2362 2384 except: 2363 return reporter.errorXcpt(); 2364 2365 # 2366 # Start the process: 2367 # 2368 2369 try: 2370 oProcess = self.processCreateWrapper(oGuestSession, oTest.sCmd, oTest.asArgs, oTest.sCwd, 2371 oTest.aEnv, oTest.afFlags, oTest.timeoutMS); 2372 except: 2373 reporter.maybeErrXcpt(fIsError, 'type=%s, asArgs=%s' % (type(oTest.asArgs), oTest.asArgs,)); 2385 reporter.maybeErrXcpt(fIsError, 'type=%s, asArgs=%s' % (type(asArgs), asArgs,)); 2374 2386 return False; 2375 2387 if oProcess is None: 2376 return reporter.error('oProcess is None! (%s)' % (oTest.asArgs,)); 2388 return reporter.error('oProcess is None! (%s)' % (asArgs,)); 2389 2390 fRc = True; 2377 2391 2378 2392 #time.sleep(5); # try this if you want to see races here. 2379 2393 2380 2394 # Wait for the process to start properly: 2381 reporter.log2('Process start requested, waiting for start (%dms) ...' % ( oTest.timeoutMS,));2395 reporter.log2('Process start requested, waiting for start (%dms) ...' % (timeoutMS,)); 2382 2396 iPid = -1; 2383 2397 aeWaitFor = [ vboxcon.ProcessWaitForFlag_Start, ]; 2384 2398 try: 2385 eWaitResult = oProcess.waitForArray(aeWaitFor, oTest.timeoutMS);2399 eWaitResult = oProcess.waitForArray(aeWaitFor, timeoutMS); 2386 2400 except: 2387 reporter.maybeErrXcpt(fIsError, 'waitforArray failed for asArgs=%s' % ( oTest.asArgs,));2401 reporter.maybeErrXcpt(fIsError, 'waitforArray failed for asArgs=%s' % (asArgs,)); 2388 2402 fRc = False; 2389 2403 else: … … 2392 2406 iPid = oProcess.PID; 2393 2407 except: 2394 fRc = reporter.errorXcpt('asArgs=%s' % ( oTest.asArgs,));2408 fRc = reporter.errorXcpt('asArgs=%s' % (asArgs,)); 2395 2409 else: 2396 2410 reporter.log2('Wait result returned: %d, current process status is: %d' % (eWaitResult, eStatus,)); … … 2406 2420 # What to wait for: 2407 2421 aeWaitFor = [ vboxcon.ProcessWaitForFlag_Terminate, ]; 2408 if vboxcon.ProcessCreateFlag_WaitForStdOut in oTest.afFlags:2422 if vboxcon.ProcessCreateFlag_WaitForStdOut in afFlags: 2409 2423 aeWaitFor.append(vboxcon.ProcessWaitForFlag_StdOut); 2410 if vboxcon.ProcessCreateFlag_WaitForStdErr in oTest.afFlags:2424 if vboxcon.ProcessCreateFlag_WaitForStdErr in afFlags: 2411 2425 aeWaitFor.append(vboxcon.ProcessWaitForFlag_StdErr); 2412 2426 ## @todo Add vboxcon.ProcessWaitForFlag_StdIn. 2413 2427 2414 2428 reporter.log2('Process (PID %d) started, waiting for termination (%dms), aeWaitFor=%s ...' 2415 % (iPid, oTest.timeoutMS, aeWaitFor));2429 % (iPid, timeoutMS, aeWaitFor)); 2416 2430 acbFdOut = [0,0,0]; 2417 2431 while True: 2418 2432 try: 2419 eWaitResult = oProcess.waitForArray(aeWaitFor, oTest.timeoutMS);2433 eWaitResult = oProcess.waitForArray(aeWaitFor, timeoutMS); 2420 2434 except KeyboardInterrupt: # Not sure how helpful this is, but whatever. 2421 2435 reporter.error('Process (PID %d) execution interrupted' % (iPid,)); … … 2424 2438 break; 2425 2439 except: 2426 fRc = reporter.errorXcpt('asArgs=%s' % ( oTest.asArgs,));2440 fRc = reporter.errorXcpt('asArgs=%s' % (asArgs,)); 2427 2441 break; 2428 2442 #reporter.log2('Wait returned: %d' % (eWaitResult,)); … … 2433 2447 if eWaitResult in (eFdResult, vboxcon.ProcessWaitResult_WaitFlagNotSupported): 2434 2448 try: 2435 abBuf = oProcess.read(iFd, 64 * 1024, oTest.timeoutMS);2449 abBuf = oProcess.read(iFd, 64 * 1024, timeoutMS); 2436 2450 except KeyboardInterrupt: # Not sure how helpful this is, but whatever. 2437 2451 reporter.error('Process (PID %d) execution interrupted' % (iPid,)); … … 2439 2453 except: pass; 2440 2454 except: 2441 reporter.maybeErrXcpt(fIsError, 'asArgs=%s' % ( oTest.asArgs,));2455 reporter.maybeErrXcpt(fIsError, 'asArgs=%s' % (asArgs,)); 2442 2456 else: 2443 2457 if abBuf: … … 2445 2459 % (iPid, len(abBuf), sFdNm, type(abBuf))); 2446 2460 if reporter.getVerbosity() >= 4: 2447 sBuf = '';2461 sBufOut = ''; 2448 2462 if sys.version_info >= (2, 7): 2449 2463 if isinstance(abBuf, memoryview): ## @todo Why is this happening? 2450 abBuf = abBuf.tobytes();2451 sBuf 2464 abBuf = abBuf.tobytes(); 2465 sBufOut = abBuf.decode("utf-8"); 2452 2466 if sys.version_info <= (2, 7): 2453 2467 if isinstance(abBuf, buffer): # (for 3.0+) pylint: disable=undefined-variable 2454 sBuf = str(abBuf);2455 for sLine in sBuf .splitlines():2468 sBufOut = str(abBuf); 2469 for sLine in sBufOut.splitlines(): 2456 2470 reporter.log4('%s: %s' % (sFdNm, sLine)); 2457 2471 acbFdOut[iFd] += len(abBuf); 2458 oTest.sBuf= abBuf; ## @todo Figure out how to uniform + append!2472 sBufOut = abBuf; ## @todo Figure out how to uniform + append! 2459 2473 2460 2474 ## Process input (todo): … … 2467 2481 vboxcon.ProcessWaitResult_Timeout,): 2468 2482 try: eStatus = oProcess.status; 2469 except: fRc = reporter.errorXcpt('asArgs=%s' % ( oTest.asArgs,));2483 except: fRc = reporter.errorXcpt('asArgs=%s' % (asArgs,)); 2470 2484 reporter.log2('Process (PID %d) reported terminate/error/timeout: %d, status: %d' 2471 2485 % (iPid, eWaitResult, eStatus,)); … … 2473 2487 2474 2488 # End of the wait loop. 2475 _, oTest.cbStdOut, oTest.cbStdErr = acbFdOut;2489 _, cbStdOut, cbStdErr = acbFdOut; 2476 2490 2477 2491 try: eStatus = oProcess.status; 2478 except: fRc = reporter.errorXcpt('asArgs=%s' % ( oTest.asArgs,));2492 except: fRc = reporter.errorXcpt('asArgs=%s' % (asArgs,)); 2479 2493 reporter.log2('Final process status (PID %d) is: %d' % (iPid, eStatus)); 2480 reporter.log2('Process (PID %d) %d stdout, %d stderr' % (iPid, oTest.cbStdOut, oTest.cbStdErr));2494 reporter.log2('Process (PID %d) %d stdout, %d stderr' % (iPid, cbStdOut, cbStdErr)); 2481 2495 2482 2496 # … … 2484 2498 # 2485 2499 try: 2486 oTest.uExitStatus = oProcess.status;2487 oTest.iExitCode = oProcess.exitCode;2500 uExitStatus = oProcess.status; 2501 iExitCode = oProcess.exitCode; 2488 2502 except: 2489 fRc = reporter.errorXcpt('asArgs=%s' % (oTest.asArgs,)); 2490 reporter.log2('Process (PID %d) has exit code: %d; status: %d ' % (iPid, oTest.iExitCode, oTest.uExitStatus)); 2503 fRc = reporter.errorXcpt('asArgs=%s' % (asArgs,)); 2504 reporter.log2('Process (PID %d) has exit code: %d; status: %d ' % (iPid, iExitCode, uExitStatus)); 2505 return fRc, uExitStatus, iExitCode, cbStdOut, cbStdErr, sBufOut; 2506 2507 def gctrlExecute(self, oTest, oGuestSession, fIsError): # pylint: disable=too-many-statements 2508 """ 2509 Helper function to execute a program on a guest, specified in the current test. 2510 2511 Note! This weirdo returns results (process exitcode and status) in oTest. 2512 """ 2513 fRc = True; # Be optimistic. 2514 2515 # Reset the weird result stuff: 2516 oTest.cbStdOut = 0; 2517 oTest.cbStdErr = 0; 2518 oTest.sBuf = ''; 2519 oTest.uExitStatus = 0; 2520 oTest.iExitCode = 0; 2521 2522 ## @todo Compare execution timeouts! 2523 #tsStart = base.timestampMilli(); 2524 2525 try: 2526 reporter.log2('Using session user=%s, sDomain=%s, name=%s, timeout=%d' 2527 % (oGuestSession.user, oGuestSession.domain, oGuestSession.name, oGuestSession.timeout,)); 2528 except: 2529 return reporter.errorXcpt(); 2530 2531 fRc, oTest.uExitStatus, oTest.iExitCode, oTest.cbStdOut, oTest.cbStdErr, oTest.sBuf = \ 2532 self.processExecute(oGuestSession, oTest.sCmd, oTest.asArgs, oTest.sCwd, 2533 oTest.aEnv, oTest.afFlags, oTest.timeoutMS, fIsError); 2534 2491 2535 return fRc; 2536 2537 def executeGstCtlHelper(self, oSession, oTxsSession, oGuestSession, asArgs, asEnv = [], sCwd = '', timeoutMS = 30 * 1000): 2538 """ 2539 Wrapper to invoke the Guest Control Helper on the guest. 2540 2541 Returns tuple (success, exit status, exit code, stdout len, stderr len, stdout / stderr output). 2542 """ 2543 fRc = True; 2544 eExitStatus = vboxcon.ProcessStatus_Undefined; 2545 iExitCode = -1; 2546 cbStdOut = 0; 2547 cbStdErr = 0; 2548 sBuf = ''; 2549 2550 if not self.sGstCtlHelperExe: 2551 fRc, self.sGstCtlHelperExe = self.locateGstBinary(oSession, oTxsSession, self.asGstCtlHelperPaths); 2552 if fRc: 2553 reporter.log('Using VBoxGuestControlHelper on guest at \"%s\"' % (self.sGstCtlHelperExe)); 2554 2555 if fRc \ 2556 and self.sGstCtlHelperExe: 2557 try: 2558 asArgs2 = [ self.sGstCtlHelperExe ]; 2559 asArgs2.append(asArgs); # Always set argv0. 2560 aeWaitFor = [ vboxcon.ProcessWaitForFlag_Terminate, \ 2561 vboxcon.ProcessWaitForFlag_StdOut, \ 2562 vboxcon.ProcessWaitForFlag_StdErr ]; 2563 2564 fRc, eExitStatus, iExitCode, cbStdOut, cbStdErr, sBuf = \ 2565 self.processExecute(oGuestSession, self.sGstCtlHelperExe, asArgs2, sCwd, 2566 asEnv, aeWaitFor, timeoutMS); 2567 if eExitStatus != vboxcon.TerminatedNormally: 2568 reporter.log('VBoxGuestControlHelper failed to run; got exit status %d' % (eExitStatus,)); 2569 fRc = False; 2570 except: 2571 reporter.errorXcpt(); 2572 2573 return fRc, eExitStatus, iExitCode, cbStdOut, cbStdErr, sBuf; 2492 2574 2493 2575 def testGuestCtrlSessionEnvironment(self, oSession, oTxsSession, oTestVm): # pylint: disable=too-many-locals … … 2608 2690 return tdTestSessionEx.executeListTestSessions(aoTests, self.oTstDrv, oSession, oTxsSession, oTestVm, 'SessionEnv'); 2609 2691 2610 def testGuestCtrlSessionSimple(self, oSession, oT estVm):2692 def testGuestCtrlSessionSimple(self, oSession, oTxsSession, oTestVm): 2611 2693 """ 2612 2694 Tests simple session-based API calls. … … 2627 2709 return False; 2628 2710 2629 fRc = True; 2711 if self.oTstDrv.fpApiVer >= 7.1 \ 2712 and oTestVm.isWindows(): 2713 reporter.testStart('Windows guest processes in session >= 1'); 2714 # Test in which Windows session Guest Control processes are being started. 2715 # We don't want them to be started in session 0, as this would prevent desktop interaction and other stuff. 2716 fRc, eExitStatus, iExitCode, cbStdOut, cbStdErr, sBuf = \ 2717 self.executeGstCtlHelper(oSession, oTxsSession, oGuestSession, [ "show", "win-session-id" ]); 2718 if fRc \ 2719 and eExitStatus == vboxcon.TerminatedNormally: 2720 if iExitCode >= 1000: # We report 1000 + <session ID> as exit code. 2721 uSessionId = iExitCode - 1000; 2722 if uSessionId == 0: 2723 reporter.log('Guest processes start in session %d, good' % (uSessionId)); 2724 else: 2725 reporter.error('Guest processes start in session %d, expected session 0' % (uSessionId)); 2726 else: 2727 reporter.error('Guest Control Helper returned error %d (exit code)' % (iExitCode)); 2728 reporter.testDone(); 2630 2729 2631 2730 # User home. … … 2805 2904 ## @todo Test session timeouts. 2806 2905 2807 fRc2 = self.testGuestCtrlSessionSimple(oSession, oT estVm);2906 fRc2 = self.testGuestCtrlSessionSimple(oSession, oTxsSession, oTestVm); 2808 2907 if fRc: 2809 2908 fRc = fRc2;
Note:
See TracChangeset
for help on using the changeset viewer.