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 |
11 import os | 11 import os |
12 import sys | 12 import sys |
13 import time | 13 import time |
14 | 14 |
15 from mopy import gtest | 15 from mopy import gtest |
16 from mopy.config import Config | 16 from mopy.config import Config |
17 | 17 |
18 | 18 |
19 def main(): | 19 def main(): |
20 parser = argparse.ArgumentParser(description="An application test runner.") | 20 parser = argparse.ArgumentParser(description="An application test runner.") |
21 parser.add_argument("test_list_file", type=file, | 21 parser.add_argument("test_list_file", type=file, |
22 help="a file listing apptests to run") | 22 help="a file listing apptests to run") |
23 parser.add_argument("build_dir", type=str, help="the build output directory") | 23 parser.add_argument("build_dir", type=str, help="the build output directory") |
24 parser.add_argument("--verbose", default=False, action='store_true') | 24 parser.add_argument("--verbose", default=False, action='store_true') |
| 25 parser.add_argument('--repeat_count', default=1, metavar='INT', |
| 26 action='store', type=int) |
25 parser.add_argument('--write-full-results-to', metavar='FILENAME', | 27 parser.add_argument('--write-full-results-to', metavar='FILENAME', |
26 help='Path to write the JSON list of full results.') | 28 help='Path to write the JSON list of full results.') |
27 args = parser.parse_args() | 29 args = parser.parse_args() |
28 | 30 |
29 gtest.set_color() | 31 gtest.set_color() |
30 logger = logging.getLogger() | 32 logger = logging.getLogger() |
31 logging.basicConfig(stream=sys.stdout, format="%(levelname)s:%(message)s") | 33 logging.basicConfig(stream=sys.stdout, format="%(levelname)s:%(message)s") |
32 logger.setLevel(logging.DEBUG if args.verbose else logging.WARNING) | 34 logger.setLevel(logging.DEBUG if args.verbose else logging.WARNING) |
33 logger.debug("Initialized logging: level=%s" % logger.level) | 35 logger.debug("Initialized logging: level=%s" % logger.level) |
34 | 36 |
35 logger.debug("Test list file: %s", args.test_list_file) | 37 logger.debug("Test list file: %s", args.test_list_file) |
36 config = Config(args.build_dir) | 38 config = Config(args.build_dir) |
37 execution_globals = {"config": config} | 39 execution_globals = {"config": config} |
38 exec args.test_list_file in execution_globals | 40 exec args.test_list_file in execution_globals |
39 test_list = execution_globals["tests"] | 41 test_list = execution_globals["tests"] |
40 logger.debug("Test list: %s" % test_list) | 42 logger.debug("Test list: %s" % test_list) |
41 | 43 |
42 shell = None | 44 shell = None |
43 if config.target_os == Config.OS_ANDROID: | 45 if config.target_os == Config.OS_ANDROID: |
44 from mopy.android import AndroidShell | 46 from mopy.android import AndroidShell |
45 shell = AndroidShell(config) | 47 shell = AndroidShell(config) |
46 result = shell.InitShell() | 48 result = shell.InitShell() |
47 if result != 0: | 49 if result != 0: |
48 return result | 50 return result |
49 | 51 |
50 tests = [] | 52 tests = [] |
51 passed = [] | 53 passed = [] |
52 failed = [] | 54 failed = [] |
53 for test_dict in test_list: | 55 for _ in range(args.repeat_count): |
54 test = test_dict["test"] | 56 for test_dict in test_list: |
55 test_name = test_dict.get("name", test) | 57 test = test_dict["test"] |
56 test_type = test_dict.get("type", "gtest") | 58 test_name = test_dict.get("name", test) |
57 test_args = test_dict.get("args", []) | 59 test_type = test_dict.get("type", "gtest") |
| 60 test_args = test_dict.get("args", []) |
58 | 61 |
59 print "Running %s...%s" % (test_name, ("\n" if args.verbose else "")), | 62 print "Running %s...%s" % (test_name, ("\n" if args.verbose else "")), |
60 sys.stdout.flush() | 63 sys.stdout.flush() |
61 | 64 |
62 tests.append(test_name) | 65 tests.append(test_name) |
63 assert test_type in ("gtest", "gtest_isolated") | 66 assert test_type in ("gtest", "gtest_isolated") |
64 isolate = test_type == "gtest_isolated" | 67 isolate = test_type == "gtest_isolated" |
65 result = gtest.run_apptest(config, shell, test_args, test, isolate) | 68 result = gtest.run_apptest(config, shell, test_args, test, isolate) |
66 passed.extend([test_name] if result else []) | 69 passed.extend([test_name] if result else []) |
67 failed.extend([] if result else [test_name]) | 70 failed.extend([] if result else [test_name]) |
68 print "[ PASSED ]" if result else "[ FAILED ]", | 71 print "[ PASSED ]" if result else "[ FAILED ]", |
69 print test_name if args.verbose or not result else "" | 72 print test_name if args.verbose or not result else "" |
| 73 |
| 74 if failed: |
| 75 break; |
70 | 76 |
71 print "[ PASSED ] %d apptests" % len(passed), | 77 print "[ PASSED ] %d apptests" % len(passed), |
72 print ": %s" % ", ".join(passed) if passed else "" | 78 print ": %s" % ", ".join(passed) if passed else "" |
73 print "[ FAILED ] %d apptests" % len(failed), | 79 print "[ FAILED ] %d apptests" % len(failed), |
74 print ": %s" % ", ".join(failed) if failed else "" | 80 print ": %s" % ", ".join(failed) if failed else "" |
75 | 81 |
76 if args.write_full_results_to: | 82 if args.write_full_results_to: |
77 _WriteJSONResults(tests, failed, args.write_full_results_to) | 83 _WriteJSONResults(tests, failed, args.write_full_results_to) |
78 | 84 |
79 return 1 if failed else 0 | 85 return 1 if failed else 0 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 trie[path] = value | 124 trie[path] = value |
119 return | 125 return |
120 directory, rest = path.split('.', 1) | 126 directory, rest = path.split('.', 1) |
121 if directory not in trie: | 127 if directory not in trie: |
122 trie[directory] = {} | 128 trie[directory] = {} |
123 _AddPathToTrie(trie[directory], rest, value) | 129 _AddPathToTrie(trie[directory], rest, value) |
124 | 130 |
125 | 131 |
126 if __name__ == '__main__': | 132 if __name__ == '__main__': |
127 sys.exit(main()) | 133 sys.exit(main()) |
OLD | NEW |