<commit_before># Copyright 2015 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.

import re
from recipe_engine.types import freeze


TEST_CONFIGS = freeze({
  'benchmarks': {
    'name': 'Benchmarks',
    'tests': ['benchmarks'],
    'test_args': ['--download-data'],
  },
  'mjsunit': {
    'name': 'Mjsunit',
    'tests': ['mjsunit'],
  },
  'mozilla': {
    'name': 'Mozilla',
    'tests': ['mozilla'],
  },
  'optimize_for_size': {
    'name': 'OptimizeForSize',
    'tests': ['optimize_for_size'],
    'suite_mapping': ['mjsunit', 'cctest', 'webkit', 'intl'],
    'test_args': ['--no-variants', '--extra-flags=--optimize-for-size'],
  },
  'simdjs': {
    'name': 'SimdJs - all',
    'tests': ['simdjs'],
    'test_args': ['--download-data'],
  },
  'test262': {
    'name': 'Test262 - no variants',
    'tests': ['test262'],
    'test_args': ['--no-variants', '--download-data'],
  },
  'test262_variants': {
    'name': 'Test262',
    'tests': ['test262'],
    'test_args': ['--download-data'],
  },
  'unittests': {
    'name': 'Unittests',
    'tests': ['unittests'],
  },
  'v8testing': {
    'name': 'Check',
    'tests': ['bot_default'],
    'suite_mapping': [
        'mjsunit', 'cctest', 'webkit', 'message', 'preparser', 'intl'],
  },
  'webkit': {
    'name': 'Webkit',
    'tests': ['webkit'],
  },
})


class BaseTest(object):
  def __init__(self, test_step_config, api, v8):
    self.test_step_config = test_step_config
    self.name = test_step_config.name
    self.api = api
    self.v8 = v8

  @property
  def uses_swarming(self):
    """Returns true if the test uses swarming."""
    return False

  def apply_filter(self):
    # Run all tests by default.
    return True

  def pre_run(self, test=None, **kwargs):  # pragma: no cover
    pass

  def run(self, test=None, **kwargs):  # pragma: no cover
    raise NotImplementedError()

  def rerun(self, failure_dict, **kwargs):  # pragma: no cover
    raise NotImplementedError()


class V8Test(BaseTest):
  def apply_filter(self):
    self.applied_test_filter = self.v8._applied_test_filter(
        TEST_CONFIGS[self.name])
    if self.v8.test_filter and not self.applied_test_filter:
      self.api.step(TEST_CONFIGS[self.name]['name'] + ' - skipped', cmd=None)
      return False
    return True

  def run(self, test=None, **kwargs):
    test = test or TEST_CONFIGS[self.name]

    def step_test_data():
      return self.v8.test_api.output_json(
          self.v8._test_data.get('test_failures', False),
          self.v8._test_data.get('wrong_results', False),
          self.v8._test_data.get('flakes', False))

    full_args, env = self.v8._setup_test_runner(test, self.applied_test_filter)
    if self.v8.c.testing.may_shard and self.v8.c.testing.SHARD_COUNT > 1:
      full_args += [
        '--shard-count=%d' % self.v8.c.testing.SHARD_COUNT,
        '--shard-run=%d' % self.v8.c.testing.SHARD_RUN,
      ]
    full_args += [
      '--json-test-results',
      self.api.json.output(add_json_log=False),
    ]
    self.api.python(
      test['name'],
      self.api.path['checkout'].join('tools', 'run-tests.py'),
      full_args,
      cwd=self.api.path['checkout'],
      env=env,
      # The outcome is controlled by the json test result of the step.
      ok_ret='any',
      step_test_data=step_test_data,
      **kwargs
    )
    return self.post_run(test)

  def post_run(self, test):
    # The active step was either a local test run or the swarming collect step.
    step_result = self.api.step.active_result
    json_output = step_result.json.output

    # Log used test filters.
    if self.applied_test_filter:
      step_result.presentation.logs['test filter'] = self.applied_test_filter

    # The output is expected to be a list of architecture dicts that
    # each contain a results list. On buildbot, there is only one
    # architecture.
    assert len(json_output) == 1
    self.v8._update_durations(json_output[0], step_result.presentation)
    failure_factory=Failure.factory_func(self.test_step_config)
    failure_log, failures, flake_log, flakes = (
        self.v8._get_failure_logs(json_output[0], failure_factory))
    self.v8._update_failure_presentation(
        failure_log, failures, step_result.presentation)

    if failure_log and failures:
      # Mark the test step as failure only if there were real failures (i.e.<commit_msg>V8 Buildbot: Keep test-runner-exit-code control on the v8-side.<commit_after># Copyright 2015 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.

import re
from recipe_engine.types import freeze


TEST_CONFIGS = freeze({
  'benchmarks': {
    'name': 'Benchmarks',
    'tests': ['benchmarks'],
    'test_args': ['--download-data'],
  },
  'mjsunit': {
    'name': 'Mjsunit',
    'tests': ['mjsunit'],
  },
  'mozilla': {
    'name': 'Mozilla',
    'tests': ['mozilla'],
  },
  'optimize_for_size': {
    'name': 'OptimizeForSize',
    'tests': ['optimize_for_size'],
    'suite_mapping': ['mjsunit', 'cctest', 'webkit', 'intl'],
    'test_args': ['--no-variants', '--extra-flags=--optimize-for-size'],
  },
  'simdjs': {
    'name': 'SimdJs - all',
    'tests': ['simdjs'],
    'test_args': ['--download-data'],
  },
  'test262': {
    'name': 'Test262 - no variants',
    'tests': ['test262'],
    'test_args': ['--no-variants', '--download-data'],
  },
  'test262_variants': {
    'name': 'Test262',
    'tests': ['test262'],
    'test_args': ['--download-data'],
  },
  'unittests': {
    'name': 'Unittests',
    'tests': ['unittests'],
  },
  'v8testing': {
    'name': 'Check',
    'tests': ['bot_default'],
    'suite_mapping': [
        'mjsunit', 'cctest', 'webkit', 'message', 'preparser', 'intl'],
  },
  'webkit': {
    'name': 'Webkit',
    'tests': ['webkit'],
  },
})


class BaseTest(object):
  def __init__(self, test_step_config, api, v8):
    self.test_step_config = test_step_config
    self.name = test_step_config.name
    self.api = api
    self.v8 = v8

  @property
  def uses_swarming(self):
    """Returns true if the test uses swarming."""
    return False

  def apply_filter(self):
    # Run all tests by default.
    return True

  def pre_run(self, test=None, **kwargs):  # pragma: no cover
    pass

  def run(self, test=None, **kwargs):  # pragma: no cover
    raise NotImplementedError()

  def rerun(self, failure_dict, **kwargs):  # pragma: no cover
    raise NotImplementedError()


class V8Test(BaseTest):
  def apply_filter(self):
    self.applied_test_filter = self.v8._applied_test_filter(
        TEST_CONFIGS[self.name])
    if self.v8.test_filter and not self.applied_test_filter:
      self.api.step(TEST_CONFIGS[self.name]['name'] + ' - skipped', cmd=None)
      return False
    return True

  def run(self, test=None, **kwargs):
    test = test or TEST_CONFIGS[self.name]

    def step_test_data():
      return self.v8.test_api.output_json(
          self.v8._test_data.get('test_failures', False),
          self.v8._test_data.get('wrong_results', False),
          self.v8._test_data.get('flakes', False))

    full_args, env = self.v8._setup_test_runner(test, self.applied_test_filter)
    if self.v8.c.testing.may_shard and self.v8.c.testing.SHARD_COUNT > 1:
      full_args += [
        '--shard-count=%d' % self.v8.c.testing.SHARD_COUNT,
        '--shard-run=%d' % self.v8.c.testing.SHARD_RUN,
      ]
    full_args += [
      '--json-test-results',
      self.api.json.output(add_json_log=False),
    ]
    self.api.python(
      test['name'],
      self.api.path['checkout'].join('tools', 'run-tests.py'),
      full_args,
      cwd=self.api.path['checkout'],
      env=env,
      step_test_data=step_test_data,
      **kwargs
    )
    return self.post_run(test)

  def post_run(self, test):
    # The active step was either a local test run or the swarming collect step.
    step_result = self.api.step.active_result
    json_output = step_result.json.output

    # Log used test filters.
    if self.applied_test_filter:
      step_result.presentation.logs['test filter'] = self.applied_test_filter

    # The output is expected to be a list of architecture dicts that
    # each contain a results list. On buildbot, there is only one
    # architecture.
    assert len(json_output) == 1
    self.v8._update_durations(json_output[0], step_result.presentation)
    failure_factory=Failure.factory_func(self.test_step_config)
    failure_log, failures, flake_log, flakes = (
        self.v8._get_failure_logs(json_output[0], failure_factory))
    self.v8._update_failure_presentation(
        failure_log, failures, step_result.presentation)

    if failure_log and failures:
      # Mark the test step as failure only if there were real failures (i.e.
{'fraction_non_alphanumeric': 0.15097751158322975, 'fraction_numerical': 0.010396654989264323, 'mean_word_length': 3.2102759276879165, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3508928', 'n_tokens_mistral': 3141, 'n_tokens_neox': 3024, 'n_words': 673}