1 | # -*- coding: utf-8 -*-
|
---|
2 | # $Id: vbox.py 71539 2018-03-28 13:09:16Z vboxsync $
|
---|
3 | # pylint: disable=C0302
|
---|
4 |
|
---|
5 | """
|
---|
6 | VirtualBox Specific base testdriver.
|
---|
7 | """
|
---|
8 |
|
---|
9 | __copyright__ = \
|
---|
10 | """
|
---|
11 | Copyright (C) 2010-2018 Oracle Corporation
|
---|
12 |
|
---|
13 | This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
14 | available from http://www.virtualbox.org. This file is free software;
|
---|
15 | you can redistribute it and/or modify it under the terms of the GNU
|
---|
16 | General Public License (GPL) as published by the Free Software
|
---|
17 | Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
18 | VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
19 | hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
20 |
|
---|
21 | The contents of this file may alternatively be used under the terms
|
---|
22 | of the Common Development and Distribution License Version 1.0
|
---|
23 | (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
24 | VirtualBox OSE distribution, in which case the provisions of the
|
---|
25 | CDDL are applicable instead of those of the GPL.
|
---|
26 |
|
---|
27 | You may elect to license modified versions of this file under the
|
---|
28 | terms and conditions of either the GPL or the CDDL or both.
|
---|
29 | """
|
---|
30 | __version__ = "$Revision: 71539 $"
|
---|
31 |
|
---|
32 |
|
---|
33 | # Standard Python imports.
|
---|
34 | import datetime
|
---|
35 | import os
|
---|
36 | import platform
|
---|
37 | import re;
|
---|
38 | import sys
|
---|
39 | import threading
|
---|
40 | import time
|
---|
41 | import traceback
|
---|
42 |
|
---|
43 | # Figure out where the validation kit lives and make sure it's in the path.
|
---|
44 | try: __file__
|
---|
45 | except: __file__ = sys.argv[0];
|
---|
46 | g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)));
|
---|
47 | if g_ksValidationKitDir not in sys.path:
|
---|
48 | sys.path.append(g_ksValidationKitDir);
|
---|
49 |
|
---|
50 | # Validation Kit imports.
|
---|
51 | from common import utils;
|
---|
52 | from testdriver import base;
|
---|
53 | from testdriver import btresolver;
|
---|
54 | from testdriver import reporter;
|
---|
55 | from testdriver import vboxcon;
|
---|
56 | from testdriver import vboxtestvms;
|
---|
57 |
|
---|
58 | # Python 3 hacks:
|
---|
59 | if sys.version_info[0] >= 3:
|
---|
60 | xrange = range; # pylint: disable=redefined-builtin,invalid-name
|
---|
61 | long = int; # pylint: disable=redefined-builtin,invalid-name
|
---|
62 |
|
---|
63 | #
|
---|
64 | # Exception and Error Unification Hacks.
|
---|
65 | # Note! This is pretty gross stuff. Be warned!
|
---|
66 | # TODO: Find better ways of doing these things, preferrably in vboxapi.
|
---|
67 | #
|
---|
68 |
|
---|
69 | ComException = None; # pylint: disable=C0103
|
---|
70 | __fnComExceptionGetAttr__ = None; # pylint: disable=C0103
|
---|
71 |
|
---|
72 | def __MyDefaultGetAttr(oSelf, sName):
|
---|
73 | """ __getattribute__/__getattr__ default fake."""
|
---|
74 | try:
|
---|
75 | oAttr = oSelf.__dict__[sName];
|
---|
76 | except:
|
---|
77 | oAttr = dir(oSelf)[sName];
|
---|
78 | return oAttr;
|
---|
79 |
|
---|
80 | def __MyComExceptionGetAttr(oSelf, sName):
|
---|
81 | """ ComException.__getattr__ wrapper - both XPCOM and COM. """
|
---|
82 | try:
|
---|
83 | oAttr = __fnComExceptionGetAttr__(oSelf, sName);
|
---|
84 | except AttributeError:
|
---|
85 | if platform.system() == 'Windows':
|
---|
86 | if sName == 'errno':
|
---|
87 | oAttr = __fnComExceptionGetAttr__(oSelf, 'hresult');
|
---|
88 | elif sName == 'msg':
|
---|
89 | oAttr = __fnComExceptionGetAttr__(oSelf, 'strerror');
|
---|
90 | else:
|
---|
91 | raise;
|
---|
92 | else:
|
---|
93 | if sName == 'hresult':
|
---|
94 | oAttr = __fnComExceptionGetAttr__(oSelf, 'errno');
|
---|
95 | elif sName == 'strerror':
|
---|
96 | oAttr = __fnComExceptionGetAttr__(oSelf, 'msg');
|
---|
97 | elif sName == 'excepinfo':
|
---|
98 | oAttr = None;
|
---|
99 | elif sName == 'argerror':
|
---|
100 | oAttr = None;
|
---|
101 | else:
|
---|
102 | raise;
|
---|
103 | #print '__MyComExceptionGetAttr(,%s) -> "%s"' % (sName, oAttr);
|
---|
104 | return oAttr;
|
---|
105 |
|
---|
106 | def __deployExceptionHacks__(oNativeComExceptionClass):
|
---|
107 | """
|
---|
108 | Deploys the exception and error hacks that helps unifying COM and XPCOM
|
---|
109 | exceptions and errors.
|
---|
110 | """
|
---|
111 | global ComException # pylint: disable=C0103
|
---|
112 | global __fnComExceptionGetAttr__ # pylint: disable=C0103
|
---|
113 |
|
---|
114 | # Hook up our attribute getter for the exception class (ASSUMES new-style).
|
---|
115 | if __fnComExceptionGetAttr__ is None:
|
---|
116 | try:
|
---|
117 | __fnComExceptionGetAttr__ = getattr(oNativeComExceptionClass, '__getattr__');
|
---|
118 | except:
|
---|
119 | try:
|
---|
120 | __fnComExceptionGetAttr__ = getattr(oNativeComExceptionClass, '__getattribute__');
|
---|
121 | except:
|
---|
122 | __fnComExceptionGetAttr__ = __MyDefaultGetAttr;
|
---|
123 | setattr(oNativeComExceptionClass, '__getattr__', __MyComExceptionGetAttr)
|
---|
124 |
|
---|
125 | # Make the modified classes accessible (are there better ways to do this?)
|
---|
126 | ComException = oNativeComExceptionClass
|
---|
127 | return None;
|
---|
128 |
|
---|
129 |
|
---|
130 |
|
---|
131 | #
|
---|
132 | # Utility functions.
|
---|
133 | #
|
---|
134 |
|
---|
135 | def isIpAddrValid(sIpAddr):
|
---|
136 | """
|
---|
137 | Checks if a IPv4 address looks valid. This will return false for
|
---|
138 | localhost and similar.
|
---|
139 | Returns True / False.
|
---|
140 | """
|
---|
141 | if sIpAddr is None: return False;
|
---|
142 | if len(sIpAddr.split('.')) != 4: return False;
|
---|
143 | if sIpAddr.endswith('.0'): return False;
|
---|
144 | if sIpAddr.endswith('.255'): return False;
|
---|
145 | if sIpAddr.startswith('127.'): return False;
|
---|
146 | if sIpAddr.startswith('169.254.'): return False;
|
---|
147 | if sIpAddr.startswith('192.0.2.'): return False;
|
---|
148 | if sIpAddr.startswith('224.0.0.'): return False;
|
---|
149 | return True;
|
---|
150 |
|
---|
151 | def stringifyErrorInfo(oErrInfo):
|
---|
152 | """
|
---|
153 | Stringifies the error information in a IVirtualBoxErrorInfo object.
|
---|
154 |
|
---|
155 | Returns string with error info.
|
---|
156 | """
|
---|
157 | try:
|
---|
158 | rc = oErrInfo.resultCode;
|
---|
159 | sText = oErrInfo.text;
|
---|
160 | sIid = oErrInfo.interfaceID;
|
---|
161 | sComponent = oErrInfo.component;
|
---|
162 | except:
|
---|
163 | sRet = 'bad error object (%s)?' % (oErrInfo,);
|
---|
164 | traceback.print_exc();
|
---|
165 | else:
|
---|
166 | sRet = 'rc=%s text="%s" IID=%s component=%s' % (ComError.toString(rc), sText, sIid, sComponent);
|
---|
167 | return sRet;
|
---|
168 |
|
---|
169 | def reportError(oErr, sText):
|
---|
170 | """
|
---|
171 | Report a VirtualBox error on oErr. oErr can be IVirtualBoxErrorInfo
|
---|
172 | or IProgress. Anything else is ignored.
|
---|
173 |
|
---|
174 | Returns the same a reporter.error().
|
---|
175 | """
|
---|
176 | try:
|
---|
177 | oErrObj = oErr.errorInfo; # IProgress.
|
---|
178 | except:
|
---|
179 | oErrObj = oErr;
|
---|
180 | reporter.error(sText);
|
---|
181 | return reporter.error(stringifyErrorInfo(oErrObj));
|
---|
182 |
|
---|
183 |
|
---|
184 | #
|
---|
185 | # Classes
|
---|
186 | #
|
---|
187 |
|
---|
188 | class ComError(object):
|
---|
189 | """
|
---|
190 | Unified COM and XPCOM status code repository.
|
---|
191 | This works more like a module than a class since it's replacing a module.
|
---|
192 | """
|
---|
193 |
|
---|
194 | # The VBOX_E_XXX bits:
|
---|
195 | __VBOX_E_BASE = -2135228416;
|
---|
196 | VBOX_E_OBJECT_NOT_FOUND = __VBOX_E_BASE + 1;
|
---|
197 | VBOX_E_INVALID_VM_STATE = __VBOX_E_BASE + 2;
|
---|
198 | VBOX_E_VM_ERROR = __VBOX_E_BASE + 3;
|
---|
199 | VBOX_E_FILE_ERROR = __VBOX_E_BASE + 4;
|
---|
200 | VBOX_E_IPRT_ERROR = __VBOX_E_BASE + 5;
|
---|
201 | VBOX_E_PDM_ERROR = __VBOX_E_BASE + 6;
|
---|
202 | VBOX_E_INVALID_OBJECT_STATE = __VBOX_E_BASE + 7;
|
---|
203 | VBOX_E_HOST_ERROR = __VBOX_E_BASE + 8;
|
---|
204 | VBOX_E_NOT_SUPPORTED = __VBOX_E_BASE + 9;
|
---|
205 | VBOX_E_XML_ERROR = __VBOX_E_BASE + 10;
|
---|
206 | VBOX_E_INVALID_SESSION_STATE = __VBOX_E_BASE + 11;
|
---|
207 | VBOX_E_OBJECT_IN_USE = __VBOX_E_BASE + 12;
|
---|
208 | VBOX_E_DONT_CALL_AGAIN = __VBOX_E_BASE + 13;
|
---|
209 |
|
---|
210 | # Reverse lookup table.
|
---|
211 | dDecimalToConst = {}; # pylint: disable=C0103
|
---|
212 |
|
---|
213 | def __init__(self):
|
---|
214 | raise base.GenError('No instances, please');
|
---|
215 |
|
---|
216 | @staticmethod
|
---|
217 | def copyErrors(oNativeComErrorClass):
|
---|
218 | """
|
---|
219 | Copy all error codes from oNativeComErrorClass to this class and
|
---|
220 | install compatability mappings.
|
---|
221 | """
|
---|
222 |
|
---|
223 | # First, add the VBOX_E_XXX constants to dDecimalToConst.
|
---|
224 | for sAttr in dir(ComError):
|
---|
225 | if sAttr.startswith('VBOX_E'):
|
---|
226 | oAttr = getattr(ComError, sAttr);
|
---|
227 | ComError.dDecimalToConst[oAttr] = sAttr;
|
---|
228 |
|
---|
229 | # Copy all error codes from oNativeComErrorClass to this class.
|
---|
230 | for sAttr in dir(oNativeComErrorClass):
|
---|
231 | if sAttr[0].isupper():
|
---|
232 | oAttr = getattr(oNativeComErrorClass, sAttr);
|
---|
233 | setattr(ComError, sAttr, oAttr);
|
---|
234 | if isinstance(oAttr, int):
|
---|
235 | ComError.dDecimalToConst[oAttr] = sAttr;
|
---|
236 |
|
---|
237 | # Install mappings to the other platform.
|
---|
238 | if platform.system() == 'Windows':
|
---|
239 | ComError.NS_OK = ComError.S_OK;
|
---|
240 | ComError.NS_ERROR_FAILURE = ComError.E_FAIL;
|
---|
241 | ComError.NS_ERROR_ABORT = ComError.E_ABORT;
|
---|
242 | ComError.NS_ERROR_NULL_POINTER = ComError.E_POINTER;
|
---|
243 | ComError.NS_ERROR_NO_INTERFACE = ComError.E_NOINTERFACE;
|
---|
244 | ComError.NS_ERROR_INVALID_ARG = ComError.E_INVALIDARG;
|
---|
245 | ComError.NS_ERROR_OUT_OF_MEMORY = ComError.E_OUTOFMEMORY;
|
---|
246 | ComError.NS_ERROR_NOT_IMPLEMENTED = ComError.E_NOTIMPL;
|
---|
247 | ComError.NS_ERROR_UNEXPECTED = ComError.E_UNEXPECTED;
|
---|
248 | else:
|
---|
249 | ComError.E_ACCESSDENIED = -2147024891; # see VBox/com/defs.h
|
---|
250 | ComError.S_OK = ComError.NS_OK;
|
---|
251 | ComError.E_FAIL = ComError.NS_ERROR_FAILURE;
|
---|
252 | ComError.E_ABORT = ComError.NS_ERROR_ABORT;
|
---|
253 | ComError.E_POINTER = ComError.NS_ERROR_NULL_POINTER;
|
---|
254 | ComError.E_NOINTERFACE = ComError.NS_ERROR_NO_INTERFACE;
|
---|
255 | ComError.E_INVALIDARG = ComError.NS_ERROR_INVALID_ARG;
|
---|
256 | ComError.E_OUTOFMEMORY = ComError.NS_ERROR_OUT_OF_MEMORY;
|
---|
257 | ComError.E_NOTIMPL = ComError.NS_ERROR_NOT_IMPLEMENTED;
|
---|
258 | ComError.E_UNEXPECTED = ComError.NS_ERROR_UNEXPECTED;
|
---|
259 | ComError.DISP_E_EXCEPTION = -2147352567; # For COM compatability only.
|
---|
260 | return True;
|
---|
261 |
|
---|
262 | @staticmethod
|
---|
263 | def getXcptResult(oXcpt):
|
---|
264 | """
|
---|
265 | Gets the result code for an exception.
|
---|
266 | Returns COM status code (or E_UNEXPECTED).
|
---|
267 | """
|
---|
268 | if platform.system() == 'Windows':
|
---|
269 | # The DISP_E_EXCEPTION + excptinfo fun needs checking up, only
|
---|
270 | # empirical info on it so far.
|
---|
271 | try:
|
---|
272 | hrXcpt = oXcpt.hresult;
|
---|
273 | except AttributeError:
|
---|
274 | hrXcpt = ComError.E_UNEXPECTED;
|
---|
275 | if hrXcpt == ComError.DISP_E_EXCEPTION and oXcpt.excepinfo is not None:
|
---|
276 | hrXcpt = oXcpt.excepinfo[5];
|
---|
277 | else:
|
---|
278 | try:
|
---|
279 | hrXcpt = oXcpt.errno;
|
---|
280 | except AttributeError:
|
---|
281 | hrXcpt = ComError.E_UNEXPECTED;
|
---|
282 | return hrXcpt;
|
---|
283 |
|
---|
284 | @staticmethod
|
---|
285 | def equal(oXcpt, hr):
|
---|
286 | """
|
---|
287 | Checks if the ComException e is not equal to the COM status code hr.
|
---|
288 | This takes DISP_E_EXCEPTION & excepinfo into account.
|
---|
289 |
|
---|
290 | This method can be used with any Exception derivate, however it will
|
---|
291 | only return True for classes similar to the two ComException variants.
|
---|
292 | """
|
---|
293 | if platform.system() == 'Windows':
|
---|
294 | # The DISP_E_EXCEPTION + excptinfo fun needs checking up, only
|
---|
295 | # empirical info on it so far.
|
---|
296 | try:
|
---|
297 | hrXcpt = oXcpt.hresult;
|
---|
298 | except AttributeError:
|
---|
299 | return False;
|
---|
300 | if hrXcpt == ComError.DISP_E_EXCEPTION and oXcpt.excepinfo is not None:
|
---|
301 | hrXcpt = oXcpt.excepinfo[5];
|
---|
302 | else:
|
---|
303 | try:
|
---|
304 | hrXcpt = oXcpt.errno;
|
---|
305 | except AttributeError:
|
---|
306 | return False;
|
---|
307 | return hrXcpt == hr;
|
---|
308 |
|
---|
309 | @staticmethod
|
---|
310 | def notEqual(oXcpt, hr):
|
---|
311 | """
|
---|
312 | Checks if the ComException e is not equal to the COM status code hr.
|
---|
313 | See equal() for more details.
|
---|
314 | """
|
---|
315 | return not ComError.equal(oXcpt, hr)
|
---|
316 |
|
---|
317 | @staticmethod
|
---|
318 | def toString(hr):
|
---|
319 | """
|
---|
320 | Converts the specified COM status code to a string.
|
---|
321 | """
|
---|
322 | try:
|
---|
323 | sStr = ComError.dDecimalToConst[int(hr)];
|
---|
324 | except KeyError:
|
---|
325 | hrLong = long(hr);
|
---|
326 | sStr = '%#x (%d)' % (hrLong, hrLong);
|
---|
327 | return sStr;
|
---|
328 |
|
---|
329 |
|
---|
330 | class Build(object): # pylint: disable=R0903
|
---|
331 | """
|
---|
332 | A VirtualBox build.
|
---|
333 |
|
---|
334 | Note! After dropping the installation of VBox from this code and instead
|
---|
335 | realizing that with the vboxinstall.py wrapper driver, this class is
|
---|
336 | of much less importance and contains unnecessary bits and pieces.
|
---|
337 | """
|
---|
338 |
|
---|
339 | def __init__(self, oDriver, strInstallPath):
|
---|
340 | """
|
---|
341 | Construct a build object from a build file name and/or install path.
|
---|
342 | """
|
---|
343 | # Initialize all members first.
|
---|
344 | self.oDriver = oDriver;
|
---|
345 | self.sInstallPath = strInstallPath;
|
---|
346 | self.sSdkPath = None;
|
---|
347 | self.sSrcRoot = None;
|
---|
348 | self.sKind = None;
|
---|
349 | self.sDesignation = None;
|
---|
350 | self.sType = None;
|
---|
351 | self.sOs = None;
|
---|
352 | self.sArch = None;
|
---|
353 | self.sGuestAdditionsIso = None;
|
---|
354 |
|
---|
355 | # Figure out the values as best we can.
|
---|
356 | if strInstallPath is None:
|
---|
357 | #
|
---|
358 | # Both parameters are None, which means we're falling back on a
|
---|
359 | # build in the development tree.
|
---|
360 | #
|
---|
361 | self.sKind = "development";
|
---|
362 |
|
---|
363 | if self.sType is None:
|
---|
364 | self.sType = os.environ.get("KBUILD_TYPE", os.environ.get("BUILD_TYPE", "release"));
|
---|
365 | if self.sOs is None:
|
---|
366 | self.sOs = os.environ.get("KBUILD_TARGET", os.environ.get("BUILD_TARGET", oDriver.sHost));
|
---|
367 | if self.sArch is None:
|
---|
368 | self.sArch = os.environ.get("KBUILD_TARGET_ARCH", os.environ.get("BUILD_TARGET_ARCH", oDriver.sHostArch));
|
---|
369 |
|
---|
370 | sOut = os.path.join('out', self.sOs + '.' + self.sArch, self.sType);
|
---|
371 | sSearch = os.environ.get('VBOX_TD_DEV_TREE', os.path.dirname(__file__)); # Env.var. for older trees or testboxscript.
|
---|
372 | sCandidat = None;
|
---|
373 | for i in range(0, 10): # pylint: disable=W0612
|
---|
374 | sBldDir = os.path.join(sSearch, sOut);
|
---|
375 | if os.path.isdir(sBldDir):
|
---|
376 | sCandidat = os.path.join(sBldDir, 'bin', 'VBoxSVC' + base.exeSuff());
|
---|
377 | if os.path.isfile(sCandidat):
|
---|
378 | self.sSdkPath = os.path.join(sBldDir, 'bin/sdk');
|
---|
379 | break;
|
---|
380 | sCandidat = os.path.join(sBldDir, 'dist/VirtualBox.app/Contents/MacOS/VBoxSVC');
|
---|
381 | if os.path.isfile(sCandidat):
|
---|
382 | self.sSdkPath = os.path.join(sBldDir, 'dist/sdk');
|
---|
383 | break;
|
---|
384 | sSearch = os.path.abspath(os.path.join(sSearch, '..'));
|
---|
385 | if sCandidat is None or not os.path.isfile(sCandidat):
|
---|
386 | raise base.GenError();
|
---|
387 | self.sInstallPath = os.path.abspath(os.path.dirname(sCandidat));
|
---|
388 | self.sSrcRoot = os.path.abspath(sSearch);
|
---|
389 |
|
---|
390 | self.sDesignation = os.environ.get('TEST_BUILD_DESIGNATION', None);
|
---|
391 | if self.sDesignation is None:
|
---|
392 | try:
|
---|
393 | oFile = utils.openNoInherit(os.path.join(self.sSrcRoot, sOut, 'revision.kmk'), 'r');
|
---|
394 | except:
|
---|
395 | pass;
|
---|
396 | else:
|
---|
397 | s = oFile.readline();
|
---|
398 | oFile.close();
|
---|
399 | oMatch = re.search("VBOX_SVN_REV=(\\d+)", s);
|
---|
400 | if oMatch is not None:
|
---|
401 | self.sDesignation = oMatch.group(1);
|
---|
402 |
|
---|
403 | if self.sDesignation is None:
|
---|
404 | self.sDesignation = 'XXXXX'
|
---|
405 | else:
|
---|
406 | #
|
---|
407 | # We've been pointed to an existing installation, this could be
|
---|
408 | # in the out dir of a svn checkout, untarred VBoxAll or a real
|
---|
409 | # installation directory.
|
---|
410 | #
|
---|
411 | self.sKind = "preinstalled";
|
---|
412 | self.sType = "release";
|
---|
413 | self.sOs = oDriver.sHost;
|
---|
414 | self.sArch = oDriver.sHostArch;
|
---|
415 | self.sInstallPath = os.path.abspath(strInstallPath);
|
---|
416 | self.sSdkPath = os.path.join(self.sInstallPath, 'sdk');
|
---|
417 | self.sSrcRoot = None;
|
---|
418 | self.sDesignation = os.environ.get('TEST_BUILD_DESIGNATION', 'XXXXX');
|
---|
419 | ## @todo Much more work is required here.
|
---|
420 |
|
---|
421 | # Do some checks.
|
---|
422 | sVMMR0 = os.path.join(self.sInstallPath, 'VMMR0.r0');
|
---|
423 | if not os.path.isfile(sVMMR0) and utils.getHostOs() == 'solaris': # solaris is special.
|
---|
424 | sVMMR0 = os.path.join(self.sInstallPath, 'amd64' if utils.getHostArch() == 'amd64' else 'i386', 'VMMR0.r0');
|
---|
425 | if not os.path.isfile(sVMMR0):
|
---|
426 | raise base.GenError('%s is missing' % (sVMMR0,));
|
---|
427 |
|
---|
428 | # Guest additions location is different on windows for some _stupid_ reason.
|
---|
429 | if self.sOs == 'win' and self.sKind != 'development':
|
---|
430 | self.sGuestAdditionsIso = '%s/VBoxGuestAdditions.iso' % (self.sInstallPath,);
|
---|
431 | elif self.sOs == 'darwin':
|
---|
432 | self.sGuestAdditionsIso = '%s/VBoxGuestAdditions.iso' % (self.sInstallPath,);
|
---|
433 | elif self.sOs == 'solaris':
|
---|
434 | self.sGuestAdditionsIso = '%s/VBoxGuestAdditions.iso' % (self.sInstallPath,);
|
---|
435 | else:
|
---|
436 | self.sGuestAdditionsIso = '%s/additions/VBoxGuestAdditions.iso' % (self.sInstallPath,);
|
---|
437 |
|
---|
438 | # __init__ end;
|
---|
439 |
|
---|
440 | def isDevBuild(self):
|
---|
441 | """ Returns True if it's development build (kind), otherwise False. """
|
---|
442 | return self.sKind == 'development';
|
---|
443 |
|
---|
444 |
|
---|
445 | class EventHandlerBase(object):
|
---|
446 | """
|
---|
447 | Base class for both Console and VirtualBox event handlers.
|
---|
448 | """
|
---|
449 |
|
---|
450 | def __init__(self, dArgs, fpApiVer, sName = None):
|
---|
451 | self.oVBoxMgr = dArgs['oVBoxMgr'];
|
---|
452 | self.oEventSrc = dArgs['oEventSrc']; # Console/VirtualBox for < 3.3
|
---|
453 | self.oListener = dArgs['oListener'];
|
---|
454 | self.fPassive = self.oListener != None;
|
---|
455 | self.sName = sName
|
---|
456 | self.fShutdown = False;
|
---|
457 | self.oThread = None;
|
---|
458 | self.fpApiVer = fpApiVer;
|
---|
459 | self.dEventNo2Name = {};
|
---|
460 | for sKey, iValue in self.oVBoxMgr.constants.all_values('VBoxEventType').items():
|
---|
461 | self.dEventNo2Name[iValue] = sKey;
|
---|
462 |
|
---|
463 | def threadForPassiveMode(self):
|
---|
464 | """
|
---|
465 | The thread procedure for the event processing thread.
|
---|
466 | """
|
---|
467 | assert self.fPassive is not None;
|
---|
468 | while not self.fShutdown:
|
---|
469 | try:
|
---|
470 | oEvt = self.oEventSrc.getEvent(self.oListener, 500);
|
---|
471 | except:
|
---|
472 | if not self.oVBoxMgr.xcptIsDeadInterface(): reporter.logXcpt();
|
---|
473 | else: reporter.log('threadForPassiveMode/%s: interface croaked (ignored)' % (self.sName,));
|
---|
474 | break;
|
---|
475 | if oEvt:
|
---|
476 | self.handleEvent(oEvt);
|
---|
477 | if not self.fShutdown:
|
---|
478 | try:
|
---|
479 | self.oEventSrc.eventProcessed(self.oListener, oEvt);
|
---|
480 | except:
|
---|
481 | reporter.logXcpt();
|
---|
482 | break;
|
---|
483 | self.unregister(fWaitForThread = False);
|
---|
484 | return None;
|
---|
485 |
|
---|
486 | def startThreadForPassiveMode(self):
|
---|
487 | """
|
---|
488 | Called when working in passive mode.
|
---|
489 | """
|
---|
490 | self.oThread = threading.Thread(target = self.threadForPassiveMode, \
|
---|
491 | args=(), name=('PAS-%s' % (self.sName,)));
|
---|
492 | self.oThread.setDaemon(True)
|
---|
493 | self.oThread.start();
|
---|
494 | return None;
|
---|
495 |
|
---|
496 | def unregister(self, fWaitForThread = True):
|
---|
497 | """
|
---|
498 | Unregister the event handler.
|
---|
499 | """
|
---|
500 | fRc = False;
|
---|
501 | if not self.fShutdown:
|
---|
502 | self.fShutdown = True;
|
---|
503 |
|
---|
504 | if self.oEventSrc is not None:
|
---|
505 | if self.fpApiVer < 3.3:
|
---|
506 | try:
|
---|
507 | self.oEventSrc.unregisterCallback(self.oListener);
|
---|
508 | fRc = True;
|
---|
509 | except:
|
---|
510 | reporter.errorXcpt('unregisterCallback failed on %s' % (self.oListener,));
|
---|
511 | else:
|
---|
512 | try:
|
---|
513 | self.oEventSrc.unregisterListener(self.oListener);
|
---|
514 | fRc = True;
|
---|
515 | except:
|
---|
516 | if self.oVBoxMgr.xcptIsDeadInterface():
|
---|
517 | reporter.log('unregisterListener failed on %s because of dead interface (%s)'
|
---|
518 | % (self.oListener, self.oVBoxMgr.xcptToString(),));
|
---|
519 | else:
|
---|
520 | reporter.errorXcpt('unregisterListener failed on %s' % (self.oListener,));
|
---|
521 |
|
---|
522 | if self.oThread is not None \
|
---|
523 | and self.oThread != threading.current_thread():
|
---|
524 | self.oThread.join();
|
---|
525 | self.oThread = None;
|
---|
526 |
|
---|
527 | _ = fWaitForThread;
|
---|
528 | return fRc;
|
---|
529 |
|
---|
530 | def handleEvent(self, oEvt):
|
---|
531 | """
|
---|
532 | Compatibility wrapper that child classes implement.
|
---|
533 | """
|
---|
534 | _ = oEvt;
|
---|
535 | return None;
|
---|
536 |
|
---|
537 | @staticmethod
|
---|
538 | def registerDerivedEventHandler(oVBoxMgr, fpApiVer, oSubClass, dArgsCopy,
|
---|
539 | oSrcParent, sSrcParentNm, sICallbackNm,
|
---|
540 | fMustSucceed = True, sLogSuffix = ''):
|
---|
541 | """
|
---|
542 | Registers the callback / event listener.
|
---|
543 | """
|
---|
544 | dArgsCopy['oVBoxMgr'] = oVBoxMgr;
|
---|
545 | dArgsCopy['oListener'] = None;
|
---|
546 | if fpApiVer < 3.3:
|
---|
547 | dArgsCopy['oEventSrc'] = oSrcParent;
|
---|
548 | try:
|
---|
549 | oRet = oVBoxMgr.createCallback(sICallbackNm, oSubClass, dArgsCopy);
|
---|
550 | except:
|
---|
551 | reporter.errorXcpt('%s::registerCallback(%s) failed%s' % (sSrcParentNm, oRet, sLogSuffix));
|
---|
552 | else:
|
---|
553 | try:
|
---|
554 | oSrcParent.registerCallback(oRet);
|
---|
555 | return oRet;
|
---|
556 | except Exception as oXcpt:
|
---|
557 | if fMustSucceed or ComError.notEqual(oXcpt, ComError.E_UNEXPECTED):
|
---|
558 | reporter.errorXcpt('%s::registerCallback(%s)%s' % (sSrcParentNm, oRet, sLogSuffix));
|
---|
559 | else:
|
---|
560 | fPassive = sys.platform == 'win32'; # or webservices.
|
---|
561 | try:
|
---|
562 | oEventSrc = oSrcParent.eventSource;
|
---|
563 | dArgsCopy['oEventSrc'] = oEventSrc;
|
---|
564 | if not fPassive:
|
---|
565 | oListener = oRet = oVBoxMgr.createListener(oSubClass, dArgsCopy);
|
---|
566 | else:
|
---|
567 | oListener = oEventSrc.createListener();
|
---|
568 | dArgsCopy['oListener'] = oListener;
|
---|
569 | oRet = oSubClass(dArgsCopy);
|
---|
570 | except:
|
---|
571 | reporter.errorXcpt('%s::eventSource.createListener(%s) failed%s' % (sSrcParentNm, oListener, sLogSuffix));
|
---|
572 | else:
|
---|
573 | try:
|
---|
574 | oEventSrc.registerListener(oListener, [vboxcon.VBoxEventType_Any], not fPassive);
|
---|
575 | except Exception as oXcpt:
|
---|
576 | if fMustSucceed or ComError.notEqual(oXcpt, ComError.E_UNEXPECTED):
|
---|
577 | reporter.errorXcpt('%s::eventSource.registerListener(%s) failed%s' \
|
---|
578 | % (sSrcParentNm, oListener, sLogSuffix));
|
---|
579 | else:
|
---|
580 | if not fPassive:
|
---|
581 | if sys.platform == 'win32':
|
---|
582 | from win32com.server.util import unwrap # pylint: disable=import-error
|
---|
583 | oRet = unwrap(oRet);
|
---|
584 | oRet.oListener = oListener;
|
---|
585 | else:
|
---|
586 | oRet.startThreadForPassiveMode();
|
---|
587 | return oRet;
|
---|
588 | return None;
|
---|
589 |
|
---|
590 |
|
---|
591 |
|
---|
592 |
|
---|
593 | class ConsoleEventHandlerBase(EventHandlerBase):
|
---|
594 | """
|
---|
595 | Base class for handling IConsole events.
|
---|
596 |
|
---|
597 | The class has IConsoleCallback (<=3.2) compatible callback methods which
|
---|
598 | the user can override as needed.
|
---|
599 |
|
---|
600 | Note! This class must not inherit from object or we'll get type errors in VBoxPython.
|
---|
601 | """
|
---|
602 | def __init__(self, dArgs, sName = None):
|
---|
603 | self.oSession = dArgs['oSession'];
|
---|
604 | self.oConsole = dArgs['oConsole'];
|
---|
605 | if sName is None:
|
---|
606 | sName = self.oSession.sName;
|
---|
607 | EventHandlerBase.__init__(self, dArgs, self.oSession.fpApiVer, sName);
|
---|
608 |
|
---|
609 |
|
---|
610 | # pylint: disable=C0111,R0913,W0613
|
---|
611 | def onMousePointerShapeChange(self, fVisible, fAlpha, xHot, yHot, cx, cy, abShape):
|
---|
612 | reporter.log2('onMousePointerShapeChange/%s' % (self.sName));
|
---|
613 | def onMouseCapabilityChange(self, fSupportsAbsolute, *aArgs): # Extra argument was added in 3.2.
|
---|
614 | reporter.log2('onMouseCapabilityChange/%s' % (self.sName));
|
---|
615 | def onKeyboardLedsChange(self, fNumLock, fCapsLock, fScrollLock):
|
---|
616 | reporter.log2('onKeyboardLedsChange/%s' % (self.sName));
|
---|
617 | def onStateChange(self, eState):
|
---|
618 | reporter.log2('onStateChange/%s' % (self.sName));
|
---|
619 | def onAdditionsStateChange(self):
|
---|
620 | reporter.log2('onAdditionsStateChange/%s' % (self.sName));
|
---|
621 | def onNetworkAdapterChange(self, oNic):
|
---|
622 | reporter.log2('onNetworkAdapterChange/%s' % (self.sName));
|
---|
623 | def onSerialPortChange(self, oPort):
|
---|
624 | reporter.log2('onSerialPortChange/%s' % (self.sName));
|
---|
625 | def onParallelPortChange(self, oPort):
|
---|
626 | reporter.log2('onParallelPortChange/%s' % (self.sName));
|
---|
627 | def onStorageControllerChange(self):
|
---|
628 | reporter.log2('onStorageControllerChange/%s' % (self.sName));
|
---|
629 | def onMediumChange(self, attachment):
|
---|
630 | reporter.log2('onMediumChange/%s' % (self.sName));
|
---|
631 | def onCPUChange(self, iCpu, fAdd):
|
---|
632 | reporter.log2('onCPUChange/%s' % (self.sName));
|
---|
633 | def onVRDPServerChange(self):
|
---|
634 | reporter.log2('onVRDPServerChange/%s' % (self.sName));
|
---|
635 | def onRemoteDisplayInfoChange(self):
|
---|
636 | reporter.log2('onRemoteDisplayInfoChange/%s' % (self.sName));
|
---|
637 | def onUSBControllerChange(self):
|
---|
638 | reporter.log2('onUSBControllerChange/%s' % (self.sName));
|
---|
639 | def onUSBDeviceStateChange(self, oDevice, fAttached, oError):
|
---|
640 | reporter.log2('onUSBDeviceStateChange/%s' % (self.sName));
|
---|
641 | def onSharedFolderChange(self, fGlobal):
|
---|
642 | reporter.log2('onSharedFolderChange/%s' % (self.sName));
|
---|
643 | def onRuntimeError(self, fFatal, sErrId, sMessage):
|
---|
644 | reporter.log2('onRuntimeError/%s' % (self.sName));
|
---|
645 | def onCanShowWindow(self):
|
---|
646 | reporter.log2('onCanShowWindow/%s' % (self.sName));
|
---|
647 | return True
|
---|
648 | def onShowWindow(self):
|
---|
649 | reporter.log2('onShowWindow/%s' % (self.sName));
|
---|
650 | return None;
|
---|
651 | # pylint: enable=C0111,R0913,W0613
|
---|
652 |
|
---|
653 | def handleEvent(self, oEvt):
|
---|
654 | """
|
---|
655 | Compatibility wrapper.
|
---|
656 | """
|
---|
657 | try:
|
---|
658 | oEvtBase = self.oVBoxMgr.queryInterface(oEvt, 'IEvent');
|
---|
659 | eType = oEvtBase.type;
|
---|
660 | except:
|
---|
661 | reporter.logXcpt();
|
---|
662 | return None;
|
---|
663 | if eType == vboxcon.VBoxEventType_OnRuntimeError:
|
---|
664 | try:
|
---|
665 | oEvtIt = self.oVBoxMgr.queryInterface(oEvtBase, 'IRuntimeErrorEvent');
|
---|
666 | return self.onRuntimeError(oEvtIt.fatal, oEvtIt.id, oEvtIt.message)
|
---|
667 | except:
|
---|
668 | reporter.logXcpt();
|
---|
669 | ## @todo implement the other events.
|
---|
670 | if eType != vboxcon.VBoxEventType_OnMousePointerShapeChanged:
|
---|
671 | if eType in self.dEventNo2Name:
|
---|
672 | reporter.log2('%s(%s)/%s' % (self.dEventNo2Name[eType], str(eType), self.sName));
|
---|
673 | else:
|
---|
674 | reporter.log2('%s/%s' % (str(eType), self.sName));
|
---|
675 | return None;
|
---|
676 |
|
---|
677 |
|
---|
678 | class VirtualBoxEventHandlerBase(EventHandlerBase):
|
---|
679 | """
|
---|
680 | Base class for handling IVirtualBox events.
|
---|
681 |
|
---|
682 | The class has IConsoleCallback (<=3.2) compatible callback methods which
|
---|
683 | the user can override as needed.
|
---|
684 |
|
---|
685 | Note! This class must not inherit from object or we'll get type errors in VBoxPython.
|
---|
686 | """
|
---|
687 | def __init__(self, dArgs, sName = "emanon"):
|
---|
688 | self.oVBoxMgr = dArgs['oVBoxMgr'];
|
---|
689 | self.oVBox = dArgs['oVBox'];
|
---|
690 | EventHandlerBase.__init__(self, dArgs, self.oVBox.fpApiVer, sName);
|
---|
691 |
|
---|
692 | # pylint: disable=C0111,W0613
|
---|
693 | def onMachineStateChange(self, sMachineId, eState):
|
---|
694 | pass;
|
---|
695 | def onMachineDataChange(self, sMachineId):
|
---|
696 | pass;
|
---|
697 | def onExtraDataCanChange(self, sMachineId, sKey, sValue):
|
---|
698 | # The COM bridge does tuples differently. Not very funny if you ask me... ;-)
|
---|
699 | if self.oVBoxMgr.type == 'MSCOM':
|
---|
700 | return '', 0, True;
|
---|
701 | return True, ''
|
---|
702 | def onExtraDataChange(self, sMachineId, sKey, sValue):
|
---|
703 | pass;
|
---|
704 | def onMediumRegistered(self, sMediumId, eMediumType, fRegistered):
|
---|
705 | pass;
|
---|
706 | def onMachineRegistered(self, sMachineId, fRegistered):
|
---|
707 | pass;
|
---|
708 | def onSessionStateChange(self, sMachineId, eState):
|
---|
709 | pass;
|
---|
710 | def onSnapshotTaken(self, sMachineId, sSnapshotId):
|
---|
711 | pass;
|
---|
712 | def onSnapshotDiscarded(self, sMachineId, sSnapshotId):
|
---|
713 | pass;
|
---|
714 | def onSnapshotChange(self, sMachineId, sSnapshotId):
|
---|
715 | pass;
|
---|
716 | def onGuestPropertyChange(self, sMachineId, sName, sValue, sFlags):
|
---|
717 | pass;
|
---|
718 | # pylint: enable=C0111,W0613
|
---|
719 |
|
---|
720 | def handleEvent(self, oEvt):
|
---|
721 | """
|
---|
722 | Compatibility wrapper.
|
---|
723 | """
|
---|
724 | try:
|
---|
725 | oEvtBase = self.oVBoxMgr.queryInterface(oEvt, 'IEvent');
|
---|
726 | eType = oEvtBase.type;
|
---|
727 | except:
|
---|
728 | reporter.logXcpt();
|
---|
729 | return None;
|
---|
730 | if eType == vboxcon.VBoxEventType_OnMachineStateChanged:
|
---|
731 | try:
|
---|
732 | oEvtIt = self.oVBoxMgr.queryInterface(oEvtBase, 'IMachineStateChangedEvent');
|
---|
733 | return self.onMachineStateChange(oEvtIt.machineId, oEvtIt.state)
|
---|
734 | except:
|
---|
735 | reporter.logXcpt();
|
---|
736 | elif eType == vboxcon.VBoxEventType_OnGuestPropertyChanged:
|
---|
737 | try:
|
---|
738 | oEvtIt = self.oVBoxMgr.queryInterface(oEvtBase, 'IGuestPropertyChangedEvent');
|
---|
739 | return self.onGuestPropertyChange(oEvtIt.machineId, oEvtIt.name, oEvtIt.value, oEvtIt.flags);
|
---|
740 | except:
|
---|
741 | reporter.logXcpt();
|
---|
742 | ## @todo implement the other events.
|
---|
743 | if eType in self.dEventNo2Name:
|
---|
744 | reporter.log2('%s(%s)/%s' % (self.dEventNo2Name[eType], str(eType), self.sName));
|
---|
745 | else:
|
---|
746 | reporter.log2('%s/%s' % (str(eType), self.sName));
|
---|
747 | return None;
|
---|
748 |
|
---|
749 |
|
---|
750 | class SessionConsoleEventHandler(ConsoleEventHandlerBase):
|
---|
751 | """
|
---|
752 | For catching machine state changes and waking up the task machinery at that point.
|
---|
753 | """
|
---|
754 | def __init__(self, dArgs):
|
---|
755 | ConsoleEventHandlerBase.__init__(self, dArgs);
|
---|
756 |
|
---|
757 | def onMachineStateChange(self, sMachineId, eState): # pylint: disable=W0613
|
---|
758 | """ Just interrupt the wait loop here so it can check again. """
|
---|
759 | _ = sMachineId; _ = eState;
|
---|
760 | self.oVBoxMgr.interruptWaitEvents();
|
---|
761 |
|
---|
762 | def onRuntimeError(self, fFatal, sErrId, sMessage):
|
---|
763 | reporter.log('onRuntimeError/%s: fFatal=%d sErrId=%s sMessage=%s' % (self.sName, fFatal, sErrId, sMessage));
|
---|
764 | oSession = self.oSession;
|
---|
765 | if oSession is not None: # paranoia
|
---|
766 | if sErrId == 'HostMemoryLow':
|
---|
767 | oSession.signalHostMemoryLow();
|
---|
768 | if sys.platform == 'win32':
|
---|
769 | from testdriver import winbase;
|
---|
770 | winbase.logMemoryStats();
|
---|
771 | oSession.signalTask();
|
---|
772 | self.oVBoxMgr.interruptWaitEvents();
|
---|
773 |
|
---|
774 |
|
---|
775 |
|
---|
776 | class TestDriver(base.TestDriver): # pylint: disable=R0902
|
---|
777 | """
|
---|
778 | This is the VirtualBox test driver.
|
---|
779 | """
|
---|
780 |
|
---|
781 | def __init__(self):
|
---|
782 | base.TestDriver.__init__(self);
|
---|
783 | self.fImportedVBoxApi = False;
|
---|
784 | self.fpApiVer = 3.2;
|
---|
785 | self.oBuild = None;
|
---|
786 | self.oVBoxMgr = None;
|
---|
787 | self.oVBox = None;
|
---|
788 | self.aoRemoteSessions = [];
|
---|
789 | self.aoVMs = []; ## @todo not sure if this list will be of any use.
|
---|
790 | self.oTestVmManager = vboxtestvms.TestVmManager(self.sResourcePath);
|
---|
791 | self.oTestVmSet = vboxtestvms.TestVmSet();
|
---|
792 | self.sSessionTypeDef = 'headless';
|
---|
793 | self.sSessionType = self.sSessionTypeDef;
|
---|
794 | self.fEnableVrdp = True;
|
---|
795 | self.uVrdpBasePortDef = 6000;
|
---|
796 | self.uVrdpBasePort = self.uVrdpBasePortDef;
|
---|
797 | self.sDefBridgedNic = None;
|
---|
798 | self.fUseDefaultSvc = False;
|
---|
799 | self.sLogSelfGroups = '';
|
---|
800 | self.sLogSelfFlags = 'time';
|
---|
801 | self.sLogSelfDest = '';
|
---|
802 | self.sLogSessionGroups = '';
|
---|
803 | self.sLogSessionFlags = 'time';
|
---|
804 | self.sLogSessionDest = '';
|
---|
805 | self.sLogSvcGroups = '';
|
---|
806 | self.sLogSvcFlags = 'time';
|
---|
807 | self.sLogSvcDest = '';
|
---|
808 | self.sSelfLogFile = None;
|
---|
809 | self.sVBoxSvcLogFile = None;
|
---|
810 | self.oVBoxSvcProcess = None;
|
---|
811 | self.sVBoxSvcPidFile = None;
|
---|
812 | self.fVBoxSvcInDebugger = False;
|
---|
813 | self.sVBoxValidationKit = None;
|
---|
814 | self.sVBoxValidationKitIso = None;
|
---|
815 | self.sVBoxBootSectors = None;
|
---|
816 | self.fAlwaysUploadLogs = False;
|
---|
817 | self.fAlwaysUploadScreenshots = False;
|
---|
818 | self.fEnableDebugger = True;
|
---|
819 |
|
---|
820 | # Quietly detect build and validation kit.
|
---|
821 | self._detectBuild(False);
|
---|
822 | self._detectValidationKit(False);
|
---|
823 |
|
---|
824 | # Make sure all debug logs goes to the scratch area unless
|
---|
825 | # specified otherwise (more of this later on).
|
---|
826 | if 'VBOX_LOG_DEST' not in os.environ:
|
---|
827 | os.environ['VBOX_LOG_DEST'] = 'nodeny dir=%s' % (self.sScratchPath);
|
---|
828 |
|
---|
829 |
|
---|
830 | def _detectBuild(self, fQuiet = False):
|
---|
831 | """
|
---|
832 | This is used internally to try figure a locally installed build when
|
---|
833 | running tests manually.
|
---|
834 | """
|
---|
835 | if self.oBuild is not None:
|
---|
836 | return True;
|
---|
837 |
|
---|
838 | # Try dev build first since that's where I'll be using it first...
|
---|
839 | if True is True:
|
---|
840 | try:
|
---|
841 | self.oBuild = Build(self, None);
|
---|
842 | return True;
|
---|
843 | except base.GenError:
|
---|
844 | pass;
|
---|
845 |
|
---|
846 | # Try default installation locations.
|
---|
847 | if self.sHost == 'win':
|
---|
848 | sProgFiles = os.environ.get('ProgramFiles', 'C:\\Program Files');
|
---|
849 | asLocs = [
|
---|
850 | os.path.join(sProgFiles, 'Oracle', 'VirtualBox'),
|
---|
851 | os.path.join(sProgFiles, 'OracleVM', 'VirtualBox'),
|
---|
852 | os.path.join(sProgFiles, 'Sun', 'VirtualBox'),
|
---|
853 | ];
|
---|
854 | elif self.sHost == 'solaris':
|
---|
855 | asLocs = [ '/opt/VirtualBox-3.2', '/opt/VirtualBox-3.1', '/opt/VirtualBox-3.0', '/opt/VirtualBox' ];
|
---|
856 | elif self.sHost == 'darwin':
|
---|
857 | asLocs = [ '/Applications/VirtualBox.app/Contents/MacOS' ];
|
---|
858 | elif self.sHost == 'linux':
|
---|
859 | asLocs = [ '/opt/VirtualBox-3.2', '/opt/VirtualBox-3.1', '/opt/VirtualBox-3.0', '/opt/VirtualBox' ];
|
---|
860 | else:
|
---|
861 | asLocs = [ '/opt/VirtualBox' ];
|
---|
862 | if 'VBOX_INSTALL_PATH' in os.environ:
|
---|
863 | asLocs.insert(0, os.environ['VBOX_INSTALL_PATH']);
|
---|
864 |
|
---|
865 | for sLoc in asLocs:
|
---|
866 | try:
|
---|
867 | self.oBuild = Build(self, sLoc);
|
---|
868 | return True;
|
---|
869 | except base.GenError:
|
---|
870 | pass;
|
---|
871 |
|
---|
872 | if not fQuiet:
|
---|
873 | reporter.error('failed to find VirtualBox installation');
|
---|
874 | return False;
|
---|
875 |
|
---|
876 | def _detectValidationKit(self, fQuiet = False):
|
---|
877 | """
|
---|
878 | This is used internally by the constructor to try locate an unzipped
|
---|
879 | VBox Validation Kit somewhere in the immediate proximity.
|
---|
880 | """
|
---|
881 | if self.sVBoxValidationKit is not None:
|
---|
882 | return True;
|
---|
883 |
|
---|
884 | #
|
---|
885 | # Normally it's found where we're running from, which is the same as
|
---|
886 | # the script directly on the testboxes.
|
---|
887 | #
|
---|
888 | asCandidates = [self.sScriptPath, ];
|
---|
889 | if g_ksValidationKitDir not in asCandidates:
|
---|
890 | asCandidates.append(g_ksValidationKitDir);
|
---|
891 | if os.getcwd() not in asCandidates:
|
---|
892 | asCandidates.append(os.getcwd());
|
---|
893 | if self.oBuild is not None and self.oBuild.sInstallPath not in asCandidates:
|
---|
894 | asCandidates.append(self.oBuild.sInstallPath);
|
---|
895 |
|
---|
896 | #
|
---|
897 | # When working out of the tree, we'll search the current directory
|
---|
898 | # as well as parent dirs.
|
---|
899 | #
|
---|
900 | for sDir in list(asCandidates):
|
---|
901 | for i in range(10):
|
---|
902 | sDir = os.path.dirname(sDir);
|
---|
903 | if sDir not in asCandidates:
|
---|
904 | asCandidates.append(sDir);
|
---|
905 |
|
---|
906 | #
|
---|
907 | # Do the searching.
|
---|
908 | #
|
---|
909 | sCandidate = None;
|
---|
910 | for i, _ in enumerate(asCandidates):
|
---|
911 | sCandidate = asCandidates[i];
|
---|
912 | if os.path.isfile(os.path.join(sCandidate, 'VBoxValidationKit.iso')):
|
---|
913 | break;
|
---|
914 | sCandidate = os.path.join(sCandidate, 'validationkit');
|
---|
915 | if os.path.isfile(os.path.join(sCandidate, 'VBoxValidationKit.iso')):
|
---|
916 | break;
|
---|
917 | sCandidate = None;
|
---|
918 |
|
---|
919 | fRc = sCandidate is not None;
|
---|
920 | if fRc is False:
|
---|
921 | if not fQuiet:
|
---|
922 | reporter.error('failed to find VBox Validation Kit installation (candidates: %s)' % (asCandidates,));
|
---|
923 | sCandidate = os.path.join(self.sScriptPath, 'validationkit'); # Don't leave the values as None.
|
---|
924 |
|
---|
925 | #
|
---|
926 | # Set the member values.
|
---|
927 | #
|
---|
928 | self.sVBoxValidationKit = sCandidate;
|
---|
929 | self.sVBoxValidationKitIso = os.path.join(sCandidate, 'VBoxValidationKit.iso');
|
---|
930 | self.sVBoxBootSectors = os.path.join(sCandidate, 'bootsectors');
|
---|
931 | return fRc;
|
---|
932 |
|
---|
933 | def _makeEnvironmentChanges(self):
|
---|
934 | """
|
---|
935 | Make the necessary VBox related environment changes.
|
---|
936 | Children not importing the VBox API should call this.
|
---|
937 | """
|
---|
938 | # Make sure we've got our own VirtualBox config and VBoxSVC (on XPCOM at least).
|
---|
939 | if not self.fUseDefaultSvc:
|
---|
940 | os.environ['VBOX_USER_HOME'] = os.path.join(self.sScratchPath, 'VBoxUserHome');
|
---|
941 | sUser = os.environ.get('USERNAME', os.environ.get('USER', os.environ.get('LOGNAME', 'unknown')));
|
---|
942 | os.environ['VBOX_IPC_SOCKETID'] = sUser + '-VBoxTest';
|
---|
943 | return True;
|
---|
944 |
|
---|
945 | def importVBoxApi(self):
|
---|
946 | """
|
---|
947 | Import the 'vboxapi' module from the VirtualBox build we're using and
|
---|
948 | instantiate the two basic objects.
|
---|
949 |
|
---|
950 | This will try detect an development or installed build if no build has
|
---|
951 | been associated with the driver yet.
|
---|
952 | """
|
---|
953 | if self.fImportedVBoxApi:
|
---|
954 | return True;
|
---|
955 |
|
---|
956 | self._makeEnvironmentChanges();
|
---|
957 |
|
---|
958 | # Do the detecting.
|
---|
959 | self._detectBuild();
|
---|
960 | if self.oBuild is None:
|
---|
961 | return False;
|
---|
962 |
|
---|
963 | # Avoid crashing when loading the 32-bit module (or whatever it is that goes bang).
|
---|
964 | if self.oBuild.sArch == 'x86' \
|
---|
965 | and self.sHost == 'darwin' \
|
---|
966 | and platform.architecture()[0] == '64bit' \
|
---|
967 | and self.oBuild.sKind == 'development' \
|
---|
968 | and os.getenv('VERSIONER_PYTHON_PREFER_32_BIT') != 'yes':
|
---|
969 | reporter.log("WARNING: 64-bit python on darwin, 32-bit VBox development build => crash");
|
---|
970 | reporter.log("WARNING: bash-3.2$ /usr/bin/python2.5 ./testdriver");
|
---|
971 | reporter.log("WARNING: or");
|
---|
972 | reporter.log("WARNING: bash-3.2$ VERSIONER_PYTHON_PREFER_32_BIT=yes ./testdriver");
|
---|
973 | return False;
|
---|
974 |
|
---|
975 | # Start VBoxSVC and load the vboxapi bits.
|
---|
976 | if self._startVBoxSVC() is True:
|
---|
977 | assert(self.oVBoxSvcProcess is not None);
|
---|
978 |
|
---|
979 | sSavedSysPath = sys.path;
|
---|
980 | self._setupVBoxApi();
|
---|
981 | sys.path = sSavedSysPath;
|
---|
982 |
|
---|
983 | # Adjust the default machine folder.
|
---|
984 | if self.fImportedVBoxApi and not self.fUseDefaultSvc and self.fpApiVer >= 4.0:
|
---|
985 | sNewFolder = os.path.join(self.sScratchPath, 'VBoxUserHome', 'Machines');
|
---|
986 | try:
|
---|
987 | self.oVBox.systemProperties.defaultMachineFolder = sNewFolder;
|
---|
988 | except:
|
---|
989 | self.fImportedVBoxApi = False;
|
---|
990 | self.oVBoxMgr = None;
|
---|
991 | self.oVBox = None;
|
---|
992 | reporter.logXcpt("defaultMachineFolder exception (sNewFolder=%s)" % (sNewFolder,));
|
---|
993 |
|
---|
994 | # Kill VBoxSVC on failure.
|
---|
995 | if self.oVBoxMgr is None:
|
---|
996 | self._stopVBoxSVC();
|
---|
997 | else:
|
---|
998 | assert(self.oVBoxSvcProcess is None);
|
---|
999 | return self.fImportedVBoxApi;
|
---|
1000 |
|
---|
1001 | def _startVBoxSVC(self): # pylint: disable=R0915
|
---|
1002 | """ Starts VBoxSVC. """
|
---|
1003 | assert(self.oVBoxSvcProcess is None);
|
---|
1004 |
|
---|
1005 | # Setup vbox logging for VBoxSVC now and start it manually. This way
|
---|
1006 | # we can control both logging and shutdown.
|
---|
1007 | self.sVBoxSvcLogFile = '%s/VBoxSVC-debug.log' % (self.sScratchPath,);
|
---|
1008 | try: os.remove(self.sVBoxSvcLogFile);
|
---|
1009 | except: pass;
|
---|
1010 | os.environ['VBOX_LOG'] = self.sLogSvcGroups;
|
---|
1011 | os.environ['VBOX_LOG_FLAGS'] = '%s append' % (self.sLogSvcFlags,); # Append becuse of VBoxXPCOMIPCD.
|
---|
1012 | if self.sLogSvcDest:
|
---|
1013 | os.environ['VBOX_LOG_DEST'] = 'nodeny ' + self.sLogSvcDest;
|
---|
1014 | else:
|
---|
1015 | os.environ['VBOX_LOG_DEST'] = 'nodeny file=%s' % (self.sVBoxSvcLogFile,);
|
---|
1016 | os.environ['VBOXSVC_RELEASE_LOG_FLAGS'] = 'time append';
|
---|
1017 |
|
---|
1018 | # Always leave a pid file behind so we can kill it during cleanup-before.
|
---|
1019 | self.sVBoxSvcPidFile = '%s/VBoxSVC.pid' % (self.sScratchPath,);
|
---|
1020 | fWritePidFile = True;
|
---|
1021 |
|
---|
1022 | cMsFudge = 1;
|
---|
1023 | sVBoxSVC = '%s/VBoxSVC' % (self.oBuild.sInstallPath,); ## @todo .exe and stuff.
|
---|
1024 | if self.fVBoxSvcInDebugger:
|
---|
1025 | if self.sHost in ('darwin', 'freebsd', 'linux', 'solaris', ):
|
---|
1026 | # Start VBoxSVC in gdb in a new terminal.
|
---|
1027 | #sTerm = '/usr/bin/gnome-terminal'; - doesn't work, some fork+exec stuff confusing us.
|
---|
1028 | sTerm = '/usr/bin/xterm';
|
---|
1029 | if not os.path.isfile(sTerm): sTerm = '/usr/X11/bin/xterm';
|
---|
1030 | if not os.path.isfile(sTerm): sTerm = '/usr/X11R6/bin/xterm';
|
---|
1031 | if not os.path.isfile(sTerm): sTerm = '/usr/bin/xterm';
|
---|
1032 | if not os.path.isfile(sTerm): sTerm = 'xterm';
|
---|
1033 | sGdb = '/usr/bin/gdb';
|
---|
1034 | if not os.path.isfile(sGdb): sGdb = '/usr/local/bin/gdb';
|
---|
1035 | if not os.path.isfile(sGdb): sGdb = '/usr/sfw/bin/gdb';
|
---|
1036 | if not os.path.isfile(sGdb): sGdb = 'gdb';
|
---|
1037 | sGdbCmdLine = '%s --args %s --pidfile %s' % (sGdb, sVBoxSVC, self.sVBoxSvcPidFile);
|
---|
1038 | reporter.log('term="%s" gdb="%s"' % (sTerm, sGdbCmdLine));
|
---|
1039 | os.environ['SHELL'] = self.sOrgShell; # Non-working shell may cause gdb and/or the term problems.
|
---|
1040 | ## @todo -e is deprecated; use "-- <args>".
|
---|
1041 | self.oVBoxSvcProcess = base.Process.spawnp(sTerm, sTerm, '-e', sGdbCmdLine);
|
---|
1042 | os.environ['SHELL'] = self.sOurShell;
|
---|
1043 | if self.oVBoxSvcProcess is not None:
|
---|
1044 | reporter.log('Press enter or return after starting VBoxSVC in the debugger...');
|
---|
1045 | sys.stdin.read(1);
|
---|
1046 | fWritePidFile = False;
|
---|
1047 |
|
---|
1048 | elif self.sHost == 'win':
|
---|
1049 | sWinDbg = 'c:\\Program Files\\Debugging Tools for Windows\\windbg.exe';
|
---|
1050 | if not os.path.isfile(sWinDbg): sWinDbg = 'c:\\Program Files\\Debugging Tools for Windows (x64)\\windbg.exe';
|
---|
1051 | if not os.path.isfile(sWinDbg): sWinDbg = 'c:\\Programme\\Debugging Tools for Windows\\windbg.exe'; # Localization rulez! pylint: disable=C0301
|
---|
1052 | if not os.path.isfile(sWinDbg): sWinDbg = 'c:\\Programme\\Debugging Tools for Windows (x64)\\windbg.exe';
|
---|
1053 | if not os.path.isfile(sWinDbg): sWinDbg = 'windbg'; # WinDbg must be in the path; better than nothing.
|
---|
1054 | # Assume that everything WinDbg needs is defined using the environment variables.
|
---|
1055 | # See WinDbg help for more information.
|
---|
1056 | reporter.log('windbg="%s"' % (sWinDbg));
|
---|
1057 | self.oVBoxSvcProcess = base.Process.spawn(sWinDbg, sWinDbg, sVBoxSVC + base.exeSuff());
|
---|
1058 | if self.oVBoxSvcProcess is not None:
|
---|
1059 | reporter.log('Press enter or return after starting VBoxSVC in the debugger...');
|
---|
1060 | sys.stdin.read(1);
|
---|
1061 | fWritePidFile = False;
|
---|
1062 | ## @todo add a pipe interface similar to xpcom if feasible, i.e. if
|
---|
1063 | # we can get actual handle values for pipes in python.
|
---|
1064 |
|
---|
1065 | else:
|
---|
1066 | reporter.error('Port me!');
|
---|
1067 | else: # Run without a debugger attached.
|
---|
1068 | if self.sHost in ('darwin', 'freebsd', 'linux', 'solaris', ):
|
---|
1069 | #
|
---|
1070 | # XPCOM - We can use a pipe to let VBoxSVC notify us when it's ready.
|
---|
1071 | #
|
---|
1072 | iPipeR, iPipeW = os.pipe();
|
---|
1073 | if hasattr(os, 'set_inheritable'):
|
---|
1074 | os.set_inheritable(iPipeW, True); # pylint: disable=no-member
|
---|
1075 | os.environ['NSPR_INHERIT_FDS'] = 'vboxsvc:startup-pipe:5:0x%x' % (iPipeW,);
|
---|
1076 | reporter.log2("NSPR_INHERIT_FDS=%s" % (os.environ['NSPR_INHERIT_FDS']));
|
---|
1077 |
|
---|
1078 | self.oVBoxSvcProcess = base.Process.spawn(sVBoxSVC, sVBoxSVC, '--auto-shutdown'); # SIGUSR1 requirement.
|
---|
1079 | try: # Try make sure we get the SIGINT and not VBoxSVC.
|
---|
1080 | os.setpgid(self.oVBoxSvcProcess.getPid(), 0); # pylint: disable=E1101
|
---|
1081 | os.setpgid(0, 0); # pylint: disable=E1101
|
---|
1082 | except:
|
---|
1083 | reporter.logXcpt();
|
---|
1084 |
|
---|
1085 | os.close(iPipeW);
|
---|
1086 | try:
|
---|
1087 | sResponse = os.read(iPipeR, 32);
|
---|
1088 | except:
|
---|
1089 | reporter.logXcpt();
|
---|
1090 | sResponse = None;
|
---|
1091 | os.close(iPipeR);
|
---|
1092 |
|
---|
1093 | if hasattr(sResponse, 'decode'):
|
---|
1094 | sResponse = sResponse.decode('utf-8', 'ignore');
|
---|
1095 |
|
---|
1096 | if sResponse is None or sResponse.strip() != 'READY':
|
---|
1097 | reporter.error('VBoxSVC failed starting up... (sResponse=%s)' % (sResponse,));
|
---|
1098 | if not self.oVBoxSvcProcess.wait(5000):
|
---|
1099 | self.oVBoxSvcProcess.terminate(2500);
|
---|
1100 | self.oVBoxSvcProcess.wait(5000);
|
---|
1101 | self.oVBoxSvcProcess = None;
|
---|
1102 |
|
---|
1103 | elif self.sHost == 'win':
|
---|
1104 | #
|
---|
1105 | # Windows - Just fudge it for now.
|
---|
1106 | #
|
---|
1107 | cMsFudge = 2000;
|
---|
1108 | self.oVBoxSvcProcess = base.Process.spawn(sVBoxSVC, sVBoxSVC);
|
---|
1109 |
|
---|
1110 | else:
|
---|
1111 | reporter.error('Port me!');
|
---|
1112 |
|
---|
1113 | #
|
---|
1114 | # Enable automatic crash reporting if we succeeded.
|
---|
1115 | #
|
---|
1116 | if self.oVBoxSvcProcess is not None:
|
---|
1117 | self.oVBoxSvcProcess.enableCrashReporting('crash/report/svc', 'crash/dump/svc');
|
---|
1118 |
|
---|
1119 | #
|
---|
1120 | # Fudge and pid file.
|
---|
1121 | #
|
---|
1122 | if self.oVBoxSvcProcess != None and not self.oVBoxSvcProcess.wait(cMsFudge):
|
---|
1123 | if fWritePidFile:
|
---|
1124 | iPid = self.oVBoxSvcProcess.getPid();
|
---|
1125 | try:
|
---|
1126 | oFile = utils.openNoInherit(self.sVBoxSvcPidFile, "w+");
|
---|
1127 | oFile.write('%s' % (iPid,));
|
---|
1128 | oFile.close();
|
---|
1129 | except:
|
---|
1130 | reporter.logXcpt('sPidFile=%s' % (self.sVBoxSvcPidFile,));
|
---|
1131 | reporter.log('VBoxSVC PID=%u' % (iPid,));
|
---|
1132 |
|
---|
1133 | #
|
---|
1134 | # Finally add the task so we'll notice when it dies in a relatively timely manner.
|
---|
1135 | #
|
---|
1136 | self.addTask(self.oVBoxSvcProcess);
|
---|
1137 | else:
|
---|
1138 | self.oVBoxSvcProcess = None;
|
---|
1139 | try: os.remove(self.sVBoxSvcPidFile);
|
---|
1140 | except: pass;
|
---|
1141 |
|
---|
1142 | return self.oVBoxSvcProcess != None;
|
---|
1143 |
|
---|
1144 |
|
---|
1145 | def _killVBoxSVCByPidFile(self, sPidFile):
|
---|
1146 | """ Kill a VBoxSVC given the pid from it's pid file. """
|
---|
1147 |
|
---|
1148 | # Read the pid file.
|
---|
1149 | if not os.path.isfile(sPidFile):
|
---|
1150 | return False;
|
---|
1151 | try:
|
---|
1152 | oFile = utils.openNoInherit(sPidFile, "r");
|
---|
1153 | sPid = oFile.readline().strip();
|
---|
1154 | oFile.close();
|
---|
1155 | except:
|
---|
1156 | reporter.logXcpt('sPidfile=%s' % (sPidFile,));
|
---|
1157 | return False;
|
---|
1158 |
|
---|
1159 | # Convert the pid to an integer and validate the range a little bit.
|
---|
1160 | try:
|
---|
1161 | iPid = long(sPid);
|
---|
1162 | except:
|
---|
1163 | reporter.logXcpt('sPidfile=%s sPid="%s"' % (sPidFile, sPid));
|
---|
1164 | return False;
|
---|
1165 | if iPid <= 0:
|
---|
1166 | reporter.log('negative pid - sPidfile=%s sPid="%s" iPid=%d' % (sPidFile, sPid, iPid));
|
---|
1167 | return False;
|
---|
1168 |
|
---|
1169 | # Take care checking that it's VBoxSVC we're about to inhume.
|
---|
1170 | if base.processCheckPidAndName(iPid, "VBoxSVC") is not True:
|
---|
1171 | reporter.log('Ignoring stale VBoxSVC pid file (pid=%s)' % (iPid,));
|
---|
1172 | return False;
|
---|
1173 |
|
---|
1174 | # Loop thru our different ways of getting VBoxSVC to terminate.
|
---|
1175 | for aHow in [ [ base.sendUserSignal1, 5000, 'Dropping VBoxSVC a SIGUSR1 hint...'], \
|
---|
1176 | [ base.processInterrupt, 5000, 'Dropping VBoxSVC a SIGINT hint...'], \
|
---|
1177 | [ base.processTerminate, 7500, 'VBoxSVC is still around, killing it...'] ]:
|
---|
1178 | reporter.log(aHow[2]);
|
---|
1179 | if aHow[0](iPid) is True:
|
---|
1180 | msStart = base.timestampMilli();
|
---|
1181 | while base.timestampMilli() - msStart < 5000 \
|
---|
1182 | and base.processExists(iPid):
|
---|
1183 | time.sleep(0.2);
|
---|
1184 |
|
---|
1185 | fRc = not base.processExists(iPid);
|
---|
1186 | if fRc is True:
|
---|
1187 | break;
|
---|
1188 | if fRc:
|
---|
1189 | reporter.log('Successfully killed VBoxSVC (pid=%s)' % (iPid,));
|
---|
1190 | else:
|
---|
1191 | reporter.log('Failed to kill VBoxSVC (pid=%s)' % (iPid,));
|
---|
1192 | return fRc;
|
---|
1193 |
|
---|
1194 | def _stopVBoxSVC(self):
|
---|
1195 | """
|
---|
1196 | Stops VBoxSVC. Try the polite way first.
|
---|
1197 | """
|
---|
1198 |
|
---|
1199 | if self.oVBoxSvcProcess:
|
---|
1200 | self.removeTask(self.oVBoxSvcProcess);
|
---|
1201 | self.oVBoxSvcProcess.enableCrashReporting(None, None); # Disables it.
|
---|
1202 |
|
---|
1203 | fRc = False;
|
---|
1204 | if self.oVBoxSvcProcess is not None \
|
---|
1205 | and not self.fVBoxSvcInDebugger:
|
---|
1206 | # by process object.
|
---|
1207 | if self.oVBoxSvcProcess.isRunning():
|
---|
1208 | reporter.log('Dropping VBoxSVC a SIGUSR1 hint...');
|
---|
1209 | if not self.oVBoxSvcProcess.sendUserSignal1() \
|
---|
1210 | or not self.oVBoxSvcProcess.wait(5000):
|
---|
1211 | reporter.log('Dropping VBoxSVC a SIGINT hint...');
|
---|
1212 | if not self.oVBoxSvcProcess.interrupt() \
|
---|
1213 | or not self.oVBoxSvcProcess.wait(5000):
|
---|
1214 | reporter.log('VBoxSVC is still around, killing it...');
|
---|
1215 | self.oVBoxSvcProcess.terminate();
|
---|
1216 | self.oVBoxSvcProcess.wait(7500);
|
---|
1217 | else:
|
---|
1218 | reporter.log('VBoxSVC is no longer running...');
|
---|
1219 | if not self.oVBoxSvcProcess.isRunning():
|
---|
1220 | self.oVBoxSvcProcess = None;
|
---|
1221 | else:
|
---|
1222 | # by pid file.
|
---|
1223 | self._killVBoxSVCByPidFile('%s/VBoxSVC.pid' % (self.sScratchPath,));
|
---|
1224 | return fRc;
|
---|
1225 |
|
---|
1226 | def _setupVBoxApi(self):
|
---|
1227 | """
|
---|
1228 | Import and set up the vboxapi.
|
---|
1229 | The caller saves and restores sys.path.
|
---|
1230 | """
|
---|
1231 |
|
---|
1232 | # Setup vbox logging for self (the test driver).
|
---|
1233 | self.sSelfLogFile = '%s/VBoxTestDriver.log' % (self.sScratchPath,);
|
---|
1234 | try: os.remove(self.sSelfLogFile);
|
---|
1235 | except: pass;
|
---|
1236 | os.environ['VBOX_LOG'] = self.sLogSelfGroups;
|
---|
1237 | os.environ['VBOX_LOG_FLAGS'] = '%s append' % (self.sLogSelfFlags, );
|
---|
1238 | if self.sLogSelfDest:
|
---|
1239 | os.environ['VBOX_LOG_DEST'] = 'nodeny ' + self.sLogSelfDest;
|
---|
1240 | else:
|
---|
1241 | os.environ['VBOX_LOG_DEST'] = 'nodeny file=%s' % (self.sSelfLogFile,);
|
---|
1242 | os.environ['VBOX_RELEASE_LOG_FLAGS'] = 'time append';
|
---|
1243 |
|
---|
1244 | # Hack the sys.path + environment so the vboxapi can be found.
|
---|
1245 | sys.path.insert(0, self.oBuild.sInstallPath);
|
---|
1246 | if self.oBuild.sSdkPath is not None:
|
---|
1247 | sys.path.insert(0, os.path.join(self.oBuild.sSdkPath, 'installer'))
|
---|
1248 | sys.path.insert(1, os.path.join(self.oBuild.sSdkPath, 'install')); # stupid stupid windows installer!
|
---|
1249 | sys.path.insert(2, os.path.join(self.oBuild.sSdkPath, 'bindings', 'xpcom', 'python'))
|
---|
1250 | os.environ['VBOX_PROGRAM_PATH'] = self.oBuild.sInstallPath;
|
---|
1251 | reporter.log("sys.path: %s" % (sys.path));
|
---|
1252 |
|
---|
1253 | try:
|
---|
1254 | from vboxapi import VirtualBoxManager # pylint: disable=import-error
|
---|
1255 | except:
|
---|
1256 | reporter.logXcpt('Error importing vboxapi');
|
---|
1257 | return False;
|
---|
1258 |
|
---|
1259 | # Exception and error hacks.
|
---|
1260 | try:
|
---|
1261 | # pylint: disable=import-error
|
---|
1262 | if self.sHost == 'win':
|
---|
1263 | from pythoncom import com_error as NativeComExceptionClass # pylint: disable=E0611
|
---|
1264 | import winerror as NativeComErrorClass
|
---|
1265 | else:
|
---|
1266 | from xpcom import Exception as NativeComExceptionClass
|
---|
1267 | from xpcom import nsError as NativeComErrorClass
|
---|
1268 | # pylint: enable=import-error
|
---|
1269 | except:
|
---|
1270 | reporter.logXcpt('Error importing (XP)COM related stuff for exception hacks and errors');
|
---|
1271 | return False;
|
---|
1272 | __deployExceptionHacks__(NativeComExceptionClass)
|
---|
1273 | ComError.copyErrors(NativeComErrorClass);
|
---|
1274 |
|
---|
1275 | # Create the manager.
|
---|
1276 | try:
|
---|
1277 | self.oVBoxMgr = VirtualBoxManager(None, None)
|
---|
1278 | except:
|
---|
1279 | self.oVBoxMgr = None;
|
---|
1280 | reporter.logXcpt('VirtualBoxManager exception');
|
---|
1281 | return False;
|
---|
1282 |
|
---|
1283 | # Figure the API version.
|
---|
1284 | try:
|
---|
1285 | oVBox = self.oVBoxMgr.getVirtualBox();
|
---|
1286 |
|
---|
1287 | try:
|
---|
1288 | sVer = oVBox.version;
|
---|
1289 | except:
|
---|
1290 | reporter.logXcpt('Failed to get VirtualBox version, assuming 4.0.0');
|
---|
1291 | sVer = "4.0.0";
|
---|
1292 | reporter.log("IVirtualBox.version=%s" % (sVer,));
|
---|
1293 |
|
---|
1294 | # Convert the string to three integer values and check ranges.
|
---|
1295 | asVerComponents = sVer.split('.');
|
---|
1296 | try:
|
---|
1297 | sLast = asVerComponents[2].split('_')[0].split('r')[0];
|
---|
1298 | aiVerComponents = (int(asVerComponents[0]), int(asVerComponents[1]), int(sLast));
|
---|
1299 | except:
|
---|
1300 | raise base.GenError('Malformed version "%s"' % (sVer,));
|
---|
1301 | if aiVerComponents[0] < 3 or aiVerComponents[0] > 19:
|
---|
1302 | raise base.GenError('Malformed version "%s" - 1st component is out of bounds 3..19: %u'
|
---|
1303 | % (sVer, aiVerComponents[0]));
|
---|
1304 | if aiVerComponents[1] < 0 or aiVerComponents[1] > 9:
|
---|
1305 | raise base.GenError('Malformed version "%s" - 2nd component is out of bounds 0..9: %u'
|
---|
1306 | % (sVer, aiVerComponents[1]));
|
---|
1307 | if aiVerComponents[2] < 0 or aiVerComponents[2] > 99:
|
---|
1308 | raise base.GenError('Malformed version "%s" - 3rd component is out of bounds 0..99: %u'
|
---|
1309 | % (sVer, aiVerComponents[2]));
|
---|
1310 |
|
---|
1311 | # Convert the three integers into a floating point value. The API is table witin a
|
---|
1312 | # x.y release, so the third component only indicates whether it's a stable or
|
---|
1313 | # development build of the next release.
|
---|
1314 | self.fpApiVer = aiVerComponents[0] + 0.1 * aiVerComponents[1];
|
---|
1315 | if aiVerComponents[2] >= 51:
|
---|
1316 | if self.fpApiVer not in [4.3, 3.2,]:
|
---|
1317 | self.fpApiVer += 0.1;
|
---|
1318 | else:
|
---|
1319 | self.fpApiVer += 1.1;
|
---|
1320 |
|
---|
1321 | # Patch VBox manage to gloss over portability issues (error constants, etc).
|
---|
1322 | self._patchVBoxMgr();
|
---|
1323 |
|
---|
1324 | # Wrap oVBox.
|
---|
1325 | from testdriver.vboxwrappers import VirtualBoxWrapper;
|
---|
1326 | self.oVBox = VirtualBoxWrapper(oVBox, self.oVBoxMgr, self.fpApiVer, self);
|
---|
1327 |
|
---|
1328 | # Install the constant wrapping hack.
|
---|
1329 | vboxcon.goHackModuleClass.oVBoxMgr = self.oVBoxMgr; # VBoxConstantWrappingHack.
|
---|
1330 | vboxcon.fpApiVer = self.fpApiVer;
|
---|
1331 |
|
---|
1332 | except:
|
---|
1333 | self.oVBoxMgr = None;
|
---|
1334 | self.oVBox = None;
|
---|
1335 | reporter.logXcpt("getVirtualBox / API version exception");
|
---|
1336 | return False;
|
---|
1337 |
|
---|
1338 | # Done
|
---|
1339 | self.fImportedVBoxApi = True;
|
---|
1340 | reporter.log('Found version %s (%s)' % (self.fpApiVer, sVer));
|
---|
1341 | return True;
|
---|
1342 |
|
---|
1343 | def _patchVBoxMgr(self):
|
---|
1344 | """
|
---|
1345 | Glosses over missing self.oVBoxMgr methods on older VBox versions.
|
---|
1346 | """
|
---|
1347 |
|
---|
1348 | def _xcptGetResult(oSelf, oXcpt = None):
|
---|
1349 | """ See vboxapi. """
|
---|
1350 | _ = oSelf;
|
---|
1351 | if oXcpt is None: oXcpt = sys.exc_info()[1];
|
---|
1352 | if sys.platform == 'win32':
|
---|
1353 | import winerror; # pylint: disable=import-error
|
---|
1354 | hrXcpt = oXcpt.hresult;
|
---|
1355 | if hrXcpt == winerror.DISP_E_EXCEPTION:
|
---|
1356 | hrXcpt = oXcpt.excepinfo[5];
|
---|
1357 | else:
|
---|
1358 | hrXcpt = oXcpt.error;
|
---|
1359 | return hrXcpt;
|
---|
1360 |
|
---|
1361 | def _xcptIsDeadInterface(oSelf, oXcpt = None):
|
---|
1362 | """ See vboxapi. """
|
---|
1363 | return oSelf.xcptGetStatus(oXcpt) in [
|
---|
1364 | 0x80004004, -2147467260, # NS_ERROR_ABORT
|
---|
1365 | 0x800706be, -2147023170, # NS_ERROR_CALL_FAILED (RPC_S_CALL_FAILED)
|
---|
1366 | 0x800706ba, -2147023174, # RPC_S_SERVER_UNAVAILABLE.
|
---|
1367 | 0x800706be, -2147023170, # RPC_S_CALL_FAILED.
|
---|
1368 | 0x800706bf, -2147023169, # RPC_S_CALL_FAILED_DNE.
|
---|
1369 | 0x80010108, -2147417848, # RPC_E_DISCONNECTED.
|
---|
1370 | 0x800706b5, -2147023179, # RPC_S_UNKNOWN_IF
|
---|
1371 | ];
|
---|
1372 |
|
---|
1373 | def _xcptIsOurXcptKind(oSelf, oXcpt = None):
|
---|
1374 | """ See vboxapi. """
|
---|
1375 | _ = oSelf;
|
---|
1376 | if oXcpt is None: oXcpt = sys.exc_info()[1];
|
---|
1377 | if sys.platform == 'win32':
|
---|
1378 | from pythoncom import com_error as NativeComExceptionClass # pylint: disable=import-error,E0611
|
---|
1379 | else:
|
---|
1380 | from xpcom import Exception as NativeComExceptionClass # pylint: disable=import-error
|
---|
1381 | return isinstance(oXcpt, NativeComExceptionClass);
|
---|
1382 |
|
---|
1383 | def _xcptIsEqual(oSelf, oXcpt, hrStatus):
|
---|
1384 | """ See vboxapi. """
|
---|
1385 | hrXcpt = oSelf.xcptGetResult(oXcpt);
|
---|
1386 | return hrXcpt == hrStatus or hrXcpt == hrStatus - 0x100000000;
|
---|
1387 |
|
---|
1388 | def _xcptToString(oSelf, oXcpt):
|
---|
1389 | """ See vboxapi. """
|
---|
1390 | _ = oSelf;
|
---|
1391 | if oXcpt is None: oXcpt = sys.exc_info()[1];
|
---|
1392 | return str(oXcpt);
|
---|
1393 |
|
---|
1394 | # Add utilities found in newer vboxapi revision.
|
---|
1395 | if not hasattr(self.oVBoxMgr, 'xcptIsDeadInterface'):
|
---|
1396 | import types;
|
---|
1397 | self.oVBoxMgr.xcptGetResult = types.MethodType(_xcptGetResult, self.oVBoxMgr);
|
---|
1398 | self.oVBoxMgr.xcptIsDeadInterface = types.MethodType(_xcptIsDeadInterface, self.oVBoxMgr);
|
---|
1399 | self.oVBoxMgr.xcptIsOurXcptKind = types.MethodType(_xcptIsOurXcptKind, self.oVBoxMgr);
|
---|
1400 | self.oVBoxMgr.xcptIsEqual = types.MethodType(_xcptIsEqual, self.oVBoxMgr);
|
---|
1401 | self.oVBoxMgr.xcptToString = types.MethodType(_xcptToString, self.oVBoxMgr);
|
---|
1402 |
|
---|
1403 |
|
---|
1404 | def _teardownVBoxApi(self): # pylint: disable=too-many-statements
|
---|
1405 | """
|
---|
1406 | Drop all VBox object references and shutdown com/xpcom.
|
---|
1407 | """
|
---|
1408 | if not self.fImportedVBoxApi:
|
---|
1409 | return True;
|
---|
1410 | import gc;
|
---|
1411 |
|
---|
1412 | # Drop all references we've have to COM objects.
|
---|
1413 | self.aoRemoteSessions = [];
|
---|
1414 | self.aoVMs = [];
|
---|
1415 | self.oVBoxMgr = None;
|
---|
1416 | self.oVBox = None;
|
---|
1417 | vboxcon.goHackModuleClass.oVBoxMgr = None; # VBoxConstantWrappingHack.
|
---|
1418 |
|
---|
1419 | # Do garbage collection to try get rid of those objects.
|
---|
1420 | try:
|
---|
1421 | gc.collect();
|
---|
1422 | except:
|
---|
1423 | reporter.logXcpt();
|
---|
1424 | self.fImportedVBoxApi = False;
|
---|
1425 |
|
---|
1426 | # Check whether the python is still having any COM objects/interfaces around.
|
---|
1427 | cVBoxMgrs = 0;
|
---|
1428 | aoObjsLeftBehind = [];
|
---|
1429 | if self.sHost == 'win':
|
---|
1430 | import pythoncom; # pylint: disable=import-error
|
---|
1431 | try:
|
---|
1432 | cIfs = pythoncom._GetInterfaceCount(); # pylint: disable=no-member,protected-access
|
---|
1433 | cObjs = pythoncom._GetGatewayCount(); # pylint: disable=no-member,protected-access
|
---|
1434 | if cObjs == 0 and cIfs == 0:
|
---|
1435 | reporter.log('_teardownVBoxApi: no interfaces or objects left behind.');
|
---|
1436 | else:
|
---|
1437 | reporter.log('_teardownVBoxApi: Python COM still has %s objects and %s interfaces...' % ( cObjs, cIfs));
|
---|
1438 |
|
---|
1439 | from win32com.client import DispatchBaseClass; # pylint: disable=import-error
|
---|
1440 | for oObj in gc.get_objects():
|
---|
1441 | if isinstance(oObj, DispatchBaseClass):
|
---|
1442 | reporter.log('_teardownVBoxApi: %s' % (oObj,));
|
---|
1443 | aoObjsLeftBehind.append(oObj);
|
---|
1444 | elif utils.getObjectTypeName(oObj) == 'VirtualBoxManager':
|
---|
1445 | reporter.log('_teardownVBoxApi: %s' % (oObj,));
|
---|
1446 | cVBoxMgrs += 1;
|
---|
1447 | aoObjsLeftBehind.append(oObj);
|
---|
1448 | oObj = None;
|
---|
1449 | except:
|
---|
1450 | reporter.logXcpt();
|
---|
1451 |
|
---|
1452 | # If not being used, we can safely uninitialize COM.
|
---|
1453 | if cIfs == 0 and cObjs == 0 and cVBoxMgrs == 0 and not aoObjsLeftBehind:
|
---|
1454 | reporter.log('_teardownVBoxApi: Calling CoUninitialize...');
|
---|
1455 | try: pythoncom.CoUninitialize(); # pylint: disable=no-member
|
---|
1456 | except: reporter.logXcpt();
|
---|
1457 | else:
|
---|
1458 | reporter.log('_teardownVBoxApi: Returned from CoUninitialize.');
|
---|
1459 | else:
|
---|
1460 | try:
|
---|
1461 | # XPCOM doesn't crash and burn like COM if you shut it down with interfaces and objects around.
|
---|
1462 | # Also, it keeps a number of internal objects and interfaces around to do its job, so shutting
|
---|
1463 | # it down before we go looking for dangling interfaces is more or less required.
|
---|
1464 | from xpcom import _xpcom as _xpcom; # pylint: disable=import-error
|
---|
1465 | hrc = _xpcom.DeinitCOM();
|
---|
1466 | cIfs = _xpcom._GetInterfaceCount(); # pylint: disable=W0212
|
---|
1467 | cObjs = _xpcom._GetGatewayCount(); # pylint: disable=W0212
|
---|
1468 |
|
---|
1469 | if cObjs == 0 and cIfs == 0:
|
---|
1470 | reporter.log('_teardownVBoxApi: No XPCOM interfaces or objects active. (hrc=%#x)' % (hrc,));
|
---|
1471 | else:
|
---|
1472 | reporter.log('_teardownVBoxApi: %s XPCOM objects and %s interfaces still around! (hrc=%#x)'
|
---|
1473 | % (cObjs, cIfs, hrc));
|
---|
1474 | if hasattr(_xpcom, '_DumpInterfaces'):
|
---|
1475 | try: _xpcom._DumpInterfaces(); # pylint: disable=W0212
|
---|
1476 | except: reporter.logXcpt('_teardownVBoxApi: _DumpInterfaces failed');
|
---|
1477 |
|
---|
1478 | from xpcom.client import Component; # pylint: disable=import-error
|
---|
1479 | for oObj in gc.get_objects():
|
---|
1480 | if isinstance(oObj, Component):
|
---|
1481 | reporter.log('_teardownVBoxApi: %s' % (oObj,));
|
---|
1482 | aoObjsLeftBehind.append(oObj);
|
---|
1483 | if utils.getObjectTypeName(oObj) == 'VirtualBoxManager':
|
---|
1484 | reporter.log('_teardownVBoxApi: %s' % (oObj,));
|
---|
1485 | cVBoxMgrs += 1;
|
---|
1486 | aoObjsLeftBehind.append(oObj);
|
---|
1487 | oObj = None;
|
---|
1488 | except:
|
---|
1489 | reporter.logXcpt();
|
---|
1490 |
|
---|
1491 | # Try get the referrers to (XP)COM interfaces and objects that was left behind.
|
---|
1492 | for iObj in range(len(aoObjsLeftBehind)): # pylint: disable=consider-using-enumerate
|
---|
1493 | try:
|
---|
1494 | aoReferrers = gc.get_referrers(aoObjsLeftBehind[iObj]);
|
---|
1495 | reporter.log('_teardownVBoxApi: Found %u referrers to %s:' % (len(aoReferrers), aoObjsLeftBehind[iObj],));
|
---|
1496 | for oReferrer in aoReferrers:
|
---|
1497 | oMyFrame = sys._getframe(0); # pylint: disable=protected-access
|
---|
1498 | if oReferrer is oMyFrame:
|
---|
1499 | reporter.log('_teardownVBoxApi: - frame of this function');
|
---|
1500 | elif oReferrer is aoObjsLeftBehind:
|
---|
1501 | reporter.log('_teardownVBoxApi: - aoObjsLeftBehind');
|
---|
1502 | else:
|
---|
1503 | fPrinted = False;
|
---|
1504 | if isinstance(oReferrer, (dict, list, tuple)):
|
---|
1505 | try:
|
---|
1506 | aoSubReferreres = gc.get_referrers(oReferrer);
|
---|
1507 | for oSubRef in aoSubReferreres:
|
---|
1508 | if not isinstance(oSubRef, list) \
|
---|
1509 | and not isinstance(oSubRef, dict) \
|
---|
1510 | and oSubRef is not oMyFrame \
|
---|
1511 | and oSubRef is not aoSubReferreres:
|
---|
1512 | reporter.log('_teardownVBoxApi: - %s :: %s:'
|
---|
1513 | % (utils.getObjectTypeName(oSubRef), utils.getObjectTypeName(oReferrer)));
|
---|
1514 | fPrinted = True;
|
---|
1515 | break;
|
---|
1516 | del aoSubReferreres;
|
---|
1517 | except:
|
---|
1518 | reporter.logXcpt('subref');
|
---|
1519 | if not fPrinted:
|
---|
1520 | reporter.log('_teardownVBoxApi: - %s:' % (utils.getObjectTypeName(oReferrer),));
|
---|
1521 | try:
|
---|
1522 | import pprint;
|
---|
1523 | for sLine in pprint.pformat(oReferrer, width = 130).split('\n'):
|
---|
1524 | reporter.log('_teardownVBoxApi: %s' % (sLine,));
|
---|
1525 | except:
|
---|
1526 | reporter.log('_teardownVBoxApi: %s' % (oReferrer,));
|
---|
1527 | except:
|
---|
1528 | reporter.logXcpt();
|
---|
1529 | del aoObjsLeftBehind;
|
---|
1530 |
|
---|
1531 | # Force garbage collection again, just for good measure.
|
---|
1532 | try:
|
---|
1533 | gc.collect();
|
---|
1534 | time.sleep(0.5); # fudge factor
|
---|
1535 | except:
|
---|
1536 | reporter.logXcpt();
|
---|
1537 | return True;
|
---|
1538 |
|
---|
1539 | def _powerOffAllVms(self):
|
---|
1540 | """
|
---|
1541 | Tries to power off all running VMs.
|
---|
1542 | """
|
---|
1543 | for oSession in self.aoRemoteSessions:
|
---|
1544 | uPid = oSession.getPid();
|
---|
1545 | if uPid is not None:
|
---|
1546 | reporter.log('_powerOffAllVms: PID is %s for %s, trying to kill it.' % (uPid, oSession.sName,));
|
---|
1547 | base.processKill(uPid);
|
---|
1548 | else:
|
---|
1549 | reporter.log('_powerOffAllVms: No PID for %s' % (oSession.sName,));
|
---|
1550 | oSession.close();
|
---|
1551 | return None;
|
---|
1552 |
|
---|
1553 |
|
---|
1554 |
|
---|
1555 | #
|
---|
1556 | # Build type, OS and arch getters.
|
---|
1557 | #
|
---|
1558 |
|
---|
1559 | def getBuildType(self):
|
---|
1560 | """
|
---|
1561 | Get the build type.
|
---|
1562 | """
|
---|
1563 | if not self._detectBuild():
|
---|
1564 | return 'release';
|
---|
1565 | return self.oBuild.sType;
|
---|
1566 |
|
---|
1567 | def getBuildOs(self):
|
---|
1568 | """
|
---|
1569 | Get the build OS.
|
---|
1570 | """
|
---|
1571 | if not self._detectBuild():
|
---|
1572 | return self.sHost;
|
---|
1573 | return self.oBuild.sOs;
|
---|
1574 |
|
---|
1575 | def getBuildArch(self):
|
---|
1576 | """
|
---|
1577 | Get the build arch.
|
---|
1578 | """
|
---|
1579 | if not self._detectBuild():
|
---|
1580 | return self.sHostArch;
|
---|
1581 | return self.oBuild.sArch;
|
---|
1582 |
|
---|
1583 | def getGuestAdditionsIso(self):
|
---|
1584 | """
|
---|
1585 | Get the path to the guest addition iso.
|
---|
1586 | """
|
---|
1587 | if not self._detectBuild():
|
---|
1588 | return None;
|
---|
1589 | return self.oBuild.sGuestAdditionsIso;
|
---|
1590 |
|
---|
1591 | #
|
---|
1592 | # Override everything from the base class so the testdrivers don't have to
|
---|
1593 | # check whether we have overridden a method or not.
|
---|
1594 | #
|
---|
1595 |
|
---|
1596 | def showUsage(self):
|
---|
1597 | rc = base.TestDriver.showUsage(self);
|
---|
1598 | reporter.log('');
|
---|
1599 | reporter.log('Generic VirtualBox Options:');
|
---|
1600 | reporter.log(' --vbox-session-type <type>');
|
---|
1601 | reporter.log(' Sets the session type. Typical values are: gui, headless, sdl');
|
---|
1602 | reporter.log(' Default: %s' % (self.sSessionTypeDef));
|
---|
1603 | reporter.log(' --vrdp, --no-vrdp');
|
---|
1604 | reporter.log(' Enables VRDP, ports starting at 6000');
|
---|
1605 | reporter.log(' Default: --vrdp');
|
---|
1606 | reporter.log(' --vrdp-base-port <port>');
|
---|
1607 | reporter.log(' Sets the base for VRDP port assignments.');
|
---|
1608 | reporter.log(' Default: %s' % (self.uVrdpBasePortDef));
|
---|
1609 | reporter.log(' --vbox-default-bridged-nic <interface>');
|
---|
1610 | reporter.log(' Sets the default interface for bridged networking.');
|
---|
1611 | reporter.log(' Default: autodetect');
|
---|
1612 | reporter.log(' --vbox-use-svc-defaults');
|
---|
1613 | reporter.log(' Use default locations and files for VBoxSVC. This is useful');
|
---|
1614 | reporter.log(' for automatically configuring the test VMs for debugging.');
|
---|
1615 | reporter.log(' --vbox-self-log');
|
---|
1616 | reporter.log(' The VBox logger group settings for the testdriver.');
|
---|
1617 | reporter.log(' --vbox-self-log-flags');
|
---|
1618 | reporter.log(' The VBox logger flags settings for the testdriver.');
|
---|
1619 | reporter.log(' --vbox-self-log-dest');
|
---|
1620 | reporter.log(' The VBox logger destination settings for the testdriver.');
|
---|
1621 | reporter.log(' --vbox-session-log');
|
---|
1622 | reporter.log(' The VM session logger group settings.');
|
---|
1623 | reporter.log(' --vbox-session-log-flags');
|
---|
1624 | reporter.log(' The VM session logger flags.');
|
---|
1625 | reporter.log(' --vbox-session-log-dest');
|
---|
1626 | reporter.log(' The VM session logger destination settings.');
|
---|
1627 | reporter.log(' --vbox-svc-log');
|
---|
1628 | reporter.log(' The VBoxSVC logger group settings.');
|
---|
1629 | reporter.log(' --vbox-svc-log-flags');
|
---|
1630 | reporter.log(' The VBoxSVC logger flag settings.');
|
---|
1631 | reporter.log(' --vbox-svc-log-dest');
|
---|
1632 | reporter.log(' The VBoxSVC logger destination settings.');
|
---|
1633 | reporter.log(' --vbox-log');
|
---|
1634 | reporter.log(' The VBox logger group settings for everyone.');
|
---|
1635 | reporter.log(' --vbox-log-flags');
|
---|
1636 | reporter.log(' The VBox logger flags settings for everyone.');
|
---|
1637 | reporter.log(' --vbox-log-dest');
|
---|
1638 | reporter.log(' The VBox logger destination settings for everyone.');
|
---|
1639 | reporter.log(' --vbox-svc-debug');
|
---|
1640 | reporter.log(' Start VBoxSVC in a debugger');
|
---|
1641 | reporter.log(' --vbox-always-upload-logs');
|
---|
1642 | reporter.log(' Whether to always upload log files, or only do so on failure.');
|
---|
1643 | reporter.log(' --vbox-always-upload-screenshots');
|
---|
1644 | reporter.log(' Whether to always upload final screen shots, or only do so on failure.');
|
---|
1645 | reporter.log(' --vbox-debugger, --no-vbox-debugger');
|
---|
1646 | reporter.log(' Enables the VBox debugger, port at 5000');
|
---|
1647 | reporter.log(' Default: --vbox-debugger');
|
---|
1648 | if self.oTestVmSet is not None:
|
---|
1649 | self.oTestVmSet.showUsage();
|
---|
1650 | return rc;
|
---|
1651 |
|
---|
1652 | def parseOption(self, asArgs, iArg): # pylint: disable=R0915
|
---|
1653 | if asArgs[iArg] == '--vbox-session-type':
|
---|
1654 | iArg += 1;
|
---|
1655 | if iArg >= len(asArgs):
|
---|
1656 | raise base.InvalidOption('The "--vbox-session-type" takes an argument');
|
---|
1657 | self.sSessionType = asArgs[iArg];
|
---|
1658 | elif asArgs[iArg] == '--vrdp':
|
---|
1659 | self.fEnableVrdp = True;
|
---|
1660 | elif asArgs[iArg] == '--no-vrdp':
|
---|
1661 | self.fEnableVrdp = False;
|
---|
1662 | elif asArgs[iArg] == '--vrdp-base-port':
|
---|
1663 | iArg += 1;
|
---|
1664 | if iArg >= len(asArgs):
|
---|
1665 | raise base.InvalidOption('The "--vrdp-base-port" takes an argument');
|
---|
1666 | try: self.uVrdpBasePort = int(asArgs[iArg]);
|
---|
1667 | except: raise base.InvalidOption('The "--vrdp-base-port" value "%s" is not a valid integer' % (asArgs[iArg],));
|
---|
1668 | if self.uVrdpBasePort <= 0 or self.uVrdpBasePort >= 65530:
|
---|
1669 | raise base.InvalidOption('The "--vrdp-base-port" value "%s" is not in the valid range (1..65530)'
|
---|
1670 | % (asArgs[iArg],));
|
---|
1671 | elif asArgs[iArg] == '--vbox-default-bridged-nic':
|
---|
1672 | iArg += 1;
|
---|
1673 | if iArg >= len(asArgs):
|
---|
1674 | raise base.InvalidOption('The "--vbox-default-bridged-nic" takes an argument');
|
---|
1675 | self.sDefBridgedNic = asArgs[iArg];
|
---|
1676 | elif asArgs[iArg] == '--vbox-use-svc-defaults':
|
---|
1677 | self.fUseDefaultSvc = True;
|
---|
1678 | elif asArgs[iArg] == '--vbox-self-log':
|
---|
1679 | iArg += 1;
|
---|
1680 | if iArg >= len(asArgs):
|
---|
1681 | raise base.InvalidOption('The "--vbox-self-log" takes an argument');
|
---|
1682 | self.sLogSelfGroups = asArgs[iArg];
|
---|
1683 | elif asArgs[iArg] == '--vbox-self-log-flags':
|
---|
1684 | iArg += 1;
|
---|
1685 | if iArg >= len(asArgs):
|
---|
1686 | raise base.InvalidOption('The "--vbox-self-log-flags" takes an argument');
|
---|
1687 | self.sLogSelfFlags = asArgs[iArg];
|
---|
1688 | elif asArgs[iArg] == '--vbox-self-log-dest':
|
---|
1689 | iArg += 1;
|
---|
1690 | if iArg >= len(asArgs):
|
---|
1691 | raise base.InvalidOption('The "--vbox-self-log-dest" takes an argument');
|
---|
1692 | self.sLogSelfDest = asArgs[iArg];
|
---|
1693 | elif asArgs[iArg] == '--vbox-session-log':
|
---|
1694 | iArg += 1;
|
---|
1695 | if iArg >= len(asArgs):
|
---|
1696 | raise base.InvalidOption('The "--vbox-session-log" takes an argument');
|
---|
1697 | self.sLogSessionGroups = asArgs[iArg];
|
---|
1698 | elif asArgs[iArg] == '--vbox-session-log-flags':
|
---|
1699 | iArg += 1;
|
---|
1700 | if iArg >= len(asArgs):
|
---|
1701 | raise base.InvalidOption('The "--vbox-session-log-flags" takes an argument');
|
---|
1702 | self.sLogSessionFlags = asArgs[iArg];
|
---|
1703 | elif asArgs[iArg] == '--vbox-session-log-dest':
|
---|
1704 | iArg += 1;
|
---|
1705 | if iArg >= len(asArgs):
|
---|
1706 | raise base.InvalidOption('The "--vbox-session-log-dest" takes an argument');
|
---|
1707 | self.sLogSessionDest = asArgs[iArg];
|
---|
1708 | elif asArgs[iArg] == '--vbox-svc-log':
|
---|
1709 | iArg += 1;
|
---|
1710 | if iArg >= len(asArgs):
|
---|
1711 | raise base.InvalidOption('The "--vbox-svc-log" takes an argument');
|
---|
1712 | self.sLogSvcGroups = asArgs[iArg];
|
---|
1713 | elif asArgs[iArg] == '--vbox-svc-log-flags':
|
---|
1714 | iArg += 1;
|
---|
1715 | if iArg >= len(asArgs):
|
---|
1716 | raise base.InvalidOption('The "--vbox-svc-log-flags" takes an argument');
|
---|
1717 | self.sLogSvcFlags = asArgs[iArg];
|
---|
1718 | elif asArgs[iArg] == '--vbox-svc-log-dest':
|
---|
1719 | iArg += 1;
|
---|
1720 | if iArg >= len(asArgs):
|
---|
1721 | raise base.InvalidOption('The "--vbox-svc-log-dest" takes an argument');
|
---|
1722 | self.sLogSvcDest = asArgs[iArg];
|
---|
1723 | elif asArgs[iArg] == '--vbox-log':
|
---|
1724 | iArg += 1;
|
---|
1725 | if iArg >= len(asArgs):
|
---|
1726 | raise base.InvalidOption('The "--vbox-log" takes an argument');
|
---|
1727 | self.sLogSelfGroups = asArgs[iArg];
|
---|
1728 | self.sLogSessionGroups = asArgs[iArg];
|
---|
1729 | self.sLogSvcGroups = asArgs[iArg];
|
---|
1730 | elif asArgs[iArg] == '--vbox-log-flags':
|
---|
1731 | iArg += 1;
|
---|
1732 | if iArg >= len(asArgs):
|
---|
1733 | raise base.InvalidOption('The "--vbox-svc-flags" takes an argument');
|
---|
1734 | self.sLogSelfFlags = asArgs[iArg];
|
---|
1735 | self.sLogSessionFlags = asArgs[iArg];
|
---|
1736 | self.sLogSvcFlags = asArgs[iArg];
|
---|
1737 | elif asArgs[iArg] == '--vbox-log-dest':
|
---|
1738 | iArg += 1;
|
---|
1739 | if iArg >= len(asArgs):
|
---|
1740 | raise base.InvalidOption('The "--vbox-log-dest" takes an argument');
|
---|
1741 | self.sLogSelfDest = asArgs[iArg];
|
---|
1742 | self.sLogSessionDest = asArgs[iArg];
|
---|
1743 | self.sLogSvcDest = asArgs[iArg];
|
---|
1744 | elif asArgs[iArg] == '--vbox-svc-debug':
|
---|
1745 | self.fVBoxSvcInDebugger = True;
|
---|
1746 | elif asArgs[iArg] == '--vbox-always-upload-logs':
|
---|
1747 | self.fAlwaysUploadLogs = True;
|
---|
1748 | elif asArgs[iArg] == '--vbox-always-upload-screenshots':
|
---|
1749 | self.fAlwaysUploadScreenshots = True;
|
---|
1750 | elif asArgs[iArg] == '--vbox-debugger':
|
---|
1751 | self.fEnableDebugger = True;
|
---|
1752 | elif asArgs[iArg] == '--no-vbox-debugger':
|
---|
1753 | self.fEnableDebugger = False;
|
---|
1754 | else:
|
---|
1755 | # Relevant for selecting VMs to test?
|
---|
1756 | if self.oTestVmSet is not None:
|
---|
1757 | iRc = self.oTestVmSet.parseOption(asArgs, iArg);
|
---|
1758 | if iRc != iArg:
|
---|
1759 | return iRc;
|
---|
1760 |
|
---|
1761 | # Hand it to the base class.
|
---|
1762 | return base.TestDriver.parseOption(self, asArgs, iArg);
|
---|
1763 | return iArg + 1;
|
---|
1764 |
|
---|
1765 | def completeOptions(self):
|
---|
1766 | return base.TestDriver.completeOptions(self);
|
---|
1767 |
|
---|
1768 | def getResourceSet(self):
|
---|
1769 | if self.oTestVmSet is not None:
|
---|
1770 | return self.oTestVmSet.getResourceSet();
|
---|
1771 | return base.TestDriver.getResourceSet(self);
|
---|
1772 |
|
---|
1773 | def actionExtract(self):
|
---|
1774 | return base.TestDriver.actionExtract(self);
|
---|
1775 |
|
---|
1776 | def actionVerify(self):
|
---|
1777 | return base.TestDriver.actionVerify(self);
|
---|
1778 |
|
---|
1779 | def actionConfig(self):
|
---|
1780 | return base.TestDriver.actionConfig(self);
|
---|
1781 |
|
---|
1782 | def actionExecute(self):
|
---|
1783 | return base.TestDriver.actionExecute(self);
|
---|
1784 |
|
---|
1785 | def actionCleanupBefore(self):
|
---|
1786 | """
|
---|
1787 | Kill any VBoxSVC left behind by a previous test run.
|
---|
1788 | """
|
---|
1789 | self._killVBoxSVCByPidFile('%s/VBoxSVC.pid' % (self.sScratchPath,));
|
---|
1790 | return base.TestDriver.actionCleanupBefore(self);
|
---|
1791 |
|
---|
1792 | def actionCleanupAfter(self):
|
---|
1793 | """
|
---|
1794 | Clean up the VBox bits and then call the base driver.
|
---|
1795 |
|
---|
1796 | If your test driver overrides this, it should normally call us at the
|
---|
1797 | end of the job.
|
---|
1798 | """
|
---|
1799 |
|
---|
1800 | # Kill any left over VM processes.
|
---|
1801 | self._powerOffAllVms();
|
---|
1802 |
|
---|
1803 | # Drop all VBox object references and shutdown xpcom then
|
---|
1804 | # terminating VBoxSVC, with extreme prejudice if need be.
|
---|
1805 | self._teardownVBoxApi();
|
---|
1806 | self._stopVBoxSVC();
|
---|
1807 |
|
---|
1808 | # Add the VBoxSVC and testdriver debug+release log files.
|
---|
1809 | if self.fAlwaysUploadLogs or reporter.getErrorCount() > 0:
|
---|
1810 | if self.sVBoxSvcLogFile is not None and os.path.isfile(self.sVBoxSvcLogFile):
|
---|
1811 | reporter.addLogFile(self.sVBoxSvcLogFile, 'log/debug/svc', 'Debug log file for VBoxSVC');
|
---|
1812 | self.sVBoxSvcLogFile = None;
|
---|
1813 |
|
---|
1814 | if self.sSelfLogFile is not None and os.path.isfile(self.sSelfLogFile):
|
---|
1815 | reporter.addLogFile(self.sSelfLogFile, 'log/debug/client', 'Debug log file for the test driver');
|
---|
1816 | self.sSelfLogFile = None;
|
---|
1817 |
|
---|
1818 | sVBoxSvcRelLog = os.path.join(self.sScratchPath, 'VBoxUserHome', 'VBoxSVC.log');
|
---|
1819 | if os.path.isfile(sVBoxSvcRelLog):
|
---|
1820 | reporter.addLogFile(sVBoxSvcRelLog, 'log/release/svc', 'Release log file for VBoxSVC');
|
---|
1821 | for sSuff in [ '.1', '.2', '.3', '.4', '.5', '.6', '.7', '.8' ]:
|
---|
1822 | if os.path.isfile(sVBoxSvcRelLog + sSuff):
|
---|
1823 | reporter.addLogFile(sVBoxSvcRelLog + sSuff, 'log/release/svc', 'Release log file for VBoxSVC');
|
---|
1824 | # Testbox debugging - START - TEMPORARY, REMOVE ASAP.
|
---|
1825 | if self.sHost in ('darwin', 'freebsd', 'linux', 'solaris', ):
|
---|
1826 | try:
|
---|
1827 | reporter.log('> ls -la %s' % (os.path.join(self.sScratchPath, 'VBoxUserHome'),));
|
---|
1828 | utils.processCall(['ls', '-la', os.path.join(self.sScratchPath, 'VBoxUserHome')]);
|
---|
1829 | reporter.log('> ls -la %s' % (self.sScratchPath,));
|
---|
1830 | utils.processCall(['ls', '-la', self.sScratchPath]);
|
---|
1831 | except: pass;
|
---|
1832 | # Testbox debugging - END - TEMPORARY, REMOVE ASAP.
|
---|
1833 |
|
---|
1834 | # Finally, call the base driver to wipe the scratch space.
|
---|
1835 | return base.TestDriver.actionCleanupAfter(self);
|
---|
1836 |
|
---|
1837 | def actionAbort(self):
|
---|
1838 | """
|
---|
1839 | Terminate VBoxSVC if we've got a pid file.
|
---|
1840 | """
|
---|
1841 | #
|
---|
1842 | # Take default action first, then kill VBoxSVC. The other way around
|
---|
1843 | # is problematic since the testscript would continue running and possibly
|
---|
1844 | # trigger a new VBoxSVC to start.
|
---|
1845 | #
|
---|
1846 | fRc1 = base.TestDriver.actionAbort(self);
|
---|
1847 | fRc2 = self._killVBoxSVCByPidFile('%s/VBoxSVC.pid' % (self.sScratchPath,));
|
---|
1848 | return fRc1 is True and fRc2 is True;
|
---|
1849 |
|
---|
1850 | def onExit(self, iRc):
|
---|
1851 | """
|
---|
1852 | Stop VBoxSVC if we've started it.
|
---|
1853 | """
|
---|
1854 | if self.oVBoxSvcProcess is not None:
|
---|
1855 | reporter.log('*** Shutting down the VBox API... (iRc=%s)' % (iRc,));
|
---|
1856 | self._powerOffAllVms();
|
---|
1857 | self._teardownVBoxApi();
|
---|
1858 | self._stopVBoxSVC();
|
---|
1859 | reporter.log('*** VBox API shutdown done.');
|
---|
1860 | return base.TestDriver.onExit(self, iRc);
|
---|
1861 |
|
---|
1862 |
|
---|
1863 | #
|
---|
1864 | # Task wait method override.
|
---|
1865 | #
|
---|
1866 |
|
---|
1867 | def notifyAboutReadyTask(self, oTask):
|
---|
1868 | """
|
---|
1869 | Overriding base.TestDriver.notifyAboutReadyTask.
|
---|
1870 | """
|
---|
1871 | try:
|
---|
1872 | self.oVBoxMgr.interruptWaitEvents();
|
---|
1873 | reporter.log2('vbox.notifyAboutReadyTask: called interruptWaitEvents');
|
---|
1874 | except:
|
---|
1875 | reporter.logXcpt('vbox.notifyAboutReadyTask');
|
---|
1876 | return base.TestDriver.notifyAboutReadyTask(self, oTask);
|
---|
1877 |
|
---|
1878 | def waitForTasksSleepWorker(self, cMsTimeout):
|
---|
1879 | """
|
---|
1880 | Overriding base.TestDriver.waitForTasksSleepWorker.
|
---|
1881 | """
|
---|
1882 | try:
|
---|
1883 | rc = self.oVBoxMgr.waitForEvents(int(cMsTimeout));
|
---|
1884 | _ = rc; #reporter.log2('vbox.waitForTasksSleepWorker(%u): true (waitForEvents -> %s)' % (cMsTimeout, rc));
|
---|
1885 | reporter.doPollWork('vbox.TestDriver.waitForTasksSleepWorker');
|
---|
1886 | return True;
|
---|
1887 | except KeyboardInterrupt:
|
---|
1888 | raise;
|
---|
1889 | except:
|
---|
1890 | reporter.logXcpt('vbox.waitForTasksSleepWorker');
|
---|
1891 | return False;
|
---|
1892 |
|
---|
1893 | #
|
---|
1894 | # Utility methods.
|
---|
1895 | #
|
---|
1896 |
|
---|
1897 | def processEvents(self, cMsTimeout = 0):
|
---|
1898 | """
|
---|
1899 | Processes events, returning after the first batch has been processed
|
---|
1900 | or the time limit has been reached.
|
---|
1901 |
|
---|
1902 | Only Ctrl-C exception, no return.
|
---|
1903 | """
|
---|
1904 | try:
|
---|
1905 | self.oVBoxMgr.waitForEvents(cMsTimeout);
|
---|
1906 | except KeyboardInterrupt:
|
---|
1907 | raise;
|
---|
1908 | except:
|
---|
1909 | pass;
|
---|
1910 | return None;
|
---|
1911 |
|
---|
1912 | def processPendingEvents(self):
|
---|
1913 | """ processEvents(0) - no waiting. """
|
---|
1914 | return self.processEvents(0);
|
---|
1915 |
|
---|
1916 | def sleep(self, cSecs):
|
---|
1917 | """
|
---|
1918 | Sleep for a specified amount of time, processing XPCOM events all the while.
|
---|
1919 | """
|
---|
1920 | cMsTimeout = long(cSecs * 1000);
|
---|
1921 | msStart = base.timestampMilli();
|
---|
1922 | self.processEvents(0);
|
---|
1923 | while True:
|
---|
1924 | cMsElapsed = base.timestampMilli() - msStart;
|
---|
1925 | if cMsElapsed > cMsTimeout:
|
---|
1926 | break;
|
---|
1927 | #reporter.log2('cMsTimeout=%s - cMsElapsed=%d => %s' % (cMsTimeout, cMsElapsed, cMsTimeout - cMsElapsed));
|
---|
1928 | self.processEvents(cMsTimeout - cMsElapsed);
|
---|
1929 | return None;
|
---|
1930 |
|
---|
1931 | def _logVmInfoUnsafe(self, oVM): # pylint: disable=R0915,R0912
|
---|
1932 | """
|
---|
1933 | Internal worker for logVmInfo that is wrapped in try/except.
|
---|
1934 |
|
---|
1935 | This is copy, paste, search, replace and edit of infoCmd from vboxshell.py.
|
---|
1936 | """
|
---|
1937 | oOsType = self.oVBox.getGuestOSType(oVM.OSTypeId)
|
---|
1938 | reporter.log(" Name: %s" % (oVM.name));
|
---|
1939 | reporter.log(" ID: %s" % (oVM.id));
|
---|
1940 | reporter.log(" OS Type: %s - %s" % (oVM.OSTypeId, oOsType.description));
|
---|
1941 | reporter.log(" Machine state: %s" % (oVM.state));
|
---|
1942 | reporter.log(" Session state: %s" % (oVM.sessionState));
|
---|
1943 | if self.fpApiVer >= 4.2:
|
---|
1944 | reporter.log(" Session PID: %u (%#x)" % (oVM.sessionPID, oVM.sessionPID));
|
---|
1945 | else:
|
---|
1946 | reporter.log(" Session PID: %u (%#x)" % (oVM.sessionPid, oVM.sessionPid));
|
---|
1947 | if self.fpApiVer >= 5.0:
|
---|
1948 | reporter.log(" Session Name: %s" % (oVM.sessionName));
|
---|
1949 | else:
|
---|
1950 | reporter.log(" Session Name: %s" % (oVM.sessionType));
|
---|
1951 | reporter.log(" CPUs: %s" % (oVM.CPUCount));
|
---|
1952 | reporter.log(" RAM: %sMB" % (oVM.memorySize));
|
---|
1953 | reporter.log(" VRAM: %sMB" % (oVM.VRAMSize));
|
---|
1954 | reporter.log(" Monitors: %s" % (oVM.monitorCount));
|
---|
1955 | if oVM.chipsetType == vboxcon.ChipsetType_PIIX3: sType = "PIIX3";
|
---|
1956 | elif oVM.chipsetType == vboxcon.ChipsetType_ICH9: sType = "ICH9";
|
---|
1957 | else: sType = "unknown %s" % (oVM.chipsetType);
|
---|
1958 | reporter.log(" Chipset: %s" % (sType));
|
---|
1959 | if oVM.firmwareType == vboxcon.FirmwareType_BIOS: sType = "BIOS";
|
---|
1960 | elif oVM.firmwareType == vboxcon.FirmwareType_EFI: sType = "EFI";
|
---|
1961 | elif oVM.firmwareType == vboxcon.FirmwareType_EFI32: sType = "EFI32";
|
---|
1962 | elif oVM.firmwareType == vboxcon.FirmwareType_EFI64: sType = "EFI64";
|
---|
1963 | elif oVM.firmwareType == vboxcon.FirmwareType_EFIDUAL: sType = "EFIDUAL";
|
---|
1964 | else: sType = "unknown %s" % (oVM.firmwareType);
|
---|
1965 | reporter.log(" Firmware: %s" % (sType));
|
---|
1966 | reporter.log(" HwVirtEx: %s" % (oVM.getHWVirtExProperty(vboxcon.HWVirtExPropertyType_Enabled)));
|
---|
1967 | reporter.log(" VPID support: %s" % (oVM.getHWVirtExProperty(vboxcon.HWVirtExPropertyType_VPID)));
|
---|
1968 | reporter.log(" Nested paging: %s" % (oVM.getHWVirtExProperty(vboxcon.HWVirtExPropertyType_NestedPaging)));
|
---|
1969 | if self.fpApiVer >= 4.2 and hasattr(vboxcon, 'CPUPropertyType_LongMode'):
|
---|
1970 | reporter.log(" Long-mode: %s" % (oVM.getCPUProperty(vboxcon.CPUPropertyType_LongMode)));
|
---|
1971 | if self.fpApiVer >= 3.2:
|
---|
1972 | reporter.log(" PAE: %s" % (oVM.getCPUProperty(vboxcon.CPUPropertyType_PAE)));
|
---|
1973 | if self.fpApiVer < 5.0:
|
---|
1974 | reporter.log(" Synthetic CPU: %s" % (oVM.getCPUProperty(vboxcon.CPUPropertyType_Synthetic)));
|
---|
1975 | else:
|
---|
1976 | reporter.log(" PAE: %s" % (oVM.getCpuProperty(vboxcon.CpuPropertyType_PAE)));
|
---|
1977 | reporter.log(" Synthetic CPU: %s" % (oVM.getCpuProperty(vboxcon.CpuPropertyType_Synthetic)));
|
---|
1978 | reporter.log(" ACPI: %s" % (oVM.BIOSSettings.ACPIEnabled));
|
---|
1979 | reporter.log(" IO-APIC: %s" % (oVM.BIOSSettings.IOAPICEnabled));
|
---|
1980 | if self.fpApiVer >= 3.2:
|
---|
1981 | if self.fpApiVer >= 4.2:
|
---|
1982 | reporter.log(" HPET: %s" % (oVM.HPETEnabled));
|
---|
1983 | else:
|
---|
1984 | reporter.log(" HPET: %s" % (oVM.hpetEnabled));
|
---|
1985 | reporter.log(" 3D acceleration: %s" % (oVM.accelerate3DEnabled));
|
---|
1986 | reporter.log(" 2D acceleration: %s" % (oVM.accelerate2DVideoEnabled));
|
---|
1987 | reporter.log(" TeleporterEnabled: %s" % (oVM.teleporterEnabled));
|
---|
1988 | reporter.log(" TeleporterPort: %s" % (oVM.teleporterPort));
|
---|
1989 | reporter.log(" TeleporterAddress: %s" % (oVM.teleporterAddress));
|
---|
1990 | reporter.log(" TeleporterPassword: %s" % (oVM.teleporterPassword));
|
---|
1991 | reporter.log(" Clipboard mode: %s" % (oVM.clipboardMode));
|
---|
1992 | if self.fpApiVer >= 5.0:
|
---|
1993 | reporter.log(" Drag and drop mode: %s" % (oVM.dnDMode));
|
---|
1994 | elif self.fpApiVer >= 4.3:
|
---|
1995 | reporter.log(" Drag and drop mode: %s" % (oVM.dragAndDropMode));
|
---|
1996 | if self.fpApiVer >= 4.0:
|
---|
1997 | reporter.log(" VRDP server: %s" % (oVM.VRDEServer.enabled));
|
---|
1998 | try: sPorts = oVM.VRDEServer.getVRDEProperty("TCP/Ports");
|
---|
1999 | except: sPorts = "";
|
---|
2000 | reporter.log(" VRDP server ports: %s" % (sPorts));
|
---|
2001 | reporter.log(" VRDP auth: %s (%s)" % (oVM.VRDEServer.authType, oVM.VRDEServer.authLibrary));
|
---|
2002 | else:
|
---|
2003 | reporter.log(" VRDP server: %s" % (oVM.VRDPServer.enabled));
|
---|
2004 | reporter.log(" VRDP server ports: %s" % (oVM.VRDPServer.ports));
|
---|
2005 | reporter.log(" Last changed: %s" % (oVM.lastStateChange));
|
---|
2006 |
|
---|
2007 | aoControllers = self.oVBoxMgr.getArray(oVM, 'storageControllers')
|
---|
2008 | if aoControllers:
|
---|
2009 | reporter.log(" Controllers:");
|
---|
2010 | for oCtrl in aoControllers:
|
---|
2011 | reporter.log(" %s %s bus: %s type: %s" % (oCtrl.name, oCtrl.controllerType, oCtrl.bus, oCtrl.controllerType));
|
---|
2012 | oAudioAdapter = oVM.audioAdapter;
|
---|
2013 | if oAudioAdapter.audioController == vboxcon.AudioControllerType_AC97: sType = "AC97";
|
---|
2014 | elif oAudioAdapter.audioController == vboxcon.AudioControllerType_SB16: sType = "SB16";
|
---|
2015 | elif oAudioAdapter.audioController == vboxcon.AudioControllerType_HDA: sType = "HDA";
|
---|
2016 | else: sType = "unknown %s" % (oAudioAdapter.audioController);
|
---|
2017 | reporter.log(" AudioController: %s" % (sType));
|
---|
2018 | reporter.log(" AudioEnabled: %s" % (oAudioAdapter.enabled));
|
---|
2019 | if oAudioAdapter.audioDriver == vboxcon.AudioDriverType_CoreAudio: sType = "CoreAudio";
|
---|
2020 | elif oAudioAdapter.audioDriver == vboxcon.AudioDriverType_DirectSound: sType = "DirectSound";
|
---|
2021 | elif oAudioAdapter.audioDriver == vboxcon.AudioDriverType_Pulse: sType = "PulseAudio";
|
---|
2022 | elif oAudioAdapter.audioDriver == vboxcon.AudioDriverType_OSS: sType = "OSS";
|
---|
2023 | elif oAudioAdapter.audioDriver == vboxcon.AudioDriverType_Null: sType = "NULL";
|
---|
2024 | else: sType = "unknown %s" % (oAudioAdapter.audioDriver);
|
---|
2025 | reporter.log(" Host AudioDriver: %s" % (sType));
|
---|
2026 |
|
---|
2027 | self.processPendingEvents();
|
---|
2028 | aoAttachments = self.oVBoxMgr.getArray(oVM, 'mediumAttachments')
|
---|
2029 | if aoAttachments:
|
---|
2030 | reporter.log(" Attachments:");
|
---|
2031 | for oAtt in aoAttachments:
|
---|
2032 | sCtrl = "Controller: %s port: %s device: %s type: %s" % (oAtt.controller, oAtt.port, oAtt.device, oAtt.type);
|
---|
2033 | oMedium = oAtt.medium
|
---|
2034 | if oAtt.type == vboxcon.DeviceType_HardDisk:
|
---|
2035 | reporter.log(" %s: HDD" % sCtrl);
|
---|
2036 | reporter.log(" Id: %s" % (oMedium.id));
|
---|
2037 | reporter.log(" Name: %s" % (oMedium.name));
|
---|
2038 | reporter.log(" Format: %s" % (oMedium.format));
|
---|
2039 | reporter.log(" Location: %s" % (oMedium.location));
|
---|
2040 |
|
---|
2041 | if oAtt.type == vboxcon.DeviceType_DVD:
|
---|
2042 | reporter.log(" %s: DVD" % sCtrl);
|
---|
2043 | if oMedium:
|
---|
2044 | reporter.log(" Id: %s" % (oMedium.id));
|
---|
2045 | reporter.log(" Name: %s" % (oMedium.name));
|
---|
2046 | if oMedium.hostDrive:
|
---|
2047 | reporter.log(" Host DVD %s" % (oMedium.location));
|
---|
2048 | if oAtt.passthrough:
|
---|
2049 | reporter.log(" [passthrough mode]");
|
---|
2050 | else:
|
---|
2051 | reporter.log(" Virtual image: %s" % (oMedium.location));
|
---|
2052 | reporter.log(" Size: %s" % (oMedium.size));
|
---|
2053 | else:
|
---|
2054 | reporter.log(" empty");
|
---|
2055 |
|
---|
2056 | if oAtt.type == vboxcon.DeviceType_Floppy:
|
---|
2057 | reporter.log(" %s: Floppy" % sCtrl);
|
---|
2058 | if oMedium:
|
---|
2059 | reporter.log(" Id: %s" % (oMedium.id));
|
---|
2060 | reporter.log(" Name: %s" % (oMedium.name));
|
---|
2061 | if oMedium.hostDrive:
|
---|
2062 | reporter.log(" Host floppy: %s" % (oMedium.location));
|
---|
2063 | else:
|
---|
2064 | reporter.log(" Virtual image: %s" % (oMedium.location));
|
---|
2065 | reporter.log(" Size: %s" % (oMedium.size));
|
---|
2066 | else:
|
---|
2067 | reporter.log(" empty");
|
---|
2068 | self.processPendingEvents();
|
---|
2069 |
|
---|
2070 | reporter.log(" Network Adapter:");
|
---|
2071 | for iSlot in range(0, 32):
|
---|
2072 | try: oNic = oVM.getNetworkAdapter(iSlot)
|
---|
2073 | except: break;
|
---|
2074 | if not oNic.enabled:
|
---|
2075 | reporter.log2(" slot #%d found but not enabled, skipping" % (iSlot,));
|
---|
2076 | continue;
|
---|
2077 | if oNic.adapterType == vboxcon.NetworkAdapterType_Am79C973: sType = "PCNet";
|
---|
2078 | elif oNic.adapterType == vboxcon.NetworkAdapterType_Am79C970A: sType = "PCNetOld";
|
---|
2079 | elif oNic.adapterType == vboxcon.NetworkAdapterType_I82545EM: sType = "E1000";
|
---|
2080 | elif oNic.adapterType == vboxcon.NetworkAdapterType_I82540EM: sType = "E1000Desk";
|
---|
2081 | elif oNic.adapterType == vboxcon.NetworkAdapterType_I82543GC: sType = "E1000Srv2";
|
---|
2082 | elif oNic.adapterType == vboxcon.NetworkAdapterType_Virtio: sType = "Virtio";
|
---|
2083 | else: sType = "unknown %s" % (oNic.adapterType);
|
---|
2084 | reporter.log(" slot #%d: type: %s (%s) MAC Address: %s lineSpeed: %s" % \
|
---|
2085 | (iSlot, sType, oNic.adapterType, oNic.MACAddress, oNic.lineSpeed) );
|
---|
2086 |
|
---|
2087 | if oNic.attachmentType == vboxcon.NetworkAttachmentType_NAT:
|
---|
2088 | reporter.log(" attachmentType: NAT (%s)" % (oNic.attachmentType));
|
---|
2089 | if self.fpApiVer >= 4.1:
|
---|
2090 | reporter.log(" nat-network: %s" % (oNic.NATNetwork,));
|
---|
2091 | elif oNic.attachmentType == vboxcon.NetworkAttachmentType_Bridged:
|
---|
2092 | reporter.log(" attachmentType: Bridged (%s)" % (oNic.attachmentType));
|
---|
2093 | if self.fpApiVer >= 4.1:
|
---|
2094 | reporter.log(" hostInterface: %s" % (oNic.bridgedInterface));
|
---|
2095 | else:
|
---|
2096 | reporter.log(" hostInterface: %s" % (oNic.hostInterface));
|
---|
2097 | elif oNic.attachmentType == vboxcon.NetworkAttachmentType_Internal:
|
---|
2098 | reporter.log(" attachmentType: Internal (%s)" % (oNic.attachmentType));
|
---|
2099 | reporter.log(" intnet-name: %s" % (oNic.internalNetwork,));
|
---|
2100 | elif oNic.attachmentType == vboxcon.NetworkAttachmentType_HostOnly:
|
---|
2101 | reporter.log(" attachmentType: HostOnly (%s)" % (oNic.attachmentType));
|
---|
2102 | if self.fpApiVer >= 4.1:
|
---|
2103 | reporter.log(" hostInterface: %s" % (oNic.hostOnlyInterface));
|
---|
2104 | else:
|
---|
2105 | reporter.log(" hostInterface: %s" % (oNic.hostInterface));
|
---|
2106 | else:
|
---|
2107 | if self.fpApiVer >= 4.1:
|
---|
2108 | if oNic.attachmentType == vboxcon.NetworkAttachmentType_Generic:
|
---|
2109 | reporter.log(" attachmentType: Generic (%s)" % (oNic.attachmentType));
|
---|
2110 | reporter.log(" generic-driver: %s" % (oNic.GenericDriver));
|
---|
2111 | else:
|
---|
2112 | reporter.log(" attachmentType: unknown-%s" % (oNic.attachmentType));
|
---|
2113 | else:
|
---|
2114 | reporter.log(" attachmentType: unknown-%s" % (oNic.attachmentType));
|
---|
2115 | if oNic.traceEnabled:
|
---|
2116 | reporter.log(" traceFile: %s" % (oNic.traceFile));
|
---|
2117 | self.processPendingEvents();
|
---|
2118 |
|
---|
2119 | reporter.log(" Serial ports:");
|
---|
2120 | for iSlot in range(0, 8):
|
---|
2121 | try: oPort = oVM.getSerialPort(iSlot)
|
---|
2122 | except: break;
|
---|
2123 | if oPort is not None and oPort.enabled:
|
---|
2124 | enmHostMode = oPort.hostMode;
|
---|
2125 | if enmHostMode == vboxcon.PortMode_Disconnected: sType = "Disconnected";
|
---|
2126 | elif enmHostMode == vboxcon.PortMode_HostPipe: sType = "HostPipe";
|
---|
2127 | elif enmHostMode == vboxcon.PortMode_HostDevice: sType = "HostDevice";
|
---|
2128 | elif enmHostMode == vboxcon.PortMode_RawFile: sType = "RawFile";
|
---|
2129 | elif enmHostMode == vboxcon.PortMode_TCP: sType = "TCP";
|
---|
2130 | else: sType = "unknown %s" % (enmHostMode);
|
---|
2131 | reporter.log(" slot #%d: hostMode: %s (%s) I/O port: %s IRQ: %s server: %s path: %s" %
|
---|
2132 | (iSlot, sType, enmHostMode, oPort.IOBase, oPort.IRQ, oPort.server, oPort.path,) );
|
---|
2133 | self.processPendingEvents();
|
---|
2134 |
|
---|
2135 | return True;
|
---|
2136 |
|
---|
2137 | def logVmInfo(self, oVM): # pylint: disable=R0915,R0912
|
---|
2138 | """
|
---|
2139 | Logs VM configuration details.
|
---|
2140 |
|
---|
2141 | This is copy, past, search, replace and edit of infoCmd from vboxshell.py.
|
---|
2142 | """
|
---|
2143 | try:
|
---|
2144 | fRc = self._logVmInfoUnsafe(oVM);
|
---|
2145 | except:
|
---|
2146 | reporter.logXcpt();
|
---|
2147 | fRc = False;
|
---|
2148 | return fRc;
|
---|
2149 |
|
---|
2150 | def logVmInfoByName(self, sName):
|
---|
2151 | """
|
---|
2152 | logVmInfo + getVmByName.
|
---|
2153 | """
|
---|
2154 | return self.logVmInfo(self.getVmByName(sName));
|
---|
2155 |
|
---|
2156 | def tryFindGuestOsId(self, sIdOrDesc):
|
---|
2157 | """
|
---|
2158 | Takes a guest OS ID or Description and returns the ID.
|
---|
2159 | If nothing matching it is found, the input is returned unmodified.
|
---|
2160 | """
|
---|
2161 |
|
---|
2162 | if self.fpApiVer >= 4.0:
|
---|
2163 | if sIdOrDesc == 'Solaris (64 bit)':
|
---|
2164 | sIdOrDesc = 'Oracle Solaris 10 5/09 and earlier (64 bit)';
|
---|
2165 |
|
---|
2166 | try:
|
---|
2167 | aoGuestTypes = self.oVBoxMgr.getArray(self.oVBox, 'GuestOSTypes');
|
---|
2168 | except:
|
---|
2169 | reporter.logXcpt();
|
---|
2170 | else:
|
---|
2171 | for oGuestOS in aoGuestTypes:
|
---|
2172 | try:
|
---|
2173 | sId = oGuestOS.id;
|
---|
2174 | sDesc = oGuestOS.description;
|
---|
2175 | except:
|
---|
2176 | reporter.logXcpt();
|
---|
2177 | else:
|
---|
2178 | if sIdOrDesc == sId or sIdOrDesc == sDesc:
|
---|
2179 | sIdOrDesc = sId;
|
---|
2180 | break;
|
---|
2181 | self.processPendingEvents();
|
---|
2182 | return sIdOrDesc
|
---|
2183 |
|
---|
2184 | def resourceFindVmHd(self, sVmName, sFlavor):
|
---|
2185 | """
|
---|
2186 | Search the test resources for the most recent VM HD.
|
---|
2187 |
|
---|
2188 | Returns path relative to the test resource root.
|
---|
2189 | """
|
---|
2190 | ## @todo implement a proper search algo here.
|
---|
2191 | return '4.2/' + sFlavor + '/' + sVmName + '/t-' + sVmName + '.vdi';
|
---|
2192 |
|
---|
2193 |
|
---|
2194 | #
|
---|
2195 | # VM Api wrappers that logs errors, hides exceptions and other details.
|
---|
2196 | #
|
---|
2197 |
|
---|
2198 | # pylint: disable=R0913,R0914,R0915
|
---|
2199 | def createTestVM(self,
|
---|
2200 | sName,
|
---|
2201 | iGroup,
|
---|
2202 | sHd = None,
|
---|
2203 | cMbRam = None,
|
---|
2204 | cCpus = 1,
|
---|
2205 | fVirtEx = None,
|
---|
2206 | fNestedPaging = None,
|
---|
2207 | sDvdImage = None,
|
---|
2208 | sKind = "Other",
|
---|
2209 | fIoApic = None,
|
---|
2210 | fPae = None,
|
---|
2211 | fFastBootLogo = True,
|
---|
2212 | eNic0Type = None,
|
---|
2213 | eNic0AttachType = None,
|
---|
2214 | sNic0NetName = 'default',
|
---|
2215 | sNic0MacAddr = 'grouped',
|
---|
2216 | sFloppy = None,
|
---|
2217 | fNatForwardingForTxs = None,
|
---|
2218 | sHddControllerType = 'IDE Controller',
|
---|
2219 | fVmmDevTestingPart = None,
|
---|
2220 | fVmmDevTestingMmio = False,
|
---|
2221 | sFirmwareType = 'bios',
|
---|
2222 | sChipsetType = 'piix3',
|
---|
2223 | sDvdControllerType = 'IDE Controller',
|
---|
2224 | sCom1RawFile = None):
|
---|
2225 | """
|
---|
2226 | Creates a test VM with a immutable HD from the test resources.
|
---|
2227 | """
|
---|
2228 | if not self.importVBoxApi():
|
---|
2229 | return None;
|
---|
2230 |
|
---|
2231 | # create + register the VM
|
---|
2232 | try:
|
---|
2233 | if self.fpApiVer >= 4.2: # Introduces grouping (third parameter, empty for now).
|
---|
2234 | oVM = self.oVBox.createMachine("", sName, [], self.tryFindGuestOsId(sKind), "");
|
---|
2235 | elif self.fpApiVer >= 4.0:
|
---|
2236 | oVM = self.oVBox.createMachine("", sName, self.tryFindGuestOsId(sKind), "", False);
|
---|
2237 | elif self.fpApiVer >= 3.2:
|
---|
2238 | oVM = self.oVBox.createMachine(sName, self.tryFindGuestOsId(sKind), "", "", False);
|
---|
2239 | else:
|
---|
2240 | oVM = self.oVBox.createMachine(sName, self.tryFindGuestOsId(sKind), "", "");
|
---|
2241 | try:
|
---|
2242 | oVM.saveSettings();
|
---|
2243 | try:
|
---|
2244 | self.oVBox.registerMachine(oVM);
|
---|
2245 | except:
|
---|
2246 | raise;
|
---|
2247 | except:
|
---|
2248 | reporter.logXcpt();
|
---|
2249 | if self.fpApiVer >= 4.0:
|
---|
2250 | try:
|
---|
2251 | if self.fpApiVer >= 4.3:
|
---|
2252 | oProgress = oVM.deleteConfig([]);
|
---|
2253 | else:
|
---|
2254 | oProgress = oVM.delete(None);
|
---|
2255 | self.waitOnProgress(oProgress);
|
---|
2256 | except:
|
---|
2257 | reporter.logXcpt();
|
---|
2258 | else:
|
---|
2259 | try: oVM.deleteSettings();
|
---|
2260 | except: reporter.logXcpt();
|
---|
2261 | raise;
|
---|
2262 | except:
|
---|
2263 | reporter.errorXcpt('failed to create vm "%s"' % (sName));
|
---|
2264 | return None;
|
---|
2265 |
|
---|
2266 | # Configure the VM.
|
---|
2267 | fRc = True;
|
---|
2268 | oSession = self.openSession(oVM);
|
---|
2269 | if oSession is not None:
|
---|
2270 | fRc = oSession.setupPreferredConfig();
|
---|
2271 |
|
---|
2272 | if fRc and cMbRam is not None :
|
---|
2273 | fRc = oSession.setRamSize(cMbRam);
|
---|
2274 | if fRc and cCpus is not None:
|
---|
2275 | fRc = oSession.setCpuCount(cCpus);
|
---|
2276 | if fRc and fVirtEx is not None:
|
---|
2277 | fRc = oSession.enableVirtEx(fVirtEx);
|
---|
2278 | if fRc and fNestedPaging is not None:
|
---|
2279 | fRc = oSession.enableNestedPaging(fNestedPaging);
|
---|
2280 | if fRc and fIoApic is not None:
|
---|
2281 | fRc = oSession.enableIoApic(fIoApic);
|
---|
2282 | if fRc and fPae is not None:
|
---|
2283 | fRc = oSession.enablePae(fPae);
|
---|
2284 | if fRc and sDvdImage is not None:
|
---|
2285 | fRc = oSession.attachDvd(sDvdImage, sDvdControllerType);
|
---|
2286 | if fRc and sHd is not None:
|
---|
2287 | fRc = oSession.attachHd(sHd, sHddControllerType);
|
---|
2288 | if fRc and sFloppy is not None:
|
---|
2289 | fRc = oSession.attachFloppy(sFloppy);
|
---|
2290 | if fRc and eNic0Type is not None:
|
---|
2291 | fRc = oSession.setNicType(eNic0Type, 0);
|
---|
2292 | if fRc and (eNic0AttachType is not None or (sNic0NetName is not None and sNic0NetName != 'default')):
|
---|
2293 | fRc = oSession.setNicAttachment(eNic0AttachType, sNic0NetName, 0);
|
---|
2294 | if fRc and sNic0MacAddr is not None:
|
---|
2295 | if sNic0MacAddr == 'grouped':
|
---|
2296 | sNic0MacAddr = '%02u' % (iGroup);
|
---|
2297 | fRc = oSession.setNicMacAddress(sNic0MacAddr, 0);
|
---|
2298 | if fRc and fNatForwardingForTxs is True:
|
---|
2299 | fRc = oSession.setupNatForwardingForTxs();
|
---|
2300 | if fRc and fFastBootLogo is not None:
|
---|
2301 | fRc = oSession.setupBootLogo(fFastBootLogo);
|
---|
2302 | if fRc and self.fEnableVrdp:
|
---|
2303 | fRc = oSession.setupVrdp(True, self.uVrdpBasePort + iGroup);
|
---|
2304 | if fRc and fVmmDevTestingPart is not None:
|
---|
2305 | fRc = oSession.enableVmmDevTestingPart(fVmmDevTestingPart, fVmmDevTestingMmio);
|
---|
2306 | if fRc and sFirmwareType == 'bios':
|
---|
2307 | fRc = oSession.setFirmwareType(vboxcon.FirmwareType_BIOS);
|
---|
2308 | elif sFirmwareType == 'efi':
|
---|
2309 | fRc = oSession.setFirmwareType(vboxcon.FirmwareType_EFI);
|
---|
2310 | if fRc and self.fEnableDebugger:
|
---|
2311 | fRc = oSession.setExtraData('VBoxInternal/DBGC/Enabled', '1');
|
---|
2312 | if fRc and sChipsetType == 'piix3':
|
---|
2313 | fRc = oSession.setChipsetType(vboxcon.ChipsetType_PIIX3);
|
---|
2314 | elif sChipsetType == 'ich9':
|
---|
2315 | fRc = oSession.setChipsetType(vboxcon.ChipsetType_ICH9);
|
---|
2316 | if fRc and sCom1RawFile:
|
---|
2317 | fRc = oSession.setupSerialToRawFile(0, sCom1RawFile);
|
---|
2318 |
|
---|
2319 | if fRc: fRc = oSession.saveSettings();
|
---|
2320 | if not fRc: oSession.discardSettings(True);
|
---|
2321 | oSession.close();
|
---|
2322 | if not fRc:
|
---|
2323 | try: self.oVBox.unregisterMachine(oVM.id);
|
---|
2324 | except: pass;
|
---|
2325 | if self.fpApiVer >= 4.0:
|
---|
2326 | try:
|
---|
2327 | if self.fpApiVer >= 4.3:
|
---|
2328 | oProgress = oVM.deleteConfig([]);
|
---|
2329 | else:
|
---|
2330 | oProgress = oVM.delete(None);
|
---|
2331 | self.waitOnProgress(oProgress);
|
---|
2332 | except:
|
---|
2333 | reporter.logXcpt();
|
---|
2334 | else:
|
---|
2335 | try: oVM.deleteSettings();
|
---|
2336 | except: reporter.logXcpt();
|
---|
2337 | return None;
|
---|
2338 |
|
---|
2339 | # success.
|
---|
2340 | reporter.log('created "%s" with name "%s"' % (oVM.id, sName));
|
---|
2341 | self.aoVMs.append(oVM);
|
---|
2342 | self.logVmInfo(oVM); # testing...
|
---|
2343 | return oVM;
|
---|
2344 | # pylint: enable=R0913,R0914,R0915
|
---|
2345 |
|
---|
2346 | def addTestMachine(self, sNameOrId, fQuiet = False):
|
---|
2347 | """
|
---|
2348 | Adds an already existing (that is, configured) test VM to the
|
---|
2349 | test VM list.
|
---|
2350 | """
|
---|
2351 | # find + add the VM to the list.
|
---|
2352 | try:
|
---|
2353 | if self.fpApiVer >= 4.0:
|
---|
2354 | oVM = self.oVBox.findMachine(sNameOrId);
|
---|
2355 | else:
|
---|
2356 | reporter.error('fpApiVer=%s - did you remember to initialize the API' % (self.fpApiVer,));
|
---|
2357 | except:
|
---|
2358 | reporter.errorXcpt('could not find vm "%s"' % (sNameOrId,));
|
---|
2359 | return None;
|
---|
2360 |
|
---|
2361 | self.aoVMs.append(oVM);
|
---|
2362 | if not fQuiet:
|
---|
2363 | reporter.log('Added "%s" with name "%s"' % (oVM.id, sNameOrId));
|
---|
2364 | self.logVmInfo(oVM);
|
---|
2365 | return oVM;
|
---|
2366 |
|
---|
2367 | def openSession(self, oVM):
|
---|
2368 | """
|
---|
2369 | Opens a session for the VM. Returns the a Session wrapper object that
|
---|
2370 | will automatically close the session when the wrapper goes out of scope.
|
---|
2371 |
|
---|
2372 | On failure None is returned and an error is logged.
|
---|
2373 | """
|
---|
2374 | try:
|
---|
2375 | sUuid = oVM.id;
|
---|
2376 | except:
|
---|
2377 | reporter.errorXcpt('failed to get the UUID for VM "%s"' % (oVM,));
|
---|
2378 | return None;
|
---|
2379 |
|
---|
2380 | # This loop is a kludge to deal with us racing the closing of the
|
---|
2381 | # direct session of a previous VM run. See waitOnDirectSessionClose.
|
---|
2382 | for i in range(10):
|
---|
2383 | try:
|
---|
2384 | if self.fpApiVer <= 3.2:
|
---|
2385 | oSession = self.oVBoxMgr.openMachineSession(sUuid);
|
---|
2386 | else:
|
---|
2387 | oSession = self.oVBoxMgr.openMachineSession(oVM);
|
---|
2388 | break;
|
---|
2389 | except:
|
---|
2390 | if i == 9:
|
---|
2391 | reporter.errorXcpt('failed to open session for "%s" ("%s")' % (sUuid, oVM));
|
---|
2392 | return None;
|
---|
2393 | if i > 0:
|
---|
2394 | reporter.logXcpt('warning: failed to open session for "%s" ("%s") - retrying in %u secs' % (sUuid, oVM, i));
|
---|
2395 | self.waitOnDirectSessionClose(oVM, 5000 + i * 1000);
|
---|
2396 | from testdriver.vboxwrappers import SessionWrapper;
|
---|
2397 | return SessionWrapper(oSession, oVM, self.oVBox, self.oVBoxMgr, self, False);
|
---|
2398 |
|
---|
2399 | def getVmByName(self, sName):
|
---|
2400 | """
|
---|
2401 | Get a test VM by name. Returns None if not found, logged.
|
---|
2402 | """
|
---|
2403 | # Look it up in our 'cache'.
|
---|
2404 | for oVM in self.aoVMs:
|
---|
2405 | try:
|
---|
2406 | #reporter.log2('cur: %s / %s (oVM=%s)' % (oVM.name, oVM.id, oVM));
|
---|
2407 | if oVM.name == sName:
|
---|
2408 | return oVM;
|
---|
2409 | except:
|
---|
2410 | reporter.errorXcpt('failed to get the name from the VM "%s"' % (oVM));
|
---|
2411 |
|
---|
2412 | # Look it up the standard way.
|
---|
2413 | return self.addTestMachine(sName, fQuiet = True);
|
---|
2414 |
|
---|
2415 | def getVmByUuid(self, sUuid):
|
---|
2416 | """
|
---|
2417 | Get a test VM by uuid. Returns None if not found, logged.
|
---|
2418 | """
|
---|
2419 | # Look it up in our 'cache'.
|
---|
2420 | for oVM in self.aoVMs:
|
---|
2421 | try:
|
---|
2422 | if oVM.id == sUuid:
|
---|
2423 | return oVM;
|
---|
2424 | except:
|
---|
2425 | reporter.errorXcpt('failed to get the UUID from the VM "%s"' % (oVM));
|
---|
2426 |
|
---|
2427 | # Look it up the standard way.
|
---|
2428 | return self.addTestMachine(sUuid, fQuiet = True);
|
---|
2429 |
|
---|
2430 | def waitOnProgress(self, oProgress, cMsTimeout = 1000000, fErrorOnTimeout = True, cMsInterval = 1000):
|
---|
2431 | """
|
---|
2432 | Waits for a progress object to complete. Returns the status code.
|
---|
2433 | """
|
---|
2434 | # Wait for progress no longer than cMsTimeout time period.
|
---|
2435 | tsStart = datetime.datetime.now()
|
---|
2436 | while True:
|
---|
2437 | self.processPendingEvents();
|
---|
2438 | try:
|
---|
2439 | if oProgress.completed:
|
---|
2440 | break;
|
---|
2441 | except:
|
---|
2442 | return -1;
|
---|
2443 | self.processPendingEvents();
|
---|
2444 |
|
---|
2445 | tsNow = datetime.datetime.now()
|
---|
2446 | tsDelta = tsNow - tsStart
|
---|
2447 | if ((tsDelta.microseconds + tsDelta.seconds * 1000000) // 1000) > cMsTimeout:
|
---|
2448 | if fErrorOnTimeout:
|
---|
2449 | reporter.errorTimeout('Timeout while waiting for progress.')
|
---|
2450 | return -1
|
---|
2451 |
|
---|
2452 | reporter.doPollWork('vbox.TestDriver.waitOnProgress');
|
---|
2453 | try: oProgress.waitForCompletion(cMsInterval);
|
---|
2454 | except: return -2;
|
---|
2455 |
|
---|
2456 | try: rc = oProgress.resultCode;
|
---|
2457 | except: rc = -2;
|
---|
2458 | self.processPendingEvents();
|
---|
2459 | return rc;
|
---|
2460 |
|
---|
2461 | def waitOnDirectSessionClose(self, oVM, cMsTimeout):
|
---|
2462 | """
|
---|
2463 | Waits for the VM process to close it's current direct session.
|
---|
2464 |
|
---|
2465 | Returns None.
|
---|
2466 | """
|
---|
2467 | # Get the original values so we're not subject to
|
---|
2468 | try:
|
---|
2469 | eCurState = oVM.sessionState;
|
---|
2470 | if self.fpApiVer >= 5.0:
|
---|
2471 | sCurName = sOrgName = oVM.sessionName;
|
---|
2472 | else:
|
---|
2473 | sCurName = sOrgName = oVM.sessionType;
|
---|
2474 | if self.fpApiVer >= 4.2:
|
---|
2475 | iCurPid = iOrgPid = oVM.sessionPID;
|
---|
2476 | else:
|
---|
2477 | iCurPid = iOrgPid = oVM.sessionPid;
|
---|
2478 | except Exception as oXcpt:
|
---|
2479 | if ComError.notEqual(oXcpt, ComError.E_ACCESSDENIED):
|
---|
2480 | reporter.logXcpt();
|
---|
2481 | self.processPendingEvents();
|
---|
2482 | return None;
|
---|
2483 | self.processPendingEvents();
|
---|
2484 |
|
---|
2485 | msStart = base.timestampMilli();
|
---|
2486 | while iCurPid == iOrgPid \
|
---|
2487 | and sCurName == sOrgName \
|
---|
2488 | and sCurName != '' \
|
---|
2489 | and base.timestampMilli() - msStart < cMsTimeout \
|
---|
2490 | and ( eCurState == vboxcon.SessionState_Unlocking \
|
---|
2491 | or eCurState == vboxcon.SessionState_Spawning \
|
---|
2492 | or eCurState == vboxcon.SessionState_Locked):
|
---|
2493 | self.processEvents(1000);
|
---|
2494 | try:
|
---|
2495 | eCurState = oVM.sessionState;
|
---|
2496 | sCurName = oVM.sessionName if self.fpApiVer >= 5.0 else oVM.sessionType;
|
---|
2497 | iCurPid = oVM.sessionPID if self.fpApiVer >= 4.2 else oVM.sessionPid;
|
---|
2498 | except Exception as oXcpt:
|
---|
2499 | if ComError.notEqual(oXcpt, ComError.E_ACCESSDENIED):
|
---|
2500 | reporter.logXcpt();
|
---|
2501 | break;
|
---|
2502 | self.processPendingEvents();
|
---|
2503 | self.processPendingEvents();
|
---|
2504 | return None;
|
---|
2505 |
|
---|
2506 | def uploadStartupLogFile(self, oVM, sVmName):
|
---|
2507 | """
|
---|
2508 | Uploads the VBoxStartup.log when present.
|
---|
2509 | """
|
---|
2510 | fRc = True;
|
---|
2511 | try:
|
---|
2512 | sLogFile = os.path.join(oVM.logFolder, 'VBoxHardening.log');
|
---|
2513 | except:
|
---|
2514 | reporter.logXcpt();
|
---|
2515 | fRc = False;
|
---|
2516 | else:
|
---|
2517 | if os.path.isfile(sLogFile):
|
---|
2518 | reporter.addLogFile(sLogFile, 'log/release/vm', '%s hardening log' % (sVmName, ),
|
---|
2519 | sAltName = '%s-%s' % (sVmName, os.path.basename(sLogFile),));
|
---|
2520 | return fRc;
|
---|
2521 |
|
---|
2522 | def annotateAndUploadProcessReport(self, sProcessReport, sFilename, sKind, sDesc):
|
---|
2523 | """
|
---|
2524 | Annotates the given VM process report and uploads it if successfull.
|
---|
2525 | """
|
---|
2526 | fRc = False;
|
---|
2527 | if self.oBuild is not None and self.oBuild.sInstallPath is not None:
|
---|
2528 | oResolver = btresolver.BacktraceResolver(self.sScratchPath, self.oBuild.sInstallPath,
|
---|
2529 | self.getBuildOs(), self.getBuildArch(),
|
---|
2530 | fnLog = reporter.log);
|
---|
2531 | fRcTmp = oResolver.prepareEnv();
|
---|
2532 | if fRcTmp:
|
---|
2533 | reporter.log('Successfully prepared environment');
|
---|
2534 | sReportDbgSym = oResolver.annotateReport(sProcessReport);
|
---|
2535 | if sReportDbgSym is not None:
|
---|
2536 | reporter.addLogString(sReportDbgSym, sFilename, sKind, sDesc);
|
---|
2537 | fRc = True;
|
---|
2538 | else:
|
---|
2539 | reporter.log('Annotating report failed');
|
---|
2540 | oResolver.cleanupEnv();
|
---|
2541 | return fRc;
|
---|
2542 |
|
---|
2543 | def startVmEx(self, oVM, fWait = True, sType = None, sName = None, asEnv = None): # pylint: disable=R0914,R0915
|
---|
2544 | """
|
---|
2545 | Start the VM, returning the VM session and progress object on success.
|
---|
2546 | The session is also added to the task list and to the aoRemoteSessions set.
|
---|
2547 |
|
---|
2548 | asEnv is a list of string on the putenv() form.
|
---|
2549 |
|
---|
2550 | On failure (None, None) is returned and an error is logged.
|
---|
2551 | """
|
---|
2552 | # Massage and check the input.
|
---|
2553 | if sType is None:
|
---|
2554 | sType = self.sSessionType;
|
---|
2555 | if sName is None:
|
---|
2556 | try: sName = oVM.name;
|
---|
2557 | except: sName = 'bad-vm-handle';
|
---|
2558 | reporter.log('startVmEx: sName=%s fWait=%s sType=%s' % (sName, fWait, sType));
|
---|
2559 | if oVM is None:
|
---|
2560 | return (None, None);
|
---|
2561 |
|
---|
2562 | ## @todo Do this elsewhere.
|
---|
2563 | # Hack alert. Disables all annoying GUI popups.
|
---|
2564 | if sType == 'gui' and not self.aoRemoteSessions:
|
---|
2565 | try:
|
---|
2566 | self.oVBox.setExtraData('GUI/Input/AutoCapture', 'false');
|
---|
2567 | if self.fpApiVer >= 3.2:
|
---|
2568 | self.oVBox.setExtraData('GUI/LicenseAgreed', '8');
|
---|
2569 | else:
|
---|
2570 | self.oVBox.setExtraData('GUI/LicenseAgreed', '7');
|
---|
2571 | self.oVBox.setExtraData('GUI/RegistrationData', 'triesLeft=0');
|
---|
2572 | self.oVBox.setExtraData('GUI/SUNOnlineData', 'triesLeft=0');
|
---|
2573 | self.oVBox.setExtraData('GUI/SuppressMessages', 'confirmVMReset,remindAboutMouseIntegrationOn,'
|
---|
2574 | 'remindAboutMouseIntegrationOff,remindAboutPausedVMInput,confirmInputCapture,'
|
---|
2575 | 'confirmGoingFullscreen,remindAboutInaccessibleMedia,remindAboutWrongColorDepth,'
|
---|
2576 | 'confirmRemoveMedium,allPopupPanes,allMessageBoxes,all');
|
---|
2577 | self.oVBox.setExtraData('GUI/UpdateDate', 'never');
|
---|
2578 | self.oVBox.setExtraData('GUI/PreventBetaWarning', self.oVBox.version);
|
---|
2579 | except:
|
---|
2580 | reporter.logXcpt();
|
---|
2581 |
|
---|
2582 | # The UUID for the name.
|
---|
2583 | try:
|
---|
2584 | sUuid = oVM.id;
|
---|
2585 | except:
|
---|
2586 | reporter.errorXcpt('failed to get the UUID for VM "%s"' % (oVM));
|
---|
2587 | return (None, None);
|
---|
2588 | self.processPendingEvents();
|
---|
2589 |
|
---|
2590 | # Construct the environment.
|
---|
2591 | sLogFile = '%s/VM-%s.log' % (self.sScratchPath, sUuid);
|
---|
2592 | try: os.remove(sLogFile);
|
---|
2593 | except: pass;
|
---|
2594 | if self.sLogSessionDest:
|
---|
2595 | sLogDest = self.sLogSessionDest;
|
---|
2596 | else:
|
---|
2597 | sLogDest = 'file=%s' % sLogFile;
|
---|
2598 | sEnv = 'VBOX_LOG=%s\nVBOX_LOG_FLAGS=%s\nVBOX_LOG_DEST=nodeny %s\nVBOX_RELEASE_LOG_FLAGS=append time' \
|
---|
2599 | % (self.sLogSessionGroups, self.sLogSessionFlags, sLogDest,);
|
---|
2600 | # Extra audio logging
|
---|
2601 | sEnv += '\nVBOX_RELEASE_LOG=drv_audio.e.l.l2+drv_host_audio.e.l.l2'
|
---|
2602 | if sType == 'gui':
|
---|
2603 | sEnv += '\nVBOX_GUI_DBG_ENABLED=1'
|
---|
2604 | if asEnv is not None and asEnv:
|
---|
2605 | sEnv += '\n' + ('\n'.join(asEnv));
|
---|
2606 |
|
---|
2607 | # Shortcuts for local testing.
|
---|
2608 | oProgress = oWrapped = None;
|
---|
2609 | oTestVM = self.oTestVmSet.findTestVmByName(sName) if self.oTestVmSet is not None else None;
|
---|
2610 | try:
|
---|
2611 | if oTestVM is not None \
|
---|
2612 | and oTestVM.fSnapshotRestoreCurrent is True:
|
---|
2613 | if oVM.state is vboxcon.MachineState_Running:
|
---|
2614 | reporter.log2('Machine "%s" already running.' % (sName,));
|
---|
2615 | oProgress = None;
|
---|
2616 | oWrapped = self.openSession(oVM);
|
---|
2617 | else:
|
---|
2618 | reporter.log2('Checking if snapshot for machine "%s" exists.' % (sName,));
|
---|
2619 | oSessionWrapperRestore = self.openSession(oVM);
|
---|
2620 | if oSessionWrapperRestore is not None:
|
---|
2621 | oSnapshotCur = oVM.currentSnapshot;
|
---|
2622 | if oSnapshotCur is not None:
|
---|
2623 | reporter.log2('Restoring snapshot for machine "%s".' % (sName,));
|
---|
2624 | oSessionWrapperRestore.restoreSnapshot(oSnapshotCur);
|
---|
2625 | reporter.log2('Current snapshot for machine "%s" restored.' % (sName,));
|
---|
2626 | else:
|
---|
2627 | reporter.log('warning: no current snapshot for machine "%s" found.' % (sName,));
|
---|
2628 | oSessionWrapperRestore.close();
|
---|
2629 | except:
|
---|
2630 | reporter.errorXcpt();
|
---|
2631 | return (None, None);
|
---|
2632 |
|
---|
2633 | # Open a remote session, wait for this operation to complete.
|
---|
2634 | # (The loop is a kludge to deal with us racing the closing of the
|
---|
2635 | # direct session of a previous VM run. See waitOnDirectSessionClose.)
|
---|
2636 | if oWrapped is None:
|
---|
2637 | for i in range(10):
|
---|
2638 | try:
|
---|
2639 | if self.fpApiVer < 4.3 \
|
---|
2640 | or (self.fpApiVer == 4.3 and not hasattr(self.oVBoxMgr, 'getSessionObject')):
|
---|
2641 | oSession = self.oVBoxMgr.mgr.getSessionObject(self.oVBox); # pylint: disable=E1101
|
---|
2642 | elif self.fpApiVer < 5.2 \
|
---|
2643 | or (self.fpApiVer == 5.2 and hasattr(self.oVBoxMgr, 'vbox')):
|
---|
2644 | oSession = self.oVBoxMgr.getSessionObject(self.oVBox); # pylint: disable=E1101
|
---|
2645 | else:
|
---|
2646 | oSession = self.oVBoxMgr.getSessionObject(); # pylint: disable=E1101,E1120
|
---|
2647 | if self.fpApiVer < 3.3:
|
---|
2648 | oProgress = self.oVBox.openRemoteSession(oSession, sUuid, sType, sEnv);
|
---|
2649 | else:
|
---|
2650 | oProgress = oVM.launchVMProcess(oSession, sType, sEnv);
|
---|
2651 | break;
|
---|
2652 | except:
|
---|
2653 | if i == 9:
|
---|
2654 | reporter.errorXcpt('failed to start VM "%s" ("%s"), aborting.' % (sUuid, sName));
|
---|
2655 | return (None, None);
|
---|
2656 | oSession = None;
|
---|
2657 | if i >= 0:
|
---|
2658 | reporter.logXcpt('warning: failed to start VM "%s" ("%s") - retrying in %u secs.' % (sUuid, oVM, i)); # pylint: disable=C0301
|
---|
2659 | self.waitOnDirectSessionClose(oVM, 5000 + i * 1000);
|
---|
2660 | if fWait and oProgress is not None:
|
---|
2661 | rc = self.waitOnProgress(oProgress);
|
---|
2662 | if rc < 0:
|
---|
2663 | self.waitOnDirectSessionClose(oVM, 5000);
|
---|
2664 |
|
---|
2665 | # VM failed to power up, still collect VBox.log, need to wrap the session object
|
---|
2666 | # in order to use the helper for adding the log files to the report.
|
---|
2667 | from testdriver.vboxwrappers import SessionWrapper;
|
---|
2668 | oTmp = SessionWrapper(oSession, oVM, self.oVBox, self.oVBoxMgr, self, True, sName, sLogFile);
|
---|
2669 | oTmp.addLogsToReport();
|
---|
2670 | try:
|
---|
2671 | if oSession is not None:
|
---|
2672 | oSession.close();
|
---|
2673 | except: pass;
|
---|
2674 | reportError(oProgress, 'failed to open session for "%s"' % (sName));
|
---|
2675 | self.uploadStartupLogFile(oVM, sName);
|
---|
2676 | return (None, None);
|
---|
2677 | reporter.log2('waitOnProgress -> %s' % (rc,));
|
---|
2678 |
|
---|
2679 | # Wrap up the session object and push on to the list before returning it.
|
---|
2680 | if oWrapped is None:
|
---|
2681 | from testdriver.vboxwrappers import SessionWrapper;
|
---|
2682 | oWrapped = SessionWrapper(oSession, oVM, self.oVBox, self.oVBoxMgr, self, True, sName, sLogFile);
|
---|
2683 |
|
---|
2684 | oWrapped.registerEventHandlerForTask();
|
---|
2685 | self.aoRemoteSessions.append(oWrapped);
|
---|
2686 | if oWrapped is not self.aoRemoteSessions[len(self.aoRemoteSessions) - 1]:
|
---|
2687 | reporter.error('not by reference: oWrapped=%s aoRemoteSessions[%s]=%s'
|
---|
2688 | % (oWrapped, len(self.aoRemoteSessions) - 1,
|
---|
2689 | self.aoRemoteSessions[len(self.aoRemoteSessions) - 1]));
|
---|
2690 | self.addTask(oWrapped);
|
---|
2691 |
|
---|
2692 | reporter.log2('startVmEx: oSession=%s, oSessionWrapper=%s, oProgress=%s' % (oSession, oWrapped, oProgress));
|
---|
2693 |
|
---|
2694 | from testdriver.vboxwrappers import ProgressWrapper;
|
---|
2695 | return (oWrapped, ProgressWrapper(oProgress, self.oVBoxMgr, self,
|
---|
2696 | 'starting %s' % (sName,)) if oProgress else None);
|
---|
2697 |
|
---|
2698 | def startVm(self, oVM, sType=None, sName = None, asEnv = None):
|
---|
2699 | """ Simplified version of startVmEx. """
|
---|
2700 | oSession, _ = self.startVmEx(oVM, True, sType, sName, asEnv = asEnv);
|
---|
2701 | return oSession;
|
---|
2702 |
|
---|
2703 | def startVmByNameEx(self, sName, fWait=True, sType=None, asEnv = None):
|
---|
2704 | """
|
---|
2705 | Start the VM, returning the VM session and progress object on success.
|
---|
2706 | The session is also added to the task list and to the aoRemoteSessions set.
|
---|
2707 |
|
---|
2708 | On failure (None, None) is returned and an error is logged.
|
---|
2709 | """
|
---|
2710 | oVM = self.getVmByName(sName);
|
---|
2711 | if oVM is None:
|
---|
2712 | return (None, None);
|
---|
2713 | return self.startVmEx(oVM, fWait, sType, sName, asEnv = asEnv);
|
---|
2714 |
|
---|
2715 | def startVmByName(self, sName, sType=None, asEnv = None):
|
---|
2716 | """
|
---|
2717 | Start the VM, returning the VM session on success. The session is
|
---|
2718 | also added to the task list and to the aoRemoteSessions set.
|
---|
2719 |
|
---|
2720 | On failure None is returned and an error is logged.
|
---|
2721 | """
|
---|
2722 | oSession, _ = self.startVmByNameEx(sName, True, sType, asEnv = asEnv);
|
---|
2723 | return oSession;
|
---|
2724 |
|
---|
2725 | def terminateVmBySession(self, oSession, oProgress = None, fTakeScreenshot = None): # pylint: disable=R0915
|
---|
2726 | """
|
---|
2727 | Terminates the VM specified by oSession and adds the release logs to
|
---|
2728 | the test report.
|
---|
2729 |
|
---|
2730 | This will try achieve this by using powerOff, but will resort to
|
---|
2731 | tougher methods if that fails.
|
---|
2732 |
|
---|
2733 | The session will always be removed from the task list.
|
---|
2734 | The session will be closed unless we fail to kill the process.
|
---|
2735 | The session will be removed from the remote session list if closed.
|
---|
2736 |
|
---|
2737 | The progress object (a wrapper!) is for teleportation and similar VM
|
---|
2738 | operations, it will be attempted canceled before powering off the VM.
|
---|
2739 | Failures are logged but ignored.
|
---|
2740 | The progress object will always be removed from the task list.
|
---|
2741 |
|
---|
2742 | Returns True if powerOff and session close both succeed.
|
---|
2743 | Returns False if on failure (logged), including when we successfully
|
---|
2744 | kill the VM process.
|
---|
2745 | """
|
---|
2746 | reporter.log2('terminateVmBySession: oSession=%s (pid=%s) oProgress=%s' % (oSession.sName, oSession.getPid(), oProgress));
|
---|
2747 |
|
---|
2748 | # Call getPid first to make sure the PID is cached in the wrapper.
|
---|
2749 | oSession.getPid();
|
---|
2750 |
|
---|
2751 | #
|
---|
2752 | # If the host is out of memory, just skip all the info collection as it
|
---|
2753 | # requires memory too and seems to wedge.
|
---|
2754 | #
|
---|
2755 | sHostProcessInfo = None;
|
---|
2756 | sHostProcessInfoHung = None;
|
---|
2757 | sLastScreenshotPath = None;
|
---|
2758 | sOsKernelLog = None;
|
---|
2759 | sVgaText = None;
|
---|
2760 | asMiscInfos = [];
|
---|
2761 |
|
---|
2762 | if not oSession.fHostMemoryLow:
|
---|
2763 | # Try to fetch the VM process info before meddling with its state.
|
---|
2764 | if self.fAlwaysUploadLogs or reporter.testErrorCount() > 0:
|
---|
2765 | sHostProcessInfo = utils.processGetInfo(oSession.getPid(), fSudo = True);
|
---|
2766 |
|
---|
2767 | #
|
---|
2768 | # Pause the VM if we're going to take any screenshots or dig into the
|
---|
2769 | # guest. Failures are quitely ignored.
|
---|
2770 | #
|
---|
2771 | if self.fAlwaysUploadLogs or reporter.testErrorCount() > 0:
|
---|
2772 | try:
|
---|
2773 | if oSession.oVM.state in [ vboxcon.MachineState_Running,
|
---|
2774 | vboxcon.MachineState_LiveSnapshotting,
|
---|
2775 | vboxcon.MachineState_Teleporting ]:
|
---|
2776 | oSession.o.console.pause();
|
---|
2777 | except:
|
---|
2778 | reporter.logXcpt();
|
---|
2779 |
|
---|
2780 | #
|
---|
2781 | # Take Screenshot and upload it (see below) to Test Manager if appropriate/requested.
|
---|
2782 | #
|
---|
2783 | if fTakeScreenshot is True or self.fAlwaysUploadScreenshots or reporter.testErrorCount() > 0:
|
---|
2784 | sLastScreenshotPath = os.path.join(self.sScratchPath, "LastScreenshot-%s.png" % oSession.sName);
|
---|
2785 | fRc = oSession.takeScreenshot(sLastScreenshotPath);
|
---|
2786 | if fRc is not True:
|
---|
2787 | sLastScreenshotPath = None;
|
---|
2788 |
|
---|
2789 | # Query the OS kernel log from the debugger if appropriate/requested.
|
---|
2790 | if self.fAlwaysUploadLogs or reporter.testErrorCount() > 0:
|
---|
2791 | sOsKernelLog = oSession.queryOsKernelLog();
|
---|
2792 |
|
---|
2793 | # Do "info vgatext all" separately.
|
---|
2794 | if self.fAlwaysUploadLogs or reporter.testErrorCount() > 0:
|
---|
2795 | sVgaText = oSession.queryDbgInfoVgaText();
|
---|
2796 |
|
---|
2797 | # Various infos (do after kernel because of symbols).
|
---|
2798 | if self.fAlwaysUploadLogs or reporter.testErrorCount() > 0:
|
---|
2799 | # Dump the guest stack for all CPUs.
|
---|
2800 | cCpus = oSession.getCpuCount();
|
---|
2801 | if cCpus > 0:
|
---|
2802 | for iCpu in xrange(0, cCpus):
|
---|
2803 | sThis = oSession.queryDbgGuestStack(iCpu);
|
---|
2804 | if sThis:
|
---|
2805 | asMiscInfos += [
|
---|
2806 | '================ start guest stack VCPU %s ================\n' % (iCpu,),
|
---|
2807 | sThis,
|
---|
2808 | '================ end guest stack VCPU %s ==================\n' % (iCpu,),
|
---|
2809 | ];
|
---|
2810 |
|
---|
2811 | for sInfo, sArg in [ ('mode', 'all'),
|
---|
2812 | ('fflags', ''),
|
---|
2813 | ('cpumguest', 'verbose all'),
|
---|
2814 | ('cpumguestinstr', 'symbol all'),
|
---|
2815 | ('pic', ''),
|
---|
2816 | ('apic', ''),
|
---|
2817 | ('apiclvt', ''),
|
---|
2818 | ('apictimer', ''),
|
---|
2819 | ('ioapic', ''),
|
---|
2820 | ('pit', ''),
|
---|
2821 | ('phys', ''),
|
---|
2822 | ('clocks', ''),
|
---|
2823 | ('timers', ''),
|
---|
2824 | ('gdtguest', ''),
|
---|
2825 | ('ldtguest', ''),
|
---|
2826 | ]:
|
---|
2827 | if sInfo in ['apic',] and self.fpApiVer < 5.1: # asserts and burns
|
---|
2828 | continue;
|
---|
2829 | sThis = oSession.queryDbgInfo(sInfo, sArg);
|
---|
2830 | if sThis:
|
---|
2831 | if sThis[-1] != '\n':
|
---|
2832 | sThis += '\n';
|
---|
2833 | asMiscInfos += [
|
---|
2834 | '================ start %s %s ================\n' % (sInfo, sArg),
|
---|
2835 | sThis,
|
---|
2836 | '================ end %s %s ==================\n' % (sInfo, sArg),
|
---|
2837 | ];
|
---|
2838 |
|
---|
2839 | #
|
---|
2840 | # Terminate the VM
|
---|
2841 | #
|
---|
2842 |
|
---|
2843 | # Cancel the progress object if specified.
|
---|
2844 | if oProgress is not None:
|
---|
2845 | if not oProgress.isCompleted() and oProgress.isCancelable():
|
---|
2846 | reporter.log2('terminateVmBySession: canceling "%s"...' % (oProgress.sName));
|
---|
2847 | try:
|
---|
2848 | oProgress.o.cancel();
|
---|
2849 | except:
|
---|
2850 | reporter.logXcpt();
|
---|
2851 | else:
|
---|
2852 | oProgress.wait();
|
---|
2853 | self.removeTask(oProgress);
|
---|
2854 |
|
---|
2855 | # Check if the VM has terminated by itself before powering it off.
|
---|
2856 | fClose = True;
|
---|
2857 | fRc = True;
|
---|
2858 | if oSession.needsPoweringOff():
|
---|
2859 | reporter.log('terminateVmBySession: powering off "%s"...' % (oSession.sName,));
|
---|
2860 | fRc = oSession.powerOff(fFudgeOnFailure = False);
|
---|
2861 | if fRc is not True:
|
---|
2862 | # power off failed, try terminate it in a nice manner.
|
---|
2863 | fRc = False;
|
---|
2864 | uPid = oSession.getPid();
|
---|
2865 | if uPid is not None:
|
---|
2866 | #
|
---|
2867 | # Collect some information about the VM process first to have
|
---|
2868 | # some state information for further investigation why powering off failed.
|
---|
2869 | #
|
---|
2870 | sHostProcessInfoHung = utils.processGetInfo(uPid, fSudo = True);
|
---|
2871 |
|
---|
2872 | # Exterminate...
|
---|
2873 | reporter.error('terminateVmBySession: Terminating PID %u (VM %s)' % (uPid, oSession.sName));
|
---|
2874 | fClose = base.processTerminate(uPid);
|
---|
2875 | if fClose is True:
|
---|
2876 | self.waitOnDirectSessionClose(oSession.oVM, 5000);
|
---|
2877 | fClose = oSession.waitForTask(1000);
|
---|
2878 |
|
---|
2879 | if fClose is not True:
|
---|
2880 | # Being nice failed...
|
---|
2881 | reporter.error('terminateVmBySession: Termination failed, trying to kill PID %u (VM %s) instead' \
|
---|
2882 | % (uPid, oSession.sName));
|
---|
2883 | fClose = base.processKill(uPid);
|
---|
2884 | if fClose is True:
|
---|
2885 | self.waitOnDirectSessionClose(oSession.oVM, 5000);
|
---|
2886 | fClose = oSession.waitForTask(1000);
|
---|
2887 | if fClose is not True:
|
---|
2888 | reporter.error('terminateVmBySession: Failed to kill PID %u (VM %s)' % (uPid, oSession.sName));
|
---|
2889 |
|
---|
2890 | # The final steps.
|
---|
2891 | if fClose is True:
|
---|
2892 | reporter.log('terminateVmBySession: closing session "%s"...' % (oSession.sName,));
|
---|
2893 | oSession.close();
|
---|
2894 | self.waitOnDirectSessionClose(oSession.oVM, 10000);
|
---|
2895 | try:
|
---|
2896 | eState = oSession.oVM.state;
|
---|
2897 | except:
|
---|
2898 | reporter.logXcpt();
|
---|
2899 | else:
|
---|
2900 | if eState == vboxcon.MachineState_Aborted:
|
---|
2901 | reporter.error('terminateVmBySession: The VM "%s" aborted!' % (oSession.sName,));
|
---|
2902 | self.removeTask(oSession);
|
---|
2903 |
|
---|
2904 | #
|
---|
2905 | # Add the release log, debug log and a screenshot of the VM to the test report.
|
---|
2906 | #
|
---|
2907 | if self.fAlwaysUploadLogs or reporter.testErrorCount() > 0:
|
---|
2908 | oSession.addLogsToReport();
|
---|
2909 |
|
---|
2910 | # Add a screenshot if it has been requested and taken successfully.
|
---|
2911 | if sLastScreenshotPath is not None:
|
---|
2912 | if reporter.testErrorCount() > 0:
|
---|
2913 | reporter.addLogFile(sLastScreenshotPath, 'screenshot/failure', 'Last VM screenshot');
|
---|
2914 | else:
|
---|
2915 | reporter.addLogFile(sLastScreenshotPath, 'screenshot/success', 'Last VM screenshot');
|
---|
2916 |
|
---|
2917 | # Add the guest OS log if it has been requested and taken successfully.
|
---|
2918 | if sOsKernelLog is not None:
|
---|
2919 | reporter.addLogString(sOsKernelLog, 'kernel.log', 'log/guest/kernel', 'Guest OS kernel log');
|
---|
2920 |
|
---|
2921 | # Add "info vgatext all" if we've got it.
|
---|
2922 | if sVgaText is not None:
|
---|
2923 | reporter.addLogString(sVgaText, 'vgatext.txt', 'info/vgatext', 'info vgatext all');
|
---|
2924 |
|
---|
2925 | # Add the "info xxxx" items if we've got any.
|
---|
2926 | if asMiscInfos:
|
---|
2927 | reporter.addLogString(u''.join(asMiscInfos), 'info.txt', 'info/collection', 'A bunch of info items.');
|
---|
2928 |
|
---|
2929 | # Add the host process info if we were able to retrieve it.
|
---|
2930 | if sHostProcessInfo is not None:
|
---|
2931 | reporter.log('Trying to annotate the VM process report, please stand by...');
|
---|
2932 | fRcTmp = self.annotateAndUploadProcessReport(sHostProcessInfo, 'vmprocess.log',
|
---|
2933 | 'process/report/vm', 'Annotated VM process state');
|
---|
2934 | # Upload the raw log for manual annotation in case resolving failed.
|
---|
2935 | if not fRcTmp:
|
---|
2936 | reporter.log('Failed to annotate VM process report, uploading raw report');
|
---|
2937 | reporter.addLogString(sHostProcessInfo, 'vmprocess.log', 'process/report/vm', 'VM process state');
|
---|
2938 |
|
---|
2939 | # Add the host process info for failed power off attempts if we were able to retrieve it.
|
---|
2940 | if sHostProcessInfoHung is not None:
|
---|
2941 | reporter.log('Trying to annotate the hung VM process report, please stand by...');
|
---|
2942 | fRcTmp = self.annotateAndUploadProcessReport(sHostProcessInfoHung, 'vmprocess-hung.log',
|
---|
2943 | 'process/report/vm', 'Annotated hung VM process state');
|
---|
2944 | # Upload the raw log for manual annotation in case resolving failed.
|
---|
2945 | if not fRcTmp:
|
---|
2946 | reporter.log('Failed to annotate hung VM process report, uploading raw report');
|
---|
2947 | reporter.addLogString(sHostProcessInfoHung, 'vmprocess-hung.log', 'process/report/vm',
|
---|
2948 | 'Hung VM process state');
|
---|
2949 |
|
---|
2950 | return fRc;
|
---|
2951 |
|
---|
2952 |
|
---|
2953 | #
|
---|
2954 | # Some information query functions (mix).
|
---|
2955 | #
|
---|
2956 | # Methods require the VBox API. If the information is provided by both
|
---|
2957 | # the testboxscript as well as VBox API, we'll check if it matches.
|
---|
2958 | #
|
---|
2959 |
|
---|
2960 | def _hasHostCpuFeature(self, sEnvVar, sEnum, fpApiMinVer, fQuiet):
|
---|
2961 | """
|
---|
2962 | Common Worker for hasHostNestedPaging() and hasHostHwVirt().
|
---|
2963 |
|
---|
2964 | Returns True / False.
|
---|
2965 | Raises exception on environment / host mismatch.
|
---|
2966 | """
|
---|
2967 | fEnv = os.environ.get(sEnvVar, None);
|
---|
2968 | if fEnv is not None:
|
---|
2969 | fEnv = fEnv.lower() not in [ 'false', 'f', 'not', 'no', 'n', '0', ];
|
---|
2970 |
|
---|
2971 | fVBox = None;
|
---|
2972 | self.importVBoxApi();
|
---|
2973 | if self.fpApiVer >= fpApiMinVer and hasattr(vboxcon, sEnum):
|
---|
2974 | try:
|
---|
2975 | fVBox = self.oVBox.host.getProcessorFeature(getattr(vboxcon, sEnum));
|
---|
2976 | except:
|
---|
2977 | if not fQuiet:
|
---|
2978 | reporter.logXcpt();
|
---|
2979 |
|
---|
2980 | if fVBox is not None:
|
---|
2981 | if fEnv is not None:
|
---|
2982 | if fEnv != fVBox and not fQuiet:
|
---|
2983 | reporter.log('TestBox configuration overwritten: fVBox=%s (%s) vs. fEnv=%s (%s)'
|
---|
2984 | % (fVBox, sEnum, fEnv, sEnvVar));
|
---|
2985 | return fEnv;
|
---|
2986 | return fVBox;
|
---|
2987 | if fEnv is not None:
|
---|
2988 | return fEnv;
|
---|
2989 | return False;
|
---|
2990 |
|
---|
2991 | def hasHostHwVirt(self, fQuiet = False):
|
---|
2992 | """
|
---|
2993 | Checks if hardware assisted virtualization is supported by the host.
|
---|
2994 |
|
---|
2995 | Returns True / False.
|
---|
2996 | Raises exception on environment / host mismatch.
|
---|
2997 | """
|
---|
2998 | return self._hasHostCpuFeature('TESTBOX_HAS_HW_VIRT', 'ProcessorFeature_HWVirtEx', 3.1, fQuiet);
|
---|
2999 |
|
---|
3000 | def hasHostNestedPaging(self, fQuiet = False):
|
---|
3001 | """
|
---|
3002 | Checks if nested paging is supported by the host.
|
---|
3003 |
|
---|
3004 | Returns True / False.
|
---|
3005 | Raises exception on environment / host mismatch.
|
---|
3006 | """
|
---|
3007 | return self._hasHostCpuFeature('TESTBOX_HAS_NESTED_PAGING', 'ProcessorFeature_NestedPaging', 4.2, fQuiet) \
|
---|
3008 | and self.hasHostHwVirt(fQuiet);
|
---|
3009 |
|
---|
3010 | def hasHostLongMode(self, fQuiet = False):
|
---|
3011 | """
|
---|
3012 | Checks if the host supports 64-bit guests.
|
---|
3013 |
|
---|
3014 | Returns True / False.
|
---|
3015 | Raises exception on environment / host mismatch.
|
---|
3016 | """
|
---|
3017 | # Note that the testboxscript doesn't export this variable atm.
|
---|
3018 | return self._hasHostCpuFeature('TESTBOX_HAS_LONG_MODE', 'ProcessorFeature_LongMode', 3.1, fQuiet);
|
---|
3019 |
|
---|
3020 | def getHostCpuCount(self, fQuiet = False):
|
---|
3021 | """
|
---|
3022 | Returns the number of CPUs on the host.
|
---|
3023 |
|
---|
3024 | Returns True / False.
|
---|
3025 | Raises exception on environment / host mismatch.
|
---|
3026 | """
|
---|
3027 | cEnv = os.environ.get('TESTBOX_CPU_COUNT', None);
|
---|
3028 | if cEnv is not None:
|
---|
3029 | cEnv = int(cEnv);
|
---|
3030 |
|
---|
3031 | try:
|
---|
3032 | cVBox = self.oVBox.host.processorOnlineCount;
|
---|
3033 | except:
|
---|
3034 | if not fQuiet:
|
---|
3035 | reporter.logXcpt();
|
---|
3036 | cVBox = None;
|
---|
3037 |
|
---|
3038 | if cVBox is not None:
|
---|
3039 | if cEnv is not None:
|
---|
3040 | assert cVBox == cEnv, 'Misconfigured TestBox: VBox: %u CPUs, testboxscript: %u CPUs' % (cVBox, cEnv);
|
---|
3041 | return cVBox;
|
---|
3042 | if cEnv is not None:
|
---|
3043 | return cEnv;
|
---|
3044 | return 1;
|
---|
3045 |
|
---|
3046 | def _getHostCpuDesc(self, fQuiet = False):
|
---|
3047 | """
|
---|
3048 | Internal method used for getting the host CPU description from VBoxSVC.
|
---|
3049 | Returns description string, on failure an empty string is returned.
|
---|
3050 | """
|
---|
3051 | try:
|
---|
3052 | return self.oVBox.host.getProcessorDescription(0);
|
---|
3053 | except:
|
---|
3054 | if not fQuiet:
|
---|
3055 | reporter.logXcpt();
|
---|
3056 | return '';
|
---|
3057 |
|
---|
3058 | def isHostCpuAmd(self, fQuiet = False):
|
---|
3059 | """
|
---|
3060 | Checks if the host CPU vendor is AMD.
|
---|
3061 |
|
---|
3062 | Returns True / False.
|
---|
3063 | """
|
---|
3064 | sCpuDesc = self._getHostCpuDesc(fQuiet);
|
---|
3065 | return sCpuDesc.startswith("AMD") or sCpuDesc == 'AuthenticAMD';
|
---|
3066 |
|
---|
3067 | def isHostCpuIntel(self, fQuiet = False):
|
---|
3068 | """
|
---|
3069 | Checks if the host CPU vendor is Intel.
|
---|
3070 |
|
---|
3071 | Returns True / False.
|
---|
3072 | """
|
---|
3073 | sCpuDesc = self._getHostCpuDesc(fQuiet);
|
---|
3074 | return sCpuDesc.startswith("Intel") or sCpuDesc == 'GenuineIntel';
|
---|
3075 |
|
---|
3076 | def isHostCpuVia(self, fQuiet = False):
|
---|
3077 | """
|
---|
3078 | Checks if the host CPU vendor is VIA (or Centaur).
|
---|
3079 |
|
---|
3080 | Returns True / False.
|
---|
3081 | """
|
---|
3082 | sCpuDesc = self._getHostCpuDesc(fQuiet);
|
---|
3083 | return sCpuDesc.startswith("VIA") or sCpuDesc == 'CentaurHauls';
|
---|
3084 |
|
---|
3085 | def isHostCpuP4(self, fQuiet = False):
|
---|
3086 | """
|
---|
3087 | Checks if the host CPU is a Pentium 4 / Pentium D.
|
---|
3088 |
|
---|
3089 | Returns True / False.
|
---|
3090 | """
|
---|
3091 | if not self.isHostCpuIntel(fQuiet):
|
---|
3092 | return False;
|
---|
3093 |
|
---|
3094 | (uFamilyModel, _, _, _) = self.oVBox.host.getProcessorCPUIDLeaf(0, 0x1, 0);
|
---|
3095 | return ((uFamilyModel >> 8) & 0xf) == 0xf;
|
---|
3096 |
|
---|
3097 | def hasRawModeSupport(self, fQuiet = False):
|
---|
3098 | """
|
---|
3099 | Checks if raw-mode is supported by VirtualBox that the testbox is
|
---|
3100 | configured for it.
|
---|
3101 |
|
---|
3102 | Returns True / False.
|
---|
3103 | Raises no exceptions.
|
---|
3104 |
|
---|
3105 | Note! Differs from the rest in that we don't require the
|
---|
3106 | TESTBOX_WITH_RAW_MODE value to match the API. It is
|
---|
3107 | sometimes helpful to disable raw-mode on individual
|
---|
3108 | test boxes. (This probably goes for
|
---|
3109 | """
|
---|
3110 | # The environment variable can be used to disable raw-mode.
|
---|
3111 | fEnv = os.environ.get('TESTBOX_WITH_RAW_MODE', None);
|
---|
3112 | if fEnv is not None:
|
---|
3113 | fEnv = fEnv.lower() not in [ 'false', 'f', 'not', 'no', 'n', '0', ];
|
---|
3114 | if fEnv is False:
|
---|
3115 | return False;
|
---|
3116 |
|
---|
3117 | # Starting with 5.0 GA / RC2 the API can tell us whether VBox was built
|
---|
3118 | # with raw-mode support or not.
|
---|
3119 | self.importVBoxApi();
|
---|
3120 | if self.fpApiVer >= 5.0:
|
---|
3121 | try:
|
---|
3122 | fVBox = self.oVBox.systemProperties.rawModeSupported;
|
---|
3123 | except:
|
---|
3124 | if not fQuiet:
|
---|
3125 | reporter.logXcpt();
|
---|
3126 | fVBox = True;
|
---|
3127 | if fVBox is False:
|
---|
3128 | return False;
|
---|
3129 |
|
---|
3130 | return True;
|
---|
3131 |
|
---|
3132 | #
|
---|
3133 | # Testdriver execution methods.
|
---|
3134 | #
|
---|
3135 |
|
---|
3136 | def handleTask(self, oTask, sMethod):
|
---|
3137 | """
|
---|
3138 | Callback method for handling unknown tasks in the various run loops.
|
---|
3139 |
|
---|
3140 | The testdriver should override this if it already tasks running when
|
---|
3141 | calling startVmAndConnectToTxsViaTcp, txsRunTest or similar methods.
|
---|
3142 | Call super to handle unknown tasks.
|
---|
3143 |
|
---|
3144 | Returns True if handled, False if not.
|
---|
3145 | """
|
---|
3146 | reporter.error('%s: unknown task %s' % (sMethod, oTask));
|
---|
3147 | return False;
|
---|
3148 |
|
---|
3149 | def txsDoTask(self, oSession, oTxsSession, fnAsync, aArgs):
|
---|
3150 | """
|
---|
3151 | Generic TXS task wrapper which waits both on the TXS and the session tasks.
|
---|
3152 |
|
---|
3153 | Returns False on error, logged.
|
---|
3154 |
|
---|
3155 | Returns task result on success.
|
---|
3156 | """
|
---|
3157 | # All async methods ends with the following to args.
|
---|
3158 | cMsTimeout = aArgs[-2];
|
---|
3159 | fIgnoreErrors = aArgs[-1];
|
---|
3160 |
|
---|
3161 | fRemoveVm = self.addTask(oSession);
|
---|
3162 | fRemoveTxs = self.addTask(oTxsSession);
|
---|
3163 |
|
---|
3164 | rc = fnAsync(*aArgs); # pylint: disable=W0142
|
---|
3165 | if rc is True:
|
---|
3166 | rc = False;
|
---|
3167 | oTask = self.waitForTasks(cMsTimeout + 1);
|
---|
3168 | if oTask is oTxsSession:
|
---|
3169 | if oTxsSession.isSuccess():
|
---|
3170 | rc = oTxsSession.getResult();
|
---|
3171 | elif fIgnoreErrors is True:
|
---|
3172 | reporter.log( 'txsDoTask: task failed (%s)' % (oTxsSession.getLastReply()[1],));
|
---|
3173 | else:
|
---|
3174 | reporter.error('txsDoTask: task failed (%s)' % (oTxsSession.getLastReply()[1],));
|
---|
3175 | else:
|
---|
3176 | oTxsSession.cancelTask();
|
---|
3177 | if oTask is None:
|
---|
3178 | if fIgnoreErrors is True:
|
---|
3179 | reporter.log( 'txsDoTask: The task timed out.');
|
---|
3180 | else:
|
---|
3181 | reporter.errorTimeout('txsDoTask: The task timed out.');
|
---|
3182 | elif oTask is oSession:
|
---|
3183 | reporter.error('txsDoTask: The VM terminated unexpectedly');
|
---|
3184 | else:
|
---|
3185 | if fIgnoreErrors is True:
|
---|
3186 | reporter.log( 'txsDoTask: An unknown task %s was returned' % (oTask,));
|
---|
3187 | else:
|
---|
3188 | reporter.error('txsDoTask: An unknown task %s was returned' % (oTask,));
|
---|
3189 | else:
|
---|
3190 | reporter.error('txsDoTask: fnAsync returned %s' % (rc,));
|
---|
3191 |
|
---|
3192 | if fRemoveTxs:
|
---|
3193 | self.removeTask(oTxsSession);
|
---|
3194 | if fRemoveVm:
|
---|
3195 | self.removeTask(oSession);
|
---|
3196 | return rc;
|
---|
3197 |
|
---|
3198 | # pylint: disable=C0111
|
---|
3199 |
|
---|
3200 | def txsDisconnect(self, oSession, oTxsSession, cMsTimeout = 30000, fIgnoreErrors = False):
|
---|
3201 | return self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncDisconnect,
|
---|
3202 | (self.adjustTimeoutMs(cMsTimeout), fIgnoreErrors));
|
---|
3203 |
|
---|
3204 | def txsUuid(self, oSession, oTxsSession, cMsTimeout = 30000, fIgnoreErrors = False):
|
---|
3205 | return self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncUuid,
|
---|
3206 | (self.adjustTimeoutMs(cMsTimeout), fIgnoreErrors));
|
---|
3207 |
|
---|
3208 | def txsMkDir(self, oSession, oTxsSession, sRemoteDir, fMode = 0o700, cMsTimeout = 30000, fIgnoreErrors = False):
|
---|
3209 | return self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncMkDir,
|
---|
3210 | (sRemoteDir, fMode, self.adjustTimeoutMs(cMsTimeout), fIgnoreErrors));
|
---|
3211 |
|
---|
3212 | def txsMkDirPath(self, oSession, oTxsSession, sRemoteDir, fMode = 0o700, cMsTimeout = 30000, fIgnoreErrors = False):
|
---|
3213 | return self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncMkDirPath,
|
---|
3214 | (sRemoteDir, fMode, self.adjustTimeoutMs(cMsTimeout), fIgnoreErrors));
|
---|
3215 |
|
---|
3216 | def txsMkSymlink(self, oSession, oTxsSession, sLinkTarget, sLink, cMsTimeout = 30000, fIgnoreErrors = False):
|
---|
3217 | return self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncMkSymlink,
|
---|
3218 | (sLinkTarget, sLink, self.adjustTimeoutMs(cMsTimeout), fIgnoreErrors));
|
---|
3219 |
|
---|
3220 | def txsRmDir(self, oSession, oTxsSession, sRemoteDir, cMsTimeout = 30000, fIgnoreErrors = False):
|
---|
3221 | return self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncRmDir,
|
---|
3222 | (sRemoteDir, self.adjustTimeoutMs(cMsTimeout), fIgnoreErrors));
|
---|
3223 |
|
---|
3224 | def txsRmFile(self, oSession, oTxsSession, sRemoteFile, cMsTimeout = 30000, fIgnoreErrors = False):
|
---|
3225 | return self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncRmFile,
|
---|
3226 | (sRemoteFile, self.adjustTimeoutMs(cMsTimeout), fIgnoreErrors));
|
---|
3227 |
|
---|
3228 | def txsRmSymlink(self, oSession, oTxsSession, sRemoteSymlink, cMsTimeout = 30000, fIgnoreErrors = False):
|
---|
3229 | return self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncRmSymlink,
|
---|
3230 | (sRemoteSymlink, self.adjustTimeoutMs(cMsTimeout), fIgnoreErrors));
|
---|
3231 |
|
---|
3232 | def txsRmTree(self, oSession, oTxsSession, sRemoteTree, cMsTimeout = 30000, fIgnoreErrors = False):
|
---|
3233 | return self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncRmTree,
|
---|
3234 | (sRemoteTree, self.adjustTimeoutMs(cMsTimeout), fIgnoreErrors));
|
---|
3235 |
|
---|
3236 | def txsIsDir(self, oSession, oTxsSession, sRemoteDir, cMsTimeout = 30000, fIgnoreErrors = False):
|
---|
3237 | return self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncIsDir,
|
---|
3238 | (sRemoteDir, self.adjustTimeoutMs(cMsTimeout), fIgnoreErrors));
|
---|
3239 |
|
---|
3240 | def txsIsFile(self, oSession, oTxsSession, sRemoteFile, cMsTimeout = 30000, fIgnoreErrors = False):
|
---|
3241 | return self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncIsFile,
|
---|
3242 | (sRemoteFile, self.adjustTimeoutMs(cMsTimeout), fIgnoreErrors));
|
---|
3243 |
|
---|
3244 | def txsIsSymlink(self, oSession, oTxsSession, sRemoteSymlink, cMsTimeout = 30000, fIgnoreErrors = False):
|
---|
3245 | return self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncIsSymlink,
|
---|
3246 | (sRemoteSymlink, self.adjustTimeoutMs(cMsTimeout), fIgnoreErrors));
|
---|
3247 |
|
---|
3248 | def txsUploadFile(self, oSession, oTxsSession, sLocalFile, sRemoteFile, cMsTimeout = 30000, fIgnoreErrors = False):
|
---|
3249 | return self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncUploadFile, \
|
---|
3250 | (sLocalFile, sRemoteFile, self.adjustTimeoutMs(cMsTimeout), fIgnoreErrors));
|
---|
3251 |
|
---|
3252 | def txsUploadString(self, oSession, oTxsSession, sContent, sRemoteFile, cMsTimeout = 30000, fIgnoreErrors = False):
|
---|
3253 | return self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncUploadString, \
|
---|
3254 | (sContent, sRemoteFile, self.adjustTimeoutMs(cMsTimeout), fIgnoreErrors));
|
---|
3255 |
|
---|
3256 | def txsDownloadFile(self, oSession, oTxsSession, sRemoteFile, sLocalFile, cMsTimeout = 30000, fIgnoreErrors = False):
|
---|
3257 | return self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncDownloadFile, \
|
---|
3258 | (sRemoteFile, sLocalFile, self.adjustTimeoutMs(cMsTimeout), fIgnoreErrors));
|
---|
3259 |
|
---|
3260 | def txsDownloadFiles(self, oSession, oTxsSession, asFiles, fIgnoreErrors = False):
|
---|
3261 | """
|
---|
3262 | Convenience function to get files from the guest and stores it
|
---|
3263 | into the scratch directory for later (manual) review.
|
---|
3264 |
|
---|
3265 | Returns True on success.
|
---|
3266 |
|
---|
3267 | Returns False on failure, logged.
|
---|
3268 | """
|
---|
3269 | fRc = True;
|
---|
3270 | for sGstFile in asFiles:
|
---|
3271 | ## @todo Check for already existing files on the host and create a new
|
---|
3272 | # name for the current file to download.
|
---|
3273 | sTmpFile = os.path.join(self.sScratchPath, 'tmp-' + os.path.basename(sGstFile));
|
---|
3274 | reporter.log2('Downloading file "%s" to "%s" ...' % (sGstFile, sTmpFile));
|
---|
3275 | fRc = self.txsDownloadFile(oSession, oTxsSession, sGstFile, sTmpFile, 30 * 1000, fIgnoreErrors);
|
---|
3276 | try: os.unlink(sTmpFile);
|
---|
3277 | except: pass;
|
---|
3278 | if fRc:
|
---|
3279 | reporter.addLogFile(sTmpFile, 'misc/other', 'guest - ' + sGstFile);
|
---|
3280 | else:
|
---|
3281 | if fIgnoreErrors is not True:
|
---|
3282 | reporter.error('error downloading file "%s" to "%s"' % (sGstFile, sTmpFile));
|
---|
3283 | return fRc;
|
---|
3284 | reporter.log('warning: file "%s" was not downloaded, ignoring.' % (sGstFile,));
|
---|
3285 | return True;
|
---|
3286 |
|
---|
3287 | def txsDownloadString(self, oSession, oTxsSession, sRemoteFile, sEncoding = 'utf-8', fIgnoreEncodingErrors = True,
|
---|
3288 | cMsTimeout = 30000, fIgnoreErrors = False):
|
---|
3289 | return self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncDownloadString,
|
---|
3290 | (sRemoteFile, sEncoding, fIgnoreEncodingErrors, self.adjustTimeoutMs(cMsTimeout), fIgnoreErrors));
|
---|
3291 |
|
---|
3292 | def txsUnpackFile(self, oSession, oTxsSession, sRemoteFile, sRemoteDir, cMsTimeout = 30000, fIgnoreErrors = False):
|
---|
3293 | return self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncUnpackFile, \
|
---|
3294 | (sRemoteFile, sRemoteDir, self.adjustTimeoutMs(cMsTimeout), fIgnoreErrors));
|
---|
3295 |
|
---|
3296 | # pylint: enable=C0111
|
---|
3297 |
|
---|
3298 | def txsCdWait(self,
|
---|
3299 | oSession, # type: vboxwrappers.SessionWrapper
|
---|
3300 | oTxsSession, # type: txsclient.Session
|
---|
3301 | cMsTimeout = 30000, # type: int
|
---|
3302 | sFile = None # type: String
|
---|
3303 | ): # -> bool
|
---|
3304 | """
|
---|
3305 | Mostly an internal helper for txsRebootAndReconnectViaTcp and
|
---|
3306 | startVmAndConnectToTxsViaTcp that waits for the CDROM drive to become
|
---|
3307 | ready. It does this by polling for a file it knows to exist on the CD.
|
---|
3308 |
|
---|
3309 | Returns True on success.
|
---|
3310 |
|
---|
3311 | Returns False on failure, logged.
|
---|
3312 | """
|
---|
3313 |
|
---|
3314 | if sFile is None:
|
---|
3315 | sFile = 'valkit.txt';
|
---|
3316 | fRemoveVm = self.addTask(oSession);
|
---|
3317 | fRemoveTxs = self.addTask(oTxsSession);
|
---|
3318 | cMsTimeout = self.adjustTimeoutMs(cMsTimeout);
|
---|
3319 | msStart = base.timestampMilli();
|
---|
3320 | cMsTimeout2 = cMsTimeout;
|
---|
3321 | fRc = oTxsSession.asyncIsFile('${CDROM}/%s' % (sFile,), cMsTimeout2);
|
---|
3322 | if fRc is True:
|
---|
3323 | while True:
|
---|
3324 | # wait for it to complete.
|
---|
3325 | oTask = self.waitForTasks(cMsTimeout2 + 1);
|
---|
3326 | if oTask is not oTxsSession:
|
---|
3327 | oTxsSession.cancelTask();
|
---|
3328 | if oTask is None:
|
---|
3329 | reporter.errorTimeout('txsCdWait: The task timed out (after %s ms).'
|
---|
3330 | % (base.timestampMilli() - msStart,));
|
---|
3331 | elif oTask is oSession:
|
---|
3332 | reporter.error('txsCdWait: The VM terminated unexpectedly');
|
---|
3333 | else:
|
---|
3334 | reporter.error('txsCdWait: An unknown task %s was returned' % (oTask,));
|
---|
3335 | fRc = False;
|
---|
3336 | break;
|
---|
3337 | if oTxsSession.isSuccess():
|
---|
3338 | break;
|
---|
3339 |
|
---|
3340 | # Check for timeout.
|
---|
3341 | cMsElapsed = base.timestampMilli() - msStart;
|
---|
3342 | if cMsElapsed >= cMsTimeout:
|
---|
3343 | reporter.error('txsCdWait: timed out');
|
---|
3344 | fRc = False;
|
---|
3345 | break;
|
---|
3346 |
|
---|
3347 | # delay.
|
---|
3348 | self.sleep(1);
|
---|
3349 |
|
---|
3350 | # resubmitt the task.
|
---|
3351 | cMsTimeout2 = msStart + cMsTimeout - base.timestampMilli();
|
---|
3352 | if cMsTimeout2 < 500:
|
---|
3353 | cMsTimeout2 = 500;
|
---|
3354 | fRc = oTxsSession.asyncIsFile('${CDROM}/%s' % (sFile,), cMsTimeout2);
|
---|
3355 | if fRc is not True:
|
---|
3356 | reporter.error('txsCdWait: asyncIsFile failed');
|
---|
3357 | break;
|
---|
3358 | else:
|
---|
3359 | reporter.error('txsCdWait: asyncIsFile failed');
|
---|
3360 |
|
---|
3361 | if fRemoveTxs:
|
---|
3362 | self.removeTask(oTxsSession);
|
---|
3363 | if fRemoveVm:
|
---|
3364 | self.removeTask(oSession);
|
---|
3365 | return fRc;
|
---|
3366 |
|
---|
3367 | def txsDoConnectViaTcp(self, oSession, cMsTimeout, fNatForwardingForTxs = False):
|
---|
3368 | """
|
---|
3369 | Mostly an internal worker for connecting to TXS via TCP used by the
|
---|
3370 | *ViaTcp methods.
|
---|
3371 |
|
---|
3372 | Returns a tuplet with True/False and TxsSession/None depending on the
|
---|
3373 | result. Errors are logged.
|
---|
3374 | """
|
---|
3375 |
|
---|
3376 | reporter.log2('txsDoConnectViaTcp: oSession=%s, cMsTimeout=%s, fNatForwardingForTxs=%s'
|
---|
3377 | % (oSession, cMsTimeout, fNatForwardingForTxs));
|
---|
3378 |
|
---|
3379 | cMsTimeout = self.adjustTimeoutMs(cMsTimeout);
|
---|
3380 | oTxsConnect = oSession.txsConnectViaTcp(cMsTimeout, fNatForwardingForTxs = fNatForwardingForTxs);
|
---|
3381 | if oTxsConnect is not None:
|
---|
3382 | self.addTask(oTxsConnect);
|
---|
3383 | fRemoveVm = self.addTask(oSession);
|
---|
3384 | oTask = self.waitForTasks(cMsTimeout + 1);
|
---|
3385 | reporter.log2('txsDoConnectViaTcp: waitForTasks returned %s' % (oTask,));
|
---|
3386 | self.removeTask(oTxsConnect);
|
---|
3387 | if oTask is oTxsConnect:
|
---|
3388 | oTxsSession = oTxsConnect.getResult();
|
---|
3389 | if oTxsSession is not None:
|
---|
3390 | reporter.log('txsDoConnectViaTcp: Connected to TXS on %s.' % (oTxsSession.oTransport.sHostname,));
|
---|
3391 | return (True, oTxsSession);
|
---|
3392 |
|
---|
3393 | reporter.error('txsDoConnectViaTcp: failed to connect to TXS.');
|
---|
3394 | else:
|
---|
3395 | oTxsConnect.cancelTask();
|
---|
3396 | if oTask is None:
|
---|
3397 | reporter.errorTimeout('txsDoConnectViaTcp: connect stage 1 timed out');
|
---|
3398 | elif oTask is oSession:
|
---|
3399 | oSession.reportPrematureTermination('txsDoConnectViaTcp: ');
|
---|
3400 | else:
|
---|
3401 | reporter.error('txsDoConnectViaTcp: unknown/wrong task %s' % (oTask,));
|
---|
3402 | if fRemoveVm:
|
---|
3403 | self.removeTask(oSession);
|
---|
3404 | else:
|
---|
3405 | reporter.error('txsDoConnectViaTcp: txsConnectViaTcp failed');
|
---|
3406 | return (False, None);
|
---|
3407 |
|
---|
3408 | def startVmAndConnectToTxsViaTcp(self, sVmName, fCdWait = False, cMsTimeout = 15*60000, \
|
---|
3409 | cMsCdWait = 30000, sFileCdWait = None, \
|
---|
3410 | fNatForwardingForTxs = False):
|
---|
3411 | """
|
---|
3412 | Starts the specified VM and tries to connect to its TXS via TCP.
|
---|
3413 | The VM will be powered off if TXS doesn't respond before the specified
|
---|
3414 | time has elapsed.
|
---|
3415 |
|
---|
3416 | Returns a the VM and TXS sessions (a two tuple) on success. The VM
|
---|
3417 | session is in the task list, the TXS session is not.
|
---|
3418 | Returns (None, None) on failure, fully logged.
|
---|
3419 | """
|
---|
3420 |
|
---|
3421 | # Zap the guest IP to make sure we're not getting a stale entry
|
---|
3422 | # (unless we're restoring the VM of course).
|
---|
3423 | oTestVM = self.oTestVmSet.findTestVmByName(sVmName) if self.oTestVmSet is not None else None;
|
---|
3424 | if oTestVM is None \
|
---|
3425 | or oTestVM.fSnapshotRestoreCurrent is False:
|
---|
3426 | try:
|
---|
3427 | oSession1 = self.openSession(self.getVmByName(sVmName));
|
---|
3428 | oSession1.delGuestPropertyValue('/VirtualBox/GuestInfo/Net/0/V4/IP');
|
---|
3429 | oSession1.saveSettings(True);
|
---|
3430 | del oSession1;
|
---|
3431 | except:
|
---|
3432 | reporter.logXcpt();
|
---|
3433 |
|
---|
3434 | # Start the VM.
|
---|
3435 | reporter.log('startVmAndConnectToTxsViaTcp: Starting(/preparing) "%s" (timeout %s s)...' % (sVmName, cMsTimeout / 1000));
|
---|
3436 | reporter.flushall();
|
---|
3437 | oSession = self.startVmByName(sVmName);
|
---|
3438 | if oSession is not None:
|
---|
3439 | # Connect to TXS.
|
---|
3440 | reporter.log2('startVmAndConnectToTxsViaTcp: Started(/prepared) "%s", connecting to TXS ...' % (sVmName,));
|
---|
3441 | (fRc, oTxsSession) = self.txsDoConnectViaTcp(oSession, cMsTimeout, fNatForwardingForTxs);
|
---|
3442 | if fRc is True:
|
---|
3443 | if fCdWait:
|
---|
3444 | # Wait for CD?
|
---|
3445 | fRc = self.txsCdWait(oSession, oTxsSession, cMsCdWait, sFileCdWait);
|
---|
3446 | if fRc is not True:
|
---|
3447 | reporter.error('startVmAndConnectToTxsViaTcp: txsCdWait failed');
|
---|
3448 | if fRc is True:
|
---|
3449 | # Success!
|
---|
3450 | return (oSession, oTxsSession);
|
---|
3451 | else:
|
---|
3452 | reporter.error('startVmAndConnectToTxsViaTcp: txsDoConnectViaTcp failed');
|
---|
3453 | # If something went wrong while waiting for TXS to be started - take VM screenshot before terminate it
|
---|
3454 | self.terminateVmBySession(oSession);
|
---|
3455 | return (None, None);
|
---|
3456 |
|
---|
3457 | def txsRebootAndReconnectViaTcp(self, oSession, oTxsSession, fCdWait = False, cMsTimeout = 15*60000, \
|
---|
3458 | cMsCdWait = 30000, sFileCdWait = None, fNatForwardingForTxs = False):
|
---|
3459 | """
|
---|
3460 | Executes the TXS reboot command
|
---|
3461 |
|
---|
3462 | Returns A tuple of True and the new TXS session on success.
|
---|
3463 |
|
---|
3464 | Returns A tuple of False and either the old TXS session or None on failure.
|
---|
3465 | """
|
---|
3466 | reporter.log2('txsRebootAndReconnect: cMsTimeout=%u' % (cMsTimeout,));
|
---|
3467 |
|
---|
3468 | #
|
---|
3469 | # This stuff is a bit complicated because of rebooting being kind of
|
---|
3470 | # disruptive to the TXS and such... The protocol is that TXS will:
|
---|
3471 | # - ACK the reboot command.
|
---|
3472 | # - Shutdown the transport layer, implicitly disconnecting us.
|
---|
3473 | # - Execute the reboot operation.
|
---|
3474 | # - On failure, it will be re-init the transport layer and be
|
---|
3475 | # available pretty much immediately. UUID unchanged.
|
---|
3476 | # - On success, it will be respawed after the reboot (hopefully),
|
---|
3477 | # with a different UUID.
|
---|
3478 | #
|
---|
3479 | fRc = False;
|
---|
3480 | iStart = base.timestampMilli();
|
---|
3481 |
|
---|
3482 | # Get UUID.
|
---|
3483 | cMsTimeout2 = min(60000, cMsTimeout);
|
---|
3484 | sUuidBefore = self.txsUuid(oSession, oTxsSession, self.adjustTimeoutMs(cMsTimeout2, 60000));
|
---|
3485 | if sUuidBefore is not False:
|
---|
3486 | # Reboot.
|
---|
3487 | cMsElapsed = base.timestampMilli() - iStart;
|
---|
3488 | cMsTimeout2 = cMsTimeout - cMsElapsed;
|
---|
3489 | fRc = self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncReboot,
|
---|
3490 | (self.adjustTimeoutMs(cMsTimeout2, 60000), False));
|
---|
3491 | if fRc is True:
|
---|
3492 | # Reconnect.
|
---|
3493 | if fNatForwardingForTxs is True:
|
---|
3494 | self.sleep(22); # NAT fudge - Two fixes are wanted: 1. TXS connect retries. 2. Main API reboot/reset hint.
|
---|
3495 | cMsElapsed = base.timestampMilli() - iStart;
|
---|
3496 | (fRc, oTxsSession) = self.txsDoConnectViaTcp(oSession, cMsTimeout - cMsElapsed, fNatForwardingForTxs);
|
---|
3497 | if fRc is True:
|
---|
3498 | # Check the UUID.
|
---|
3499 | cMsElapsed = base.timestampMilli() - iStart;
|
---|
3500 | cMsTimeout2 = min(60000, cMsTimeout - cMsElapsed);
|
---|
3501 | sUuidAfter = self.txsDoTask(oSession, oTxsSession, oTxsSession.asyncUuid,
|
---|
3502 | (self.adjustTimeoutMs(cMsTimeout2, 60000), False));
|
---|
3503 | if sUuidBefore is not False:
|
---|
3504 | if sUuidAfter != sUuidBefore:
|
---|
3505 | reporter.log('The guest rebooted (UUID %s -> %s)' % (sUuidBefore, sUuidAfter))
|
---|
3506 |
|
---|
3507 | # Do CD wait if specified.
|
---|
3508 | if fCdWait:
|
---|
3509 | fRc = self.txsCdWait(oSession, oTxsSession, cMsCdWait, sFileCdWait);
|
---|
3510 | if fRc is not True:
|
---|
3511 | reporter.error('txsRebootAndReconnectViaTcp: txsCdWait failed');
|
---|
3512 | else:
|
---|
3513 | reporter.error('txsRebootAndReconnectViaTcp: failed to get UUID (after)');
|
---|
3514 | else:
|
---|
3515 | reporter.error('txsRebootAndReconnectViaTcp: did not reboot (UUID %s)' % (sUuidBefore,));
|
---|
3516 | else:
|
---|
3517 | reporter.error('txsRebootAndReconnectViaTcp: txsDoConnectViaTcp failed');
|
---|
3518 | else:
|
---|
3519 | reporter.error('txsRebootAndReconnectViaTcp: reboot failed');
|
---|
3520 | else:
|
---|
3521 | reporter.error('txsRebootAndReconnectViaTcp: failed to get UUID (before)');
|
---|
3522 | return (fRc, oTxsSession);
|
---|
3523 |
|
---|
3524 | # pylint: disable=R0914,R0913
|
---|
3525 |
|
---|
3526 | def txsRunTest(self, oTxsSession, sTestName, cMsTimeout, sExecName, asArgs = (), asAddEnv = (), sAsUser = ""):
|
---|
3527 | """
|
---|
3528 | Executes the specified test task, waiting till it completes or times out.
|
---|
3529 |
|
---|
3530 | The VM session (if any) must be in the task list.
|
---|
3531 |
|
---|
3532 | Returns True if we executed the task and nothing abnormal happend.
|
---|
3533 | Query the process status from the TXS session.
|
---|
3534 |
|
---|
3535 | Returns False if some unexpected task was signalled or we failed to
|
---|
3536 | submit the job.
|
---|
3537 | """
|
---|
3538 | reporter.testStart(sTestName);
|
---|
3539 | reporter.log2('txsRunTest: cMsTimeout=%u sExecName=%s asArgs=%s' % (cMsTimeout, sExecName, asArgs));
|
---|
3540 |
|
---|
3541 | # Submit the job.
|
---|
3542 | fRc = False;
|
---|
3543 | if oTxsSession.asyncExec(sExecName, asArgs, asAddEnv, sAsUser, cMsTimeout = self.adjustTimeoutMs(cMsTimeout)):
|
---|
3544 | self.addTask(oTxsSession);
|
---|
3545 |
|
---|
3546 | # Wait for the job to complete.
|
---|
3547 | while True:
|
---|
3548 | oTask = self.waitForTasks(cMsTimeout + 1);
|
---|
3549 | if oTask is None:
|
---|
3550 | reporter.log('txsRunTest: waitForTasks timed out');
|
---|
3551 | break;
|
---|
3552 | if oTask is oTxsSession:
|
---|
3553 | fRc = True;
|
---|
3554 | reporter.log('txsRunTest: isSuccess=%s getResult=%s' % (oTxsSession.isSuccess(), oTxsSession.getResult()));
|
---|
3555 | break;
|
---|
3556 | if not self.handleTask(oTask, 'txsRunTest'):
|
---|
3557 | break;
|
---|
3558 |
|
---|
3559 | self.removeTask(oTxsSession);
|
---|
3560 | if not oTxsSession.pollTask():
|
---|
3561 | oTxsSession.cancelTask();
|
---|
3562 | else:
|
---|
3563 | reporter.error('txsRunTest: asyncExec failed');
|
---|
3564 |
|
---|
3565 | reporter.testDone();
|
---|
3566 | return fRc;
|
---|
3567 |
|
---|
3568 | def txsRunTestRedirectStd(self, oTxsSession, sTestName, cMsTimeout, sExecName, asArgs = (), asAddEnv = (), sAsUser = "",
|
---|
3569 | oStdIn = '/dev/null', oStdOut = '/dev/null', oStdErr = '/dev/null', oTestPipe = '/dev/null'):
|
---|
3570 | """
|
---|
3571 | Executes the specified test task, waiting till it completes or times out,
|
---|
3572 | redirecting stdin, stdout and stderr to the given objects.
|
---|
3573 |
|
---|
3574 | The VM session (if any) must be in the task list.
|
---|
3575 |
|
---|
3576 | Returns True if we executed the task and nothing abnormal happend.
|
---|
3577 | Query the process status from the TXS session.
|
---|
3578 |
|
---|
3579 | Returns False if some unexpected task was signalled or we failed to
|
---|
3580 | submit the job.
|
---|
3581 | """
|
---|
3582 | reporter.testStart(sTestName);
|
---|
3583 | reporter.log2('txsRunTestRedirectStd: cMsTimeout=%u sExecName=%s asArgs=%s' % (cMsTimeout, sExecName, asArgs));
|
---|
3584 |
|
---|
3585 | # Submit the job.
|
---|
3586 | fRc = False;
|
---|
3587 | if oTxsSession.asyncExecEx(sExecName, asArgs, asAddEnv, oStdIn, oStdOut, oStdErr,
|
---|
3588 | oTestPipe, sAsUser, cMsTimeout = self.adjustTimeoutMs(cMsTimeout)):
|
---|
3589 | self.addTask(oTxsSession);
|
---|
3590 |
|
---|
3591 | # Wait for the job to complete.
|
---|
3592 | while True:
|
---|
3593 | oTask = self.waitForTasks(cMsTimeout + 1);
|
---|
3594 | if oTask is None:
|
---|
3595 | reporter.log('txsRunTestRedirectStd: waitForTasks timed out');
|
---|
3596 | break;
|
---|
3597 | if oTask is oTxsSession:
|
---|
3598 | fRc = True;
|
---|
3599 | reporter.log('txsRunTestRedirectStd: isSuccess=%s getResult=%s'
|
---|
3600 | % (oTxsSession.isSuccess(), oTxsSession.getResult()));
|
---|
3601 | break;
|
---|
3602 | if not self.handleTask(oTask, 'txsRunTestRedirectStd'):
|
---|
3603 | break;
|
---|
3604 |
|
---|
3605 | self.removeTask(oTxsSession);
|
---|
3606 | if not oTxsSession.pollTask():
|
---|
3607 | oTxsSession.cancelTask();
|
---|
3608 | else:
|
---|
3609 | reporter.error('txsRunTestRedirectStd: asyncExec failed');
|
---|
3610 |
|
---|
3611 | reporter.testDone();
|
---|
3612 | return fRc;
|
---|
3613 |
|
---|
3614 | def txsRunTest2(self, oTxsSession1, oTxsSession2, sTestName, cMsTimeout,
|
---|
3615 | sExecName1, asArgs1,
|
---|
3616 | sExecName2, asArgs2,
|
---|
3617 | asAddEnv1 = (), sAsUser1 = '', fWithTestPipe1 = True,
|
---|
3618 | asAddEnv2 = (), sAsUser2 = '', fWithTestPipe2 = True):
|
---|
3619 | """
|
---|
3620 | Executes the specified test tasks, waiting till they complete or
|
---|
3621 | times out. The 1st task is started after the 2nd one.
|
---|
3622 |
|
---|
3623 | The VM session (if any) must be in the task list.
|
---|
3624 |
|
---|
3625 | Returns True if we executed the task and nothing abnormal happend.
|
---|
3626 | Query the process status from the TXS sessions.
|
---|
3627 |
|
---|
3628 | Returns False if some unexpected task was signalled or we failed to
|
---|
3629 | submit the job.
|
---|
3630 | """
|
---|
3631 | reporter.testStart(sTestName);
|
---|
3632 |
|
---|
3633 | # Submit the jobs.
|
---|
3634 | fRc = False;
|
---|
3635 | if oTxsSession1.asyncExec(sExecName1, asArgs1, asAddEnv1, sAsUser1, fWithTestPipe1, '1-',
|
---|
3636 | self.adjustTimeoutMs(cMsTimeout)):
|
---|
3637 | self.addTask(oTxsSession1);
|
---|
3638 |
|
---|
3639 | self.sleep(2); # fudge! grr
|
---|
3640 |
|
---|
3641 | if oTxsSession2.asyncExec(sExecName2, asArgs2, asAddEnv2, sAsUser2, fWithTestPipe2, '2-',
|
---|
3642 | self.adjustTimeoutMs(cMsTimeout)):
|
---|
3643 | self.addTask(oTxsSession2);
|
---|
3644 |
|
---|
3645 | # Wait for the jobs to complete.
|
---|
3646 | cPendingJobs = 2;
|
---|
3647 | while True:
|
---|
3648 | oTask = self.waitForTasks(cMsTimeout + 1);
|
---|
3649 | if oTask is None:
|
---|
3650 | reporter.log('txsRunTest2: waitForTasks timed out');
|
---|
3651 | break;
|
---|
3652 |
|
---|
3653 | if oTask is oTxsSession1 or oTask is oTxsSession2:
|
---|
3654 | if oTask is oTxsSession1: iTask = 1;
|
---|
3655 | else: iTask = 2;
|
---|
3656 | reporter.log('txsRunTest2: #%u - isSuccess=%s getResult=%s' \
|
---|
3657 | % (iTask, oTask.isSuccess(), oTask.getResult()));
|
---|
3658 | self.removeTask(oTask);
|
---|
3659 | cPendingJobs -= 1;
|
---|
3660 | if cPendingJobs <= 0:
|
---|
3661 | fRc = True;
|
---|
3662 | break;
|
---|
3663 |
|
---|
3664 | elif not self.handleTask(oTask, 'txsRunTest'):
|
---|
3665 | break;
|
---|
3666 |
|
---|
3667 | self.removeTask(oTxsSession2);
|
---|
3668 | if not oTxsSession2.pollTask():
|
---|
3669 | oTxsSession2.cancelTask();
|
---|
3670 | else:
|
---|
3671 | reporter.error('txsRunTest2: asyncExec #2 failed');
|
---|
3672 |
|
---|
3673 | self.removeTask(oTxsSession1);
|
---|
3674 | if not oTxsSession1.pollTask():
|
---|
3675 | oTxsSession1.cancelTask();
|
---|
3676 | else:
|
---|
3677 | reporter.error('txsRunTest2: asyncExec #1 failed');
|
---|
3678 |
|
---|
3679 | reporter.testDone();
|
---|
3680 | return fRc;
|
---|
3681 |
|
---|
3682 | # pylint: enable=R0914,R0913
|
---|
3683 |
|
---|
3684 |
|
---|
3685 | #
|
---|
3686 | # Working with test results via serial port.
|
---|
3687 | #
|
---|
3688 |
|
---|
3689 | class TxsMonitorComFile(base.TdTaskBase):
|
---|
3690 | """
|
---|
3691 | Class that monitors a COM output file.
|
---|
3692 | """
|
---|
3693 |
|
---|
3694 | def __init__(self, sComRawFile, asStopWords = None):
|
---|
3695 | base.TdTaskBase.__init__(self, utils.getCallerName());
|
---|
3696 | self.sComRawFile = sComRawFile;
|
---|
3697 | self.oStopRegExp = re.compile('\\b(' + '|'.join(asStopWords if asStopWords else ('PASSED', 'FAILED',)) + ')\\b');
|
---|
3698 | self.sResult = None; ##< The result.
|
---|
3699 | self.cchDisplayed = 0; ##< Offset into the file string of what we've already fed to the logger.
|
---|
3700 |
|
---|
3701 | def toString(self):
|
---|
3702 | return '<%s sComRawFile=%s oStopRegExp=%s sResult=%s cchDisplayed=%s>' \
|
---|
3703 | % (base.TdTaskBase.toString(self), self.sComRawFile, self.oStopRegExp, self.sResult, self.cchDisplayed,);
|
---|
3704 |
|
---|
3705 | def pollTask(self, fLocked = False):
|
---|
3706 | """
|
---|
3707 | Overrides TdTaskBase.pollTask() for the purpose of polling the file.
|
---|
3708 | """
|
---|
3709 | if not fLocked:
|
---|
3710 | self.lockTask();
|
---|
3711 |
|
---|
3712 | sFile = utils.noxcptReadFile(self.sComRawFile, '', 'rU');
|
---|
3713 | if len(sFile) > self.cchDisplayed:
|
---|
3714 | sNew = sFile[self.cchDisplayed:];
|
---|
3715 | oMatch = self.oStopRegExp.search(sNew);
|
---|
3716 | if oMatch:
|
---|
3717 | # Done! Get result, flush all the output and signal the task.
|
---|
3718 | self.sResult = oMatch.group(1);
|
---|
3719 | for sLine in sNew.split('\n'):
|
---|
3720 | reporter.log('COM OUTPUT: %s' % (sLine,));
|
---|
3721 | self.cchDisplayed = len(sFile);
|
---|
3722 | self.signalTaskLocked();
|
---|
3723 | else:
|
---|
3724 | # Output whole lines only.
|
---|
3725 | offNewline = sFile.find('\n', self.cchDisplayed);
|
---|
3726 | while offNewline >= 0:
|
---|
3727 | reporter.log('COM OUTPUT: %s' % (sFile[self.cchDisplayed:offNewline]))
|
---|
3728 | self.cchDisplayed = offNewline + 1;
|
---|
3729 | offNewline = sFile.find('\n', self.cchDisplayed);
|
---|
3730 |
|
---|
3731 | fRet = self.fSignalled;
|
---|
3732 | if not fLocked:
|
---|
3733 | self.unlockTask();
|
---|
3734 | return fRet;
|
---|
3735 |
|
---|
3736 | # Our stuff.
|
---|
3737 | def getResult(self):
|
---|
3738 | """
|
---|
3739 | Returns the connected TXS session object on success.
|
---|
3740 | Returns None on failure or if the task has not yet completed.
|
---|
3741 | """
|
---|
3742 | self.oCv.acquire();
|
---|
3743 | sResult = self.sResult;
|
---|
3744 | self.oCv.release();
|
---|
3745 | return sResult;
|
---|
3746 |
|
---|
3747 | def cancelTask(self):
|
---|
3748 | """ Cancels the task. """
|
---|
3749 | self.signalTask();
|
---|
3750 | return True;
|
---|
3751 |
|
---|
3752 |
|
---|
3753 | def monitorComRawFile(self, oSession, sComRawFile, cMsTimeout = 15*60000, asStopWords = None):
|
---|
3754 | """
|
---|
3755 | Monitors the COM output file for stop words (PASSED and FAILED by default).
|
---|
3756 |
|
---|
3757 | Returns the stop word.
|
---|
3758 | Returns None on VM error and timeout.
|
---|
3759 | """
|
---|
3760 |
|
---|
3761 | reporter.log2('monitorComRawFile: oSession=%s, cMsTimeout=%s, sComRawFile=%s' % (oSession, cMsTimeout, sComRawFile));
|
---|
3762 |
|
---|
3763 | oMonitorTask = self.TxsMonitorComFile(sComRawFile, asStopWords);
|
---|
3764 | self.addTask(oMonitorTask);
|
---|
3765 |
|
---|
3766 | cMsTimeout = self.adjustTimeoutMs(cMsTimeout);
|
---|
3767 | oTask = self.waitForTasks(cMsTimeout + 1);
|
---|
3768 | reporter.log2('monitorComRawFile: waitForTasks returned %s' % (oTask,));
|
---|
3769 |
|
---|
3770 | if oTask is not oMonitorTask:
|
---|
3771 | oMonitorTask.cancelTask();
|
---|
3772 | self.removeTask(oMonitorTask);
|
---|
3773 |
|
---|
3774 | oMonitorTask.pollTask();
|
---|
3775 | return oMonitorTask.getResult();
|
---|
3776 |
|
---|
3777 |
|
---|
3778 | def runVmAndMonitorComRawFile(self, sVmName, sComRawFile, cMsTimeout = 15*60000, asStopWords = None):
|
---|
3779 | """
|
---|
3780 | Runs the specified VM and monitors the given COM output file for stop
|
---|
3781 | words (PASSED and FAILED by default).
|
---|
3782 |
|
---|
3783 | The caller is assumed to have configured the VM to use the given
|
---|
3784 | file. The method will take no action to verify this.
|
---|
3785 |
|
---|
3786 | Returns the stop word.
|
---|
3787 | Returns None on VM error and timeout.
|
---|
3788 | """
|
---|
3789 |
|
---|
3790 | # Start the VM.
|
---|
3791 | reporter.log('runVmAndMonitorComRawFile: Starting(/preparing) "%s" (timeout %s s)...' % (sVmName, cMsTimeout / 1000));
|
---|
3792 | reporter.flushall();
|
---|
3793 | oSession = self.startVmByName(sVmName);
|
---|
3794 | if oSession is not None:
|
---|
3795 | # Let it run and then terminate it.
|
---|
3796 | sRet = self.monitorComRawFile(oSession, sComRawFile, cMsTimeout, asStopWords);
|
---|
3797 | self.terminateVmBySession(oSession);
|
---|
3798 | else:
|
---|
3799 | sRet = None;
|
---|
3800 | return sRet;
|
---|
3801 |
|
---|