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