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, mode_run, mode_compile_targets): | |
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('--output', required=True) | |
38 run_parser.add_argument('--filter-file', type=argparse.FileType('r')) | |
39 run_parser.set_defaults(func=mode_run) | |
40 | |
41 run_parser = subparsers.add_parser('compile_targets') | |
42 run_parser.add_argument('--output', required=True) | |
iannucci
2014/10/22 07:23:15
type=argparse.FileType('w') ?
Paweł Hajdan Jr.
2014/10/22 09:43:27
Done.
| |
43 run_parser.set_defaults(func=mode_compile_targets) | |
44 | |
45 args = parser.parse_args(argv) | |
46 return args.func(args) | |
47 | |
48 | |
49 def run_command(argv): | |
50 print 'Running %r' % argv | |
51 rc = subprocess.call(argv) | |
52 print 'Command %r returned exit code %d' % (argv, rc) | |
53 return rc | |
54 | |
55 | |
56 @contextlib.contextmanager | |
57 def temporary_file(): | |
58 fd, path = tempfile.mkstemp() | |
59 os.close(fd) | |
60 try: | |
61 yield path | |
62 finally: | |
63 os.remove(path) | |
64 | |
65 | |
66 def parse_common_test_results(json_results): | |
iannucci
2014/10/22 07:23:14
is this /really/ common? it seems like it's got a
Paweł Hajdan Jr.
2014/10/22 09:43:27
As part of Ojan's CY work all test harnesses are s
| |
67 def convert_trie_to_flat_paths(trie, prefix=None): | |
iannucci
2014/10/22 07:23:14
lol, I think this function is in like 4 locations
Paweł Hajdan Jr.
2014/10/22 09:43:27
Acknowledged.
| |
68 # Also see webkitpy.layout_tests.layout_package.json_results_generator | |
69 result = {} | |
70 for name, data in trie.iteritems(): | |
71 if prefix: | |
72 name = prefix + '/' + name | |
73 if len(data) and not 'actual' in data and not 'expected' in data: | |
74 result.update(convert_trie_to_flat_paths(data, name)) | |
75 else: | |
76 result[name] = data | |
77 return result | |
78 | |
79 results = { | |
80 'passes': {}, | |
81 'unexpected_passes': {}, | |
82 'failures': {}, | |
83 'unexpected_failures': {}, | |
84 'flakes': {}, | |
85 'unexpected_flakes': {}, | |
86 } | |
87 | |
88 # TODO(dpranke): crbug.com/357866 - we should simplify the handling of | |
89 # both the return code and parsing the actual results, below. | |
90 | |
91 passing_statuses = ('PASS', 'SLOW', 'NEEDSREBASELINE', | |
92 'NEEDSMANUALREBASELINE') | |
93 | |
94 for test, result in convert_trie_to_flat_paths( | |
95 json_results['tests']).iteritems(): | |
96 key = 'unexpected_' if result.get('is_unexpected') else '' | |
97 data = result['actual'] | |
98 actual_results = data.split() | |
99 last_result = actual_results[-1] | |
100 expected_results = result['expected'].split() | |
101 | |
102 if (len(actual_results) > 1 and | |
103 (last_result in expected_results or last_result in passing_statuses)): | |
104 key += 'flakes' | |
105 elif last_result in passing_statuses: | |
106 key += 'passes' | |
107 # TODO(dpranke): crbug.com/357867 ... Why are we assigning result | |
108 # instead of actual_result here. Do we even need these things to be | |
109 # hashes, or just lists? | |
110 data = result | |
111 else: | |
112 key += 'failures' | |
113 results[key][test] = data | |
114 | |
115 return results | |
OLD | NEW |