OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 '''A test runner for gtest application tests.''' | 6 '''A test runner for gtest application tests.''' |
7 | 7 |
8 import argparse | 8 import argparse |
9 import json | 9 import json |
10 import logging | 10 import logging |
(...skipping 12 matching lines...) Expand all Loading... |
23 def main(): | 23 def main(): |
24 parser = argparse.ArgumentParser(description='An application test runner.') | 24 parser = argparse.ArgumentParser(description='An application test runner.') |
25 parser.add_argument('build_dir', type=str, help='The build output directory.') | 25 parser.add_argument('build_dir', type=str, help='The build output directory.') |
26 parser.add_argument('--verbose', default=False, action='store_true', | 26 parser.add_argument('--verbose', default=False, action='store_true', |
27 help='Print additional logging information.') | 27 help='Print additional logging information.') |
28 parser.add_argument('--repeat-count', default=1, metavar='INT', | 28 parser.add_argument('--repeat-count', default=1, metavar='INT', |
29 action='store', type=int, | 29 action='store', type=int, |
30 help='The number of times to repeat the set of tests.') | 30 help='The number of times to repeat the set of tests.') |
31 parser.add_argument('--write-full-results-to', metavar='FILENAME', | 31 parser.add_argument('--write-full-results-to', metavar='FILENAME', |
32 help='The path to write the JSON list of full results.') | 32 help='The path to write the JSON list of full results.') |
| 33 parser.add_argument('--test-launcher-summary-output', metavar='FILENAME', |
| 34 help='The path to write the JSON list of full results.') |
33 parser.add_argument('--test-list-file', metavar='FILENAME', type=file, | 35 parser.add_argument('--test-list-file', metavar='FILENAME', type=file, |
34 default=APPTESTS, help='The file listing tests to run.') | 36 default=APPTESTS, help='The file listing tests to run.') |
35 parser.add_argument('--apptest-filter', default='', | 37 parser.add_argument('--apptest-filter', default='', |
36 help='A comma-separated list of mojo:apptests to run.') | 38 help='A comma-separated list of mojo:apptests to run.') |
37 args, commandline_args = parser.parse_known_args() | 39 args, commandline_args = parser.parse_known_args() |
38 | 40 |
39 logger = logging.getLogger() | 41 logger = logging.getLogger() |
40 logging.basicConfig(stream=sys.stdout, format='%(levelname)s:%(message)s') | 42 logging.basicConfig(stream=sys.stdout, format='%(levelname)s:%(message)s') |
41 logger.setLevel(logging.DEBUG if args.verbose else logging.WARNING) | 43 logger.setLevel(logging.DEBUG if args.verbose else logging.WARNING) |
42 logger.debug('Initialized logging: level=%s' % logger.level) | 44 logger.debug('Initialized logging: level=%s' % logger.level) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 107 |
106 print '[==========] %d tests ran.' % len(tests) | 108 print '[==========] %d tests ran.' % len(tests) |
107 print '[ PASSED ] %d tests.' % (len(tests) - len(failed)) | 109 print '[ PASSED ] %d tests.' % (len(tests) - len(failed)) |
108 if failed: | 110 if failed: |
109 print '[ FAILED ] %d tests, listed below:' % len(failed) | 111 print '[ FAILED ] %d tests, listed below:' % len(failed) |
110 for failure in failed: | 112 for failure in failed: |
111 print '[ FAILED ] %s' % failure | 113 print '[ FAILED ] %s' % failure |
112 | 114 |
113 if args.write_full_results_to: | 115 if args.write_full_results_to: |
114 _WriteJSONResults(tests, failed, args.write_full_results_to) | 116 _WriteJSONResults(tests, failed, args.write_full_results_to) |
| 117 if args.test_launcher_summary_output: |
| 118 _WriteSwarmingJSONResults(tests, failed, args.test_launcher_summary_output) |
115 | 119 |
116 return 1 if failed else 0 | 120 return 1 if failed else 0 |
117 | 121 |
118 | 122 |
119 def _WriteJSONResults(tests, failed, write_full_results_to): | 123 def _WriteJSONResults(tests, failed, write_full_results_to): |
120 '''Write the apptest results in the Chromium JSON test results format. | 124 '''Write the apptest results in the Chromium JSON test results format. |
121 See <http://www.chromium.org/developers/the-json-test-results-format> | 125 See <http://www.chromium.org/developers/the-json-test-results-format> |
122 TODO(msw): Use Chromium and TYP testing infrastructure. | 126 TODO(msw): Use Chromium and TYP testing infrastructure. |
123 TODO(msw): Use GTest Suite.Fixture names, not the apptest names. | 127 TODO(msw): Use GTest Suite.Fixture names, not the apptest names. |
124 Adapted from chrome/test/mini_installer/test_installer.py | 128 Adapted from chrome/test/mini_installer/test_installer.py |
(...skipping 28 matching lines...) Expand all Loading... |
153 def _AddPathToTrie(trie, path, value): | 157 def _AddPathToTrie(trie, path, value): |
154 if '.' not in path: | 158 if '.' not in path: |
155 trie[path] = value | 159 trie[path] = value |
156 return | 160 return |
157 directory, rest = path.split('.', 1) | 161 directory, rest = path.split('.', 1) |
158 if directory not in trie: | 162 if directory not in trie: |
159 trie[directory] = {} | 163 trie[directory] = {} |
160 _AddPathToTrie(trie[directory], rest, value) | 164 _AddPathToTrie(trie[directory], rest, value) |
161 | 165 |
162 | 166 |
| 167 def _WriteSwarmingJSONResults(tests, failed, write_full_results_to): |
| 168 '''Writes the test results in the JSON test result format used by swarming.''' |
| 169 results = { |
| 170 'all_tests': tests, |
| 171 'disabled_tests': [], |
| 172 'global_tags': [], |
| 173 } |
| 174 |
| 175 test_results = [] |
| 176 for test in sorted(tests): |
| 177 value = [{ |
| 178 'status': 'FAILURE' if test in failed else 'SUCCESS', |
| 179 'output_snippet': '', |
| 180 'output_snippet_base64': '', |
| 181 }] |
| 182 test_results.append({test: value}) |
| 183 results['per_iteration_data'] = test_results |
| 184 |
| 185 with open(write_full_results_to, 'w') as fp: |
| 186 json.dump(results, fp, indent=2) |
| 187 fp.write('\n') |
| 188 |
| 189 return results |
| 190 |
| 191 |
163 if __name__ == '__main__': | 192 if __name__ == '__main__': |
164 sys.exit(main()) | 193 sys.exit(main()) |
OLD | NEW |