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 json | |
9 import logging | 10 import logging |
10 import os | 11 import os |
11 import platform | 12 import platform |
12 import subprocess | 13 import subprocess |
13 import sys | 14 import sys |
14 | 15 |
15 _logging = logging.getLogger() | 16 _logging = logging.getLogger() |
16 | 17 |
17 from mopy.paths import Paths | 18 from mopy.paths import Paths |
18 from mopy.transitive_hash import file_hash, transitive_hash | 19 from mopy.transitive_hash import file_hash, transitive_hash |
(...skipping 16 matching lines...) Expand all Loading... | |
35 parser.add_argument("gtest_list_file", | 36 parser.add_argument("gtest_list_file", |
36 help="The file containing the tests to run.") | 37 help="The file containing the tests to run.") |
37 parser.add_argument("root_dir", help="The build directory.") | 38 parser.add_argument("root_dir", help="The build directory.") |
38 parser.add_argument("successes_cache_filename", | 39 parser.add_argument("successes_cache_filename", |
39 help="The file caching test results.", default=None, | 40 help="The file caching test results.", default=None, |
40 nargs='?') | 41 nargs='?') |
41 args = parser.parse_args() | 42 args = parser.parse_args() |
42 | 43 |
43 _logging.debug("Test list file: %s", args.gtest_list_file) | 44 _logging.debug("Test list file: %s", args.gtest_list_file) |
44 with open(args.gtest_list_file, 'rb') as f: | 45 with open(args.gtest_list_file, 'rb') as f: |
45 gtest_list = [y for y in [x.strip() for x in f.readlines()] \ | 46 stripped_file = ''.join( |
46 if y and y[0] != '#'] | 47 [l for l in f.readlines() if not l.lstrip().startswith('#')]) |
viettrungluu
2014/12/03 16:15:37
I see.
Rather than doing something weird, why don
qsr
2014/12/03 16:38:32
Done.
| |
48 gtest_list = json.loads(stripped_file) | |
47 _logging.debug("Test list: %s" % gtest_list) | 49 _logging.debug("Test list: %s" % gtest_list) |
48 | 50 |
49 print "Running tests in directory: %s" % args.root_dir | 51 print "Running tests in directory: %s" % args.root_dir |
50 os.chdir(args.root_dir) | 52 os.chdir(args.root_dir) |
51 | 53 |
52 if args.successes_cache_filename: | 54 if args.successes_cache_filename: |
53 print "Successes cache file: %s" % args.successes_cache_filename | 55 print "Successes cache file: %s" % args.successes_cache_filename |
54 else: | 56 else: |
55 print "No successes cache file (will run all tests unconditionally)" | 57 print "No successes cache file (will run all tests unconditionally)" |
56 | 58 |
(...skipping 14 matching lines...) Expand all Loading... | |
71 | 73 |
72 # Run gtests with color if we're on a TTY (and we're not being told explicitly | 74 # Run gtests with color if we're on a TTY (and we're not being told explicitly |
73 # what to do). | 75 # what to do). |
74 if sys.stdout.isatty() and 'GTEST_COLOR' not in os.environ: | 76 if sys.stdout.isatty() and 'GTEST_COLOR' not in os.environ: |
75 _logging.debug("Setting GTEST_COLOR=yes") | 77 _logging.debug("Setting GTEST_COLOR=yes") |
76 os.environ['GTEST_COLOR'] = 'yes' | 78 os.environ['GTEST_COLOR'] = 'yes' |
77 | 79 |
78 # TODO(vtl): We may not close this file on failure. | 80 # TODO(vtl): We may not close this file on failure. |
79 successes_cache_file = open(args.successes_cache_filename, 'ab') \ | 81 successes_cache_file = open(args.successes_cache_filename, 'ab') \ |
80 if args.successes_cache_filename else None | 82 if args.successes_cache_filename else None |
81 for gtest in gtest_list: | 83 for gtest_dict in gtest_list: |
82 if gtest[0] == '*': | 84 if gtest_dict.get("disabled"): |
83 gtest = gtest[1:] | 85 continue |
86 if args.android and not gtest_dict.get("run_on_android"): | |
viettrungluu
2014/12/03 16:15:37
Having arbitrary/hacky entries like run_on_android
| |
87 continue | |
88 | |
89 gtest = gtest_dict["test"] | |
90 cacheable = gtest_dict.get("cacheable", True) | |
91 if not cacheable: | |
84 _logging.debug("%s is marked as non-cacheable" % gtest) | 92 _logging.debug("%s is marked as non-cacheable" % gtest) |
85 cacheable = False | |
86 else: | |
87 cacheable = True | |
88 | 93 |
89 gtest_file = gtest | 94 gtest_file = gtest |
90 if platform.system() == 'Windows': | 95 if platform.system() == 'Windows': |
91 gtest_file += ".exe" | 96 gtest_file += ".exe" |
92 if args.android: | 97 if args.android: |
93 gtest_file = gtest + "_apk/" + gtest + "-debug.apk" | 98 gtest_file = gtest + "_apk/" + gtest + "-debug.apk" |
94 | 99 |
95 if successes_cache_file and cacheable: | 100 if successes_cache_file and cacheable: |
96 _logging.debug("Getting transitive hash for %s ... " % gtest) | 101 _logging.debug("Getting transitive hash for %s ... " % gtest) |
97 try: | 102 try: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 print " Failed to start test" | 145 print " Failed to start test" |
141 return 1 | 146 return 1 |
142 print "All tests succeeded" | 147 print "All tests succeeded" |
143 if successes_cache_file: | 148 if successes_cache_file: |
144 successes_cache_file.close() | 149 successes_cache_file.close() |
145 | 150 |
146 return 0 | 151 return 0 |
147 | 152 |
148 if __name__ == '__main__': | 153 if __name__ == '__main__': |
149 sys.exit(main()) | 154 sys.exit(main()) |
OLD | NEW |