1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 | # $Id: tdTreeDepth1.py 96407 2022-08-22 17:43:14Z vboxsync $
|
---|
4 |
|
---|
5 | """
|
---|
6 | VirtualBox Validation Kit - Medium and Snapshot Tree Depth Test #1
|
---|
7 | """
|
---|
8 |
|
---|
9 | __copyright__ = \
|
---|
10 | """
|
---|
11 | Copyright (C) 2010-2022 Oracle and/or its affiliates.
|
---|
12 |
|
---|
13 | This file is part of VirtualBox base platform packages, as
|
---|
14 | available from https://www.virtualbox.org.
|
---|
15 |
|
---|
16 | This program is free software; you can redistribute it and/or
|
---|
17 | modify it under the terms of the GNU General Public License
|
---|
18 | as published by the Free Software Foundation, in version 3 of the
|
---|
19 | License.
|
---|
20 |
|
---|
21 | This program is distributed in the hope that it will be useful, but
|
---|
22 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
24 | General Public License for more details.
|
---|
25 |
|
---|
26 | You should have received a copy of the GNU General Public License
|
---|
27 | along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
28 |
|
---|
29 | The contents of this file may alternatively be used under the terms
|
---|
30 | of the Common Development and Distribution License Version 1.0
|
---|
31 | (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
32 | in the VirtualBox distribution, in which case the provisions of the
|
---|
33 | CDDL are applicable instead of those of the GPL.
|
---|
34 |
|
---|
35 | You may elect to license modified versions of this file under the
|
---|
36 | terms and conditions of either the GPL or the CDDL or both.
|
---|
37 |
|
---|
38 | SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
39 | """
|
---|
40 | __version__ = "$Revision: 96407 $"
|
---|
41 |
|
---|
42 |
|
---|
43 | # Standard Python imports.
|
---|
44 | import os
|
---|
45 | import sys
|
---|
46 | import random
|
---|
47 |
|
---|
48 | # Only the main script needs to modify the path.
|
---|
49 | try: __file__
|
---|
50 | except: __file__ = sys.argv[0]
|
---|
51 | g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
---|
52 | sys.path.append(g_ksValidationKitDir)
|
---|
53 |
|
---|
54 | # Validation Kit imports.
|
---|
55 | from testdriver import base
|
---|
56 | from testdriver import reporter
|
---|
57 | from testdriver import vboxcon
|
---|
58 |
|
---|
59 |
|
---|
60 | class 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 | ## @todo r=klaus: count known hard disk images, should be cImages
|
---|
145 |
|
---|
146 | reporter.log('unregistering VM')
|
---|
147 | oVM.unregister(vboxcon.CleanupMode_UnregisterOnly)
|
---|
148 | oVM = None
|
---|
149 |
|
---|
150 | cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(oVBox, 'hardDisks'))
|
---|
151 | reporter.log('API reports %i base images' % (cBaseImages))
|
---|
152 | fRc = fRc and cBaseImages == 0
|
---|
153 | if cBaseImages != 0:
|
---|
154 | reporter.error('Got %d base images after unregistering, expected %d' % (cBaseImages, 0));
|
---|
155 |
|
---|
156 | except:
|
---|
157 | reporter.errorXcpt()
|
---|
158 |
|
---|
159 | return reporter.testDone()[1] == 0
|
---|
160 |
|
---|
161 | def testSnapshotTreeDepth(self):
|
---|
162 | """
|
---|
163 | Test snapshot tree depth.
|
---|
164 | """
|
---|
165 | reporter.testStart('snapshotTreeDepth')
|
---|
166 |
|
---|
167 | try:
|
---|
168 | oVBox = self.oTstDrv.oVBoxMgr.getVirtualBox()
|
---|
169 | oVM = self.oTstDrv.createTestVM('test-snap', 1, None, 4)
|
---|
170 | assert oVM is not None
|
---|
171 |
|
---|
172 | # modify the VM config, create and attach empty HDD
|
---|
173 | oSession = self.oTstDrv.openSession(oVM)
|
---|
174 | sHddPath = os.path.join(self.oTstDrv.sScratchPath, 'TestSnapEmpty.vdi')
|
---|
175 | fRc = True
|
---|
176 | fRc = fRc and oSession.createAndAttachHd(sHddPath, cb=1024*1024, sController='SATA Controller', fImmutable=False)
|
---|
177 | fRc = fRc and oSession.saveSettings()
|
---|
178 |
|
---|
179 | # take up to 200 snapshots (255 is the snapshot tree depth limit)
|
---|
180 | cSnapshots = random.randrange(1, 200); ## @todo r=andy BUGBUG When specifying 254 here, it fails with object 251.
|
---|
181 | reporter.log('Taking %d snapshots' % (cSnapshots))
|
---|
182 | for i in range(1, cSnapshots + 1):
|
---|
183 | fRc = fRc and oSession.takeSnapshot('Snapshot ' + str(i))
|
---|
184 | fRc = oSession.close() and fRc
|
---|
185 | oSession = None
|
---|
186 | reporter.log('API reports %i snapshots' % (oVM.snapshotCount))
|
---|
187 | fRc = fRc and oVM.snapshotCount == cSnapshots
|
---|
188 | if oVM.snapshotCount != cSnapshots:
|
---|
189 | reporter.error('Got %d initial snapshots, expected %d' % (oVM.snapshotCount, cSnapshots));
|
---|
190 |
|
---|
191 | # unregister, making sure the images are closed
|
---|
192 | sSettingsFile = oVM.settingsFilePath
|
---|
193 | fDetachAll = random.choice([False, True])
|
---|
194 | if fDetachAll:
|
---|
195 | reporter.log('unregistering VM, DetachAll style')
|
---|
196 | else:
|
---|
197 | reporter.log('unregistering VM, UnregisterOnly style')
|
---|
198 | self.oTstDrv.forgetTestMachine(oVM)
|
---|
199 | if fDetachAll:
|
---|
200 | aoHDs = oVM.unregister(vboxcon.CleanupMode_DetachAllReturnHardDisksOnly)
|
---|
201 | for oHD in aoHDs:
|
---|
202 | oHD.close()
|
---|
203 | aoHDs = None
|
---|
204 | else:
|
---|
205 | oVM.unregister(vboxcon.CleanupMode_UnregisterOnly)
|
---|
206 | oVM = None
|
---|
207 |
|
---|
208 | # If there is no base image (expected) then there are no leftover
|
---|
209 | # child images either. Can be changed later once the todos above
|
---|
210 | # and below are resolved.
|
---|
211 | cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(oVBox, 'hardDisks'))
|
---|
212 | reporter.log('API reports %i base images' % (cBaseImages))
|
---|
213 | fRc = fRc and cBaseImages == 0
|
---|
214 | if cBaseImages != 0:
|
---|
215 | reporter.error('Got %d initial base images, expected %d' % (cBaseImages, 0));
|
---|
216 |
|
---|
217 | # re-register to test loading of settings
|
---|
218 | reporter.log('opening VM %s, testing config reading' % (sSettingsFile))
|
---|
219 | if self.oTstDrv.fpApiVer >= 7.0:
|
---|
220 | # Needs a password parameter since 7.0.
|
---|
221 | oVM = oVBox.openMachine(sSettingsFile, "")
|
---|
222 | else:
|
---|
223 | oVM = oVBox.openMachine(sSettingsFile)
|
---|
224 | reporter.log('API reports %i snapshots' % (oVM.snapshotCount))
|
---|
225 | fRc = fRc and oVM.snapshotCount == cSnapshots
|
---|
226 | if oVM.snapshotCount != cSnapshots:
|
---|
227 | reporter.error('Got %d snapshots after re-registering, expected %d' % (oVM.snapshotCount, cSnapshots));
|
---|
228 |
|
---|
229 | reporter.log('unregistering VM')
|
---|
230 | oVM.unregister(vboxcon.CleanupMode_UnregisterOnly)
|
---|
231 | oVM = None
|
---|
232 |
|
---|
233 | cBaseImages = len(self.oTstDrv.oVBoxMgr.getArray(oVBox, 'hardDisks'))
|
---|
234 | reporter.log('API reports %i base images' % (cBaseImages))
|
---|
235 | fRc = fRc and cBaseImages == 0
|
---|
236 | if cBaseImages != 0:
|
---|
237 | reporter.error('Got %d base images after unregistering, expected %d' % (cBaseImages, 0));
|
---|
238 | except:
|
---|
239 | reporter.errorXcpt()
|
---|
240 |
|
---|
241 | return reporter.testDone()[1] == 0
|
---|
242 |
|
---|
243 |
|
---|
244 | if __name__ == '__main__':
|
---|
245 | sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
---|
246 | from tdApi1 import tdApi1; # pylint: disable=relative-import
|
---|
247 | sys.exit(tdApi1([SubTstDrvTreeDepth1]).main(sys.argv))
|
---|