media/webrtc/trunk/build/android/run_instrumentation_tests.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/webrtc/trunk/build/android/run_instrumentation_tests.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,92 @@
     1.4 +#!/usr/bin/env python
     1.5 +#
     1.6 +# Copyright (c) 2012 The Chromium Authors. All rights reserved.
     1.7 +# Use of this source code is governed by a BSD-style license that can be
     1.8 +# found in the LICENSE file.
     1.9 +
    1.10 +"""Runs both the Python and Java tests."""
    1.11 +
    1.12 +import optparse
    1.13 +import sys
    1.14 +import time
    1.15 +
    1.16 +from pylib import apk_info
    1.17 +from pylib import buildbot_report
    1.18 +from pylib import ports
    1.19 +from pylib import run_java_tests
    1.20 +from pylib import run_python_tests
    1.21 +from pylib import run_tests_helper
    1.22 +from pylib import test_options_parser
    1.23 +from pylib.test_result import TestResults
    1.24 +
    1.25 +
    1.26 +def SummarizeResults(java_results, python_results, annotation, build_type):
    1.27 +  """Summarize the results from the various test types.
    1.28 +
    1.29 +  Args:
    1.30 +    java_results: a TestResults object with java test case results.
    1.31 +    python_results: a TestResults object with python test case results.
    1.32 +    annotation: the annotation used for these results.
    1.33 +    build_type: 'Release' or 'Debug'.
    1.34 +
    1.35 +  Returns:
    1.36 +    A tuple (all_results, summary_string, num_failing)
    1.37 +  """
    1.38 +  all_results = TestResults.FromTestResults([java_results, python_results])
    1.39 +  summary_string = all_results.LogFull('Instrumentation', annotation,
    1.40 +                                       build_type)
    1.41 +  num_failing = (len(all_results.failed) + len(all_results.crashed) +
    1.42 +                 len(all_results.unknown))
    1.43 +  return all_results, summary_string, num_failing
    1.44 +
    1.45 +
    1.46 +def DispatchInstrumentationTests(options):
    1.47 +  """Dispatches the Java and Python instrumentation tests, sharding if possible.
    1.48 +
    1.49 +  Uses the logging module to print the combined final results and
    1.50 +  summary of the Java and Python tests. If the java_only option is set, only
    1.51 +  the Java tests run. If the python_only option is set, only the python tests
    1.52 +  run. If neither are set, run both Java and Python tests.
    1.53 +
    1.54 +  Args:
    1.55 +    options: command-line options for running the Java and Python tests.
    1.56 +
    1.57 +  Returns:
    1.58 +    An integer representing the number of failing tests.
    1.59 +  """
    1.60 +  # Reset the test port allocation. It's important to do it before starting
    1.61 +  # to dispatch any tests.
    1.62 +  if not ports.ResetTestServerPortAllocation():
    1.63 +    raise Exception('Failed to reset test server port.')
    1.64 +  start_date = int(time.time() * 1000)
    1.65 +  java_results = TestResults()
    1.66 +  python_results = TestResults()
    1.67 +
    1.68 +  if options.run_java_tests:
    1.69 +    java_results = run_java_tests.DispatchJavaTests(
    1.70 +        options,
    1.71 +        [apk_info.ApkInfo(options.test_apk_path, options.test_apk_jar_path)])
    1.72 +  if options.run_python_tests:
    1.73 +    python_results = run_python_tests.DispatchPythonTests(options)
    1.74 +
    1.75 +  all_results, summary_string, num_failing = SummarizeResults(
    1.76 +      java_results, python_results, options.annotation, options.build_type)
    1.77 +  return num_failing
    1.78 +
    1.79 +
    1.80 +def main(argv):
    1.81 +  option_parser = optparse.OptionParser()
    1.82 +  test_options_parser.AddInstrumentationOptions(option_parser)
    1.83 +  options, args = option_parser.parse_args(argv)
    1.84 +  test_options_parser.ValidateInstrumentationOptions(option_parser, options,
    1.85 +                                                     args)
    1.86 +
    1.87 +  run_tests_helper.SetLogLevel(options.verbose_count)
    1.88 +  buildbot_report.PrintNamedStep(
    1.89 +      'Instrumentation tests: %s - %s' % (', '.join(options.annotation),
    1.90 +                                          options.test_apk))
    1.91 +  return DispatchInstrumentationTests(options)
    1.92 +
    1.93 +
    1.94 +if __name__ == '__main__':
    1.95 +  sys.exit(main(sys.argv))

mercurial