Bug 797671: Import Webrtc.org code from stable branch 3.12 (rev 2820) rs=jesup
[gecko.git] / media / webrtc / trunk / build / android / run_instrumentation_tests.py
blob493712385c3988f1929cb1386c42e5229583c449
1 #!/usr/bin/env python
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."""
9 import sys
10 import time
12 from pylib import apk_info
13 from pylib import test_options_parser
14 from pylib import run_java_tests
15 from pylib import run_python_tests
16 from pylib import run_tests_helper
17 from pylib.test_result import TestResults
20 def SummarizeResults(java_results, python_results, annotation, build_type):
21 """Summarize the results from the various test types.
23 Args:
24 java_results: a TestResults object with java test case results.
25 python_results: a TestResults object with python test case results.
26 annotation: the annotation used for these results.
27 build_type: 'Release' or 'Debug'.
29 Returns:
30 A tuple (all_results, summary_string, num_failing)
31 """
32 all_results = TestResults.FromTestResults([java_results, python_results])
33 summary_string = all_results.LogFull('Instrumentation', annotation,
34 build_type)
35 num_failing = (len(all_results.failed) + len(all_results.crashed) +
36 len(all_results.unknown))
37 return all_results, summary_string, num_failing
40 def DispatchInstrumentationTests(options):
41 """Dispatches the Java and Python instrumentation tests, sharding if possible.
43 Uses the logging module to print the combined final results and
44 summary of the Java and Python tests. If the java_only option is set, only
45 the Java tests run. If the python_only option is set, only the python tests
46 run. If neither are set, run both Java and Python tests.
48 Args:
49 options: command-line options for running the Java and Python tests.
51 Returns:
52 An integer representing the number of failing tests.
53 """
54 start_date = int(time.time() * 1000)
55 java_results = TestResults()
56 python_results = TestResults()
58 if options.run_java_tests:
59 java_results = run_java_tests.DispatchJavaTests(
60 options,
61 [apk_info.ApkInfo(options.test_apk_path, options.test_apk_jar_path)])
62 if options.run_python_tests:
63 python_results = run_python_tests.DispatchPythonTests(options)
65 all_results, summary_string, num_failing = SummarizeResults(
66 java_results, python_results, options.annotation, options.build_type)
67 return num_failing
70 def main(argv):
71 options = test_options_parser.ParseInstrumentationArgs(argv)
72 run_tests_helper.SetLogLevel(options.verbose_count)
73 return DispatchInstrumentationTests(options)
76 if __name__ == '__main__':
77 sys.exit(main(sys.argv))