VirtualBox

Changeset 84137 in vbox


Ignore:
Timestamp:
May 4, 2020 1:36:02 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
137732
Message:

Validation Kit/tdAAddBasic1.py: Implemented proper Guest Additions run level waiting/detection.

File:
1 edited

Legend:

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

    r84113 r84137  
    5252from tdAddSharedFolders1 import SubTstDrvAddSharedFolders1;
    5353
     54
     55
     56class tdAddBasicConsoleCallbacks(vbox.ConsoleEventHandlerBase):
     57    """
     58    For catching the Guest Additions change state events.
     59    """
     60    def __init__(self, dArgs):
     61        oTstDrv  = dArgs['oTstDrv'];
     62        oVBoxMgr = dArgs['oVBoxMgr']; _ = oVBoxMgr;
     63        oGuest   = dArgs['oGuest'];
     64
     65        vbox.ConsoleEventHandlerBase.__init__(self, dArgs, 'tdAddBasic1');
     66        self.oTstDrv  = oTstDrv;
     67        self.oGuest   = oGuest;
     68
     69    def handleEvent(self, oEvt):
     70        try:
     71            oEvtBase = self.oVBoxMgr.queryInterface(oEvt, 'IEvent');
     72            eType = oEvtBase.type;
     73        except:
     74            reporter.logXcpt();
     75            return None;
     76        if eType == vboxcon.VBoxEventType_OnAdditionsStateChanged:
     77            return self.onAdditionsStateChanged();
     78        return None;
     79
     80    def onAdditionsStateChanged(self):
     81        reporter.log('onAdditionsStateChange');
     82        self.oTstDrv.fGAStatusCallbackFired = True;
     83        self.oTstDrv.iGAStatusCallbackRunlevel = self.oGuest.additionsRunLevel;
     84        self.oVBoxMgr.interruptWaitEvents();
     85        return None;
    5486
    5587class tdAddBasic1(vbox.TestDriver):                                         # pylint: disable=too-many-instance-attributes
     
    72104        self.addSubTestDriver(SubTstDrvAddGuestCtrl(self));
    73105        self.addSubTestDriver(SubTstDrvAddSharedFolders1(self));
     106
     107        self.fGAStatusCallbackFired    = False;
     108        self.iGAStatusCallbackRunlevel = 0;
    74109
    75110    #
     
    207242        return fRc;
    208243
     244    def waitForGuestAdditionsRunLevel(self, oSession, oGuest, cMsTimeout, iRunLevel):
     245        """
     246        Waits for the Guest Additions to reach a specific run level.
     247
     248        Returns success status.
     249        """
     250        # No need to wait as we already reached the run level?
     251        if iRunLevel == oGuest.additionsRunLevel:
     252            reporter.log('Already reached run level %s' % iRunLevel);
     253            return True;
     254
     255        reporter.log('Waiting for Guest Additions to reach run level %s ...' % iRunLevel);
     256
     257        oConsoleCallbacks = oSession.registerDerivedEventHandler(tdAddBasicConsoleCallbacks, \
     258                                                                 {'oTstDrv':self, 'oGuest':oGuest, });
     259        fRc = False;
     260        if oConsoleCallbacks is not None:
     261            # Wait for 5 minutes max.
     262            tsStart = base.timestampMilli();
     263            while base.timestampMilli() - tsStart < cMsTimeout:
     264                oTask = self.waitForTasks(1000);
     265                if oTask is not None:
     266                    break;
     267                if self.fGAStatusCallbackFired:
     268                    reporter.log('Reached new run level %s' % iRunLevel);
     269                    if iRunLevel == self.iGAStatusCallbackRunlevel:
     270                        fRc = True;
     271                        break;
     272                    self.fGAStatusCallbackFired = False;
     273            if not fRc:
     274                reporter.testFailure('Guest Additions status did not change to required level');
     275
     276            # cleanup.
     277            oConsoleCallbacks.unregister();
     278
     279        reporter.log('Waiting for Guest Additions to reach run level %s ended with %s' % (iRunLevel, fRc));
     280        return fRc;
     281
    209282    def testInstallAdditions(self, oSession, oTxsSession, oTestVm):
    210283        """
     
    223296        # Verify installation of Guest Additions using commmon bits.
    224297        #
    225         if fRc is True:
    226             #
    227             # Wait for the GAs to come up.
    228             #
    229 
    230             ## @todo need to signed up for a OnAdditionsStateChanged and wait runlevel to
    231             #  at least reach Userland.
    232 
     298        if fRc:
    233299            #
    234300            # Check if the additions are operational.
     
    237303            except:
    238304                reporter.errorXcpt('Getting IGuest failed.');
     305                return (False, oTxsSession);
     306
     307            #
     308            # Wait for the GAs to come up.
     309            #
     310            fRc = self.waitForGuestAdditionsRunLevel(oSession, oGuest, 5 * 60 * 1000, vboxcon.AdditionsRunLevelType_Userland);
     311            if not fRc:
    239312                return (False, oTxsSession);
    240313
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