VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/api/tdTreeDepth1.py@ 94598

Last change on this file since 94598 was 94598, checked in by vboxsync, 3 years ago

Main/Machine+Medium+Snapshot+VirtualBox: Recursion elimination to save stack space. Caused trouble with the current settings limits already in ASAN builds, now much higher limits would be possible, but that's not urgent. Also fix the behavior of forgetting medium objects when unregistering VMs (was previously not doing what the API documentation said in the CleanupMode_UnregisterOnly case). bugref:7717

Settings.cpp: Recursion elimination and make the handling of settings reading and writing more similar.

ValidationKit/tests/api/tdTreeDepth1.py: Improve testcase. Make sure that VM unregistering does the right thing with the associated medium objects.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: tdTreeDepth1.py 94598 2022-04-13 21:50:00Z vboxsync $
4
5"""
6VirtualBox Validation Kit - Medium and Snapshot Tree Depth Test #1
7"""
8
9__copyright__ = \
10"""
11Copyright (C) 2010-2022 Oracle Corporation
12
13This file is part of VirtualBox Open Source Edition (OSE), as
14available from http://www.virtualbox.org. This file is free software;
15you can redistribute it and/or modify it under the terms of the GNU
16General Public License (GPL) as published by the Free Software
17Foundation, in version 2 as it comes in the "COPYING" file of the
18VirtualBox OSE distribution. VirtualBox OSE is distributed in the
19hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20
21The contents of this file may alternatively be used under the terms
22of the Common Development and Distribution License Version 1.0
23(CDDL) only, as it comes in the "COPYING.CDDL" file of the
24VirtualBox OSE distribution, in which case the provisions of the
25CDDL are applicable instead of those of the GPL.
26
27You may elect to license modified versions of this file under the
28terms and conditions of either the GPL or the CDDL or both.
29"""
30__version__ = "$Revision: 94598 $"
31
32
33# Standard Python imports.
34import os
35import sys
36import random
37
38# Only the main script needs to modify the path.
39try: __file__
40except: __file__ = sys.argv[0]
41g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
42sys.path.append(g_ksValidationKitDir)
43
44# Validation Kit imports.
45from testdriver import base
46from testdriver import reporter
47from testdriver import vboxcon
48
49
50class SubTstDrvTreeDepth1(base.SubTestDriverBase):
51 """
52 Sub-test driver for Medium and Snapshot Tree Depth Test #1.
53 """
54
55 def __init__(self, oTstDrv):
56 base.SubTestDriverBase.__init__(self, oTstDrv, 'tree-depth', 'Media and Snapshot tree depths');
57
58 def testIt(self):
59 """
60 Execute the sub-testcase.
61 """
62 return self.testMediumTreeDepth() \
63 and self.testSnapshotTreeDepth()
64
65 #
66 # Test execution helpers.
67 #
68
69 def testMediumTreeDepth(self):
70 """
71 Test medium tree depth.
72 """
73 reporter.testStart('mediumTreeDepth')
74
75 try:
76 oVBox = self.oTstDrv.oVBoxMgr.getVirtualBox()
77 oVM = self.oTstDrv.createTestVM('test-medium', 1, None, 4)
78 assert oVM is not None
79
80 # create chain with 300 disk images (medium tree depth limit)
81 fRc = True
82 oSession = self.oTstDrv.openSession(oVM)
83 cImages = 38 #00
84 for i in range(1, cImages + 1):
85 sHddPath = os.path.join(self.oTstDrv.sScratchPath, 'Test' + str(i) + '.vdi')
86 if i == 1:
87 oHd = oSession.createBaseHd(sHddPath, cb=1024*1024)
88 else:
89 oHd = oSession.createDiffHd(oHd, sHddPath)
90 if oHd is None:
91 fRc = False
92 break
93
94 # modify the VM config, attach HDD
95 fRc = fRc and oSession.attachHd(sHddPath, sController='SATA Controller', fImmutable=False, fForceResource=False)
96 fRc = fRc and oSession.saveSettings()
97 fRc = oSession.close() and fRc
98 ## @todo r=klaus: count known hard disk images, should be cImages
99
100 # unregister, making sure the images are closed
101 sSettingsFile = oVM.settingsFilePath
102 fDetachAll = random.choice([False, True])
103 if fDetachAll:
104 reporter.log('unregistering VM, DetachAll style')
105 else:
106 reporter.log('unregistering VM, UnregisterOnly style')
107 self.oTstDrv.forgetTestMachine(oVM)
108 if fDetachAll:
109 aoHDs = oVM.unregister(vboxcon.CleanupMode_DetachAllReturnHardDisksOnly)
110 for oHD in aoHDs:
111 oHD.close()
112 aoHDs = None
113 else:
114 oVM.unregister(vboxcon.CleanupMode_UnregisterOnly)
115 oVM = None
116
117 # If there is no base image (expected) then there are no leftover
118 # child images either. Can be changed later once the todos above
119 # and below are resolved.
120 cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(oVBox, 'hardDisks'))
121 reporter.log('API reports %i base images' % (cBaseImages))
122 fRc = fRc and cBaseImages == 0
123
124 # re-register to test loading of settings
125 reporter.log('opening VM %s, testing config reading' % (sSettingsFile))
126 oVM = oVBox.openMachine(sSettingsFile)
127 ## @todo r=klaus: count known hard disk images, should be cImages
128
129 reporter.log('unregistering VM')
130 oVM.unregister(vboxcon.CleanupMode_UnregisterOnly)
131 oVM = None
132
133 cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(oVBox, 'hardDisks'))
134 reporter.log('API reports %i base images' % (cBaseImages))
135 fRc = fRc and cBaseImages == 0
136
137 assert fRc is True
138 except:
139 reporter.errorXcpt()
140
141 return reporter.testDone()[1] == 0
142
143 def testSnapshotTreeDepth(self):
144 """
145 Test snapshot tree depth.
146 """
147 reporter.testStart('snapshotTreeDepth')
148
149 try:
150 oVBox = self.oTstDrv.oVBoxMgr.getVirtualBox()
151 oVM = self.oTstDrv.createTestVM('test-snap', 1, None, 4)
152 assert oVM is not None
153
154 # modify the VM config, create and attach empty HDD
155 oSession = self.oTstDrv.openSession(oVM)
156 sHddPath = os.path.join(self.oTstDrv.sScratchPath, 'TestSnapEmpty.vdi')
157 fRc = True
158 fRc = fRc and oSession.createAndAttachHd(sHddPath, cb=1024*1024, sController='SATA Controller', fImmutable=False)
159 fRc = fRc and oSession.saveSettings()
160
161 # take 250 snapshots (snapshot tree depth limit)
162 cSnapshots = 13 #00
163 for i in range(1, cSnapshots + 1):
164 fRc = fRc and oSession.takeSnapshot('Snapshot ' + str(i))
165 fRc = oSession.close() and fRc
166 oSession = None
167 reporter.log('API reports %i snapshots' % (oVM.snapshotCount))
168 fRc = fRc and oVM.snapshotCount == cSnapshots
169
170 assert fRc is True
171
172 # unregister, making sure the images are closed
173 sSettingsFile = oVM.settingsFilePath
174 fDetachAll = random.choice([False, True])
175 if fDetachAll:
176 reporter.log('unregistering VM, DetachAll style')
177 else:
178 reporter.log('unregistering VM, UnregisterOnly style')
179 self.oTstDrv.forgetTestMachine(oVM)
180 if fDetachAll:
181 aoHDs = oVM.unregister(vboxcon.CleanupMode_DetachAllReturnHardDisksOnly)
182 for oHD in aoHDs:
183 oHD.close()
184 aoHDs = None
185 else:
186 oVM.unregister(vboxcon.CleanupMode_UnregisterOnly)
187 oVM = None
188
189 # If there is no base image (expected) then there are no leftover
190 # child images either. Can be changed later once the todos above
191 # and below are resolved.
192 cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(oVBox, 'hardDisks'))
193 reporter.log('API reports %i base images' % (cBaseImages))
194 fRc = fRc and cBaseImages == 0
195
196 # re-register to test loading of settings
197 reporter.log('opening VM %s, testing config reading' % (sSettingsFile))
198 oVM = oVBox.openMachine(sSettingsFile)
199 reporter.log('API reports %i snapshots' % (oVM.snapshotCount))
200 fRc = fRc and oVM.snapshotCount == cSnapshots
201
202 reporter.log('unregistering VM')
203 oVM.unregister(vboxcon.CleanupMode_UnregisterOnly)
204 oVM = None
205
206 cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(oVBox, 'hardDisks'))
207 reporter.log('API reports %i base images' % (cBaseImages))
208 fRc = fRc and cBaseImages == 0
209
210 assert fRc is True
211 except:
212 reporter.errorXcpt()
213
214 return reporter.testDone()[1] == 0
215
216
217if __name__ == '__main__':
218 sys.path.append(os.path.dirname(os.path.abspath(__file__)))
219 from tdApi1 import tdApi1; # pylint: disable=relative-import
220 sys.exit(tdApi1([SubTstDrvTreeDepth1]).main(sys.argv))
221
Note: See TracBrowser for help on using the repository browser.

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