def DispatchPythonTests(options):
  """Dispatches the Monkey tests, sharding it if there multiple devices."""
  logger = logging.getLogger()
  logger.setLevel(logging.DEBUG)
  attached_devices = android_commands.GetAttachedDevices()
  if not attached_devices:
    raise Exception('You have no devices attached or visible!')

  # Actually run the tests.
  logging.debug('Running monkey tests.')
  # TODO(frankf): This is a stop-gap solution. Come up with a
  # general way for running tests on every devices.
  available_tests = []
  for k in range(len(attached_devices)):
    new_method = 'testMonkey%d' % k
    setattr(MonkeyTest, new_method, MonkeyTest.testMonkey)
    available_tests.append(MonkeyTest(new_method))
  options.ensure_value('shard_retries', 1)
  sharder = python_test_sharder.PythonTestSharder(
      attached_devices, available_tests, options)
  results = sharder.RunShardedTests()
  report_results.LogFull(
      results=results,
      test_type='Monkey',
      test_package='Monkey',
      build_type=options.build_type)
  report_results.PrintAnnotation(results)
Exemple #2
0
def Dispatch(options):
    attached_devices = []
    if options.test_device:
        attached_devices = [options.test_device]
    else:
        attached_devices = android_commands.GetAttachedDevices()

    if not attached_devices:
        logging.critical('A device must be attached and online.')
        return 1

    # 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.')

    test_suite_dir = os.path.join(cmd_helper.OutDirectory.get(),
                                  options.build_type)
    options.test_suite = os.path.join(
        test_suite_dir, 'apks', constants.BROWSERTEST_SUITE_NAME + '.apk')

    # Constructs a new TestRunner with the current options.
    def RunnerFactory(device, shard_index):
        return test_runner.TestRunner(device, options.test_suite,
                                      options.test_arguments, options.timeout,
                                      options.cleanup_test_files, options.tool,
                                      options.build_type, options.webkit,
                                      constants.BROWSERTEST_TEST_PACKAGE_NAME,
                                      constants.BROWSERTEST_TEST_ACTIVITY_NAME,
                                      constants.BROWSERTEST_COMMAND_LINE_FILE)

        # Get tests and split them up based on the number of devices.

    if options.gtest_filter:
        all_tests = [t for t in options.gtest_filter.split(':') if t]
    else:
        all_enabled = gtest_dispatch.GetAllEnabledTests(
            RunnerFactory, attached_devices)
        all_tests = _FilterTests(all_enabled)

    # Run tests.
    # TODO(nileshagrawal): remove this abnormally long setup timeout once fewer
    # files are pushed to the devices for content_browsertests: crbug.com/138275
    setup_timeout = 20 * 60  # 20 minutes
    test_results = shard.ShardAndRunTests(RunnerFactory,
                                          attached_devices,
                                          all_tests,
                                          options.build_type,
                                          setup_timeout=setup_timeout,
                                          test_timeout=None,
                                          num_retries=options.num_retries)
    report_results.LogFull(results=test_results,
                           test_type='Unit test',
                           test_package=constants.BROWSERTEST_SUITE_NAME,
                           build_type=options.build_type,
                           flakiness_server=options.flakiness_dashboard_server)
    report_results.PrintAnnotation(test_results)
Exemple #3
0
def _RunATestSuite(options, suite_name):
    """Run a single test suite.

  Helper for Dispatch() to allow stop/restart of the emulator across
  test bundles.  If using the emulator, we start it on entry and stop
  it on exit.

  Args:
    options: options for running the tests.
    suite_name: name of the test suite being run.

  Returns:
    0 if successful, number of failing tests otherwise.
  """
    step_name = os.path.basename(options.test_suite).replace('-debug.apk', '')
    attached_devices = []
    buildbot_emulators = []

    if options.use_emulator:
        buildbot_emulators = emulator.LaunchEmulators(options.emulator_count,
                                                      options.abi,
                                                      wait_for_boot=True)
        attached_devices = [e.device for e in buildbot_emulators]
    elif options.test_device:
        attached_devices = [options.test_device]
    else:
        attached_devices = android_commands.GetAttachedDevices()

    if not attached_devices:
        logging.critical('A device must be attached and online.')
        return 1

    # 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.')

    # Constructs a new TestRunner with the current options.
    def RunnerFactory(device, shard_index):
        return test_runner.TestRunner(device, options.test_suite,
                                      options.test_arguments, options.timeout,
                                      options.cleanup_test_files, options.tool,
                                      options.build_type, options.webkit,
                                      constants.GTEST_TEST_PACKAGE_NAME,
                                      constants.GTEST_TEST_ACTIVITY_NAME,
                                      constants.GTEST_COMMAND_LINE_FILE)

    # Get tests and split them up based on the number of devices.
    if options.gtest_filter:
        all_tests = [t for t in options.gtest_filter.split(':') if t]
    else:
        all_tests = GetAllEnabledTests(RunnerFactory, attached_devices)
    num_devices = len(attached_devices)
    tests = [':'.join(all_tests[i::num_devices]) for i in xrange(num_devices)]
    tests = [t for t in tests if t]

    # Run tests.
    test_results = shard.ShardAndRunTests(RunnerFactory,
                                          attached_devices,
                                          tests,
                                          options.build_type,
                                          test_timeout=None,
                                          num_retries=options.num_retries)

    report_results.LogFull(results=test_results,
                           test_type='Unit test',
                           test_package=suite_name,
                           build_type=options.build_type,
                           flakiness_server=options.flakiness_dashboard_server)
    report_results.PrintAnnotation(test_results)

    for buildbot_emulator in buildbot_emulators:
        buildbot_emulator.Shutdown()

    return len(test_results.GetNotPass())