Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: scripts/common/gtest_utils.py

Issue 109223007: GTTF: Make runtest.py use the new test launcher's JSON summary. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | scripts/slave/runtest.py » ('j') | scripts/slave/runtest.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import json
6 import re 7 import re
8 import tempfile
7 9
8 10
9 class GTestLogParser(object): 11 class GTestLogParser(object):
10 """This helper class process GTest test output.""" 12 """This helper class process GTest test output."""
11 13
12 def __init__(self): 14 def __init__(self):
13 # State tracking for log parsing 15 # State tracking for log parsing
14 self.completed = False 16 self.completed = False
15 self._current_test = '' 17 self._current_test = ''
16 self._failure_description = [] 18 self._failure_description = []
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 if results: 383 if results:
382 test_name = results.group(1) 384 test_name = results.group(1)
383 status = self._StatusOfTest(test_name) 385 status = self._StatusOfTest(test_name)
384 if status in ('not known', 'OK'): 386 if status in ('not known', 'OK'):
385 self._test_status[test_name] = ( 387 self._test_status[test_name] = (
386 'failed', ['Unknown error, see stdio log.']) 388 'failed', ['Unknown error, see stdio log.'])
387 else: 389 else:
388 self._parsing_failures = False 390 self._parsing_failures = False
389 elif line.startswith('Failing tests:'): 391 elif line.startswith('Failing tests:'):
390 self._parsing_failures = True 392 self._parsing_failures = True
393
394
395 class GTestJSONParser(object):
396 def __init__(self):
397 self.json_file = None
398
399 self.passed_tests = set()
400 self.failed_tests = set()
401 self.flaky_tests = set()
402 self.test_logs = {}
403
404 self.parsing_errors = []
405
406 self.master_name = None
407
408 def ProcessLine(self, line):
409 # Deliberately do nothing - we parse out-of-band JSON summary
410 # instead of in-band stdout.
411 pass
412
413 def PassedTests(self):
414 return sorted(self.passed_tests)
415
416 def FailedTests(self, include_fails=False, include_flaky=False):
417 return sorted(self.failed_tests)
418
419 def FailureDescription(self, test):
420 return self.test_logs.get(test, [])
421
422 @staticmethod
423 def SuppressionHashes():
424 return []
425
426 def ParsingErrors(self):
427 return self.parsing_errors
428
429 def ClearParsingErrors(self):
430 self.parsing_errors = ['Cleared.']
431
432 @staticmethod
433 def DisabledTests():
434 # TODO(phajdan.jr): Count disabled tests when JSON summary includes them.
435 return 0
436
437 def FlakyTests(self):
438 return len(self.flaky_tests)
439
440 @staticmethod
441 def RunningTests():
442 return []
443
444 def OpenJSONFile(self, cmdline_path):
445 if cmdline_path:
446 self.json_file = open(cmdline_path, 'rw')
447 return cmdline_path
448 else:
449 self.json_file = tempfile.NamedTemporaryFile(mode='r')
450 return self.json_file.name
451
452 def ProcessAndCloseJSONFile(self):
453 if not self.json_file:
454 return
455
456 try:
457 json_output = self.json_file.read()
458 json_data = json.loads(json_output)
ghost stip (do not use) 2013/12/16 21:18:50 I'm assuming you're not using json.load() because
Paweł Hajdan Jr. 2013/12/17 16:51:56 Yes.
459 except ValueError:
460 self.parsing_errors = json_output.split('\n')
461 else:
ghost stip (do not use) 2013/12/16 21:18:50 didn't know you could do that
462 for iteration_data in json_data['per_iteration_data']:
463 for test_name, test_runs in iteration_data.iteritems():
464 if test_runs[-1]['status'] == 'SUCCESS':
465 self.passed_tests.add(test_name)
466 else:
467 self.failed_tests.add(test_name)
468
469 if len(test_runs) > 1:
470 self.flaky_tests.add(test_name)
471
472 if test_name not in self.test_logs:
473 self.test_logs[test_name] = []
ghost stip (do not use) 2013/12/16 21:18:50 remove line 472, make this self.test_logs.setdefau
Paweł Hajdan Jr. 2013/12/17 16:51:56 Done.
474 for run_index, run_data in enumerate(test_runs, start=1):
475 run_lines = ['%s (run #%d):' % (test_name, run_index)]
476 decoded_lines = run_data['output_snippet'].decode('string_escape')
477 run_lines.extend(decoded_lines.split('\n'))
478 self.test_logs[test_name].extend(run_lines)
479 finally:
480 self.json_file.close()
481 self.json_file = None
OLDNEW
« no previous file with comments | « no previous file | scripts/slave/runtest.py » ('j') | scripts/slave/runtest.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698