VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/shutdown/tdGuestOsShutdown1.py@ 102455

Last change on this file since 102455 was 101035, checked in by vboxsync, 15 months ago

Initial commit (based draft v2 / on patch v5) for implementing platform architecture support for x86 and ARM. bugref:10384

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 13.0 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5VMM Guest OS boot tests.
6"""
7
8__copyright__ = \
9"""
10Copyright (C) 2010-2023 Oracle and/or its affiliates.
11
12This file is part of VirtualBox base platform packages, as
13available from https://www.virtualbox.org.
14
15This program is free software; you can redistribute it and/or
16modify it under the terms of the GNU General Public License
17as published by the Free Software Foundation, in version 3 of the
18License.
19
20This program is distributed in the hope that it will be useful, but
21WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with this program; if not, see <https://www.gnu.org/licenses>.
27
28The contents of this file may alternatively be used under the terms
29of the Common Development and Distribution License Version 1.0
30(CDDL), a copy of it is provided in the "COPYING.CDDL" file included
31in the VirtualBox distribution, in which case the provisions of the
32CDDL are applicable instead of those of the GPL.
33
34You may elect to license modified versions of this file under the
35terms and conditions of either the GPL or the CDDL or both.
36
37SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
38"""
39__version__ = "$Revision: 101035 $"
40
41
42# Standard Python imports.
43import os
44import sys
45import time
46
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 vbox
56from testdriver import base
57from testdriver import reporter
58from testdriver import vboxcon
59
60
61class tdGuestOsBootTest1(vbox.TestDriver):
62 """
63 VMM Unit Tests Set.
64
65 Scenario:
66 - Create VM that corresponds to Guest OS pre-installed on selected HDD
67 - Start VM and wait for TXS server connection (which is started after Guest successfully booted)
68 """
69
70 ksSataController = 'SATA Controller'
71 ksIdeController = 'IDE Controller'
72
73 # VM parameters required to run HDD image.
74 # Format: { HDD image filename: (sKind, HDD controller type) }
75 kaoVmParams = {
76 't-win80.vdi': ( 'Windows 8 (64 bit)', ksSataController ),
77 }
78
79 # List of platforms which are able to suspend and resume host automatically.
80 # In order to add new platform, self._SuspendResume() should be adapted.
81 kasSuspendAllowedPlatforms = ( 'darwin' )
82
83 kcMsVmStartLimit = 5 * 60000
84 kcMsVmShutdownLimit = 1 * 60000
85
86 def __init__(self):
87 """
88 Reinitialize child class instance.
89 """
90 vbox.TestDriver.__init__(self)
91
92 self.sVmName = 'TestVM'
93 self.sHddName = None
94 self.sHddPathBase = os.path.join(self.sResourcePath, '4.2', 'nat', 'win80')
95 self.oVM = None
96
97 # TODO: that should be moved to some common place
98 self.fEnableIOAPIC = True
99 self.cCpus = 1
100 self.fEnableNestedPaging = True
101 self.fEnablePAE = False
102 self.fSuspendHost = False
103 self.cSecSuspendTime = 60
104 self.cShutdownIters = 1
105 self.fExtraVm = False
106 self.sExtraVmName = "TestVM-Extra"
107 self.oExtraVM = None
108 self.fLocalCatch = False
109
110 #
111 # Overridden methods.
112 #
113
114 def showUsage(self):
115 """
116 Extend usage info
117 """
118 rc = vbox.TestDriver.showUsage(self)
119 reporter.log(' --boot-hdd <HDD image file name>')
120
121 reporter.log(' --cpus <# CPUs>')
122 reporter.log(' --no-ioapic')
123 reporter.log(' --no-nested-paging')
124 reporter.log(' --pae')
125 reporter.log(' --suspend-host')
126 reporter.log(' --suspend-time <sec>')
127 reporter.log(' --shutdown-iters <# iters>')
128 reporter.log(' --extra-vm')
129 reporter.log(' --local-catch')
130 return rc
131
132 def parseOption(self, asArgs, iArg):
133 """
134 Extend standard options set
135 """
136 if asArgs[iArg] == '--boot-hdd':
137 iArg += 1
138 if iArg >= len(asArgs): raise base.InvalidOption('The "--boot-hdd" option requires an argument')
139 self.sHddName = asArgs[iArg]
140
141 elif asArgs[iArg] == '--cpus':
142 iArg += 1
143 if iArg >= len(asArgs): raise base.InvalidOption('The "--cpus" option requires an argument')
144 self.cCpus = int(asArgs[iArg])
145 elif asArgs[iArg] == '--no-ioapic':
146 self.fEnableIOAPIC = False
147 elif asArgs[iArg] == '--no-nested-paging':
148 self.fEnableNestedPaging = False
149 elif asArgs[iArg] == '--pae':
150 self.fEnablePAE = True
151 elif asArgs[iArg] == '--suspend-host':
152 self.fSuspendHost = True
153 elif asArgs[iArg] == '--suspend-time':
154 iArg += 1
155 if iArg >= len(asArgs): raise base.InvalidOption('The "--suspend-time" option requires an argument')
156 self.cSecSuspendTime = int(asArgs[iArg])
157 elif asArgs[iArg] == '--shutdown-iters':
158 iArg += 1
159 if iArg >= len(asArgs): raise base.InvalidOption('The "--shutdown-iters" option requires an argument')
160 self.cShutdownIters = int(asArgs[iArg])
161 elif asArgs[iArg] == '--extra-vm':
162 self.fExtraVm = True
163 elif asArgs[iArg] == '--local-catch':
164 self.fLocalCatch = True
165 else:
166 return vbox.TestDriver.parseOption(self, asArgs, iArg)
167
168 return iArg + 1
169
170 def getResourceSet(self):
171 """
172 Returns a set of file and/or directory names relative to
173 TESTBOX_PATH_RESOURCES.
174 """
175 return [os.path.join(self.sHddPathBase, sRsrc) for sRsrc in self.kaoVmParams];
176
177 def _addVM(self, sVmName, sNicTraceFile=None):
178 """
179 Create VM
180 """
181 # Get VM params specific to HDD image
182 sKind, sController = self.kaoVmParams[self.sHddName]
183
184 # Create VM itself
185 eNic0AttachType = vboxcon.NetworkAttachmentType_NAT
186 sHddPath = os.path.join(self.sHddPathBase, self.sHddName)
187 assert os.path.isfile(sHddPath)
188
189 oVM = \
190 self.createTestVM(sVmName, 1, sKind=sKind, cCpus=self.cCpus,
191 eNic0AttachType=eNic0AttachType, sDvdImage = self.sVBoxValidationKitIso)
192 assert oVM is not None
193
194 oSession = self.openSession(oVM)
195
196 # Attach an HDD
197 fRc = oSession.attachHd(sHddPath, sController, fImmutable=True)
198
199 # Enable HW virt
200 fRc = fRc and oSession.enableVirtExX86(True)
201
202 # Enable I/O APIC
203 fRc = fRc and oSession.enableIoApic(self.fEnableIOAPIC)
204
205 # Enable Nested Paging
206 fRc = fRc and oSession.enableNestedPagingX86(self.fEnableNestedPaging)
207
208 # Enable PAE
209 fRc = fRc and oSession.enablePaeX86(self.fEnablePAE)
210
211 if (sNicTraceFile is not None):
212 fRc = fRc and oSession.setNicTraceEnabled(True, sNicTraceFile)
213
214 # Remote desktop
215 oSession.setupVrdp(True)
216
217 fRc = fRc and oSession.saveSettings()
218 fRc = fRc and oSession.close()
219 assert fRc is True
220
221 return oVM
222
223 def actionConfig(self):
224 """
225 Configure pre-conditions.
226 """
227
228 if not self.importVBoxApi():
229 return False
230
231 # Save time: do not start VM if there is no way to suspend host
232 if (self.fSuspendHost is True and sys.platform not in self.kasSuspendAllowedPlatforms):
233 reporter.log('Platform [%s] is not in the list of supported platforms' % sys.platform)
234 return False
235
236 assert self.sHddName is not None
237 if self.sHddName not in self.kaoVmParams:
238 reporter.log('Error: unknown HDD image specified: %s' % self.sHddName)
239 return False
240
241 if (self.fExtraVm is True):
242 self.oExtraVM = self._addVM(self.sExtraVmName)
243
244 self.oVM = self._addVM(self.sVmName)
245
246 return vbox.TestDriver.actionConfig(self)
247
248 def _SuspendResume(self, cSecTimeout):
249 """
250 Put host into sleep and automatically resume it after specified timeout.
251 """
252 fRc = False
253
254 if (sys.platform == 'darwin'):
255 tsStart = time.time()
256 fRc = os.system("/usr/bin/pmset relative wake %d" % self.cSecSuspendTime)
257 fRc |= os.system("/usr/bin/pmset sleepnow")
258 # Wait for host to wake up
259 while ((time.time() - tsStart) < self.cSecSuspendTime):
260 self.sleep(0.1)
261
262 return fRc == 0
263
264 def _waitKeyboardInterrupt(self):
265 """
266 Idle loop until user press CTRL+C
267 """
268 reporter.log('[LOCAL CATCH]: waiting for keyboard interrupt')
269 while (True):
270 try:
271 self.sleep(1)
272 except KeyboardInterrupt:
273 reporter.log('[LOCAL CATCH]: keyboard interrupt occurred')
274 break
275
276 def actionExecute(self):
277 """
278 Execute the testcase itself.
279 """
280 #self.logVmInfo(self.oVM)
281
282 reporter.testStart('SHUTDOWN GUEST')
283
284 cIter = 0
285 fRc = True
286
287 if (self.fExtraVm is True):
288 oExtraSession, oExtraTxsSession = self.startVmAndConnectToTxsViaTcp(self.sExtraVmName,
289 fCdWait=False,
290 cMsTimeout=self.kcMsVmStartLimit)
291 if oExtraSession is None or oExtraTxsSession is None:
292 reporter.error('Unable to start extra VM.')
293 if (self.fLocalCatch is True):
294 self._waitKeyboardInterrupt()
295 reporter.testDone()
296 return False
297
298 while (cIter < self.cShutdownIters):
299
300 cIter += 1
301
302 reporter.log("Starting iteration #%d." % cIter)
303
304 oSession, oTxsSession = self.startVmAndConnectToTxsViaTcp(self.sVmName,
305 fCdWait=False,
306 cMsTimeout=self.kcMsVmStartLimit)
307 if oSession is not None and oTxsSession is not None:
308 # Wait until guest reported success
309 reporter.log('Guest started. Connection to TXS service established.')
310
311 if (self.fSuspendHost is True):
312 reporter.log("Disconnect form TXS.")
313 fRc = fRc and self.txsDisconnect(oSession, oTxsSession)
314 if (fRc is not True):
315 reporter.log("Disconnect form TXS failed.")
316 else:
317 reporter.log('Put host to sleep and resume it automatically after %d seconds.' % self.cSecSuspendTime)
318 fRc = fRc and self._SuspendResume(self.cSecSuspendTime)
319 if (fRc is True):
320 reporter.log("Sleep/resume success.")
321 else:
322 reporter.log("Sleep/resume failed.")
323 reporter.log("Re-connect to TXS in 10 seconds.")
324 self.sleep(10)
325 (fRc, oTxsSession) = self.txsDoConnectViaTcp(oSession, 2 * 60 * 10000)
326 if (fRc is not True):
327 reporter.log("Re-connect to TXS failed.")
328
329 if (fRc is True):
330 reporter.log('Attempt to shutdown guest.')
331 fRc = fRc and oTxsSession.syncShutdown(cMsTimeout=(4 * 60 * 1000))
332 if (fRc is True):
333 reporter.log('Shutdown request issued successfully.')
334 self.waitOnDirectSessionClose(self.oVM, self.kcMsVmShutdownLimit)
335 reporter.log('Shutdown %s.' % ('success' if fRc is True else 'failed'))
336 else:
337 reporter.error('Shutdown request failed.')
338
339 # Do not terminate failing VM in order to catch it.
340 if (fRc is not True and self.fLocalCatch is True):
341 self._waitKeyboardInterrupt()
342 break
343
344 fRc = fRc and self.terminateVmBySession(oSession)
345 reporter.log('VM terminated.')
346
347 else:
348 reporter.error('Guest did not start (iteration %d of %d)' % (cIter, self.cShutdownIters))
349 fRc = False
350
351 # Stop if fail
352 if (fRc is not True):
353 break
354
355 # Local catch at the end.
356 if (self.fLocalCatch is True):
357 reporter.log("Test completed. Waiting for user to press CTRL+C.")
358 self._waitKeyboardInterrupt()
359
360 if (self.fExtraVm is True):
361 fRc = fRc and self.terminateVmBySession(oExtraSession)
362
363 reporter.testDone()
364 return fRc is True
365
366if __name__ == '__main__':
367 sys.exit(tdGuestOsBootTest1().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