def DispatchInstrumentationTests(options):
    """Dispatches the Java and Python instrumentation tests, sharding if possible.

  Uses the logging module to print the combined final results and
  summary of the Java and Python tests. If the java_only option is set, only
  the Java tests run. If the python_only option is set, only the python tests
  run. If neither are set, run both Java and Python tests.

  Args:
    options: command-line options for running the Java and Python tests.

  Returns:
    An integer representing the number of broken tests.
  """
    if not options.keep_test_server_ports:
        # Reset the test port allocation. It's important to do it before starting
        # to dispatch any tests.
        if not ports.ResetTestServerPortAllocation():
            raise Exception('Failed to reset test server port.')

    start_date = int(time.time() * 1000)
    java_results = TestResults()
    python_results = TestResults()

    if options.run_java_tests:
        java_results = run_java_tests.DispatchJavaTests(
            options, [
                apk_info.ApkInfo(options.test_apk_path,
                                 options.test_apk_jar_path)
            ])
    if options.run_python_tests:
        python_results = run_python_tests.DispatchPythonTests(options)

    all_results = TestResults.FromTestResults([java_results, python_results])

    all_results.LogFull(test_type='Instrumentation',
                        test_package=options.test_apk,
                        annotation=options.annotation,
                        build_type=options.build_type,
                        flakiness_server=options.flakiness_dashboard_server)

    return len(all_results.GetAllBroken())
Beispiel #2
0
def _RunInstrumentationTests(options, error_func):
    """Subcommand of RunTestsCommands which runs instrumentation tests."""
    instrumentation_options = ProcessInstrumentationOptions(
        options, error_func)

    results = base_test_result.TestRunResults()
    exit_code = 0

    if options.run_java_tests:
        runner_factory, tests = instrumentation_setup.Setup(
            instrumentation_options)

        test_results, exit_code = test_dispatcher.RunTests(
            tests,
            runner_factory,
            options.wait_for_debugger,
            options.test_device,
            shard=True,
            build_type=options.build_type,
            test_timeout=None,
            num_retries=options.num_retries)

        results.AddTestRunResults(test_results)

    if options.run_python_tests:
        test_results, test_exit_code = (
            python_dispatch.DispatchPythonTests(options))

        results.AddTestRunResults(test_results)

        # Only allow exit code escalation
        if test_exit_code and exit_code != constants.ERROR_EXIT_CODE:
            exit_code = test_exit_code

    report_results.LogFull(results=results,
                           test_type='Instrumentation',
                           test_package=os.path.basename(options.test_apk),
                           annotation=options.annotations,
                           build_type=options.build_type,
                           flakiness_server=options.flakiness_dashboard_server)

    return exit_code
def DispatchUIAutomatorTests(options):
    """Dispatches the UIAutomator tests, sharding if possible.

  Uses the logging module to print the combined final results and
  summary of the Java and Python tests. If the java_only option is set, only
  the Java tests run. If the python_only option is set, only the python tests
  run. If neither are set, run both Java and Python tests.

  Args:
    options: command-line options for running the Java and Python tests.

  Returns:
    An integer representing the number of broken tests.
  """
    if not options.keep_test_server_ports:
        # Reset the test port allocation. It's important to do it before starting
        # to dispatch any tests.
        if not ports.ResetTestServerPortAllocation():
            raise Exception('Failed to reset test server port.')

    all_results = base_test_result.TestRunResults()

    if options.run_java_tests:
        all_results.AddTestRunResults(dispatch.Dispatch(options))
    if options.run_python_tests:
        all_results.AddTestRunResults(
            run_python_tests.DispatchPythonTests(options))

    report_results.LogFull(results=all_results,
                           test_type='UIAutomator',
                           test_package=os.path.basename(options.test_jar),
                           annotation=options.annotation,
                           build_type=options.build_type,
                           flakiness_server=options.flakiness_dashboard_server)

    return len(all_results.GetNotPass())