OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Runs both the Python and Java instrumentation tests.""" | 7 """Runs both the Python and Java instrumentation tests.""" |
8 | 8 |
9 import logging | 9 import optparse |
10 import os | 10 import os |
11 import sys | 11 import sys |
12 | 12 |
13 from pylib import cmd_helper | 13 from pylib import buildbot_report |
| 14 from pylib import ports |
| 15 from pylib.base import base_test_result |
| 16 from pylib.host_driven import run_python_tests |
| 17 from pylib.instrumentation import dispatch |
| 18 from pylib.utils import report_results |
| 19 from pylib.utils import run_tests_helper |
| 20 from pylib.utils import test_options_parser |
| 21 |
| 22 |
| 23 def DispatchInstrumentationTests(options): |
| 24 """Dispatches the Java and Python instrumentation tests, sharding if possible. |
| 25 |
| 26 Uses the logging module to print the combined final results and |
| 27 summary of the Java and Python tests. If the java_only option is set, only |
| 28 the Java tests run. If the python_only option is set, only the python tests |
| 29 run. If neither are set, run both Java and Python tests. |
| 30 |
| 31 Args: |
| 32 options: command-line options for running the Java and Python tests. |
| 33 |
| 34 Returns: |
| 35 An integer representing the number of broken tests. |
| 36 """ |
| 37 if not options.keep_test_server_ports: |
| 38 # Reset the test port allocation. It's important to do it before starting |
| 39 # to dispatch any tests. |
| 40 if not ports.ResetTestServerPortAllocation(): |
| 41 raise Exception('Failed to reset test server port.') |
| 42 |
| 43 all_results = base_test_result.TestRunResults() |
| 44 |
| 45 if options.run_java_tests: |
| 46 all_results.AddTestRunResults(dispatch.Dispatch(options)) |
| 47 if options.run_python_tests: |
| 48 all_results.AddTestRunResults(run_python_tests.DispatchPythonTests(options)) |
| 49 |
| 50 report_results.LogFull( |
| 51 results=all_results, |
| 52 test_type='Instrumentation', |
| 53 test_package=os.path.basename(options.test_apk), |
| 54 annotation=options.annotations, |
| 55 build_type=options.build_type, |
| 56 flakiness_server=options.flakiness_dashboard_server) |
| 57 |
| 58 return len(all_results.GetNotPass()) |
| 59 |
| 60 |
| 61 def main(argv): |
| 62 option_parser = optparse.OptionParser() |
| 63 test_options_parser.AddInstrumentationOptions(option_parser) |
| 64 options, args = option_parser.parse_args(argv) |
| 65 test_options_parser.ValidateInstrumentationOptions(option_parser, options, |
| 66 args) |
| 67 |
| 68 run_tests_helper.SetLogLevel(options.verbose_count) |
| 69 ret = 1 |
| 70 try: |
| 71 ret = DispatchInstrumentationTests(options) |
| 72 finally: |
| 73 buildbot_report.PrintStepResultIfNeeded(options, ret) |
| 74 return ret |
14 | 75 |
15 | 76 |
16 if __name__ == '__main__': | 77 if __name__ == '__main__': |
17 args = ['python', | 78 sys.exit(main(sys.argv)) |
18 os.path.join(os.path.dirname(__file__), 'test_runner.py'), | |
19 'instrumentation'] + sys.argv[1:] | |
20 logging.warning('*' * 80) | |
21 logging.warning('This script is deprecated and will be removed soon.') | |
22 logging.warning('Use the following instead: %s', ' '.join(args)) | |
23 logging.warning('*' * 80) | |
24 sys.exit(cmd_helper.RunCmd(args)) | |
OLD | NEW |