OLD | NEW |
(Empty) | |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import argparse |
| 6 import contextlib |
| 7 import json |
| 8 import os |
| 9 import subprocess |
| 10 import tempfile |
| 11 |
| 12 |
| 13 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) |
| 14 SRC_DIR = os.path.abspath( |
| 15 os.path.join(SCRIPT_DIR, os.path.pardir, os.path.pardir)) |
| 16 |
| 17 |
| 18 # run-webkit-tests returns the number of failures as the return |
| 19 # code, but caps the return code at 101 to avoid overflow or colliding |
| 20 # with reserved values from the shell. |
| 21 MAX_FAILURES_EXIT_STATUS = 101 |
| 22 |
| 23 |
| 24 def run_script(argv, funcs): |
| 25 def parse_json(path): |
| 26 with open(path) as f: |
| 27 return json.load(f) |
| 28 parser = argparse.ArgumentParser() |
| 29 # TODO(phajdan.jr): Make build-config-fs required after passing it in recipe. |
| 30 parser.add_argument('--build-config-fs') |
| 31 parser.add_argument('--paths', type=parse_json, default={}) |
| 32 parser.add_argument('--properties', type=parse_json, default={}) |
| 33 |
| 34 subparsers = parser.add_subparsers() |
| 35 |
| 36 run_parser = subparsers.add_parser('run') |
| 37 run_parser.add_argument( |
| 38 '--output', type=argparse.FileType('w'), required=True) |
| 39 run_parser.add_argument('--filter-file', type=argparse.FileType('r')) |
| 40 run_parser.set_defaults(func=funcs['run']) |
| 41 |
| 42 run_parser = subparsers.add_parser('compile_targets') |
| 43 run_parser.add_argument( |
| 44 '--output', type=argparse.FileType('w'), required=True) |
| 45 run_parser.set_defaults(func=funcs['compile_targets']) |
| 46 |
| 47 args = parser.parse_args(argv) |
| 48 return args.func(args) |
| 49 |
| 50 |
| 51 def run_command(argv): |
| 52 print 'Running %r' % argv |
| 53 rc = subprocess.call(argv) |
| 54 print 'Command %r returned exit code %d' % (argv, rc) |
| 55 return rc |
| 56 |
| 57 |
| 58 @contextlib.contextmanager |
| 59 def temporary_file(): |
| 60 fd, path = tempfile.mkstemp() |
| 61 os.close(fd) |
| 62 try: |
| 63 yield path |
| 64 finally: |
| 65 os.remove(path) |
| 66 |
| 67 |
| 68 def parse_common_test_results(json_results): |
| 69 def convert_trie_to_flat_paths(trie, prefix=None): |
| 70 # Also see webkitpy.layout_tests.layout_package.json_results_generator |
| 71 result = {} |
| 72 for name, data in trie.iteritems(): |
| 73 if prefix: |
| 74 name = prefix + '/' + name |
| 75 if len(data) and not 'actual' in data and not 'expected' in data: |
| 76 result.update(convert_trie_to_flat_paths(data, name)) |
| 77 else: |
| 78 result[name] = data |
| 79 return result |
| 80 |
| 81 results = { |
| 82 'passes': {}, |
| 83 'unexpected_passes': {}, |
| 84 'failures': {}, |
| 85 'unexpected_failures': {}, |
| 86 'flakes': {}, |
| 87 'unexpected_flakes': {}, |
| 88 } |
| 89 |
| 90 # TODO(dpranke): crbug.com/357866 - we should simplify the handling of |
| 91 # both the return code and parsing the actual results, below. |
| 92 |
| 93 passing_statuses = ('PASS', 'SLOW', 'NEEDSREBASELINE', |
| 94 'NEEDSMANUALREBASELINE') |
| 95 |
| 96 for test, result in convert_trie_to_flat_paths( |
| 97 json_results['tests']).iteritems(): |
| 98 key = 'unexpected_' if result.get('is_unexpected') else '' |
| 99 data = result['actual'] |
| 100 actual_results = data.split() |
| 101 last_result = actual_results[-1] |
| 102 expected_results = result['expected'].split() |
| 103 |
| 104 if (len(actual_results) > 1 and |
| 105 (last_result in expected_results or last_result in passing_statuses)): |
| 106 key += 'flakes' |
| 107 elif last_result in passing_statuses: |
| 108 key += 'passes' |
| 109 # TODO(dpranke): crbug.com/357867 ... Why are we assigning result |
| 110 # instead of actual_result here. Do we even need these things to be |
| 111 # hashes, or just lists? |
| 112 data = result |
| 113 else: |
| 114 key += 'failures' |
| 115 results[key][test] = data |
| 116 |
| 117 return results |
OLD | NEW |