VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/testmanager/batch/virtual_test_sheriff.py@ 66431

Last change on this file since 66431 was 66431, checked in by vboxsync, 8 years ago

vsheriff: whitespace

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 61.0 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: virtual_test_sheriff.py 66431 2017-04-05 12:04:01Z vboxsync $
4# pylint: disable=C0301
5
6"""
7Virtual Test Sheriff.
8
9Duties:
10 - Try to a assign failure reasons to recently failed tests.
11 - Reboot or disable bad test boxes.
12
13"""
14
15__copyright__ = \
16"""
17Copyright (C) 2012-2016 Oracle Corporation
18
19This file is part of VirtualBox Open Source Edition (OSE), as
20available from http://www.virtualbox.org. This file is free software;
21you can redistribute it and/or modify it under the terms of the GNU
22General Public License (GPL) as published by the Free Software
23Foundation, in version 2 as it comes in the "COPYING" file of the
24VirtualBox OSE distribution. VirtualBox OSE is distributed in the
25hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
26
27The contents of this file may alternatively be used under the terms
28of the Common Development and Distribution License Version 1.0
29(CDDL) only, as it comes in the "COPYING.CDDL" file of the
30VirtualBox OSE distribution, in which case the provisions of the
31CDDL are applicable instead of those of the GPL.
32
33You may elect to license modified versions of this file under the
34terms and conditions of either the GPL or the CDDL or both.
35"""
36__version__ = "$Revision: 66431 $"
37
38
39# Standard python imports
40import sys;
41import os;
42import hashlib;
43import StringIO;
44from optparse import OptionParser;
45from PIL import Image; # pylint: disable=import-error
46
47# Add Test Manager's modules path
48g_ksTestManagerDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
49sys.path.append(g_ksTestManagerDir);
50
51# Test Manager imports
52from testmanager.core.db import TMDatabaseConnection;
53from testmanager.core.build import BuildDataEx;
54from testmanager.core.failurereason import FailureReasonLogic;
55from testmanager.core.testbox import TestBoxLogic, TestBoxData;
56from testmanager.core.testcase import TestCaseDataEx;
57from testmanager.core.testgroup import TestGroupData;
58from testmanager.core.testset import TestSetLogic, TestSetData;
59from testmanager.core.testresults import TestResultLogic, TestResultFileData;
60from testmanager.core.testresultfailures import TestResultFailureLogic, TestResultFailureData;
61from testmanager.core.useraccount import UserAccountLogic;
62
63
64class VirtualTestSheriffCaseFile(object):
65 """
66 A failure investigation case file.
67
68 """
69
70
71 ## Max log file we'll read into memory. (256 MB)
72 kcbMaxLogRead = 0x10000000;
73
74 def __init__(self, oSheriff, oTestSet, oTree, oBuild, oTestBox, oTestGroup, oTestCase):
75 self.oSheriff = oSheriff;
76 self.oTestSet = oTestSet; # TestSetData
77 self.oTree = oTree; # TestResultDataEx
78 self.oBuild = oBuild; # BuildDataEx
79 self.oTestBox = oTestBox; # TestBoxData
80 self.oTestGroup = oTestGroup; # TestGroupData
81 self.oTestCase = oTestCase; # TestCaseDataEx
82 self.sMainLog = ''; # The main log file. Empty string if not accessible.
83
84 # Generate a case file name.
85 self.sName = '#%u: %s' % (self.oTestSet.idTestSet, self.oTestCase.sName,)
86 self.sLongName = '#%u: "%s" on "%s" running %s %s (%s), "%s" by %s, using %s %s %s r%u' \
87 % ( self.oTestSet.idTestSet,
88 self.oTestCase.sName,
89 self.oTestBox.sName,
90 self.oTestBox.sOs,
91 self.oTestBox.sOsVersion,
92 self.oTestBox.sCpuArch,
93 self.oTestBox.sCpuName,
94 self.oTestBox.sCpuVendor,
95 self.oBuild.oCat.sProduct,
96 self.oBuild.oCat.sBranch,
97 self.oBuild.oCat.sType,
98 self.oBuild.iRevision, );
99
100 # Investigation notes.
101 self.tReason = None; # None or one of the ktReason_XXX constants.
102 self.dReasonForResultId = {}; # Reason assignments indexed by idTestResult.
103 self.dCommentForResultId = {}; # Comment assignments indexed by idTestResult.
104
105 #
106 # Reason.
107 #
108
109 def noteReason(self, tReason):
110 """ Notes down a possible reason. """
111 self.oSheriff.dprint(u'noteReason: %s -> %s' % (self.tReason, tReason,));
112 self.tReason = tReason;
113 return True;
114
115 def noteReasonForId(self, tReason, idTestResult, sComment = None):
116 """ Notes down a possible reason for a specific test result. """
117 self.oSheriff.dprint(u'noteReasonForId: %u: %s -> %s%s'
118 % (idTestResult, self.dReasonForResultId.get(idTestResult, None), tReason,
119 (u' (%s)' % (sComment,)) if sComment is not None else ''));
120 self.dReasonForResultId[idTestResult] = tReason;
121 if sComment is not None:
122 self.dCommentForResultId[idTestResult] = sComment;
123 return True;
124
125
126 #
127 # Test classification.
128 #
129
130 def isVBoxTest(self):
131 """ Test classification: VirtualBox (using the build) """
132 return self.oBuild.oCat.sProduct.lower() in [ 'virtualbox', 'vbox' ];
133
134 def isVBoxUnitTest(self):
135 """ Test case classification: The unit test doing all our testcase/*.cpp stuff. """
136 return self.isVBoxTest() \
137 and self.oTestCase.sName.lower() == 'unit tests';
138
139 def isVBoxInstallTest(self):
140 """ Test case classification: VirtualBox Guest installation test. """
141 return self.isVBoxTest() \
142 and self.oTestCase.sName.lower().startswith('install:');
143
144 def isVBoxUSBTest(self):
145 """ Test case classification: VirtualBox USB test. """
146 return self.isVBoxTest() \
147 and self.oTestCase.sName.lower().startswith('usb:');
148
149 def isVBoxStorageTest(self):
150 """ Test case classification: VirtualBox Storage test. """
151 return self.isVBoxTest() \
152 and self.oTestCase.sName.lower().startswith('storage:');
153
154 def isVBoxGAsTest(self):
155 """ Test case classification: VirtualBox Guest Additions test. """
156 return self.isVBoxTest() \
157 and self.oTestCase.sName.lower().startswith('ga\'s tests');
158
159 def isVBoxAPITest(self):
160 """ Test case classification: VirtualBox API test. """
161 return self.isVBoxTest() \
162 and self.oTestCase.sName.lower().startswith('api:');
163
164 def isVBoxBenchmarkTest(self):
165 """ Test case classification: VirtualBox Benchmark test. """
166 return self.isVBoxTest() \
167 and self.oTestCase.sName.lower().startswith('benchmark:');
168
169 def isVBoxSmokeTest(self):
170 """ Test case classification: Smoke test. """
171 return self.isVBoxTest() \
172 and self.oTestCase.sName.lower().startswith('smoketest');
173
174
175 #
176 # Utility methods.
177 #
178
179 def getMainLog(self):
180 """
181 Tries to reads the main log file since this will be the first source of information.
182 """
183 if self.sMainLog:
184 return self.sMainLog;
185 (oFile, oSizeOrError, _) = self.oTestSet.openFile('main.log', 'rb');
186 if oFile is not None:
187 try:
188 self.sMainLog = oFile.read(min(self.kcbMaxLogRead, oSizeOrError)).decode('utf-8', 'replace');
189 except Exception as oXcpt:
190 self.oSheriff.vprint(u'Error reading main log file: %s' % (oXcpt,))
191 self.sMainLog = '';
192 else:
193 self.oSheriff.vprint(u'Error opening main log file: %s' % (oSizeOrError,));
194 return self.sMainLog;
195
196 def getLogFile(self, oFile):
197 """
198 Tries to reads the given file as a utf-8 log file.
199 oFile is a TestFileDataEx instance.
200 Returns empty string if problems opening or reading the file.
201 """
202 sContent = '';
203 (oFile, oSizeOrError, _) = self.oTestSet.openFile(oFile.sFile, 'rb');
204 if oFile is not None:
205 try:
206 sContent = oFile.read(min(self.kcbMaxLogRead, oSizeOrError)).decode('utf-8', 'replace');
207 except Exception as oXcpt:
208 self.oSheriff.vprint(u'Error reading the "%s" log file: %s' % (oFile.sFile, oXcpt,))
209 else:
210 self.oSheriff.vprint(u'Error opening the "%s" log file: %s' % (oFile.sFile, oSizeOrError,));
211 return sContent;
212
213 def getScreenshotSha256(self, oFile):
214 """
215 Tries to read the given screenshot file, uncompress it, and do SHA-2
216 on the raw pixels.
217 Returns SHA-2 digest string on success, None on failure.
218 """
219 (oFile, _, _) = self.oTestSet.openFile(oFile.sFile, 'rb');
220 try:
221 abImageFile = oFile.read();
222 except Exception as oXcpt:
223 self.oSheriff.vprint(u'Error reading the "%s" image file: %s' % (oFile.sFile, oXcpt,))
224 else:
225 try:
226 oImage = Image.open(StringIO.StringIO(abImageFile));
227 except Exception as oXcpt:
228 self.oSheriff.vprint(u'Error opening the "%s" image bytes using PIL.Image.open: %s' % (oFile.sFile, oXcpt,))
229 else:
230 try:
231 oHash = hashlib.sha256();
232 oHash.update(oImage.tostring());
233 except Exception as oXcpt:
234 self.oSheriff.vprint(u'Error hashing the uncompressed image bytes for "%s": %s' % (oFile.sFile, oXcpt,))
235 else:
236 return oHash.hexdigest();
237 return None;
238
239
240
241 def isSingleTestFailure(self):
242 """
243 Figure out if this is a single test failing or if it's one of the
244 more complicated ones.
245 """
246 if self.oTree.cErrors == 1:
247 return True;
248 if self.oTree.deepCountErrorContributers() <= 1:
249 return True;
250 return False;
251
252
253
254class VirtualTestSheriff(object): # pylint: disable=R0903
255 """
256 Add build info into Test Manager database.
257 """
258
259 ## The user account for the virtual sheriff.
260 ksLoginName = 'vsheriff';
261
262 def __init__(self):
263 """
264 Parse command line.
265 """
266 self.oDb = None;
267 self.tsNow = None;
268 self.oTestResultLogic = None;
269 self.oTestSetLogic = None;
270 self.oFailureReasonLogic = None; # FailureReasonLogic;
271 self.oTestResultFailureLogic = None; # TestResultFailureLogic
272 self.oLogin = None;
273 self.uidSelf = -1;
274 self.oLogFile = None;
275 self.asBsodReasons = [];
276 self.asUnitTestReasons = [];
277
278 oParser = OptionParser();
279 oParser.add_option('--start-hours-ago', dest = 'cStartHoursAgo', metavar = '<hours>', default = 0, type = 'int',
280 help = 'When to start specified as hours relative to current time. Defauls is right now.', );
281 oParser.add_option('--hours-period', dest = 'cHoursBack', metavar = '<period-in-hours>', default = 2, type = 'int',
282 help = 'Work period specified in hours. Defauls is 2 hours.');
283 oParser.add_option('--real-run-back', dest = 'fRealRun', action = 'store_true', default = False,
284 help = 'Whether to commit the findings to the database. Default is a dry run.');
285 oParser.add_option('-q', '--quiet', dest = 'fQuiet', action = 'store_true', default = False,
286 help = 'Quiet execution');
287 oParser.add_option('-l', '--log', dest = 'sLogFile', metavar = '<logfile>', default = None,
288 help = 'Where to log messages.');
289 oParser.add_option('--debug', dest = 'fDebug', action = 'store_true', default = False,
290 help = 'Enables debug mode.');
291
292 (self.oConfig, _) = oParser.parse_args();
293
294 if self.oConfig.sLogFile:
295 self.oLogFile = open(self.oConfig.sLogFile, "a");
296 self.oLogFile.write('VirtualTestSheriff: $Revision: 66431 $ \n');
297
298
299 def eprint(self, sText):
300 """
301 Prints error messages.
302 Returns 1 (for exit code usage.)
303 """
304 print 'error: %s' % (sText,);
305 if self.oLogFile is not None:
306 self.oLogFile.write((u'error: %s\n' % (sText,)).encode('utf-8'));
307 return 1;
308
309 def dprint(self, sText):
310 """
311 Prints debug info.
312 """
313 if self.oConfig.fDebug:
314 if not self.oConfig.fQuiet:
315 print 'debug: %s' % (sText, );
316 if self.oLogFile is not None:
317 self.oLogFile.write((u'debug: %s\n' % (sText,)).encode('utf-8'));
318 return 0;
319
320 def vprint(self, sText):
321 """
322 Prints verbose info.
323 """
324 if not self.oConfig.fQuiet:
325 print 'info: %s' % (sText,);
326 if self.oLogFile is not None:
327 self.oLogFile.write((u'info: %s\n' % (sText,)).encode('utf-8'));
328 return 0;
329
330 def getFailureReason(self, tReason):
331 """ Gets the failure reason object for tReason. """
332 return self.oFailureReasonLogic.cachedLookupByNameAndCategory(tReason[1], tReason[0]);
333
334 def selfCheck(self):
335 """ Does some self checks, looking up things we expect to be in the database and such. """
336 rcExit = 0;
337 for sAttr in dir(self.__class__):
338 if sAttr.startswith('ktReason_'):
339 tReason = getattr(self.__class__, sAttr);
340 oFailureReason = self.getFailureReason(tReason);
341 if oFailureReason is None:
342 rcExit = self.eprint(u'Failed to find failure reason "%s" in category "%s" in the database!'
343 % (tReason[1], tReason[0],));
344
345 # Check the user account as well.
346 if self.oLogin is None:
347 oLogin = UserAccountLogic(self.oDb).tryFetchAccountByLoginName(VirtualTestSheriff.ksLoginName);
348 if oLogin is None:
349 rcExit = self.eprint(u'Cannot find my user account "%s"!' % (VirtualTestSheriff.ksLoginName,));
350 return rcExit;
351
352
353
354 def badTestBoxManagement(self):
355 """
356 Looks for bad test boxes and first tries once to reboot them then disables them.
357 """
358 rcExit = 0;
359
360 #
361 # We skip this entirely if we're running in the past and not in harmless debug mode.
362 #
363 if self.oConfig.cStartHoursAgo != 0 \
364 and (not self.oConfig.fDebug or self.oConfig.fRealRun):
365 return rcExit;
366 tsNow = self.tsNow if self.oConfig.fDebug else None;
367 cHoursBack = self.oConfig.cHoursBack if self.oConfig.fDebug else 2;
368 oTestBoxLogic = TestBoxLogic(self.oDb);
369
370 #
371 # Generate a list of failures reasons we consider bad-testbox behavior.
372 #
373 aidFailureReasons = [
374 self.getFailureReason(self.ktReason_Host_DriverNotUnloading).idFailureReason,
375 ];
376
377 #
378 # Get list of bad test boxes for given period and check them out individually.
379 #
380 aidBadTestBoxes = self.oTestSetLogic.fetchBadTestBoxIds(cHoursBack = cHoursBack, tsNow = tsNow,
381 aidFailureReasons = aidFailureReasons);
382 for idTestBox in aidBadTestBoxes:
383 # Skip if the testbox is already disabled or has a pending reboot command.
384 try:
385 oTestBox = TestBoxData().initFromDbWithId(self.oDb, idTestBox);
386 except Exception as oXcpt:
387 rcExit = self.eprint('Failed to get data for test box #%u in badTestBoxManagement: %s' % (idTestBox, oXcpt,));
388 continue;
389 if not oTestBox.fEnabled:
390 self.dprint(u'badTestBoxManagement: Skipping test box #%u (%s) as it has been disabled already.'
391 % ( idTestBox, oTestBox.sName, ));
392 continue;
393 if oTestBox.enmPendingCmd != TestBoxData.ksTestBoxCmd_None:
394 self.dprint(u'badTestBoxManagement: Skipping test box #%u (%s) as it has a command pending: %s'
395 % ( idTestBox, oTestBox.sName, oTestBox.enmPendingCmd));
396 continue;
397
398 # Get the most recent testsets for this box (descending on tsDone) and see how bad it is.
399 aoSets = self.oTestSetLogic.fetchSetsForTestBox(idTestBox, cHoursBack = cHoursBack, tsNow = tsNow);
400 cOkay = 0;
401 cBad = 0;
402 iFirstOkay = len(aoSets);
403 for iSet, oSet in enumerate(aoSets):
404 if oSet.enmStatus == TestSetData.ksTestStatus_BadTestBox:
405 cBad += 1;
406 else:
407 # Check for bad failure reasons.
408 oFailure = None;
409 if oSet.enmStatus in TestSetData.kasBadTestStatuses:
410 oFailure = self.oTestResultFailureLogic.getById(oSet.idTestResult);
411 if oFailure is not None and oFailure.idFailureReason in aidFailureReasons:
412 cBad += 1;
413 else:
414 # This is an okay test result then.
415 ## @todo maybe check the elapsed time here, it could still be a bad run?
416 cOkay += 1;
417 if iFirstOkay > iSet:
418 iFirstOkay = iSet;
419 if iSet > 10:
420 break;
421
422 # We react if there are two or more bad-testbox statuses at the head of the
423 # history and at least three in the last 10 results.
424 if iFirstOkay >= 2 and cBad > 2:
425 # Frank: For now don't reboot boxes automatically
426 if True or oTestBoxLogic.hasTestBoxRecentlyBeenRebooted(idTestBox, cHoursBack = cHoursBack, tsNow = tsNow):
427 self.vprint(u'Disabling testbox #%u (%s) - iFirstOkay=%u cBad=%u cOkay=%u'
428 % ( idTestBox, oTestBox.sName, iFirstOkay, cBad, cOkay));
429 if self.oConfig.fRealRun is True:
430 try:
431 oTestBoxLogic.disableTestBox(idTestBox, self.uidSelf, fCommit = True,
432 sComment = 'Automatically disabled (iFirstOkay=%u cBad=%u cOkay=%u)'
433 % (iFirstOkay, cBad, cOkay),);
434 except Exception as oXcpt:
435 rcExit = self.eprint(u'Error disabling testbox #%u (%u): %s\n' % (idTestBox, oTestBox.sName, oXcpt,));
436 else:
437 self.vprint(u'Rebooting testbox #%u (%s) - iFirstOkay=%u cBad=%u cOkay=%u'
438 % ( idTestBox, oTestBox.sName, iFirstOkay, cBad, cOkay));
439 if self.oConfig.fRealRun is True:
440 try:
441 oTestBoxLogic.rebootTestBox(idTestBox, self.uidSelf, fCommit = True,
442 sComment = 'Automatically rebooted (iFirstOkay=%u cBad=%u cOkay=%u)'
443 % (iFirstOkay, cBad, cOkay),);
444 except Exception as oXcpt:
445 rcExit = self.eprint(u'Error rebooting testbox #%u (%u): %s\n' % (idTestBox, oTestBox.sName, oXcpt,));
446 else:
447 self.dprint(u'badTestBoxManagement: #%u (%s) looks ok: iFirstOkay=%u cBad=%u cOkay=%u'
448 % ( idTestBox, oTestBox.sName, iFirstOkay, cBad, cOkay));
449 return rcExit;
450
451
452 ## @name Failure reasons we know.
453 ## @{
454 ktReason_BSOD_Recovery = ( 'BSOD', 'Recovery' );
455 ktReason_BSOD_Automatic_Repair = ( 'BSOD', 'Automatic Repair' );
456 ktReason_BSOD_C0000225 = ( 'BSOD', '0xC0000225 (boot)' );
457 ktReason_Guru_Generic = ( 'Guru Meditations', 'Generic Guru Meditation' );
458 ktReason_Guru_VERR_IEM_INSTR_NOT_IMPLEMENTED = ( 'Guru Meditations', 'VERR_IEM_INSTR_NOT_IMPLEMENTED' );
459 ktReason_Guru_VERR_IEM_ASPECT_NOT_IMPLEMENTED = ( 'Guru Meditations', 'VERR_IEM_ASPECT_NOT_IMPLEMENTED' );
460 ktReason_Guru_VERR_TRPM_DONT_PANIC = ( 'Guru Meditations', 'VERR_TRPM_DONT_PANIC' );
461 ktReason_Guru_VERR_PGM_PHYS_PAGE_RESERVED = ( 'Guru Meditations', 'VERR_PGM_PHYS_PAGE_RESERVED' );
462 ktReason_Guru_VERR_VMX_INVALID_GUEST_STATE = ( 'Guru Meditations', 'VERR_VMX_INVALID_GUEST_STATE' );
463 ktReason_Guru_VINF_EM_TRIPLE_FAULT = ( 'Guru Meditations', 'VINF_EM_TRIPLE_FAULT' );
464 ktReason_Host_HostMemoryLow = ( 'Host', 'HostMemoryLow' );
465 ktReason_Host_DriverNotLoaded = ( 'Host', 'Driver not loaded' );
466 ktReason_Host_DriverNotUnloading = ( 'Host', 'Driver not unloading' );
467 ktReason_Host_NotSignedWithBuildCert = ( 'Host', 'Not signed with build cert' );
468 ktReason_Host_LeftoverService = ( 'Host', 'Leftover service' );
469 ktReason_Host_Reboot_OSX_Watchdog_Timeout = ( 'Host Reboot', 'OSX Watchdog Timeout' );
470 ktReason_Host_Modprobe_Failed = ( 'Host', 'Modprobe failed' );
471 ktReason_Networking_Nonexistent_host_nic = ( 'Networking', 'Nonexistent host networking interface' );
472 ktReason_OSInstall_GRUB_hang = ( 'O/S Install', 'GRUB hang' );
473 ktReason_Panic_BootManagerC000000F = ( 'Panic', 'Hardware Changed' );
474 ktReason_Panic_MP_BIOS_IO_APIC = ( 'Panic', 'MP-BIOS/IO-APIC' );
475 ktReason_Panic_HugeMemory = ( 'Panic', 'Huge memory assertion' );
476 ktReason_Panic_IOAPICDoesntWork = ( 'Panic', 'IO-APIC and timer does not work' );
477 ktReason_Panic_TxUnitHang = ( 'Panic', 'Tx Unit Hang' );
478 ktReason_XPCOM_Exit_Minus_11 = ( 'API / (XP)COM', 'exit -11' );
479 ktReason_XPCOM_VBoxSVC_Hang = ( 'API / (XP)COM', 'VBoxSVC hang' );
480 ktReason_XPCOM_VBoxSVC_Hang_Plus_Heap_Corruption = ( 'API / (XP)COM', 'VBoxSVC hang + heap corruption' );
481 ktReason_XPCOM_NS_ERROR_CALL_FAILED = ( 'API / (XP)COM', 'NS_ERROR_CALL_FAILED' );
482 ktReason_Unknown_Heap_Corruption = ( 'Unknown', 'Heap corruption' );
483 ktReason_Unknown_Reboot_Loop = ( 'Unknown', 'Reboot loop' );
484 ktReason_Unknown_File_Not_Found = ( 'Unknown', 'File not found' );
485 ktReason_Unknown_VM_Crash = ( 'Unknown', 'VM crash' );
486 ktReason_VMM_kvm_lock_spinning = ( 'VMM', 'kvm_lock_spinning' );
487 ktReason_Ignore_Buggy_Test_Driver = ( 'Ignore', 'Buggy test driver' );
488 ktReason_Ignore_Stale_Files = ( 'Ignore', 'Stale files' );
489 ktReason_Buggy_Build_Broken_Build = ( 'Broken Build', 'Buggy build' );
490 ## @}
491
492 ## BSOD category.
493 ksBsodCategory = 'BSOD';
494 ## Special reason indicating that the flesh and blood sheriff has work to do.
495 ksBsodAddNew = 'Add new BSOD';
496
497 ## Unit test category.
498 ksUnitTestCategory = 'Unit';
499 ## Special reason indicating that the flesh and blood sheriff has work to do.
500 ksUnitTestAddNew = 'Add new';
501
502 ## Used for indica that we shouldn't report anything for this test result ID and
503 ## consider promoting the previous error to test set level if it's the only one.
504 ktHarmless = ( 'Probably', 'Caused by previous error' );
505
506
507 def caseClosed(self, oCaseFile):
508 """
509 Reports the findings in the case and closes it.
510 """
511 #
512 # Log it and create a dReasonForReasultId we can use below.
513 #
514 dCommentForResultId = oCaseFile.dCommentForResultId;
515 if oCaseFile.dReasonForResultId:
516 # Must weed out ktHarmless.
517 dReasonForResultId = {};
518 for idKey, tReason in oCaseFile.dReasonForResultId.items():
519 if tReason is not self.ktHarmless:
520 dReasonForResultId[idKey] = tReason;
521 if not dReasonForResultId:
522 self.vprint(u'TODO: Closing %s without a real reason, only %s.'
523 % (oCaseFile.sName, oCaseFile.dReasonForResultId));
524 return False;
525
526 # Try promote to single reason.
527 atValues = dReasonForResultId.values();
528 fSingleReason = True;
529 if len(dReasonForResultId) == 1 and dReasonForResultId.keys()[0] != oCaseFile.oTestSet.idTestResult:
530 self.dprint(u'Promoting single reason to whole set: %s' % (atValues[0],));
531 elif len(dReasonForResultId) > 1 and len(atValues) == atValues.count(atValues[0]):
532 self.dprint(u'Merged %d reasons to a single one: %s' % (len(atValues), atValues[0]));
533 else:
534 fSingleReason = False;
535 if fSingleReason:
536 dReasonForResultId = { oCaseFile.oTestSet.idTestResult: atValues[0], };
537 if dCommentForResultId:
538 dCommentForResultId = { oCaseFile.oTestSet.idTestResult: dCommentForResultId.values()[0], };
539 elif oCaseFile.tReason is not None:
540 dReasonForResultId = { oCaseFile.oTestSet.idTestResult: oCaseFile.tReason, };
541 else:
542 self.vprint(u'Closing %s without a reason - this should not happen!' % (oCaseFile.sName,));
543 return False;
544
545 self.vprint(u'Closing %s with following reason%s: %s'
546 % ( oCaseFile.sName, 's' if dReasonForResultId > 0 else '', dReasonForResultId, ));
547
548 #
549 # Add the test failure reason record(s).
550 #
551 for idTestResult, tReason in dReasonForResultId.items():
552 oFailureReason = self.getFailureReason(tReason);
553 if oFailureReason is not None:
554 sComment = 'Set by $Revision: 66431 $' # Handy for reverting later.
555 if idTestResult in dCommentForResultId:
556 sComment += ': ' + dCommentForResultId[idTestResult];
557
558 oAdd = TestResultFailureData();
559 oAdd.initFromValues(idTestResult = idTestResult,
560 idFailureReason = oFailureReason.idFailureReason,
561 uidAuthor = self.uidSelf,
562 idTestSet = oCaseFile.oTestSet.idTestSet,
563 sComment = sComment,);
564 if self.oConfig.fRealRun:
565 try:
566 self.oTestResultFailureLogic.addEntry(oAdd, self.uidSelf, fCommit = True);
567 except Exception as oXcpt:
568 self.eprint(u'caseClosed: Exception "%s" while adding reason %s for %s'
569 % (oXcpt, oAdd, oCaseFile.sLongName,));
570 else:
571 self.eprint(u'caseClosed: Cannot locate failure reason: %s / %s' % ( tReason[0], tReason[1],));
572 return True;
573
574 #
575 # Tools for assiting log parsing.
576 #
577
578 @staticmethod
579 def matchFollowedByLines(sStr, off, asFollowingLines):
580 """ Worker for isThisFollowedByTheseLines. """
581
582 # Advance off to the end of the line.
583 off = sStr.find('\n', off);
584 if off < 0:
585 return False;
586 off += 1;
587
588 # Match each string with the subsequent lines.
589 for iLine, sLine in enumerate(asFollowingLines):
590 offEnd = sStr.find('\n', off);
591 if offEnd < 0:
592 return iLine + 1 == len(asFollowingLines) and sStr.find(sLine, off) < 0;
593 if sLine and sStr.find(sLine, off, offEnd) < 0:
594 return False;
595
596 # next line.
597 off = offEnd + 1;
598
599 return True;
600
601 @staticmethod
602 def isThisFollowedByTheseLines(sStr, sFirst, asFollowingLines):
603 """
604 Looks for a line contining sFirst which is then followed by lines
605 with the strings in asFollowingLines. (No newline chars anywhere!)
606 Returns True / False.
607 """
608 off = sStr.find(sFirst, 0);
609 while off >= 0:
610 if VirtualTestSheriff.matchFollowedByLines(sStr, off, asFollowingLines):
611 return True;
612 off = sStr.find(sFirst, off + 1);
613 return False;
614
615 @staticmethod
616 def findAndReturnResetOfLine(sHaystack, sNeedle):
617 """
618 Looks for sNeedle in sHaystack.
619 Returns The text following the needle up to the end of the line.
620 Returns None if not found.
621 """
622 if sHaystack is None:
623 return None;
624 off = sHaystack.find(sNeedle);
625 if off < 0:
626 return None;
627 off += len(sNeedle)
628 offEol = sHaystack.find('\n', off);
629 if offEol < 0:
630 offEol = len(sHaystack);
631 return sHaystack[off:offEol]
632
633 @staticmethod
634 def findInAnyAndReturnResetOfLine(asHaystacks, sNeedle):
635 """
636 Looks for sNeedle in zeroe or more haystacks (asHaystack).
637 Returns The text following the first needed found up to the end of the line.
638 Returns None if not found.
639 """
640 for sHaystack in asHaystacks:
641 sRet = VirtualTestSheriff.findAndReturnResetOfLine(sHaystack, sNeedle);
642 if sRet is not None:
643 return sRet;
644 return None;
645
646
647 #
648 # The investigative units.
649 #
650
651 katSimpleInstallUninstallMainLogReasons = [
652 # ( Whether to stop on hit, reason tuple, needle text. )
653 ( False, ktReason_Host_LeftoverService,
654 'SERVICE_NAME: vbox' ),
655 ( True, ktReason_Host_Modprobe_Failed,
656 'modprobe vboxdrv failed' )
657 ];
658
659 kdatSimpleInstallUninstallMainLogReasonsPerOs = {
660 'darwin': [
661 # ( Whether to stop on hit, reason tuple, needle text. )
662 ( True, ktReason_Host_DriverNotUnloading,
663 'Can\'t remove kext org.virtualbox.kext.VBoxDrv; services failed to terminate - 0xe00002c7' ),
664 ],
665 };
666
667
668 def investigateInstallUninstallFailure(self, oCaseFile, oFailedResult, sResultLog, fInstall):
669 """
670 Investigates an install or uninstall failure.
671
672 We lump the two together since the installation typically also performs
673 an uninstall first and will be seeing similar issues to the uninstall.
674 """
675 _ = fInstall;
676
677 atSimple = self.katSimpleInstallUninstallMainLogReasons;
678 if oCaseFile.oTestBox.sOs in self.kdatSimpleInstallUninstallMainLogReasonsPerOs:
679 atSimple = self.kdatSimpleInstallUninstallMainLogReasonsPerOs[oCaseFile.oTestBox.sOs] + atSimple;
680
681 fFoundSomething = False;
682 for fStopOnHit, tReason, sNeedle in atSimple:
683 if sResultLog.find(sNeedle) > 0:
684 oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult);
685 if fStopOnHit:
686 return True;
687 fFoundSomething = True;
688
689 return fFoundSomething if fFoundSomething else None;
690
691
692 def investigateBadTestBox(self, oCaseFile):
693 """
694 Checks out bad-testbox statuses.
695 """
696 _ = oCaseFile;
697 return False;
698
699
700 def investigateVBoxUnitTest(self, oCaseFile):
701 """
702 Checks out a VBox unittest problem.
703 """
704
705 #
706 # Process simple test case failures first, using their name as reason.
707 # We do the reason management just like for BSODs.
708 #
709 cRelevantOnes = 0;
710 sMainLog = oCaseFile.getMainLog();
711 aoFailedResults = oCaseFile.oTree.getListOfFailures();
712 for oFailedResult in aoFailedResults:
713 if oFailedResult is oCaseFile.oTree:
714 self.vprint('TODO: toplevel failure');
715 cRelevantOnes += 1
716
717 elif oFailedResult.sName == 'Installing VirtualBox':
718 sResultLog = TestSetData.extractLogSectionElapsed(sMainLog, oFailedResult.tsCreated, oFailedResult.tsElapsed);
719 self.investigateInstallUninstallFailure(oCaseFile, oFailedResult, sResultLog, fInstall = True)
720 cRelevantOnes += 1
721
722 elif oFailedResult.sName == 'Uninstalling VirtualBox':
723 sResultLog = TestSetData.extractLogSectionElapsed(sMainLog, oFailedResult.tsCreated, oFailedResult.tsElapsed);
724 self.investigateInstallUninstallFailure(oCaseFile, oFailedResult, sResultLog, fInstall = False)
725 cRelevantOnes += 1
726
727 elif oFailedResult.oParent is not None:
728 # Get the 2nd level node because that's where we'll find the unit test name.
729 while oFailedResult.oParent.oParent is not None:
730 oFailedResult = oFailedResult.oParent;
731
732 # Only report a failure once.
733 if oFailedResult.idTestResult not in oCaseFile.dReasonForResultId:
734 sKey = oFailedResult.sName;
735 if sKey.startswith('testcase/'):
736 sKey = sKey[9:];
737 if sKey in self.asUnitTestReasons:
738 tReason = ( self.ksUnitTestCategory, sKey );
739 oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult);
740 else:
741 self.dprint(u'Unit test failure "%s" not found in %s;' % (sKey, self.asUnitTestReasons));
742 tReason = ( self.ksUnitTestCategory, self.ksUnitTestAddNew );
743 oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult, sComment = sKey);
744 cRelevantOnes += 1
745 else:
746 self.vprint(u'Internal error: expected oParent to NOT be None for %s' % (oFailedResult,));
747
748 #
749 # If we've caught all the relevant ones by now, report the result.
750 #
751 if len(oCaseFile.dReasonForResultId) >= cRelevantOnes:
752 return self.caseClosed(oCaseFile);
753 return False;
754
755 def extractGuestCpuStack(self, sInfoText):
756 """
757 Extracts the guest CPU stacks from the input file.
758
759 Returns a dictionary keyed by the CPU number, value being a list of
760 raw stack lines (no header).
761 Returns empty dictionary if no stacks where found.
762 """
763 dRet = {};
764 off = 0;
765 while True:
766 # Find the stack.
767 offStart = sInfoText.find('=== start guest stack VCPU ', off);
768 if offStart < 0:
769 break;
770 offEnd = sInfoText.find('=== end guest stack', offStart + 20);
771 if offEnd >= 0:
772 offEnd += 3;
773 else:
774 offEnd = sInfoText.find('=== start guest stack VCPU', offStart + 20);
775 if offEnd < 0:
776 offEnd = len(sInfoText);
777
778 sStack = sInfoText[offStart : offEnd];
779 sStack = sStack.replace('\r',''); # paranoia
780 asLines = sStack.split('\n');
781
782 # Figure the CPU.
783 asWords = asLines[0].split();
784 if len(asWords) < 6 or not asWords[5].isdigit():
785 break;
786 iCpu = int(asWords[5]);
787
788 # Add it and advance.
789 dRet[iCpu] = [sLine.rstrip() for sLine in asLines[2:-1]]
790 off = offEnd;
791 return dRet;
792
793 def investigateInfoKvmLockSpinning(self, oCaseFile, sInfoText, dLogs):
794 """ Investigates kvm_lock_spinning deadlocks """
795 #
796 # Extract the stacks. We need more than one CPU to create a deadlock.
797 #
798 dStacks = self.extractGuestCpuStack(sInfoText);
799 self.dprint('kvm_lock_spinning: found %s stacks' % (len(dStacks),));
800 if len(dStacks) >= 2:
801 #
802 # Examin each of the stacks. Each must have kvm_lock_spinning in
803 # one of the first three entries.
804 #
805 cHits = 0;
806 for iCpu in dStacks:
807 asBacktrace = dStacks[iCpu];
808 for iFrame in xrange(min(3, len(asBacktrace))):
809 if asBacktrace[iFrame].find('kvm_lock_spinning') >= 0:
810 cHits += 1;
811 break;
812 self.dprint('kvm_lock_spinning: %s/%s hits' % (cHits, len(dStacks),));
813 if cHits == len(dStacks):
814 return (True, self.ktReason_VMM_kvm_lock_spinning);
815
816 _ = dLogs; _ = oCaseFile;
817 return (False, None);
818
819 ## Things we search a main or VM log for to figure out why something went bust.
820 katSimpleMainAndVmLogReasons = [
821 # ( Whether to stop on hit, reason tuple, needle text. )
822 ( False, ktReason_Guru_Generic, 'GuruMeditation' ),
823 ( False, ktReason_Guru_Generic, 'Guru Meditation' ),
824 ( True, ktReason_Guru_VERR_IEM_INSTR_NOT_IMPLEMENTED, 'VERR_IEM_INSTR_NOT_IMPLEMENTED' ),
825 ( True, ktReason_Guru_VERR_IEM_ASPECT_NOT_IMPLEMENTED, 'VERR_IEM_ASPECT_NOT_IMPLEMENTED' ),
826 ( True, ktReason_Guru_VERR_TRPM_DONT_PANIC, 'VERR_TRPM_DONT_PANIC' ),
827 ( True, ktReason_Guru_VERR_PGM_PHYS_PAGE_RESERVED, 'VERR_PGM_PHYS_PAGE_RESERVED' ),
828 ( True, ktReason_Guru_VERR_VMX_INVALID_GUEST_STATE, 'VERR_VMX_INVALID_GUEST_STATE' ),
829 ( True, ktReason_Guru_VINF_EM_TRIPLE_FAULT, 'VINF_EM_TRIPLE_FAULT' ),
830 ( True, ktReason_Networking_Nonexistent_host_nic,
831 'rc=E_FAIL text="Nonexistent host networking interface, name \'eth0\' (VERR_INTERNAL_ERROR)"' ),
832 ( True, ktReason_Host_Reboot_OSX_Watchdog_Timeout, ': "OSX Watchdog Timeout: ' ),
833 ( False, ktReason_XPCOM_NS_ERROR_CALL_FAILED,
834 'Exception: 0x800706be (Call to remote object failed (NS_ERROR_CALL_FAILED))' ),
835 ( True, ktReason_Host_HostMemoryLow, 'HostMemoryLow' ),
836 ( True, ktReason_Host_HostMemoryLow, 'Failed to procure handy pages; rc=VERR_NO_MEMORY' ),
837 ( True, ktReason_Unknown_File_Not_Found,
838 'Error: failed to start machine. Error message: File not found. (VERR_FILE_NOT_FOUND)' ),
839 ( True, ktReason_Unknown_File_Not_Found, # lump it in with file-not-found for now.
840 'Error: failed to start machine. Error message: Not supported. (VERR_NOT_SUPPORTED)' ),
841 ( False, ktReason_Unknown_VM_Crash, 'txsDoConnectViaTcp: Machine state: Aborted' ),
842 ];
843
844 ## Things we search a VBoxHardening.log file for to figure out why something went bust.
845 katSimpleVBoxHardeningLogReasons = [
846 # ( Whether to stop on hit, reason tuple, needle text. )
847 ( True, ktReason_Host_DriverNotLoaded, 'Error opening VBoxDrvStub: STATUS_OBJECT_NAME_NOT_FOUND' ),
848 ( True, ktReason_Host_NotSignedWithBuildCert, 'Not signed with the build certificate' ),
849 ];
850
851 ## Things we search a kernel.log file for to figure out why something went bust.
852 katSimpleKernelLogReasons = [
853 # ( Whether to stop on hit, reason tuple, needle text. )
854 ( True, ktReason_Panic_HugeMemory, 'mm/huge_memory.c:1988' ),
855 ( True, ktReason_Panic_IOAPICDoesntWork, 'IO-APIC + timer doesn''t work' ),
856 ( True, ktReason_Panic_TxUnitHang, 'Detected Tx Unit Hang' ),
857 ];
858
859 ## Things we search the _RIGHT_ _STRIPPED_ vgatext for.
860 katSimpleVgaTextReasons = [
861 # ( Whether to stop on hit, reason tuple, needle text. )
862 ( True, ktReason_Panic_MP_BIOS_IO_APIC,
863 "..MP-BIOS bug: 8254 timer not connected to IO-APIC\n\n" ),
864 ( True, ktReason_Panic_MP_BIOS_IO_APIC,
865 "..MP-BIOS bug: 8254 timer not connected to IO-APIC\n"
866 "...trying to set up timer (IRQ0) through the 8259A ... failed.\n"
867 "...trying to set up timer as Virtual Wire IRQ... failed.\n"
868 "...trying to set up timer as ExtINT IRQ... failed :(.\n"
869 "Kernel panic - not syncing: IO-APIC + timer doesn't work! Boot with apic=debug\n"
870 "and send a report. Then try booting with the 'noapic' option\n"
871 "\n" ),
872 ( True, ktReason_OSInstall_GRUB_hang,
873 "-----\nGRUB Loading stage2..\n\n\n\n" ),
874 ( True, ktReason_Panic_BootManagerC000000F,
875 "Windows failed to start. A recent hardware or software change might be the" ),
876 ];
877
878 ## Things we search for in the info.txt file. Require handlers for now.
879 katInfoTextHandlers = [
880 # ( Trigger text, handler method )
881 ( "kvm_lock_spinning", investigateInfoKvmLockSpinning ),
882 ];
883
884 ## Mapping screenshot/failure SHA-256 hashes to failure reasons.
885 katSimpleScreenshotHashReasons = [
886 # ( Whether to stop on hit, reason tuple, lowercased sha-256 of PIL.Image.tostring output )
887 ( True, ktReason_BSOD_Recovery, '576f8e38d62b311cac7e3dc3436a0d0b9bd8cfd7fa9c43aafa95631520a45eac' ),
888 ( True, ktReason_BSOD_Automatic_Repair, 'c6a72076cc619937a7a39cfe9915b36d94cee0d4e3ce5ce061485792dcee2749' ),
889 ( True, ktReason_BSOD_Automatic_Repair, '26c4d8a724ff2c5e1051f3d5b650dbda7b5fdee0aa3e3c6059797f7484a515df' ),
890 ( True, ktReason_BSOD_C0000225, 'bd13a144be9dcdfb16bc863ff4c8f02a86e263c174f2cd5ffd27ca5f3aa31789' ),
891 ( True, ktReason_BSOD_C0000225, '8348b465e7ee9e59dd4e785880c57fd8677de05d11ac21e786bfde935307b42f' ),
892 ( True, ktReason_BSOD_C0000225, '1316e1fc818a73348412788e6910b8c016f237d8b4e15b20caf4a866f7a7840e' ),
893 ( True, ktReason_BSOD_C0000225, '54e0acbff365ce20a85abbe42bcd53647b8b9e80c68e45b2cd30e86bf177a0b5' ),
894 ( True, ktReason_BSOD_C0000225, '50fec50b5199923fa48b3f3e782687cc381e1c8a788ebda14e6a355fbe3bb1b3' ),
895 ];
896
897 def investigateVMResult(self, oCaseFile, oFailedResult, sResultLog):
898 """
899 Investigates a failed VM run.
900 """
901
902 def investigateLogSet():
903 """
904 Investigates the current set of VM related logs.
905 """
906 self.dprint('investigateLogSet: lengths: result log %u, VM log %u, kernel log %u, vga text %u, info text %u'
907 % ( len(sResultLog if sResultLog else ''),
908 len(sVMLog if sVMLog else ''),
909 len(sKrnlLog if sKrnlLog else ''),
910 len(sVgaText if sVgaText else ''),
911 len(sInfoText if sInfoText else ''), ));
912
913 #self.dprint(u'main.log<<<\n%s\n<<<\n' % (sResultLog,));
914 #self.dprint(u'vbox.log<<<\n%s\n<<<\n' % (sVMLog,));
915 #self.dprint(u'krnl.log<<<\n%s\n<<<\n' % (sKrnlLog,));
916 #self.dprint(u'vgatext.txt<<<\n%s\n<<<\n' % (sVgaText,));
917 #self.dprint(u'info.txt<<<\n%s\n<<<\n' % (sInfoText,));
918
919 # TODO: more
920
921 #
922 # Look for BSODs. Some stupid stupid inconsistencies in reason and log messages here, so don't try prettify this.
923 #
924 sDetails = self.findInAnyAndReturnResetOfLine([ sVMLog, sResultLog ],
925 'GIM: HyperV: Guest indicates a fatal condition! P0=');
926 if sDetails is not None:
927 # P0=%#RX64 P1=%#RX64 P2=%#RX64 P3=%#RX64 P4=%#RX64 "
928 sKey = sDetails.split(' ', 1)[0];
929 try: sKey = '0x%08X' % (int(sKey, 16),);
930 except: pass;
931 if sKey in self.asBsodReasons:
932 tReason = ( self.ksBsodCategory, sKey );
933 elif sKey.lower() in self.asBsodReasons: # just in case.
934 tReason = ( self.ksBsodCategory, sKey.lower() );
935 else:
936 self.dprint(u'BSOD "%s" not found in %s;' % (sKey, self.asBsodReasons));
937 tReason = ( self.ksBsodCategory, self.ksBsodAddNew );
938 return oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult, sComment = sDetails.strip());
939
940 #
941 # Look for linux panic.
942 #
943 if sKrnlLog is not None:
944 for fStopOnHit, tReason, sNeedle in self.katSimpleKernelLogReasons:
945 if sKrnlLog.find(sNeedle) > 0:
946 oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult);
947 if fStopOnHit:
948 return True;
949 fFoundSomething = True;
950
951 #
952 # Loop thru the simple stuff.
953 #
954 fFoundSomething = False;
955 for fStopOnHit, tReason, sNeedle in self.katSimpleMainAndVmLogReasons:
956 if sResultLog.find(sNeedle) > 0 or (sVMLog is not None and sVMLog.find(sNeedle) > 0):
957 oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult);
958 if fStopOnHit:
959 return True;
960 fFoundSomething = True;
961
962 # Continue with vga text.
963 if sVgaText:
964 for fStopOnHit, tReason, sNeedle in self.katSimpleVgaTextReasons:
965 if sVgaText.find(sNeedle) > 0:
966 oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult);
967 if fStopOnHit:
968 return True;
969 fFoundSomething = True;
970 _ = sInfoText;
971
972 # Continue with screen hashes.
973 if sScreenHash is not None:
974 for fStopOnHit, tReason, sHash in self.katSimpleScreenshotHashReasons:
975 if sScreenHash == sHash:
976 oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult);
977 if fStopOnHit:
978 return True;
979 fFoundSomething = True;
980
981 # Check VBoxHardening.log.
982 if sNtHardLog is not None:
983 for fStopOnHit, tReason, sNeedle in self.katSimpleVBoxHardeningLogReasons:
984 if sNtHardLog.find(sNeedle) > 0:
985 oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult);
986 if fStopOnHit:
987 return True;
988 fFoundSomething = True;
989
990 #
991 # Complicated stuff.
992 #
993 dLogs = {
994 'sVMLog': sVMLog,
995 'sNtHardLog': sNtHardLog,
996 'sScreenHash': sScreenHash,
997 'sKrnlLog': sKrnlLog,
998 'sVgaText': sVgaText,
999 'sInfoText': sInfoText,
1000 };
1001
1002 # info.txt.
1003 if sInfoText:
1004 for sNeedle, fnHandler in self.katInfoTextHandlers:
1005 if sInfoText.find(sNeedle) > 0:
1006 (fStop, tReason) = fnHandler(self, oCaseFile, sInfoText, dLogs);
1007 if tReason is not None:
1008 oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult);
1009 if fStop:
1010 return True;
1011 fFoundSomething = True;
1012
1013 #
1014 # Check for repeated reboots...
1015 #
1016 if sVMLog is not None:
1017 cResets = sVMLog.count('Changing the VM state from \'RUNNING\' to \'RESETTING\'');
1018 if cResets > 10:
1019 return oCaseFile.noteReasonForId(self.ktReason_Unknown_Reboot_Loop, oFailedResult.idTestResult,
1020 sComment = 'Counted %s reboots' % (cResets,));
1021
1022 return fFoundSomething;
1023
1024 #
1025 # Check if we got any VM or/and kernel logs. Treat them as sets in
1026 # case we run multiple VMs here (this is of course ASSUMING they
1027 # appear in the order that terminateVmBySession uploads them).
1028 #
1029 cTimes = 0;
1030 sVMLog = None;
1031 sNtHardLog = None;
1032 sScreenHash = None;
1033 sKrnlLog = None;
1034 sVgaText = None;
1035 sInfoText = None;
1036 for oFile in oFailedResult.aoFiles:
1037 if oFile.sKind == TestResultFileData.ksKind_LogReleaseVm:
1038 if 'VBoxHardening.log' not in oFile.sFile:
1039 if sVMLog is not None:
1040 if investigateLogSet() is True:
1041 return True;
1042 cTimes += 1;
1043 sInfoText = None;
1044 sVgaText = None;
1045 sKrnlLog = None;
1046 sScreenHash = None;
1047 sNtHardLog = None;
1048 sVMLog = oCaseFile.getLogFile(oFile);
1049 else:
1050 sNtHardLog = oCaseFile.getLogFile(oFile);
1051 elif oFile.sKind == TestResultFileData.ksKind_LogGuestKernel:
1052 sKrnlLog = oCaseFile.getLogFile(oFile);
1053 elif oFile.sKind == TestResultFileData.ksKind_InfoVgaText:
1054 sVgaText = '\n'.join([sLine.rstrip() for sLine in oCaseFile.getLogFile(oFile).split('\n')]);
1055 elif oFile.sKind == TestResultFileData.ksKind_InfoCollection:
1056 sInfoText = oCaseFile.getLogFile(oFile);
1057 elif oFile.sKind == TestResultFileData.ksKind_ScreenshotFailure:
1058 sScreenHash = oCaseFile.getScreenshotSha256(oFile);
1059 if sScreenHash is not None:
1060 sScreenHash = sScreenHash.lower();
1061 self.vprint(u'%s %s' % ( sScreenHash, oFile.sFile,));
1062
1063 if ( sVMLog is not None \
1064 or sNtHardLog is not None \
1065 or cTimes == 0) \
1066 and investigateLogSet() is True:
1067 return True;
1068
1069 return None;
1070
1071
1072 def isResultFromVMRun(self, oFailedResult, sResultLog):
1073 """
1074 Checks if this result and corresponding log snippet looks like a VM run.
1075 """
1076
1077 # Look for startVmEx/ startVmAndConnectToTxsViaTcp and similar output in the log.
1078 if sResultLog.find(' startVm') > 0:
1079 return True;
1080
1081 # Any other indicators? No?
1082 _ = oFailedResult;
1083 return False;
1084
1085 def investigateVBoxVMTest(self, oCaseFile, fSingleVM):
1086 """
1087 Checks out a VBox VM test.
1088
1089 This is generic investigation of a test running one or more VMs, like
1090 for example a smoke test or a guest installation test.
1091
1092 The fSingleVM parameter is a hint, which probably won't come in useful.
1093 """
1094 _ = fSingleVM;
1095
1096 #
1097 # Get a list of test result failures we should be looking into and the main log.
1098 #
1099 aoFailedResults = oCaseFile.oTree.getListOfFailures();
1100 sMainLog = oCaseFile.getMainLog();
1101
1102 #
1103 # There are a set of errors ending up on the top level result record.
1104 # Should deal with these first.
1105 #
1106 if len(aoFailedResults) == 1 and aoFailedResults[0] == oCaseFile.oTree:
1107 # Check if we've just got that XPCOM client smoke test shutdown issue. This will currently always
1108 # be reported on the top result because vboxinstall.py doesn't add an error for it. It is easy to
1109 # ignore other failures in the test if we're not a little bit careful here.
1110 if sMainLog.find('vboxinstaller: Exit code: -11 (') > 0:
1111 oCaseFile.noteReason(self.ktReason_XPCOM_Exit_Minus_11);
1112 return self.caseClosed(oCaseFile);
1113
1114 # Hang after starting VBoxSVC (e.g. idTestSet=136307258)
1115 if self.isThisFollowedByTheseLines(sMainLog, 'oVBoxMgr=<vboxapi.VirtualBoxManager object at',
1116 (' Timeout: ', ' Attempting to abort child...',) ):
1117 if sMainLog.find('*** glibc detected *** /') > 0:
1118 oCaseFile.noteReason(self.ktReason_XPCOM_VBoxSVC_Hang_Plus_Heap_Corruption);
1119 else:
1120 oCaseFile.noteReason(self.ktReason_XPCOM_VBoxSVC_Hang);
1121 return self.caseClosed(oCaseFile);
1122
1123 # Look for heap corruption without visible hang.
1124 if sMainLog.find('*** glibc detected *** /') > 0 \
1125 or sMainLog.find("-1073740940") > 0: # STATUS_HEAP_CORRUPTION / 0xc0000374
1126 oCaseFile.noteReason(self.ktReason_Unknown_Heap_Corruption);
1127 return self.caseClosed(oCaseFile);
1128
1129 # Out of memory w/ timeout.
1130 if sMainLog.find('sErrId=HostMemoryLow') > 0:
1131 oCaseFile.noteReason(self.ktReason_Host_HostMemoryLow);
1132 return self.caseClosed(oCaseFile);
1133
1134 # Stale files like vts_rm.exe (windows).
1135 offEnd = sMainLog.rfind('*** The test driver exits successfully. ***');
1136 if offEnd > 0 and sMainLog.find('[Error 145] The directory is not empty: ', offEnd) > 0:
1137 oCaseFile.noteReason(self.ktReason_Ignore_Stale_Files);
1138 return self.caseClosed(oCaseFile);
1139
1140 #
1141 # XPCOM screwup
1142 #
1143 if sMainLog.find('AttributeError: \'NoneType\' object has no attribute \'addObserver\'') > 0:
1144 oCaseFile.noteReason(self.ktReason_Buggy_Build_Broken_Build);
1145 return self.caseClosed(oCaseFile);
1146
1147 #
1148 # Go thru each failed result.
1149 #
1150 for oFailedResult in aoFailedResults:
1151 self.dprint(u'Looking at test result #%u - %s' % (oFailedResult.idTestResult, oFailedResult.getFullName(),));
1152 sResultLog = TestSetData.extractLogSectionElapsed(sMainLog, oFailedResult.tsCreated, oFailedResult.tsElapsed);
1153 if oFailedResult.sName == 'Installing VirtualBox':
1154 self.investigateInstallUninstallFailure(oCaseFile, oFailedResult, sResultLog, fInstall = True)
1155
1156 elif oFailedResult.sName == 'Uninstalling VirtualBox':
1157 self.investigateInstallUninstallFailure(oCaseFile, oFailedResult, sResultLog, fInstall = False)
1158
1159 elif self.isResultFromVMRun(oFailedResult, sResultLog):
1160 self.investigateVMResult(oCaseFile, oFailedResult, sResultLog);
1161
1162 elif sResultLog.find('Exception: 0x800706be (Call to remote object failed (NS_ERROR_CALL_FAILED))') > 0:
1163 oCaseFile.noteReasonForId(self.ktReason_XPCOM_NS_ERROR_CALL_FAILED, oFailedResult.idTestResult);
1164
1165 elif sResultLog.find('The machine is not mutable (state is ') > 0:
1166 self.vprint('Ignoring "machine not mutable" error as it is probably due to an earlier problem');
1167 oCaseFile.noteReasonForId(self.ktHarmless, oFailedResult.idTestResult);
1168
1169 elif sResultLog.find('** error: no action was specified') > 0 \
1170 or sResultLog.find('(len(self._asXml, asText))') > 0:
1171 oCaseFile.noteReasonForId(self.ktReason_Ignore_Buggy_Test_Driver, oFailedResult.idTestResult);
1172
1173 else:
1174 self.vprint(u'TODO: Cannot place idTestResult=%u - %s' % (oFailedResult.idTestResult, oFailedResult.sName,));
1175 self.dprint(u'%s + %s <<\n%s\n<<' % (oFailedResult.tsCreated, oFailedResult.tsElapsed, sResultLog,));
1176
1177 #
1178 # Report home and close the case if we got them all, otherwise log it.
1179 #
1180 if len(oCaseFile.dReasonForResultId) >= len(aoFailedResults):
1181 return self.caseClosed(oCaseFile);
1182
1183 if oCaseFile.dReasonForResultId:
1184 self.vprint(u'TODO: Got %u out of %u - close, but no cigar. :-/'
1185 % (len(oCaseFile.dReasonForResultId), len(aoFailedResults)));
1186 else:
1187 self.vprint(u'XXX: Could not figure out anything at all! :-(');
1188 return False;
1189
1190
1191 def reasoningFailures(self):
1192 """
1193 Guess the reason for failures.
1194 """
1195 #
1196 # Get a list of failed test sets without any assigned failure reason.
1197 #
1198 cGot = 0;
1199 aoTestSets = self.oTestSetLogic.fetchFailedSetsWithoutReason(cHoursBack = self.oConfig.cHoursBack, tsNow = self.tsNow);
1200 for oTestSet in aoTestSets:
1201 self.dprint(u'');
1202 self.dprint(u'reasoningFailures: Checking out test set #%u, status %s' % ( oTestSet.idTestSet, oTestSet.enmStatus,))
1203
1204 #
1205 # Open a case file and assign it to the right investigator.
1206 #
1207 (oTree, _ ) = self.oTestResultLogic.fetchResultTree(oTestSet.idTestSet);
1208 oBuild = BuildDataEx().initFromDbWithId( self.oDb, oTestSet.idBuild, oTestSet.tsCreated);
1209 oTestBox = TestBoxData().initFromDbWithGenId( self.oDb, oTestSet.idGenTestBox);
1210 oTestGroup = TestGroupData().initFromDbWithId( self.oDb, oTestSet.idTestGroup, oTestSet.tsCreated);
1211 oTestCase = TestCaseDataEx().initFromDbWithGenId( self.oDb, oTestSet.idGenTestCase, oTestSet.tsConfig);
1212
1213 oCaseFile = VirtualTestSheriffCaseFile(self, oTestSet, oTree, oBuild, oTestBox, oTestGroup, oTestCase);
1214
1215 if oTestSet.enmStatus == TestSetData.ksTestStatus_BadTestBox:
1216 self.dprint(u'investigateBadTestBox is taking over %s.' % (oCaseFile.sLongName,));
1217 fRc = self.investigateBadTestBox(oCaseFile);
1218
1219 elif oCaseFile.isVBoxUnitTest():
1220 self.dprint(u'investigateVBoxUnitTest is taking over %s.' % (oCaseFile.sLongName,));
1221 fRc = self.investigateVBoxUnitTest(oCaseFile);
1222
1223 elif oCaseFile.isVBoxInstallTest():
1224 self.dprint(u'investigateVBoxVMTest is taking over %s.' % (oCaseFile.sLongName,));
1225 fRc = self.investigateVBoxVMTest(oCaseFile, fSingleVM = True);
1226
1227 elif oCaseFile.isVBoxUSBTest():
1228 self.dprint(u'investigateVBoxVMTest is taking over %s.' % (oCaseFile.sLongName,));
1229 fRc = self.investigateVBoxVMTest(oCaseFile, fSingleVM = True);
1230
1231 elif oCaseFile.isVBoxStorageTest():
1232 self.dprint(u'investigateVBoxVMTest is taking over %s.' % (oCaseFile.sLongName,));
1233 fRc = self.investigateVBoxVMTest(oCaseFile, fSingleVM = True);
1234
1235 elif oCaseFile.isVBoxGAsTest():
1236 self.dprint(u'investigateVBoxVMTest is taking over %s.' % (oCaseFile.sLongName,));
1237 fRc = self.investigateVBoxVMTest(oCaseFile, fSingleVM = True);
1238
1239 elif oCaseFile.isVBoxAPITest():
1240 self.dprint(u'investigateVBoxVMTest is taking over %s.' % (oCaseFile.sLongName,));
1241 fRc = self.investigateVBoxVMTest(oCaseFile, fSingleVM = True);
1242
1243 elif oCaseFile.isVBoxBenchmarkTest():
1244 self.dprint(u'investigateVBoxVMTest is taking over %s.' % (oCaseFile.sLongName,));
1245 fRc = self.investigateVBoxVMTest(oCaseFile, fSingleVM = False);
1246
1247 elif oCaseFile.isVBoxSmokeTest():
1248 self.dprint(u'investigateVBoxVMTest is taking over %s.' % (oCaseFile.sLongName,));
1249 fRc = self.investigateVBoxVMTest(oCaseFile, fSingleVM = False);
1250
1251 else:
1252 self.vprint(u'reasoningFailures: Unable to classify test set: %s' % (oCaseFile.sLongName,));
1253 fRc = False;
1254 cGot += fRc is True;
1255
1256 self.vprint(u'reasoningFailures: Got %u out of %u' % (cGot, len(aoTestSets), ));
1257 return 0;
1258
1259
1260 def main(self):
1261 """
1262 The 'main' function.
1263 Return exit code (0, 1, etc).
1264 """
1265 # Database stuff.
1266 self.oDb = TMDatabaseConnection()
1267 self.oTestResultLogic = TestResultLogic(self.oDb);
1268 self.oTestSetLogic = TestSetLogic(self.oDb);
1269 self.oFailureReasonLogic = FailureReasonLogic(self.oDb);
1270 self.oTestResultFailureLogic = TestResultFailureLogic(self.oDb);
1271 self.asBsodReasons = self.oFailureReasonLogic.fetchForSheriffByNamedCategory(self.ksBsodCategory);
1272 self.asUnitTestReasons = self.oFailureReasonLogic.fetchForSheriffByNamedCategory(self.ksUnitTestCategory);
1273
1274 # Get a fix on our 'now' before we do anything..
1275 self.oDb.execute('SELECT CURRENT_TIMESTAMP - interval \'%s hours\'', (self.oConfig.cStartHoursAgo,));
1276 self.tsNow = self.oDb.fetchOne();
1277
1278 # If we're suppost to commit anything we need to get our user ID.
1279 rcExit = 0;
1280 if self.oConfig.fRealRun:
1281 self.oLogin = UserAccountLogic(self.oDb).tryFetchAccountByLoginName(VirtualTestSheriff.ksLoginName);
1282 if self.oLogin is None:
1283 rcExit = self.eprint('Cannot find my user account "%s"!' % (VirtualTestSheriff.ksLoginName,));
1284 else:
1285 self.uidSelf = self.oLogin.uid;
1286
1287 #
1288 # Do the stuff.
1289 #
1290 if rcExit == 0:
1291 rcExit = self.selfCheck();
1292 if rcExit == 0:
1293 rcExit = self.badTestBoxManagement();
1294 rcExit2 = self.reasoningFailures();
1295 if rcExit == 0:
1296 rcExit = rcExit2;
1297 # Redo the bad testbox management after failure reasons have been assigned (got timing issues).
1298 if rcExit == 0:
1299 rcExit = self.badTestBoxManagement();
1300
1301 # Cleanup.
1302 self.oFailureReasonLogic = None;
1303 self.oTestResultFailureLogic = None;
1304 self.oTestSetLogic = None;
1305 self.oTestResultLogic = None;
1306 self.oDb.close();
1307 self.oDb = None;
1308 if self.oLogFile is not None:
1309 self.oLogFile.close();
1310 self.oLogFile = None;
1311 return rcExit;
1312
1313if __name__ == '__main__':
1314 sys.exit(VirtualTestSheriff().main());
1315
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette