Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: mojo/tools/test_runner.py

Issue 888043002: Use a python script to configure unit tests and app tests to run. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Follow review Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/tools/mopy/config.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 ast 9 import ast
10 import logging 10 import logging
(...skipping 23 matching lines...) Expand all
34 34
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 type=file) 37 type=file)
38 parser.add_argument("root_dir", help="The build directory.") 38 parser.add_argument("root_dir", help="The build directory.")
39 parser.add_argument("successes_cache_filename", 39 parser.add_argument("successes_cache_filename",
40 help="The file caching test results.", default=None, 40 help="The file caching test results.", default=None,
41 nargs='?') 41 nargs='?')
42 args = parser.parse_args() 42 args = parser.parse_args()
43 43
44 config = ConfigForGNArgs(ParseGNConfig(args.root_dir))
45
44 _logging.debug("Test list file: %s", args.gtest_list_file) 46 _logging.debug("Test list file: %s", args.gtest_list_file)
45 gtest_list = ast.literal_eval(args.gtest_list_file.read()) 47 execution_globals = {
48 "config": config,
49 }
50 exec args.gtest_list_file in execution_globals
51 gtest_list = execution_globals["tests"]
46 _logging.debug("Test list: %s" % gtest_list) 52 _logging.debug("Test list: %s" % gtest_list)
47 53
48 config = ConfigForGNArgs(ParseGNConfig(args.root_dir))
49
50 print "Running tests in directory: %s" % args.root_dir 54 print "Running tests in directory: %s" % args.root_dir
51 os.chdir(args.root_dir) 55 os.chdir(args.root_dir)
52 56
53 if args.successes_cache_filename: 57 if args.successes_cache_filename:
54 print "Successes cache file: %s" % args.successes_cache_filename 58 print "Successes cache file: %s" % args.successes_cache_filename
55 else: 59 else:
56 print "No successes cache file (will run all tests unconditionally)" 60 print "No successes cache file (will run all tests unconditionally)"
57 61
58 if args.successes_cache_filename: 62 if args.successes_cache_filename:
59 # This file simply contains a list of transitive hashes of tests that 63 # This file simply contains a list of transitive hashes of tests that
60 # succeeded. 64 # succeeded.
61 try: 65 try:
62 _logging.debug("Trying to read successes cache file: %s", 66 _logging.debug("Trying to read successes cache file: %s",
63 args.successes_cache_filename) 67 args.successes_cache_filename)
64 with open(args.successes_cache_filename, 'rb') as f: 68 with open(args.successes_cache_filename, 'rb') as f:
65 successes = set([x.strip() for x in f.readlines()]) 69 successes = set([x.strip() for x in f.readlines()])
66 _logging.debug("Successes: %s", successes) 70 _logging.debug("Successes: %s", successes)
67 except IOError: 71 except IOError:
68 # Just assume that it didn't exist, or whatever. 72 # Just assume that it didn't exist, or whatever.
69 print ("Failed to read successes cache file %s (will create)" % 73 print ("Failed to read successes cache file %s (will create)" %
70 args.successes_cache_filename) 74 args.successes_cache_filename)
71 successes = set() 75 successes = set()
72 76
73 mopy.gtest.set_color() 77 mopy.gtest.set_color()
74 78
75 # TODO(vtl): We may not close this file on failure. 79 # TODO(vtl): We may not close this file on failure.
76 successes_cache_file = open(args.successes_cache_filename, 'ab') \ 80 successes_cache_file = open(args.successes_cache_filename, 'ab') \
77 if args.successes_cache_filename else None 81 if args.successes_cache_filename else None
78 for gtest_dict in gtest_list: 82 for gtest_dict in gtest_list:
79 if gtest_dict.get("disabled"):
80 continue
81 if not config.match_target_os(gtest_dict.get("target_os", [])):
82 continue
83
84 gtest = gtest_dict["test"] 83 gtest = gtest_dict["test"]
85 cacheable = gtest_dict.get("cacheable", True) 84 cacheable = gtest_dict.get("cacheable", True)
86 if not cacheable: 85 if not cacheable:
87 _logging.debug("%s is marked as non-cacheable" % gtest) 86 _logging.debug("%s is marked as non-cacheable" % gtest)
88 87
89 gtest_file = gtest 88 gtest_file = gtest
90 if platform.system() == 'Windows': 89 if platform.system() == 'Windows':
91 gtest_file += ".exe" 90 gtest_file += ".exe"
92 if config.target_os == Config.OS_ANDROID: 91 if config.target_os == Config.OS_ANDROID:
93 gtest_file = gtest + "_apk/" + gtest + "-debug.apk" 92 gtest_file = gtest + "_apk/" + gtest + "-debug.apk"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 print " Failed to start test" 139 print " Failed to start test"
141 return 1 140 return 1
142 print "All tests succeeded" 141 print "All tests succeeded"
143 if successes_cache_file: 142 if successes_cache_file:
144 successes_cache_file.close() 143 successes_cache_file.close()
145 144
146 return 0 145 return 0
147 146
148 if __name__ == '__main__': 147 if __name__ == '__main__':
149 sys.exit(main()) 148 sys.exit(main())
OLDNEW
« no previous file with comments | « mojo/tools/mopy/config.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698