| OLD | NEW | 
|   1 #!/usr/bin/env python |   1 #!/usr/bin/env python | 
|   2 # |   2 # | 
|   3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |   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 |   4 # Use of this source code is governed by a BSD-style license that can be | 
|   5 # found in the LICENSE file. |   5 # found in the LICENSE file. | 
|   6  |   6  | 
|   7 """Runs both the Python and Java instrumentation tests.""" |   7 """Runs both the Python and Java instrumentation tests.""" | 
|   8  |   8  | 
|   9 import optparse |   9 import optparse | 
|  10 import os |  | 
|  11 import sys |  10 import sys | 
|  12 import time |  | 
|  13  |  11  | 
|  14 from pylib import buildbot_report |  12 from pylib import buildbot_report | 
|  15 from pylib import constants |  | 
|  16 from pylib import ports |  13 from pylib import ports | 
|  17 from pylib.base import test_result |  14 from pylib.base import base_test_result | 
|  18 from pylib.host_driven import run_python_tests |  15 from pylib.host_driven import run_python_tests | 
|  19 from pylib.instrumentation import dispatch |  16 from pylib.instrumentation import dispatch | 
 |  17 from pylib.utils import report_results | 
|  20 from pylib.utils import run_tests_helper |  18 from pylib.utils import run_tests_helper | 
|  21 from pylib.utils import test_options_parser |  19 from pylib.utils import test_options_parser | 
|  22  |  20  | 
|  23  |  21  | 
|  24 def DispatchInstrumentationTests(options): |  22 def DispatchInstrumentationTests(options): | 
|  25   """Dispatches the Java and Python instrumentation tests, sharding if possible. |  23   """Dispatches the Java and Python instrumentation tests, sharding if possible. | 
|  26  |  24  | 
|  27   Uses the logging module to print the combined final results and |  25   Uses the logging module to print the combined final results and | 
|  28   summary of the Java and Python tests. If the java_only option is set, only |  26   summary of the Java and Python tests. If the java_only option is set, only | 
|  29   the Java tests run. If the python_only option is set, only the python tests |  27   the Java tests run. If the python_only option is set, only the python tests | 
|  30   run. If neither are set, run both Java and Python tests. |  28   run. If neither are set, run both Java and Python tests. | 
|  31  |  29  | 
|  32   Args: |  30   Args: | 
|  33     options: command-line options for running the Java and Python tests. |  31     options: command-line options for running the Java and Python tests. | 
|  34  |  32  | 
|  35   Returns: |  33   Returns: | 
|  36     An integer representing the number of broken tests. |  34     An integer representing the number of broken tests. | 
|  37   """ |  35   """ | 
|  38   if not options.keep_test_server_ports: |  36   if not options.keep_test_server_ports: | 
|  39     # Reset the test port allocation. It's important to do it before starting |  37     # Reset the test port allocation. It's important to do it before starting | 
|  40     # to dispatch any tests. |  38     # to dispatch any tests. | 
|  41     if not ports.ResetTestServerPortAllocation(): |  39     if not ports.ResetTestServerPortAllocation(): | 
|  42       raise Exception('Failed to reset test server port.') |  40       raise Exception('Failed to reset test server port.') | 
|  43  |  41  | 
|  44   java_results = test_result.TestResults() |  42   all_results = base_test_result.TestRunResults() | 
|  45   python_results = test_result.TestResults() |  | 
|  46  |  43  | 
|  47   if options.run_java_tests: |  44   if options.run_java_tests: | 
|  48     java_results = dispatch.Dispatch(options) |  45     all_results.AddTestRunResults(dispatch.Dispatch(options)) | 
 |  46   if options.run_python_tests: | 
 |  47     all_results.AddTestRunResults(run_python_tests.DispatchPythonTests(options)) | 
|  49  |  48  | 
|  50   if options.run_python_tests: |  49   report_results.LogFull( | 
|  51     python_results = run_python_tests.DispatchPythonTests(options) |  50       results=all_results, | 
|  52  |  | 
|  53   all_results = test_result.TestResults.FromTestResults([java_results, |  | 
|  54                                                          python_results]) |  | 
|  55  |  | 
|  56   all_results.LogFull( |  | 
|  57       test_type='Instrumentation', |  51       test_type='Instrumentation', | 
|  58       test_package=options.test_apk, |  52       test_package=options.test_apk, | 
|  59       annotation=options.annotation, |  53       annotation=options.annotation, | 
|  60       build_type=options.build_type, |  54       build_type=options.build_type, | 
|  61       flakiness_server=options.flakiness_dashboard_server) |  55       flakiness_server=options.flakiness_dashboard_server) | 
|  62  |  56  | 
|  63   return len(all_results.GetAllBroken()) |  57   return len(all_results.GetNotPass()) | 
|  64  |  58  | 
|  65  |  59  | 
|  66 def main(argv): |  60 def main(argv): | 
|  67   option_parser = optparse.OptionParser() |  61   option_parser = optparse.OptionParser() | 
|  68   test_options_parser.AddInstrumentationOptions(option_parser) |  62   test_options_parser.AddInstrumentationOptions(option_parser) | 
|  69   options, args = option_parser.parse_args(argv) |  63   options, args = option_parser.parse_args(argv) | 
|  70   test_options_parser.ValidateInstrumentationOptions(option_parser, options, |  64   test_options_parser.ValidateInstrumentationOptions(option_parser, options, | 
|  71                                                      args) |  65                                                      args) | 
|  72  |  66  | 
|  73   run_tests_helper.SetLogLevel(options.verbose_count) |  67   run_tests_helper.SetLogLevel(options.verbose_count) | 
|  74   ret = 1 |  68   ret = 1 | 
|  75   try: |  69   try: | 
|  76     ret = DispatchInstrumentationTests(options) |  70     ret = DispatchInstrumentationTests(options) | 
|  77   finally: |  71   finally: | 
|  78     buildbot_report.PrintStepResultIfNeeded(options, ret) |  72     buildbot_report.PrintStepResultIfNeeded(options, ret) | 
|  79   return ret |  73   return ret | 
|  80  |  74  | 
|  81  |  75  | 
|  82 if __name__ == '__main__': |  76 if __name__ == '__main__': | 
|  83   sys.exit(main(sys.argv)) |  77   sys.exit(main(sys.argv)) | 
| OLD | NEW |