VirtualBox

Ignore:
Timestamp:
Mar 22, 2023 12:42:20 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
156477
Message:

ValidationKit/tests/api/tdTreeDepth1.py: Invoking Python's garbage
collector directly does trigger the call to Machine::uninit() but
Machine::uninit() can take some time to close up to 64 disks or 200
snapshots which means the test may fail as it did before. Since
Machine::uninit() is asynchronous we do need a small delay after the
garbage collection to allow all of the attached media to be closed.
Also, leverage the test driver's IVirtualBox object rather than using
our own to simplify the code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/tests/api/tdTreeDepth1.py

    r99100 r99112  
    4545import sys
    4646import random
     47import time
    4748import gc
    4849
     
    125126        return True;
    126127
    127     def openAndRegisterMachine(self, oVBox, sSettingsFile):
     128    def openAndRegisterMachine(self, sSettingsFile):
    128129        """
    129130        Helper routine which opens a VM and registers it.
     
    133134            if self.oTstDrv.fpApiVer >= 7.0:
    134135                # Needs a password parameter since 7.0.
    135                 oVM = oVBox.openMachine(sSettingsFile, "");
     136                oVM = self.oTstDrv.oVBox.openMachine(sSettingsFile, "");
    136137            else:
    137                 oVM = oVBox.openMachine(sSettingsFile);
     138                oVM = self.oTstDrv.oVBox.openMachine(sSettingsFile);
    138139        except:
    139140            reporter.logXcpt('openMachine(%s) failed' % (sSettingsFile));
     
    144145
    145146        try:
    146             oVBox.registerMachine(oVM);
     147            self.oTstDrv.oVBox.registerMachine(oVM);
    147148        except:
    148149            reporter.logXcpt('registerMachine(%s) failed' % (sSettingsFile));
     
    210211        # If there is no base image (expected) then there are no leftover
    211212        # child images either.
    212         oVBox = self.oTstDrv.oVBoxMgr.getVirtualBox();
    213         if oVBox is None:
    214             return False;
    215 
    216         cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(oVBox, 'hardDisks'))
     213        cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(self.oTstDrv.oVBox, 'hardDisks'))
    217214        reporter.log('After unregister(DetachAllReturnHardDisksOnly): API reports %d base images' % (cBaseImages));
    218215        if cBaseImages != 0:
     
    220217
    221218        # re-register to test loading of settings
    222         oVM = self.openAndRegisterMachine(oVBox, sSettingsFile);
     219        oVM = self.openAndRegisterMachine(sSettingsFile);
    223220        if oVM is None:
    224221            return False;
     
    243240        # the object when the garbage collector runs however this can take several seconds
    244241        # so we invoke the Python garbage collector manually here so we don't have to wait.
    245         reporter.log('Invoking python garbage collection to trigger Machine::uninit() which will close the attached disks');
    246242        try:
    247243            gc.collect();
     
    249245            reporter.logXcpt();
    250246
    251         cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(oVBox, 'hardDisks'));
     247        reporter.log('Waiting three seconds for Machine::uninit() to be called to close the attached disks');
     248        # Fudge factor: Machine::uninit() will be invoked when the oVM object is processed
     249        # by the garbage collector above but it may take a few moments to close up to 64
     250        # disks.
     251        time.sleep(3);
     252
     253        cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(self.oTstDrv.oVBox, 'hardDisks'))
    252254        reporter.log('After unregister(UnregisterOnly): API reports %d base images' % (cBaseImages));
    253255        if cBaseImages != 0:
     
    303305        # If there is no base image (expected) then there are no leftover
    304306        # child images either.
    305         oVBox = self.oTstDrv.oVBoxMgr.getVirtualBox()
    306         if oVBox is None:
    307             return False;
    308 
    309         cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(oVBox, 'hardDisks'))
     307        cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(self.oTstDrv.oVBox, 'hardDisks'))
    310308        reporter.log('After unregister(DetachAllReturnHardDisksOnly): API reports %d base images' % (cBaseImages));
    311309        fRc = fRc and cBaseImages == 0
     
    314312
    315313        # re-register to test loading of settings
    316         oVM = self.openAndRegisterMachine(oVBox, sSettingsFile);
     314        oVM = self.openAndRegisterMachine(sSettingsFile);
    317315        if oVM is None:
    318316            return False;
     
    336334        # the object when the garbage collector runs however this can take several seconds
    337335        # so we invoke the Python garbage collector manually here so we don't have to wait.
    338         reporter.log('Invoking python garbage collection to trigger Machine::uninit() which will close the attached disks');
    339336        try:
    340337            gc.collect();
     
    342339            reporter.logXcpt();
    343340
    344         cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(oVBox, 'hardDisks'))
     341        reporter.log('Waiting three seconds for Machine::uninit() to be called to close the attached disks');
     342        # Fudge factor: Machine::uninit() will be invoked when the oVM object is processed
     343        # by the garbage collector above but it may take a few moments to close up to 200
     344        # snapshots.
     345        time.sleep(3);
     346
     347        cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(self.oTstDrv.oVBox, 'hardDisks'))
    345348        reporter.log('After unregister(UnregisterOnly): API reports %d base images' % (cBaseImages));
    346349        if cBaseImages != 0:
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