summaryrefslogtreecommitdiff
path: root/deps/v8/tools/clusterfuzz/v8_fuzz_config.py
blob: 92bf0dd3aacd0a696fd8b21ecef3cf5b27780ffe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Copyright 2018 the V8 project 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 random

# List of configuration experiments for correctness fuzzing.
# List of <probability>, <1st config name>, <2nd config name>, <2nd d8>.
# Probabilities must add up to 100.
FOOZZIE_EXPERIMENTS = [
  [10, 'ignition', 'jitless', 'd8'],
  [10, 'ignition', 'slow_path', 'd8'],
  [5, 'ignition', 'slow_path_opt', 'd8'],
  [25, 'ignition', 'ignition_turbo', 'd8'],
  [2, 'ignition_no_ic', 'ignition_turbo', 'd8'],
  [2, 'ignition', 'ignition_turbo_no_ic', 'd8'],
  [15, 'ignition', 'ignition_turbo_opt', 'd8'],
  [2, 'ignition_no_ic', 'ignition_turbo_opt', 'd8'],
  [4, 'ignition_turbo_opt', 'ignition_turbo_opt', 'clang_x64_pointer_compression/d8'],
  [5, 'ignition_turbo', 'ignition_turbo', 'clang_x64_pointer_compression/d8'],
  [4, 'ignition_turbo_opt', 'ignition_turbo_opt', 'clang_x86/d8'],
  [4, 'ignition_turbo', 'ignition_turbo', 'clang_x86/d8'],
  [4, 'ignition', 'ignition', 'clang_x86/d8'],
  [4, 'ignition', 'ignition', 'clang_x64_v8_arm64/d8'],
  [4, 'ignition', 'ignition', 'clang_x86_v8_arm/d8'],
]

# Additional flag experiments. List of tuples like
# (<likelihood to use flags in [0,1)>, <flag>).
ADDITIONAL_FLAGS = [
  (0.1, '--stress-marking=100'),
  (0.1, '--stress-scavenge=100'),
  (0.1, '--stress-compaction-random'),
  (0.1, '--random-gc-interval=2000'),
  (0.2, '--noanalyze-environment-liveness'),
  (0.1, '--stress-delay-tasks'),
  (0.01, '--thread-pool-size=1'),
  (0.01, '--thread-pool-size=2'),
  (0.01, '--thread-pool-size=4'),
  (0.01, '--thread-pool-size=8'),
  (0.1, '--interrupt-budget=1000'),
  (0.25, '--future'),
  (0.2, '--no-regexp-tier-up'),
  (0.1, '--regexp-interpret-all'),
  (0.1, '--regexp-tier-up-ticks=10'),
  (0.1, '--regexp-tier-up-ticks=100'),
]

class Config(object):
  def __init__(self, name, rng=None, random_seed=None):
    """
    Args:
      name: Name of the used fuzzer.
      rng: Random number generator for generating experiments.
      random_seed: Random-seed used for d8 throughout one fuzz session.
      TODO(machenbach): Remove random_seed after a grace period of a couple of
      days. We only have it to keep bisection stable. Afterwards we can just
      use rng.
    """
    self.name = name
    self.rng = rng or random.Random()
    self.random_seed = random_seed

  def choose_foozzie_flags(self):
    """Randomly chooses a configuration from FOOZZIE_EXPERIMENTS.

    Returns: List of flags to pass to v8_foozzie.py fuzz harness.
    """
    # TODO(machenbach): Temporarily use same RNG state for all test cases in one
    # fuzz session. See also TODO above.
    if self.random_seed is not None:
      flags_rng = random.Random(self.random_seed)
    else:
      flags_rng = random.Random()

    # Add additional flags to second config based on experiment percentages.
    extra_flags = []
    for p, flag in ADDITIONAL_FLAGS:
      if flags_rng.random() < p:
        extra_flags.append('--second-config-extra-flags=%s' % flag)

    # Calculate flags determining the experiment.
    acc = 0
    threshold = self.rng.random() * 100
    for prob, first_config, second_config, second_d8 in FOOZZIE_EXPERIMENTS:
      acc += prob
      if acc > threshold:
        return [
          '--first-config=' + first_config,
          '--second-config=' + second_config,
          '--second-d8=' + second_d8,
        ] + extra_flags
    assert False