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