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
5 # found in the LICENSE file.
7 """Runs both the Python and Java UIAutomator tests."""
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
.instrumentation
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
25 def DispatchUIAutomatorTests(options
):
26 """Dispatches the UIAutomator tests, sharding if possible.
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.
34 options: command-line options for running the Java and Python tests.
37 An integer representing the number of broken tests.
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.')
45 all_results
= base_test_result
.TestRunResults()
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
))
52 report_results
.LogFull(
54 test_type
='UIAutomator',
55 test_package
=os
.path
.basename(options
.test_jar
),
56 annotation
=options
.annotation
,
57 build_type
=options
.build_type
,
58 flakiness_server
=options
.flakiness_dashboard_server
)
60 return len(all_results
.GetNotPass())
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
)
69 run_tests_helper
.SetLogLevel(options
.verbose_count
)
72 ret
= DispatchUIAutomatorTests(options
)
74 buildbot_report
.PrintStepResultIfNeeded(options
, ret
)
78 if __name__
== '__main__':
79 sys
.exit(main(sys
.argv
))