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
5 # found in the LICENSE file.
7 """Runs both the Python and Java tests."""
14 from pylib
import apk_info
15 from pylib
import buildbot_report
16 from pylib
import constants
17 from pylib
import ports
18 from pylib
import run_java_tests
19 from pylib
import run_python_tests
20 from pylib
import run_tests_helper
21 from pylib
import test_options_parser
22 from pylib
.test_result
import TestResults
25 def DispatchInstrumentationTests(options
):
26 """Dispatches the Java and Python instrumentation 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 start_date
= int(time
.time() * 1000)
46 java_results
= TestResults()
47 python_results
= TestResults()
49 if options
.run_java_tests
:
50 java_results
= run_java_tests
.DispatchJavaTests(
52 [apk_info
.ApkInfo(options
.test_apk_path
, options
.test_apk_jar_path
)])
53 if options
.run_python_tests
:
54 python_results
= run_python_tests
.DispatchPythonTests(options
)
56 all_results
= TestResults
.FromTestResults([java_results
, python_results
])
59 test_type
='Instrumentation',
60 test_package
=options
.test_apk
,
61 annotation
=options
.annotation
,
62 build_type
=options
.build_type
,
63 flakiness_server
=options
.flakiness_dashboard_server
)
65 return len(all_results
.GetAllBroken())
69 option_parser
= optparse
.OptionParser()
70 test_options_parser
.AddInstrumentationOptions(option_parser
)
71 options
, args
= option_parser
.parse_args(argv
)
72 test_options_parser
.ValidateInstrumentationOptions(option_parser
, options
,
75 run_tests_helper
.SetLogLevel(options
.verbose_count
)
76 buildbot_report
.PrintNamedStep(
77 'Instrumentation tests: %s - %s' % (', '.join(options
.annotation
),
81 ret
= DispatchInstrumentationTests(options
)
83 buildbot_report
.PrintStepResultIfNeeded(options
, ret
)
87 if __name__
== '__main__':
88 sys
.exit(main(sys
.argv
))