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