<commit_before># Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Swarming staging recipe: runs tests for HEAD of chromium using HEAD of
swarming_client toolset on Swarming staging server instances
(*-dev.appspot.com).

Intended to catch bugs in swarming_client and Swarming servers early on, before
full roll out.

Waterfall page: https://build.chromium.org/p/chromium.swarm/waterfall
"""

DEPS = [
  'bot_update',
  'chromium',
  'commit_position',
  'file',
  'gclient',
  'isolate',
  'json',
  'path',
  'platform',
  'properties',
  'step',
  'swarming',
  'swarming_client',
  'test_results',
  'test_utils',
]


def RunSteps(api):
  # Configure isolate & swarming modules to use staging instances.
  api.isolate.isolate_server = 'https://isolateserver-dev.appspot.com'
  api.swarming.swarming_server = 'https://chromium-swarm-dev.appspot.com'
  api.swarming.verbose = True

  # Run tests from chromium.swarm buildbot with a relatively high priority
  # so that they take precedence over manually triggered tasks.
  api.swarming.default_priority = 20

  # Do not care about the OS specific version on Canary.
  api.swarming.set_default_dimension(
      'os',
      api.swarming.prefered_os_dimension(api.platform.name).split('-', 1)[0])
  api.swarming.set_default_dimension('pool', 'Chrome')
  api.swarming.add_default_tag('project:chromium')
  api.swarming.add_default_tag('purpose:staging')
  api.swarming.default_idempotent = True

  # We are building simplest Chromium flavor possible.
  if api.properties.get('platform') == 'android':
    api.chromium.set_config(
        'android', BUILD_CONFIG=api.properties.get('configuration', 'Release'))
  else:
    api.chromium.set_config(
        'chromium', BUILD_CONFIG=api.properties.get('configuration', 'Release'))

  # We are checking out Chromium with swarming_client dep unpinned and pointing
  # to ToT of swarming_client repo, see recipe_modules/gclient/config.py.
  api.gclient.set_config('chromium')
  if api.properties.get('platform') == 'android':
    api.gclient.apply_config('android')
  api.gclient.c.solutions[0].custom_vars['swarming_revision'] = ''
  api.gclient.c.revisions['src/tools/swarming_client'] = 'HEAD'

  # Enable test isolation. Modifies GYP_DEFINES used in 'runhooks' below.
  api.isolate.set_isolate_environment(api.chromium.c)

  api.chromium.cleanup_temp()
  # Checkout chromium + deps (including 'master' of swarming_client).
  step_result = api.bot_update.ensure_checkout()
  if not step_result.json.output['did_run']:
    api.gclient.checkout()

  # Ensure swarming_client version is fresh enough.
  api.swarming.check_client_version()

  targets = ['chromium_swarm_tests']
  if api.properties.get('platform') == 'android':
    targets = ['ui_android_unittests_apk_run']

  # Build all supported tests.
  api.chromium.runhooks()
  api.isolate.clean_isolated_files(api.chromium.output_dir)
  api.chromium.compile(targets=targets)
  api.isolate.remove_build_metadata()

  # Will search for *.isolated.gen.json files in the build directory and isolate
  # corresponding targets.
  api.isolate.isolate_tests(
      api.chromium.output_dir,
      verbose=True,
      env={'SWARMING_PROFILE': '1'})

  # Make swarming tasks that run isolated tests.
  tasks = [
    api.swarming.gtest_task(
        test,
        isolated_hash,
        shards=2,
        test_launcher_summary_output=api.test_utils.gtest_results(
            add_json_log=False))
    for test, isolated_hash in sorted(api.isolate.isolated_tests.iteritems())
  ]

  for task in tasks:
    if task.title.endswith('_apk'):  # pragma: no cover
      task.dimensions['os'] = 'Android'
      task.dimensions['android_devices'] = '1'

  for task in tasks:
    api.swarming.trigger_task(task)

  # And wait for ALL them to finish.
  with api.step.defer_results():
    for task in tasks:
      api.swarming.collect_task(task)

      # TODO(estaab): Move this into the swarming recipe_module behind a flag
      # after testing on staging.<commit_msg>Remove cpu restriction from android task.<commit_after># Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Swarming staging recipe: runs tests for HEAD of chromium using HEAD of
swarming_client toolset on Swarming staging server instances
(*-dev.appspot.com).

Intended to catch bugs in swarming_client and Swarming servers early on, before
full roll out.

Waterfall page: https://build.chromium.org/p/chromium.swarm/waterfall
"""

DEPS = [
  'bot_update',
  'chromium',
  'commit_position',
  'file',
  'gclient',
  'isolate',
  'json',
  'path',
  'platform',
  'properties',
  'step',
  'swarming',
  'swarming_client',
  'test_results',
  'test_utils',
]


def RunSteps(api):
  # Configure isolate & swarming modules to use staging instances.
  api.isolate.isolate_server = 'https://isolateserver-dev.appspot.com'
  api.swarming.swarming_server = 'https://chromium-swarm-dev.appspot.com'
  api.swarming.verbose = True

  # Run tests from chromium.swarm buildbot with a relatively high priority
  # so that they take precedence over manually triggered tasks.
  api.swarming.default_priority = 20

  # Do not care about the OS specific version on Canary.
  api.swarming.set_default_dimension(
      'os',
      api.swarming.prefered_os_dimension(api.platform.name).split('-', 1)[0])
  api.swarming.set_default_dimension('pool', 'Chrome')
  api.swarming.add_default_tag('project:chromium')
  api.swarming.add_default_tag('purpose:staging')
  api.swarming.default_idempotent = True

  # We are building simplest Chromium flavor possible.
  if api.properties.get('platform') == 'android':
    api.chromium.set_config(
        'android', BUILD_CONFIG=api.properties.get('configuration', 'Release'))
  else:
    api.chromium.set_config(
        'chromium', BUILD_CONFIG=api.properties.get('configuration', 'Release'))

  # We are checking out Chromium with swarming_client dep unpinned and pointing
  # to ToT of swarming_client repo, see recipe_modules/gclient/config.py.
  api.gclient.set_config('chromium')
  if api.properties.get('platform') == 'android':
    api.gclient.apply_config('android')
  api.gclient.c.solutions[0].custom_vars['swarming_revision'] = ''
  api.gclient.c.revisions['src/tools/swarming_client'] = 'HEAD'

  # Enable test isolation. Modifies GYP_DEFINES used in 'runhooks' below.
  api.isolate.set_isolate_environment(api.chromium.c)

  api.chromium.cleanup_temp()
  # Checkout chromium + deps (including 'master' of swarming_client).
  step_result = api.bot_update.ensure_checkout()
  if not step_result.json.output['did_run']:
    api.gclient.checkout()

  # Ensure swarming_client version is fresh enough.
  api.swarming.check_client_version()

  targets = ['chromium_swarm_tests']
  if api.properties.get('platform') == 'android':
    targets = ['ui_android_unittests_apk_run']

  # Build all supported tests.
  api.chromium.runhooks()
  api.isolate.clean_isolated_files(api.chromium.output_dir)
  api.chromium.compile(targets=targets)
  api.isolate.remove_build_metadata()

  # Will search for *.isolated.gen.json files in the build directory and isolate
  # corresponding targets.
  api.isolate.isolate_tests(
      api.chromium.output_dir,
      verbose=True,
      env={'SWARMING_PROFILE': '1'})

  # Make swarming tasks that run isolated tests.
  tasks = [
    api.swarming.gtest_task(
        test,
        isolated_hash,
        shards=2,
        test_launcher_summary_output=api.test_utils.gtest_results(
            add_json_log=False))
    for test, isolated_hash in sorted(api.isolate.isolated_tests.iteritems())
  ]

  for task in tasks:
    if task.title.endswith('_apk'):  # pragma: no cover
      task.dimensions['os'] = 'Android'
      task.dimensions['android_devices'] = '1'
      del task.dimensions['cpu']

  for task in tasks:
    api.swarming.trigger_task(task)

  # And wait for ALL them to finish.
  with api.step.defer_results():
    for task in tasks:
      api.swarming.collect_task(task)

      # TODO(estaab): Move this into the swarming recipe_module behind a flag
      # after testing on staging.
{'fraction_non_alphanumeric': 0.11235955056179775, 'fraction_numerical': 0.002899601304820587, 'mean_word_length': 4.072303921568627, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6333051', 'n_tokens_mistral': 2841, 'n_tokens_neox': 2636, 'n_words': 632}