OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Runs all the native unit tests. | 6 """Runs all the native unit tests. |
7 | 7 |
8 1. Copy over test binary to /data/local on device. | 8 1. Copy over test binary to /data/local on device. |
9 2. Resources: chrome/unit_tests requires resources (chrome.pak and en-US.pak) | 9 2. Resources: chrome/unit_tests requires resources (chrome.pak and en-US.pak) |
10 to be deployed to the device (in /data/local/tmp). | 10 to be deployed to the device (in /data/local/tmp). |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 import emulator | 63 import emulator |
64 import run_tests_helper | 64 import run_tests_helper |
65 from single_test_runner import SingleTestRunner | 65 from single_test_runner import SingleTestRunner |
66 from test_package_executable import TestPackageExecutable | 66 from test_package_executable import TestPackageExecutable |
67 from test_result import BaseTestResult, TestResults | 67 from test_result import BaseTestResult, TestResults |
68 | 68 |
69 _TEST_SUITES = ['base_unittests', 'sql_unittests', 'ipc_tests', 'net_unittests', | 69 _TEST_SUITES = ['base_unittests', 'sql_unittests', 'ipc_tests', 'net_unittests', |
70 'sync_unit_tests', 'content_unittests'] | 70 'sync_unit_tests', 'content_unittests'] |
71 | 71 |
72 | 72 |
73 def FullyQualifiedTestSuites(): | 73 def FullyQualifiedTestSuites(apk): |
74 """Return a fully qualified list that represents all known suites.""" | 74 """Return a fully qualified list that represents all known suites. |
75 | |
76 Args: | |
77 apk: if True, use the apk-based test runner""" | |
75 # If not specified, assume the test suites are in out/Release | 78 # If not specified, assume the test suites are in out/Release |
76 test_suite_dir = os.path.abspath(os.path.join(run_tests_helper.CHROME_DIR, | 79 test_suite_dir = os.path.abspath(os.path.join(run_tests_helper.CHROME_DIR, |
77 'out', 'Release')) | 80 'out', 'Release')) |
78 return [os.path.join(test_suite_dir, t) for t in _TEST_SUITES] | 81 if not apk: |
bulach
2012/04/12 15:51:42
nit: maybe invert and "if apk:" would be, erm, les
John Grabowski
2012/04/13 01:11:37
Done.
| |
82 suites = [os.path.join(test_suite_dir, t) for t in _TEST_SUITES] | |
83 else: | |
84 # out/Release/$SUITE_apk/ChromeNativeTests-debug.apk | |
85 suites = [os.path.join(test_suite_dir, | |
86 t + '_apk', | |
87 'ChromeNativeTests-debug.apk') | |
88 for t in _TEST_SUITES] | |
89 return suites | |
79 | 90 |
80 | 91 |
81 class TimeProfile(object): | 92 class TimeProfile(object): |
82 """Class for simple profiling of action, with logging of cost.""" | 93 """Class for simple profiling of action, with logging of cost.""" |
83 | 94 |
84 def __init__(self, description): | 95 def __init__(self, description): |
85 self._description = description | 96 self._description = description |
86 self.Start() | 97 self.Start() |
87 | 98 |
88 def Start(self): | 99 def Start(self): |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 try: | 148 try: |
138 os.kill(self._pid, signal.SIGKILL) | 149 os.kill(self._pid, signal.SIGKILL) |
139 except: | 150 except: |
140 pass | 151 pass |
141 del os.environ['DISPLAY'] | 152 del os.environ['DISPLAY'] |
142 self._pid = 0 | 153 self._pid = 0 |
143 | 154 |
144 | 155 |
145 def RunTests(device, test_suite, gtest_filter, test_arguments, rebaseline, | 156 def RunTests(device, test_suite, gtest_filter, test_arguments, rebaseline, |
146 timeout, performance_test, cleanup_test_files, tool, | 157 timeout, performance_test, cleanup_test_files, tool, |
147 log_dump_name, annotate=False): | 158 log_dump_name, apk, annotate=False): |
148 """Runs the tests. | 159 """Runs the tests. |
149 | 160 |
150 Args: | 161 Args: |
151 device: Device to run the tests. | 162 device: Device to run the tests. |
152 test_suite: A specific test suite to run, empty to run all. | 163 test_suite: A specific test suite to run, empty to run all. |
153 gtest_filter: A gtest_filter flag. | 164 gtest_filter: A gtest_filter flag. |
154 test_arguments: Additional arguments to pass to the test binary. | 165 test_arguments: Additional arguments to pass to the test binary. |
155 rebaseline: Whether or not to run tests in isolation and update the filter. | 166 rebaseline: Whether or not to run tests in isolation and update the filter. |
156 timeout: Timeout for each test. | 167 timeout: Timeout for each test. |
157 performance_test: Whether or not performance test(s). | 168 performance_test: Whether or not performance test(s). |
158 cleanup_test_files: Whether or not to cleanup test files on device. | 169 cleanup_test_files: Whether or not to cleanup test files on device. |
159 tool: Name of the Valgrind tool. | 170 tool: Name of the Valgrind tool. |
160 log_dump_name: Name of log dump file. | 171 log_dump_name: Name of log dump file. |
172 apk: boolean to state if we are using the apk based test runner | |
161 annotate: should we print buildbot-style annotations? | 173 annotate: should we print buildbot-style annotations? |
162 | 174 |
163 Returns: | 175 Returns: |
164 A TestResults object. | 176 A TestResults object. |
165 """ | 177 """ |
166 results = [] | 178 results = [] |
167 | 179 |
168 if test_suite: | 180 if test_suite: |
169 global _TEST_SUITES | 181 global _TEST_SUITES |
170 if not os.path.exists(test_suite): | 182 if (not os.path.exists(test_suite) and |
183 not os.path.splitext(test_suite)[1] == '.apk'): | |
171 logging.critical('Unrecognized test suite %s, supported: %s' % | 184 logging.critical('Unrecognized test suite %s, supported: %s' % |
172 (test_suite, _TEST_SUITES)) | 185 (test_suite, _TEST_SUITES)) |
173 if test_suite in _TEST_SUITES: | 186 if test_suite in _TEST_SUITES: |
174 logging.critical('(Remember to include the path: out/Release/%s)', | 187 logging.critical('(Remember to include the path: out/Release/%s)', |
175 test_suite) | 188 test_suite) |
176 return TestResults.FromOkAndFailed([], [BaseTestResult(test_suite, '')]) | 189 return TestResults.FromOkAndFailed([], [BaseTestResult(test_suite, '')]) |
177 fully_qualified_test_suites = [test_suite] | 190 fully_qualified_test_suites = [test_suite] |
178 else: | 191 else: |
179 fully_qualified_test_suites = FullyQualifiedTestSuites() | 192 fully_qualified_test_suites = FullyQualifiedTestSuites(apk) |
180 debug_info_list = [] | 193 debug_info_list = [] |
181 print 'Known suites: ' + str(_TEST_SUITES) | 194 print 'Known suites: ' + str(_TEST_SUITES) |
182 print 'Running these: ' + str(fully_qualified_test_suites) | 195 print 'Running these: ' + str(fully_qualified_test_suites) |
183 for t in fully_qualified_test_suites: | 196 for t in fully_qualified_test_suites: |
184 if annotate: | 197 if annotate: |
185 print '@@@BUILD_STEP Test suite %s@@@' % os.path.basename(t) | 198 print '@@@BUILD_STEP Test suite %s@@@' % os.path.basename(t) |
186 test = SingleTestRunner(device, t, gtest_filter, test_arguments, | 199 test = SingleTestRunner(device, t, gtest_filter, test_arguments, |
187 timeout, rebaseline, performance_test, | 200 timeout, rebaseline, performance_test, |
188 cleanup_test_files, tool, 0, not not log_dump_name) | 201 cleanup_test_files, tool, 0, not not log_dump_name) |
189 test.Run() | 202 test.Run() |
190 | 203 |
191 results += [test.test_results] | 204 results += [test.test_results] |
192 # Collect debug info. | 205 # Collect debug info. |
193 debug_info_list += [test.dump_debug_info] | 206 debug_info_list += [test.dump_debug_info] |
194 if rebaseline: | 207 if rebaseline: |
195 test.UpdateFilter(test.test_results.failed) | 208 test.UpdateFilter(test.test_results.failed) |
196 elif test.test_results.failed: | 209 elif test.test_results.failed: |
197 test.test_results.LogFull() | 210 test.test_results.LogFull() |
198 # Zip all debug info outputs into a file named by log_dump_name. | 211 # Zip all debug info outputs into a file named by log_dump_name. |
199 debug_info.GTestDebugInfo.ZipAndCleanResults( | 212 debug_info.GTestDebugInfo.ZipAndCleanResults( |
200 os.path.join(run_tests_helper.CHROME_DIR, 'out', 'Release', | 213 os.path.join(run_tests_helper.CHROME_DIR, 'out', 'Release', |
201 'debug_info_dumps'), | 214 'debug_info_dumps'), |
202 log_dump_name, [d for d in debug_info_list if d]) | 215 log_dump_name, [d for d in debug_info_list if d]) |
203 | 216 |
204 if annotate: | 217 if annotate: |
205 if test.test_results.timed_out: | 218 if test.test_results.timed_out: |
206 print '@@@STEP_WARNINGS@@@' | 219 print '@@@STEP_WARNINGS@@@' |
207 elif test.test_results.failed: | 220 elif test.test_results.failed: |
208 print '@@@STEP_FAILURE@@@' | 221 print '@@@STEP_FAILURE@@@' |
222 elif test.test_results.overall_fail: | |
223 print '@@@STEP_FAILURE@@@' | |
209 else: | 224 else: |
210 print 'Step success!' # No annotation needed | 225 print 'Step success!' # No annotation needed |
211 | 226 |
212 return TestResults.FromTestResults(results) | 227 return TestResults.FromTestResults(results) |
213 | 228 |
214 | 229 |
215 class TestSharder(BaseTestSharder): | 230 class TestSharder(BaseTestSharder): |
216 """Responsible for sharding the tests on the connected devices.""" | 231 """Responsible for sharding the tests on the connected devices.""" |
217 | 232 |
218 def __init__(self, attached_devices, test_suite, gtest_filter, | 233 def __init__(self, attached_devices, test_suite, gtest_filter, |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 options.performance_test, | 324 options.performance_test, |
310 options.cleanup_test_files, options.tool) | 325 options.cleanup_test_files, options.tool) |
311 test_results = sharder.RunShardedTests() | 326 test_results = sharder.RunShardedTests() |
312 else: | 327 else: |
313 test_results = RunTests(attached_devices[0], options.test_suite, | 328 test_results = RunTests(attached_devices[0], options.test_suite, |
314 options.gtest_filter, options.test_arguments, | 329 options.gtest_filter, options.test_arguments, |
315 options.rebaseline, options.timeout, | 330 options.rebaseline, options.timeout, |
316 options.performance_test, | 331 options.performance_test, |
317 options.cleanup_test_files, options.tool, | 332 options.cleanup_test_files, options.tool, |
318 options.log_dump, | 333 options.log_dump, |
334 options.apk, | |
319 annotate=options.annotate) | 335 annotate=options.annotate) |
320 | 336 |
321 for buildbot_emulator in buildbot_emulators: | 337 for buildbot_emulator in buildbot_emulators: |
322 buildbot_emulator.Shutdown() | 338 buildbot_emulator.Shutdown() |
323 | 339 |
324 # Another chance if we timed out? At this point It is safe(r) to | 340 # Another chance if we timed out? At this point It is safe(r) to |
325 # run fast and loose since we just uploaded all the test data and | 341 # run fast and loose since we just uploaded all the test data and |
326 # binary. | 342 # binary. |
327 if test_results.timed_out and options.repeat: | 343 if test_results.timed_out and options.repeat: |
328 logging.critical('Timed out; repeating in fast_and_loose mode.') | 344 logging.critical('Timed out; repeating in fast_and_loose mode.') |
(...skipping 20 matching lines...) Expand all Loading... | |
349 ListTestSuites() | 365 ListTestSuites() |
350 return 0 | 366 return 0 |
351 | 367 |
352 if options.use_xvfb: | 368 if options.use_xvfb: |
353 xvfb = Xvfb() | 369 xvfb = Xvfb() |
354 xvfb.Start() | 370 xvfb.Start() |
355 | 371 |
356 if options.test_suite: | 372 if options.test_suite: |
357 all_test_suites = [options.test_suite] | 373 all_test_suites = [options.test_suite] |
358 else: | 374 else: |
359 all_test_suites = FullyQualifiedTestSuites() | 375 all_test_suites = FullyQualifiedTestSuites(options.apk) |
360 failures = 0 | 376 failures = 0 |
361 for suite in all_test_suites: | 377 for suite in all_test_suites: |
362 options.test_suite = suite | 378 options.test_suite = suite |
363 failures += _RunATestSuite(options) | 379 failures += _RunATestSuite(options) |
364 | 380 |
365 if options.use_xvfb: | 381 if options.use_xvfb: |
366 xvfb.Stop() | 382 xvfb.Stop() |
367 return failures | 383 return failures |
368 | 384 |
369 | 385 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 'tests that hang to add to the disabled list, ' | 427 'tests that hang to add to the disabled list, ' |
412 'there is no need to redeploy the test binary ' | 428 'there is no need to redeploy the test binary ' |
413 'or data to the device again. ' | 429 'or data to the device again. ' |
414 'Don\'t use on bots by default!') | 430 'Don\'t use on bots by default!') |
415 option_parser.add_option('--repeat', dest='repeat', type='int', | 431 option_parser.add_option('--repeat', dest='repeat', type='int', |
416 default=2, | 432 default=2, |
417 help='Repeat count on test timeout') | 433 help='Repeat count on test timeout') |
418 option_parser.add_option('--annotate', default=True, | 434 option_parser.add_option('--annotate', default=True, |
419 help='Print buildbot-style annotate messages ' | 435 help='Print buildbot-style annotate messages ' |
420 'for each test suite. Default=True') | 436 'for each test suite. Default=True') |
437 option_parser.add_option('--apk', default=False, | |
438 help='Use the apk test runner ' | |
439 '(off by default for now)') | |
421 options, args = option_parser.parse_args(argv) | 440 options, args = option_parser.parse_args(argv) |
422 if len(args) > 1: | 441 if len(args) > 1: |
423 print 'Unknown argument:', args[1:] | 442 print 'Unknown argument:', args[1:] |
424 option_parser.print_usage() | 443 option_parser.print_usage() |
425 sys.exit(1) | 444 sys.exit(1) |
426 run_tests_helper.SetLogLevel(options.verbose_count) | 445 run_tests_helper.SetLogLevel(options.verbose_count) |
427 return Dispatch(options) | 446 return Dispatch(options) |
428 | 447 |
429 | 448 |
430 if __name__ == '__main__': | 449 if __name__ == '__main__': |
431 sys.exit(main(sys.argv)) | 450 sys.exit(main(sys.argv)) |
OLD | NEW |