michael@0: #!/usr/bin/env python michael@0: # michael@0: # Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: # Use of this source code is governed by a BSD-style license that can be michael@0: # found in the LICENSE file. michael@0: michael@0: """Runs both the Python and Java tests.""" michael@0: michael@0: import optparse michael@0: import sys michael@0: import time michael@0: michael@0: from pylib import apk_info michael@0: from pylib import buildbot_report michael@0: from pylib import ports michael@0: from pylib import run_java_tests michael@0: from pylib import run_python_tests michael@0: from pylib import run_tests_helper michael@0: from pylib import test_options_parser michael@0: from pylib.test_result import TestResults michael@0: michael@0: michael@0: def SummarizeResults(java_results, python_results, annotation, build_type): michael@0: """Summarize the results from the various test types. michael@0: michael@0: Args: michael@0: java_results: a TestResults object with java test case results. michael@0: python_results: a TestResults object with python test case results. michael@0: annotation: the annotation used for these results. michael@0: build_type: 'Release' or 'Debug'. michael@0: michael@0: Returns: michael@0: A tuple (all_results, summary_string, num_failing) michael@0: """ michael@0: all_results = TestResults.FromTestResults([java_results, python_results]) michael@0: summary_string = all_results.LogFull('Instrumentation', annotation, michael@0: build_type) michael@0: num_failing = (len(all_results.failed) + len(all_results.crashed) + michael@0: len(all_results.unknown)) michael@0: return all_results, summary_string, num_failing michael@0: michael@0: michael@0: def DispatchInstrumentationTests(options): michael@0: """Dispatches the Java and Python instrumentation tests, sharding if possible. michael@0: michael@0: Uses the logging module to print the combined final results and michael@0: summary of the Java and Python tests. If the java_only option is set, only michael@0: the Java tests run. If the python_only option is set, only the python tests michael@0: run. If neither are set, run both Java and Python tests. michael@0: michael@0: Args: michael@0: options: command-line options for running the Java and Python tests. michael@0: michael@0: Returns: michael@0: An integer representing the number of failing tests. michael@0: """ michael@0: # Reset the test port allocation. It's important to do it before starting michael@0: # to dispatch any tests. michael@0: if not ports.ResetTestServerPortAllocation(): michael@0: raise Exception('Failed to reset test server port.') michael@0: start_date = int(time.time() * 1000) michael@0: java_results = TestResults() michael@0: python_results = TestResults() michael@0: michael@0: if options.run_java_tests: michael@0: java_results = run_java_tests.DispatchJavaTests( michael@0: options, michael@0: [apk_info.ApkInfo(options.test_apk_path, options.test_apk_jar_path)]) michael@0: if options.run_python_tests: michael@0: python_results = run_python_tests.DispatchPythonTests(options) michael@0: michael@0: all_results, summary_string, num_failing = SummarizeResults( michael@0: java_results, python_results, options.annotation, options.build_type) michael@0: return num_failing michael@0: michael@0: michael@0: def main(argv): michael@0: option_parser = optparse.OptionParser() michael@0: test_options_parser.AddInstrumentationOptions(option_parser) michael@0: options, args = option_parser.parse_args(argv) michael@0: test_options_parser.ValidateInstrumentationOptions(option_parser, options, michael@0: args) michael@0: michael@0: run_tests_helper.SetLogLevel(options.verbose_count) michael@0: buildbot_report.PrintNamedStep( michael@0: 'Instrumentation tests: %s - %s' % (', '.join(options.annotation), michael@0: options.test_apk)) michael@0: return DispatchInstrumentationTests(options) michael@0: michael@0: michael@0: if __name__ == '__main__': michael@0: sys.exit(main(sys.argv))