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