VirtualBox

Changeset 54938 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 25, 2015 1:04:20 PM (10 years ago)
Author:
vboxsync
Message:

tdTreeDepth1.py: new test for checking if VBoxSVC can deal with the maximum medium and snapshot tree depths
vboxwrappers.py: add functionality for creating base and diff disk images, and allow attaching them to a VM

Location:
trunk/src/VBox/ValidationKit
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/testdriver/vboxwrappers.py

    r54432 r54938  
    16471647        return fRc;
    16481648
    1649     def attachHd(self, sHd, sController = "IDE Controller", iPort = 0, iDevice = 0, fImmutable = True):
     1649    def attachHd(self, sHd, sController = "IDE Controller", iPort = 0, iDevice = 0, fImmutable = True, fForceResource = True):
    16501650        """
    16511651        Attaches a HD to a VM.
     
    16531653        """
    16541654        # Input validation.
    1655         if not self.oTstDrv.isResourceFile(sHd):
     1655        if fForceResource and not self.oTstDrv.isResourceFile(sHd):
    16561656            reporter.fatal('"%s" is not in the resource set' % (sHd,));
    16571657            return None;
     
    16611661
    16621662        # Find the HD, registering it if necessary (as immutable).
    1663         sFullName = self.oTstDrv.getFullResourceName(sHd);
     1663        if fForceResource:
     1664            sFullName = self.oTstDrv.getFullResourceName(sHd);
     1665        else:
     1666            sFullName = sHd;
    16641667        try:
    16651668            oHd = self.oVBox.findHardDisk(sFullName);
     
    17031706        return fRc;
    17041707
     1708    def createBaseHd(self, sHd, sFmt = "VDI", cb = 10*1024*1024*1024):
     1709        """
     1710        Creates a base HD.
     1711        Returns Medium object on success and None on failure.  Error information is logged.
     1712        """
     1713        try:
     1714            if self.fpApiVer >= 4.4:
     1715                oHd = self.oVBox.createMedium(sFmt, sHd, vboxcon.AccessMode_ReadWrite, vboxcon.DeviceType_HardDisk);
     1716            else:
     1717                oHd = self.oVBox.createHardDisk(sFmt, sHd);
     1718            oProgressXpcom = oHd.createBaseStorage(cb, (vboxcon.MediumVariant_Standard, ))
     1719            oProgress = ProgressWrapper(oProgressXpcom, self.oVBoxMgr, self.oTstDrv, 'create base disk %s' % (sHd));
     1720            oProgress.wait();
     1721            oProgress.logResult();
     1722        except:
     1723            reporter.errorXcpt('failed to create base hd "%s"' % (sHd));
     1724            oHd = None
     1725
     1726        return oHd;
     1727
     1728    def createDiffHd(self, oParentHd, sHd, sFmt = "VDI"):
     1729        """
     1730        Creates a differencing HD.
     1731        Returns Medium object on success and None on failure.  Error information is logged.
     1732        """
     1733        try:
     1734            if self.fpApiVer >= 4.4:
     1735                oHd = self.oVBox.createMedium(sFmt, sHd, vboxcon.AccessMode_ReadWrite, vboxcon.DeviceType_HardDisk);
     1736            else:
     1737                oHd = self.oVBox.createHardDisk(sFmt, sHd);
     1738            oProgressXpcom = oParentHd.createDiffStorage(oHd, (vboxcon.MediumVariant_Standard, ))
     1739            oProgress = ProgressWrapper(oProgressXpcom, self.oVBoxMgr, self.oTstDrv, 'create diff disk %s' % (sHd));
     1740            oProgress.wait();
     1741            oProgress.logResult();
     1742        except:
     1743            reporter.errorXcpt('failed to create diff hd "%s"' % (sHd));
     1744            oHd = None
     1745
     1746        return oHd;
     1747
    17051748    def createAndAttachHd(self, sHd, sFmt = "VDI", sController = "IDE Controller", cb = 10*1024*1024*1024, \
    17061749                          iPort = 0, iDevice = 0, fImmutable = True):
     
    17121755            return False;
    17131756
    1714         try:
    1715             if self.fpApiVer >= 4.4:
    1716                 oHd = self.oVBox.createMedium(sFmt, sHd, vboxcon.AccessMode_ReadWrite, vboxcon.DeviceType_HardDisk);
    1717             else:
    1718                 oHd = self.oVBox.createHardDisk(sFmt, sHd);
    1719             oProgressXpcom = oHd.createBaseStorage(cb, (vboxcon.MediumVariant_Standard, ))
    1720             oProgress = ProgressWrapper(oProgressXpcom, self.oVBoxMgr, self.oTstDrv, 'create disk %s' % (sHd));
    1721             oProgress.wait();
    1722             oProgress.logResult();
    1723         except:
    1724             reporter.errorXcpt('failed to create hd "%s"' % (sHd));
     1757        oHd = self.createBaseHd(sHd, sFmt, cb)
     1758        if oHd is None:
    17251759            return False;
    17261760
  • trunk/src/VBox/ValidationKit/tests/api/Makefile.kmk

    r52776 r54938  
    55
    66#
    7 # Copyright (C) 2006-2014 Oracle Corporation
     7# Copyright (C) 2006-2015 Oracle Corporation
    88#
    99# This file is part of VirtualBox Open Source Edition (OSE), as
     
    3333ValidationKitTestsApi_INST = $(INST_VALIDATIONKIT)tests/api/
    3434ValidationKitTestsApi_EXEC_SOURCES := \
    35         $(PATH_SUB_CURRENT)/tdPython1.py
     35        $(PATH_SUB_CURRENT)/tdPython1.py \
     36        $(PATH_SUB_CURRENT)/tdTreeDepth1.py
    3637
    3738VBOX_VALIDATIONKIT_PYTHON_SOURCES += $(ValidationKitTestsApi_EXEC_SOURCES)
  • trunk/src/VBox/ValidationKit/tests/api/tdTreeDepth1.py

    r54788 r54938  
    44
    55"""
    6 VirtualBox Validation Kit - Python Bindings Test #1
     6VirtualBox Validation Kit - Medium and Snapshot Tree Depth Test #1
    77"""
    88
    99__copyright__ = \
    1010"""
    11 Copyright (C) 2010-2014 Oracle Corporation
     11Copyright (C) 2010-2015 Oracle Corporation
    1212
    1313This file is part of VirtualBox Open Source Edition (OSE), as
     
    4040# Only the main script needs to modify the path.
    4141try:    __file__
    42 except: __file__ = sys.argv[0];
    43 g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
    44 sys.path.append(g_ksValidationKitDir);
     42except: __file__ = sys.argv[0]
     43g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
     44sys.path.append(g_ksValidationKitDir)
    4545
    4646# Validation Kit imports.
    47 from testdriver import reporter;
    48 from testdriver import base;
    49 from testdriver import vbox;
     47from testdriver import reporter
     48from testdriver import base
     49from testdriver import vbox
     50from testdriver import vboxcon
    5051
    5152
    52 class tdPython1(vbox.TestDriver):
     53class tdTreeDepth1(vbox.TestDriver):
    5354    """
    54     Python Bindings Test #1.
     55    Medium and Snapshot Tree Depth Test #1.
    5556    """
    5657
    5758    def __init__(self):
    58         vbox.TestDriver.__init__(self);
    59         self.asRsrcs            = None;
     59        vbox.TestDriver.__init__(self)
     60        self.asRsrcs            = None
    6061
    6162
     
    6970        """
    7071        if not self.importVBoxApi():
    71             return False;
    72         return True;
     72            return False
     73        return True
    7374
    7475    def actionExecute(self):
     
    7677        Execute the testcase.
    7778        """
    78         return  self.testEventQueueWaiting() \
    79             and self.testEventQueueInterrupt();
     79        return  self.testMediumTreeDepth() \
     80            and self.testSnapshotTreeDepth()
    8081
    8182    #
     
    8384    #
    8485
    85     def testEventQueueWaitingThreadProc(self):
    86         """ Thread procedure for checking that waitForEvents fails when not called by the main thread. """
     86    def testMediumTreeDepth(self):
     87        """
     88        Test medium tree depth.
     89        """
     90        reporter.testStart('mediumTreeDepth')
     91
    8792        try:
    88             rc2 = self.oVBoxMgr.waitForEvents(0);
     93            oVM = self.createTestVM('test-medium', 1, None, 4)
     94            assert oVM is not None
     95
     96            # create chain with 300 disk images (medium tree depth limit)
     97            fRc = True
     98            oSession = self.openSession(oVM)
     99            for i in range(1, 301):
     100                sHddPath = os.path.join(self.sScratchPath, 'Test' + str(i) + '.vdi')
     101                if i is 1:
     102                    oHd = oSession.createBaseHd(sHddPath, cb=1024*1024)
     103                else:
     104                    oHd = oSession.createDiffHd(oHd, sHddPath)
     105                if oHd is None:
     106                    fRc = False
     107                    break
     108
     109            # modify the VM config, attach HDD
     110            fRc = fRc and oSession.attachHd(sHddPath, sController='SATA Controller', fImmutable=False, fForceResource=False)
     111            fRc = fRc and oSession.saveSettings()
     112            fRc = oSession.close() and fRc
     113
     114            # unregister and re-register to test loading of settings
     115            sSettingsFile = oVM.settingsFilePath
     116            reporter.log('unregistering VM')
     117            oVM.unregister(vboxcon.CleanupMode_DetachAllReturnNone)
     118            oVBox = self.oVBoxMgr.getVirtualBox()
     119            reporter.log('opening VM %s, testing config reading' % (sSettingsFile))
     120            oVM = oVBox.openMachine(sSettingsFile)
     121
     122            assert fRc is True
    89123        except:
    90             return True;
    91         reporter.error('waitForEvents() returned "%s" when called on a worker thread, expected exception.' % (rc2,));
    92         return False;
     124            reporter.errorXcpt()
    93125
    94     def testEventQueueWaiting(self):
     126        return reporter.testDone()[1] == 0
     127
     128    def testSnapshotTreeDepth(self):
    95129        """
    96         Test event queue waiting.
     130        Test snapshot tree depth.
    97131        """
    98         reporter.testStart('waitForEvents');
     132        reporter.testStart('snapshotTreeDepth')
    99133
    100         # Check return values and such.
    101         for cMsTimeout in (0, 1, 2, 3, 256, 1000, 0):
    102             iLoop = 0;
    103             while True:
    104                 try:
    105                     rc = self.oVBoxMgr.waitForEvents(cMsTimeout);
    106                 except:
    107                     reporter.errorXcpt();
    108                     break;
    109                 if not isinstance(rc, types.IntType):
    110                     reporter.error('waitForEvents returns non-integer type');
    111                     break;
    112                 if rc == 1:
    113                     break;
    114                 if rc != 0:
    115                     reporter.error('waitForEvents returns "%s", expected 0 or 1' % (rc,));
    116                     break;
    117                 iLoop += 1;
    118                 if iLoop > 10240:
    119                     reporter.error('waitForEvents returns 0 (success) %u times. '
    120                                    'Expected 1 (timeout/interrupt) after a call or two.'
    121                                    % (iLoop,));
    122                     break;
    123             if reporter.testErrorCount() != 0:
    124                 break;
     134        try:
     135            oVM = self.createTestVM('test-snap', 1, None, 4)
     136            assert oVM is not None
    125137
    126         # Check that we get an exception when trying to call the method from
    127         # a different thread.
    128         reporter.log('If running a debug build, you will see an ignored assertion now. Please ignore it.')
    129         sVBoxAssertSaved = os.environ.get('VBOX_ASSERT', 'breakpoint');
    130         os.environ['VBOX_ASSERT'] = 'ignore';
    131         oThread = threading.Thread(target=self.testEventQueueWaitingThreadProc);
    132         oThread.start();
    133         oThread.join();
    134         os.environ['VBOX_ASSERT'] = sVBoxAssertSaved;
     138            # modify the VM config, create and attach empty HDD
     139            oSession = self.openSession(oVM)
     140            sHddPath = os.path.join(self.sScratchPath, 'TestSnapEmpty.vdi')
     141            fRc = True
     142            fRc = fRc and oSession.createAndAttachHd(sHddPath, cb=1024*1024, sController='SATA Controller', fImmutable=False)
     143            fRc = fRc and oSession.saveSettings()
    135144
    136         return reporter.testDone()[1] == 0;
     145            # take 250 snapshots (snapshot tree depth limit)
     146            for i in range(1, 251):
     147                fRc = fRc and oSession.takeSnapshot('Snapshot ' + str(i))
     148            fRc = oSession.close() and fRc
    137149
    138     def interruptWaitEventsThreadProc(self):
    139         """ Thread procedure that's used for waking up the main thread. """
    140         time.sleep(2);
    141         try:
    142             rc2 = self.oVBoxMgr.interruptWaitEvents();
     150            # unregister and re-register to test loading of settings
     151            sSettingsFile = oVM.settingsFilePath
     152            reporter.log('unregistering VM')
     153            oVM.unregister(vboxcon.CleanupMode_DetachAllReturnNone)
     154            oVBox = self.oVBoxMgr.getVirtualBox()
     155            reporter.log('opening VM %s, testing config reading' % (sSettingsFile))
     156            oVM = oVBox.openMachine(sSettingsFile)
     157
     158            assert fRc is True
    143159        except:
    144             reporter.errorXcpt();
    145         else:
    146             if rc2 is True:
    147                 return True;
    148             reporter.error('interruptWaitEvents returned "%s" when called from other thread, expected True' % (rc2,));
    149         return False;
     160            reporter.errorXcpt()
    150161
    151     def testEventQueueInterrupt(self):
    152         """
    153         Test interrupting an event queue wait.
    154         """
    155         reporter.testStart('interruptWait');
    156 
    157         # interrupt ourselves first and check the return value.
    158         for i in range(0, 10):
    159             try:
    160                 rc = self.oVBoxMgr.interruptWaitEvents();
    161             except:
    162                 reporter.errorXcpt();
    163                 break;
    164             if rc is not True:
    165                 reporter.error('interruptWaitEvents returned "%s" expected True' % (rc,));
    166                 break
    167 
    168         if reporter.testErrorCount() == 0:
    169             #
    170             # Interrupt a waitForEvents call.
    171             #
    172             # This test ASSUMES that no other events are posted to the thread's
    173             # event queue once we've drained it.  Also ASSUMES the box is
    174             # relatively fast and not too busy because we're timing sensitive.
    175             #
    176             for i in range(0, 4):
    177                 # Try quiesce the event queue.
    178                 for _ in range(1, 100):
    179                     self.oVBoxMgr.waitForEvents(0);
    180 
    181                 # Create a thread that will interrupt us in 2 seconds.
    182                 try:
    183                     oThread = threading.Thread(target=self.interruptWaitEventsThreadProc);
    184                     oThread.setDaemon(False);
    185                 except:
    186                     reporter.errorXcpt();
    187                     break;
    188 
    189                 cMsTimeout = 20000;
    190                 if i == 2:
    191                     cMsTimeout = -1;
    192                 elif i == 3:
    193                     cMsTimeout = -999999;
    194 
    195                 # Do the wait.
    196                 oThread.start();
    197                 msNow = base.timestampMilli();
    198                 try:
    199                     rc = self.oVBoxMgr.waitForEvents(cMsTimeout);
    200                 except:
    201                     reporter.errorXcpt();
    202                 else:
    203                     msElapsed = base.timestampMilli() - msNow;
    204 
    205                     # Check the return code and elapsed time.
    206                     if not isinstance(rc, types.IntType):
    207                         reporter.error('waitForEvents returns non-integer type after %u ms, expected 1' % (msElapsed,));
    208                     elif rc != 1:
    209                         reporter.error('waitForEvents returned "%s" after %u ms, expected 1' % (rc, msElapsed));
    210                     if msElapsed > 15000:
    211                         reporter.error('waitForEvents after %u ms, expected just above 2-3 seconds' % (msElapsed,));
    212                     elif msElapsed < 100:
    213                         reporter.error('waitForEvents after %u ms, expected more than 100 ms.' % (msElapsed,));
    214 
    215                 oThread.join();
    216                 oThread = None;
    217                 if reporter.testErrorCount() != 0:
    218                     break;
    219                 reporter.log('Iteration %u was successful...' % (i + 1,));
    220         return reporter.testDone()[1] == 0;
     162        return reporter.testDone()[1] == 0
    221163
    222164
    223165if __name__ == '__main__':
    224     sys.exit(tdPython1().main(sys.argv));
     166    sys.exit(tdTreeDepth1().main(sys.argv))
    225167
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