2018-02-20 23:16:09 +00:00
|
|
|
# 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.
|
|
|
|
|
2020-02-12 14:56:15 +00:00
|
|
|
import json
|
|
|
|
import os
|
2018-02-20 23:16:09 +00:00
|
|
|
import random
|
|
|
|
|
2020-02-12 14:56:15 +00:00
|
|
|
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
2018-02-20 23:16:09 +00:00
|
|
|
# List of configuration experiments for correctness fuzzing.
|
|
|
|
# List of <probability>, <1st config name>, <2nd config name>, <2nd d8>.
|
|
|
|
# Probabilities must add up to 100.
|
2020-02-12 14:56:15 +00:00
|
|
|
with open(os.path.join(THIS_DIR, 'v8_fuzz_experiments.json')) as f:
|
|
|
|
FOOZZIE_EXPERIMENTS = json.load(f)
|
2018-02-20 23:16:09 +00:00
|
|
|
|
2019-07-11 14:12:06 +00:00
|
|
|
# Additional flag experiments. List of tuples like
|
|
|
|
# (<likelihood to use flags in [0,1)>, <flag>).
|
2020-02-12 14:56:15 +00:00
|
|
|
with open(os.path.join(THIS_DIR, 'v8_fuzz_flags.json')) as f:
|
|
|
|
ADDITIONAL_FLAGS = json.load(f)
|
|
|
|
|
2019-07-11 14:12:06 +00:00
|
|
|
|
2018-02-20 23:16:09 +00:00
|
|
|
class Config(object):
|
2019-11-10 15:34:31 +00:00
|
|
|
def __init__(self, name, rng=None):
|
2019-07-11 13:49:25 +00:00
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2018-02-20 23:16:09 +00:00
|
|
|
self.name = name
|
|
|
|
self.rng = rng or random.Random()
|
|
|
|
|
2020-02-17 14:07:48 +00:00
|
|
|
def choose_foozzie_flags(self, foozzie_experiments=None, additional_flags=None):
|
2018-02-20 23:16:09 +00:00
|
|
|
"""Randomly chooses a configuration from FOOZZIE_EXPERIMENTS.
|
|
|
|
|
2020-02-17 14:07:48 +00:00
|
|
|
Args:
|
|
|
|
foozzie_experiments: Override experiment config for testing.
|
|
|
|
additional_flags: Override additional flags for testing.
|
|
|
|
|
2018-02-20 23:16:09 +00:00
|
|
|
Returns: List of flags to pass to v8_foozzie.py fuzz harness.
|
|
|
|
"""
|
2020-02-17 14:07:48 +00:00
|
|
|
foozzie_experiments = foozzie_experiments or FOOZZIE_EXPERIMENTS
|
|
|
|
additional_flags = additional_flags or ADDITIONAL_FLAGS
|
2019-07-11 14:12:06 +00:00
|
|
|
|
|
|
|
# Add additional flags to second config based on experiment percentages.
|
|
|
|
extra_flags = []
|
2020-02-17 14:07:48 +00:00
|
|
|
for p, flags in additional_flags:
|
2019-11-10 15:34:31 +00:00
|
|
|
if self.rng.random() < p:
|
2020-02-17 14:07:48 +00:00
|
|
|
for flag in flags.split():
|
|
|
|
extra_flags.append('--second-config-extra-flags=%s' % flag)
|
2019-07-11 14:12:06 +00:00
|
|
|
|
|
|
|
# Calculate flags determining the experiment.
|
2018-02-20 23:16:09 +00:00
|
|
|
acc = 0
|
|
|
|
threshold = self.rng.random() * 100
|
2020-02-17 14:07:48 +00:00
|
|
|
for prob, first_config, second_config, second_d8 in foozzie_experiments:
|
2018-02-20 23:16:09 +00:00
|
|
|
acc += prob
|
|
|
|
if acc > threshold:
|
|
|
|
return [
|
|
|
|
'--first-config=' + first_config,
|
|
|
|
'--second-config=' + second_config,
|
|
|
|
'--second-d8=' + second_d8,
|
2019-07-11 14:12:06 +00:00
|
|
|
] + extra_flags
|
2018-02-20 23:16:09 +00:00
|
|
|
assert False
|