VirtualBox

Changeset 77613 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 8, 2019 10:44:51 AM (6 years ago)
Author:
vboxsync
Message:

Guest Control/Validation Kit: Added a test case for bugref:9398.

File:
1 edited

Legend:

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

    r77552 r77613  
    5151import struct
    5252import sys
     53import threading
    5354import time
    5455
     
    946947        self.asTestsDef = \
    947948        [
    948             'session_basic', 'session_env', 'session_file_ref', 'session_dir_ref', 'session_proc_ref',
     949            'session_basic', 'session_env', 'session_file_ref', 'session_dir_ref', 'session_proc_ref', 'session_reboot',
    949950            'exec_basic', 'exec_errorlevel', 'exec_timeout',
    950951            'dir_create', 'dir_create_temp', 'dir_read',
     
    10181019        if fSkip is False:
    10191020            fRc, oTxsSession = self.testGuestCtrlSessionProcRefs(oSession, oTxsSession, oTestVm);
     1021        reporter.testDone(fSkip);
     1022
     1023        reporter.testStart('Session w/ Guest Reboot');
     1024        fSkip = 'session_reboot' not in self.asTests;
     1025        if fSkip is False:
     1026            fRc, oTxsSession = self.testGuestCtrlSessionReboot(oSession, oTxsSession, oTestVm);
    10201027        reporter.testDone(fSkip);
    10211028
     
    21432150        return (fRc, oTxsSession);
    21442151
     2152    def threadForTestGuestCtrlSessionReboot(self, oSession, oTxsSession, oGuestProcess):
     2153        """
     2154        Thread routine which waits for the stale guest process getting terminated (or some error)
     2155        while the main test routine reboots the guest. It then compares the expected guest process result
     2156        and logs an error if appropriate.
     2157        """
     2158        reporter.log('Waiting for stale process getting killed ...');
     2159        waitResult = oGuestProcess.waitForArray([ vboxcon.ProcessWaitForFlag_Terminate ], 5 * 60 * 1000);
     2160
     2161        if  waitResult == vboxcon.ProcessWaitResult_Terminate \
     2162        and oGuestProcess.status == vboxcon.ProcessStatus_Down:
     2163            reporter.log('Stale process was correctly terminated (status: down)');
     2164        else:
     2165            reporter.error('Got wrong stale process result: waitResult is %d, current process status is: %d' \
     2166                            % (waitResult, oGuestProcess.status));
     2167            fRc = False;
     2168
     2169    def testGuestCtrlSessionReboot(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
     2170        """
     2171        Tests guest object notifications when a guest gets rebooted / shutdown.
     2172        These notifications gets sent from the guest sessions in order to make API clients
     2173        aware of guest session changes.
     2174
     2175        For that to test we create a stale guest process and trigger a reboot on the guest.
     2176        """
     2177
     2178        if oTestVm.isWindows():
     2179            sImage = "C:\\windows\\system32\\cmd.exe";
     2180        else:
     2181            sImage = "/bin/sh";
     2182
     2183        # Use credential defaults.
     2184        oCreds = tdCtxCreds();
     2185        oCreds.applyDefaultsIfNotSet(oTestVm);
     2186
     2187        fRc = True;
     2188
     2189        try:
     2190            reporter.log('Creating session ...');
     2191            oGuest = oSession.o.console.guest;
     2192            oGuestSession = oGuest.createSession(oCreds.sUser, oCreds.sPassword, oCreds.sDomain, 'testGuestCtrlExecReboot');
     2193            try:
     2194                fWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];
     2195                waitResult = oGuestSession.waitForArray(fWaitFor, 30 * 1000);
     2196                if      waitResult != vboxcon.GuestSessionWaitResult_Start \
     2197                    and waitResult != vboxcon.GuestSessionWaitResult_WaitFlagNotSupported:
     2198                    reporter.error('Session did not start successfully, returned wait result: %d' \
     2199                                   % (waitResult));
     2200                    return (False, oTxsSession);
     2201                reporter.log('Session successfully started');
     2202            except:
     2203                # Just log, don't assume an error here (will be done in the main loop then).
     2204                reporter.logXcpt('Waiting for guest session to start failed:');
     2205                return (False, oTxsSession);
     2206
     2207            try:
     2208                aArgs = [ sImage ];
     2209                aEnv = [];
     2210                aFlags = [];
     2211                oGuestProcess = oGuestSession.processCreate(sImage,
     2212                                                            aArgs if self.oTstDrv.fpApiVer >= 5.0 else aArgs[1:], aEnv, aFlags,
     2213                                                            30 * 1000);
     2214                waitResult = oGuestProcess.waitForArray([ vboxcon.ProcessWaitForFlag_Start ], 30 * 1000);
     2215                reporter.log2('Starting process wait result returned: %d, current process status is: %d' \
     2216                              % (waitResult, oGuestProcess.status));
     2217            except:
     2218                reporter.logXcpt('Creating stale process failed:');
     2219                fRc = False;
     2220
     2221            if fRc:
     2222                reporter.log('Creating reboot thread ...');
     2223                oThreadReboot = threading.Thread(target = self.threadForTestGuestCtrlSessionReboot,
     2224                                                 args=(oSession, oTxsSession, oGuestProcess), name=('threadForTestGuestCtrlSessionReboot'));
     2225                oThreadReboot.setDaemon(True);
     2226                oThreadReboot.start();
     2227
     2228                reporter.log('Waiting for reboot ....');
     2229                time.sleep(15);
     2230                reporter.log('Rebooting guest');
     2231                self.oTstDrv.txsRebootAndReconnectViaTcp(oSession, oTxsSession, cMsTimeout = 3 * 60000,
     2232                                                         fNatForwardingForTxs = True);
     2233            try:
     2234                reporter.log2('Closing guest session ...');
     2235                oGuestSession.close();
     2236                oGuestSession = None;
     2237            except:
     2238                # Just log, don't assume an error here (will be done in the main loop then).
     2239                reporter.logXcpt('Closing guest session failed:');
     2240                fRc = False;
     2241        except:
     2242            reporter.logXcpt('Could not create one session:');
     2243
     2244        return (fRc, oTxsSession);
     2245
    21452246    def testGuestCtrlExecErrorLevel(self, oSession, oTxsSession, oTestVm):
    21462247        """
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette