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 "smart" test runner for gtest unit tests (that caches successes).""" | 6 """A "smart" test runner for gtest unit tests (that caches successes).""" |
7 | 7 |
8 import argparse | 8 import argparse |
9 import logging | 9 import logging |
10 import os | 10 import os |
(...skipping 24 matching lines...) Expand all Loading... |
35 parser.add_argument("gtest_list_file", | 35 parser.add_argument("gtest_list_file", |
36 help="The file containing the tests to run.") | 36 help="The file containing the tests to run.") |
37 parser.add_argument("root_dir", help="The build directory.") | 37 parser.add_argument("root_dir", help="The build directory.") |
38 parser.add_argument("successes_cache_filename", | 38 parser.add_argument("successes_cache_filename", |
39 help="The file caching test results.", default=None, | 39 help="The file caching test results.", default=None, |
40 nargs='?') | 40 nargs='?') |
41 args = parser.parse_args() | 41 args = parser.parse_args() |
42 | 42 |
43 _logging.debug("Test list file: %s", args.gtest_list_file) | 43 _logging.debug("Test list file: %s", args.gtest_list_file) |
44 with open(args.gtest_list_file, 'rb') as f: | 44 with open(args.gtest_list_file, 'rb') as f: |
45 gtest_list = [y for y in [x.strip() for x in f.readlines()] \ | 45 gtest_list = eval(f.read()) |
46 if y and y[0] != '#'] | |
47 _logging.debug("Test list: %s" % gtest_list) | 46 _logging.debug("Test list: %s" % gtest_list) |
48 | 47 |
49 print "Running tests in directory: %s" % args.root_dir | 48 print "Running tests in directory: %s" % args.root_dir |
50 os.chdir(args.root_dir) | 49 os.chdir(args.root_dir) |
51 | 50 |
52 if args.successes_cache_filename: | 51 if args.successes_cache_filename: |
53 print "Successes cache file: %s" % args.successes_cache_filename | 52 print "Successes cache file: %s" % args.successes_cache_filename |
54 else: | 53 else: |
55 print "No successes cache file (will run all tests unconditionally)" | 54 print "No successes cache file (will run all tests unconditionally)" |
56 | 55 |
(...skipping 14 matching lines...) Expand all Loading... |
71 | 70 |
72 # Run gtests with color if we're on a TTY (and we're not being told explicitly | 71 # Run gtests with color if we're on a TTY (and we're not being told explicitly |
73 # what to do). | 72 # what to do). |
74 if sys.stdout.isatty() and 'GTEST_COLOR' not in os.environ: | 73 if sys.stdout.isatty() and 'GTEST_COLOR' not in os.environ: |
75 _logging.debug("Setting GTEST_COLOR=yes") | 74 _logging.debug("Setting GTEST_COLOR=yes") |
76 os.environ['GTEST_COLOR'] = 'yes' | 75 os.environ['GTEST_COLOR'] = 'yes' |
77 | 76 |
78 # TODO(vtl): We may not close this file on failure. | 77 # TODO(vtl): We may not close this file on failure. |
79 successes_cache_file = open(args.successes_cache_filename, 'ab') \ | 78 successes_cache_file = open(args.successes_cache_filename, 'ab') \ |
80 if args.successes_cache_filename else None | 79 if args.successes_cache_filename else None |
81 for gtest in gtest_list: | 80 for gtest_dict in gtest_list: |
82 if gtest[0] == '*': | 81 if gtest_dict.get("disabled"): |
83 gtest = gtest[1:] | 82 continue |
| 83 if args.android and not gtest_dict.get("run_on_android"): |
| 84 continue |
| 85 |
| 86 gtest = gtest_dict["test"] |
| 87 cacheable = gtest_dict.get("cacheable", True) |
| 88 if not cacheable: |
84 _logging.debug("%s is marked as non-cacheable" % gtest) | 89 _logging.debug("%s is marked as non-cacheable" % gtest) |
85 cacheable = False | |
86 else: | |
87 cacheable = True | |
88 | 90 |
89 gtest_file = gtest | 91 gtest_file = gtest |
90 if platform.system() == 'Windows': | 92 if platform.system() == 'Windows': |
91 gtest_file += ".exe" | 93 gtest_file += ".exe" |
92 if args.android: | 94 if args.android: |
93 gtest_file = gtest + "_apk/" + gtest + "-debug.apk" | 95 gtest_file = gtest + "_apk/" + gtest + "-debug.apk" |
94 | 96 |
95 if successes_cache_file and cacheable: | 97 if successes_cache_file and cacheable: |
96 _logging.debug("Getting transitive hash for %s ... " % gtest) | 98 _logging.debug("Getting transitive hash for %s ... " % gtest) |
97 try: | 99 try: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 print " Failed to start test" | 142 print " Failed to start test" |
141 return 1 | 143 return 1 |
142 print "All tests succeeded" | 144 print "All tests succeeded" |
143 if successes_cache_file: | 145 if successes_cache_file: |
144 successes_cache_file.close() | 146 successes_cache_file.close() |
145 | 147 |
146 return 0 | 148 return 0 |
147 | 149 |
148 if __name__ == '__main__': | 150 if __name__ == '__main__': |
149 sys.exit(main()) | 151 sys.exit(main()) |
OLD | NEW |