VirtualBox

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

Last change on this file since 98988 was 98826, checked in by vboxsync, 2 years ago

ValidationKit/tests/api/tdTreeDepth1.py: The test case calls
VirtualBox::openMachine() to supposedly re-register the VM but
this only opens the VM and does not register it. Add the missing
IVirtualBox::registerMachine() calls to register the opened VM.

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

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