VirtualBox

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

Last change on this file since 72732 was 70816, checked in by vboxsync, 7 years ago

ValidationKit: For API tests move some redundant object construction to the test constructor, saving a few lines, and what's most important avoid a variable in global scope which pylint doesn't like.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: tdTreeDepth1.py 70816 2018-01-30 18:20:29Z vboxsync $
4
5"""
6VirtualBox Validation Kit - Medium and Snapshot Tree Depth Test #1
7"""
8
9__copyright__ = \
10"""
11Copyright (C) 2010-2017 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: 70816 $"
31
32
33# Standard Python imports.
34import os
35import sys
36
37# Only the main script needs to modify the path.
38try: __file__
39except: __file__ = sys.argv[0]
40g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
41sys.path.append(g_ksValidationKitDir)
42
43# Validation Kit imports.
44from testdriver import base
45from testdriver import reporter
46from testdriver import vboxcon
47
48
49class SubTstDrvTreeDepth1(base.SubTestDriverBase):
50 """
51 Sub-test driver for Medium and Snapshot Tree Depth Test #1.
52 """
53
54 def __init__(self, oTstDrv):
55 base.SubTestDriverBase.__init__(self, 'tree-depth', oTstDrv)
56
57 def testIt(self):
58 """
59 Execute the sub-testcase.
60 """
61 return self.testMediumTreeDepth() \
62 and self.testSnapshotTreeDepth()
63
64 #
65 # Test execution helpers.
66 #
67
68 def testMediumTreeDepth(self):
69 """
70 Test medium tree depth.
71 """
72 reporter.testStart('mediumTreeDepth')
73
74 try:
75 oVM = self.oTstDrv.createTestVM('test-medium', 1, None, 4)
76 assert oVM is not None
77
78 # create chain with 300 disk images (medium tree depth limit)
79 fRc = True
80 oSession = self.oTstDrv.openSession(oVM)
81 for i in range(1, 301):
82 sHddPath = os.path.join(self.oTstDrv.sScratchPath, 'Test' + str(i) + '.vdi')
83 if i is 1:
84 oHd = oSession.createBaseHd(sHddPath, cb=1024*1024)
85 else:
86 oHd = oSession.createDiffHd(oHd, sHddPath)
87 if oHd is None:
88 fRc = False
89 break
90
91 # modify the VM config, attach HDD
92 fRc = fRc and oSession.attachHd(sHddPath, sController='SATA Controller', fImmutable=False, fForceResource=False)
93 fRc = fRc and oSession.saveSettings()
94 fRc = oSession.close() and fRc
95
96 # unregister and re-register to test loading of settings
97 sSettingsFile = oVM.settingsFilePath
98 reporter.log('unregistering VM')
99 oVM.unregister(vboxcon.CleanupMode_DetachAllReturnNone)
100 oVBox = self.oTstDrv.oVBoxMgr.getVirtualBox()
101 reporter.log('opening VM %s, testing config reading' % (sSettingsFile))
102 oVM = oVBox.openMachine(sSettingsFile)
103
104 assert fRc is True
105 except:
106 reporter.errorXcpt()
107
108 return reporter.testDone()[1] == 0
109
110 def testSnapshotTreeDepth(self):
111 """
112 Test snapshot tree depth.
113 """
114 reporter.testStart('snapshotTreeDepth')
115
116 try:
117 oVM = self.oTstDrv.createTestVM('test-snap', 1, None, 4)
118 assert oVM is not None
119
120 # modify the VM config, create and attach empty HDD
121 oSession = self.oTstDrv.openSession(oVM)
122 sHddPath = os.path.join(self.oTstDrv.sScratchPath, 'TestSnapEmpty.vdi')
123 fRc = True
124 fRc = fRc and oSession.createAndAttachHd(sHddPath, cb=1024*1024, sController='SATA Controller', fImmutable=False)
125 fRc = fRc and oSession.saveSettings()
126
127 # take 250 snapshots (snapshot tree depth limit)
128 for i in range(1, 251):
129 fRc = fRc and oSession.takeSnapshot('Snapshot ' + str(i))
130 fRc = oSession.close() and fRc
131
132 # unregister and re-register to test loading of settings
133 sSettingsFile = oVM.settingsFilePath
134 reporter.log('unregistering VM')
135 oVM.unregister(vboxcon.CleanupMode_DetachAllReturnNone)
136 oVBox = self.oTstDrv.oVBoxMgr.getVirtualBox()
137 reporter.log('opening VM %s, testing config reading' % (sSettingsFile))
138 oVM = oVBox.openMachine(sSettingsFile)
139
140 assert fRc is True
141 except:
142 reporter.errorXcpt()
143
144 return reporter.testDone()[1] == 0
145
146
147if __name__ == '__main__':
148 sys.path.append(os.path.dirname(os.path.abspath(__file__)))
149 from tdApi1 import tdApi1
150 sys.exit(tdApi1([SubTstDrvTreeDepth1]).main(sys.argv))
151
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