2016-12-19 10:13:48 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright 2016 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.
|
|
|
|
|
|
|
|
"""
|
|
|
|
V8 correctness fuzzer launcher script.
|
|
|
|
"""
|
|
|
|
|
2019-02-19 08:28:26 +00:00
|
|
|
# for py2/py3 compatibility
|
|
|
|
from __future__ import print_function
|
|
|
|
|
2016-12-19 10:13:48 +00:00
|
|
|
import argparse
|
2017-01-16 19:53:35 +00:00
|
|
|
import hashlib
|
2016-12-19 10:13:48 +00:00
|
|
|
import itertools
|
2019-11-13 14:30:54 +00:00
|
|
|
import json
|
2016-12-19 10:13:48 +00:00
|
|
|
import os
|
2018-01-15 11:08:29 +00:00
|
|
|
import random
|
2016-12-19 10:13:48 +00:00
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import traceback
|
|
|
|
|
2019-11-15 08:54:43 +00:00
|
|
|
from collections import namedtuple
|
|
|
|
|
2020-06-27 17:45:53 +00:00
|
|
|
from v8_commands import Command, FailException, PassException
|
2016-12-19 10:13:48 +00:00
|
|
|
import v8_suppressions
|
|
|
|
|
2020-03-28 12:45:36 +00:00
|
|
|
PYTHON3 = sys.version_info >= (3, 0)
|
|
|
|
|
2016-12-19 10:13:48 +00:00
|
|
|
CONFIGS = dict(
|
2018-07-18 10:54:32 +00:00
|
|
|
default=[],
|
2017-03-10 10:52:58 +00:00
|
|
|
ignition=[
|
|
|
|
'--turbo-filter=~',
|
2017-04-28 13:33:43 +00:00
|
|
|
'--noopt',
|
2018-07-18 10:46:43 +00:00
|
|
|
'--liftoff',
|
|
|
|
'--no-wasm-tier-up',
|
2017-03-10 10:52:58 +00:00
|
|
|
],
|
2017-04-18 13:27:56 +00:00
|
|
|
ignition_asm=[
|
|
|
|
'--turbo-filter=~',
|
2017-04-28 13:33:43 +00:00
|
|
|
'--noopt',
|
2017-04-18 13:27:56 +00:00
|
|
|
'--validate-asm',
|
|
|
|
'--stress-validate-asm',
|
|
|
|
],
|
2017-03-10 10:52:58 +00:00
|
|
|
ignition_eager=[
|
|
|
|
'--turbo-filter=~',
|
2017-04-28 13:33:43 +00:00
|
|
|
'--noopt',
|
2017-03-10 10:52:58 +00:00
|
|
|
'--no-lazy',
|
|
|
|
'--no-lazy-inner-functions',
|
|
|
|
],
|
2019-05-22 08:24:58 +00:00
|
|
|
ignition_no_ic=[
|
|
|
|
'--turbo-filter=~',
|
|
|
|
'--noopt',
|
|
|
|
'--liftoff',
|
|
|
|
'--no-wasm-tier-up',
|
|
|
|
'--no-use-ic',
|
2019-06-25 08:47:50 +00:00
|
|
|
'--no-lazy-feedback-allocation',
|
2019-05-22 08:24:58 +00:00
|
|
|
],
|
2018-07-18 10:54:32 +00:00
|
|
|
ignition_turbo=[],
|
2019-05-22 08:24:58 +00:00
|
|
|
ignition_turbo_no_ic=[
|
|
|
|
'--no-use-ic',
|
|
|
|
],
|
2017-03-10 10:52:58 +00:00
|
|
|
ignition_turbo_opt=[
|
|
|
|
'--always-opt',
|
2018-07-18 10:46:43 +00:00
|
|
|
'--no-liftoff',
|
2017-03-10 10:52:58 +00:00
|
|
|
],
|
2017-03-03 15:06:46 +00:00
|
|
|
ignition_turbo_opt_eager=[
|
2017-03-10 10:52:58 +00:00
|
|
|
'--always-opt',
|
|
|
|
'--no-lazy',
|
|
|
|
'--no-lazy-inner-functions',
|
|
|
|
],
|
2019-02-01 20:35:28 +00:00
|
|
|
jitless=[
|
|
|
|
'--jitless',
|
|
|
|
],
|
2018-01-05 11:59:07 +00:00
|
|
|
slow_path=[
|
|
|
|
'--force-slow-path',
|
|
|
|
],
|
|
|
|
slow_path_opt=[
|
|
|
|
'--always-opt',
|
|
|
|
'--force-slow-path',
|
|
|
|
],
|
2018-01-05 11:53:46 +00:00
|
|
|
trusted=[
|
|
|
|
'--no-untrusted-code-mitigations',
|
|
|
|
],
|
|
|
|
trusted_opt=[
|
|
|
|
'--always-opt',
|
|
|
|
'--no-untrusted-code-mitigations',
|
|
|
|
],
|
2016-12-19 10:13:48 +00:00
|
|
|
)
|
|
|
|
|
2020-06-29 13:46:52 +00:00
|
|
|
BASELINE_CONFIG = 'ignition'
|
|
|
|
DEFAULT_CONFIG = 'ignition_turbo'
|
|
|
|
DEFAULT_D8 = 'd8'
|
|
|
|
|
2016-12-19 10:13:48 +00:00
|
|
|
# Return codes.
|
|
|
|
RETURN_PASS = 0
|
2016-12-20 09:33:55 +00:00
|
|
|
RETURN_FAIL = 2
|
2016-12-19 10:13:48 +00:00
|
|
|
|
|
|
|
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
|
2020-11-27 13:29:37 +00:00
|
|
|
SMOKE_TESTS = os.path.join(BASE_PATH, 'v8_smoke_tests.js')
|
2016-12-19 10:13:48 +00:00
|
|
|
|
2020-06-24 08:19:13 +00:00
|
|
|
# Timeout for one d8 run.
|
2020-11-27 13:29:37 +00:00
|
|
|
SMOKE_TEST_TIMEOUT_SEC = 1
|
2020-06-24 08:19:13 +00:00
|
|
|
TEST_TIMEOUT_SEC = 3
|
|
|
|
|
2019-11-13 14:30:54 +00:00
|
|
|
SUPPORTED_ARCHS = ['ia32', 'x64', 'arm', 'arm64']
|
|
|
|
|
2016-12-19 10:13:48 +00:00
|
|
|
# Output for suppressed failure case.
|
2016-12-20 09:33:55 +00:00
|
|
|
FAILURE_HEADER_TEMPLATE = """#
|
2016-12-19 10:13:48 +00:00
|
|
|
# V8 correctness failure
|
|
|
|
# V8 correctness configs: %(configs)s
|
2017-01-16 13:00:50 +00:00
|
|
|
# V8 correctness sources: %(source_key)s
|
2016-12-20 09:33:55 +00:00
|
|
|
# V8 correctness suppression: %(suppression)s
|
|
|
|
"""
|
2016-12-19 10:13:48 +00:00
|
|
|
|
|
|
|
# Extended output for failure case. The 'CHECK' is for the minimizer.
|
2016-12-20 09:33:55 +00:00
|
|
|
FAILURE_TEMPLATE = FAILURE_HEADER_TEMPLATE + """#
|
2016-12-19 10:13:48 +00:00
|
|
|
# CHECK
|
|
|
|
#
|
|
|
|
# Compared %(first_config_label)s with %(second_config_label)s
|
|
|
|
#
|
|
|
|
# Flags of %(first_config_label)s:
|
|
|
|
%(first_config_flags)s
|
|
|
|
# Flags of %(second_config_label)s:
|
|
|
|
%(second_config_flags)s
|
|
|
|
#
|
|
|
|
# Difference:
|
2019-02-28 11:22:50 +00:00
|
|
|
%(difference)s%(source_file_text)s
|
2017-01-16 13:00:50 +00:00
|
|
|
#
|
2016-12-19 10:13:48 +00:00
|
|
|
### Start of configuration %(first_config_label)s:
|
|
|
|
%(first_config_output)s
|
|
|
|
### End of configuration %(first_config_label)s
|
|
|
|
#
|
|
|
|
### Start of configuration %(second_config_label)s:
|
|
|
|
%(second_config_output)s
|
|
|
|
### End of configuration %(second_config_label)s
|
2016-12-20 09:33:55 +00:00
|
|
|
"""
|
2016-12-19 10:13:48 +00:00
|
|
|
|
2019-02-28 11:22:50 +00:00
|
|
|
SOURCE_FILE_TEMPLATE = """
|
|
|
|
#
|
|
|
|
# Source file:
|
|
|
|
%s"""
|
|
|
|
|
|
|
|
|
2017-01-09 18:19:40 +00:00
|
|
|
FUZZ_TEST_RE = re.compile(r'.*fuzz(-\d+\.js)')
|
2017-01-16 13:00:50 +00:00
|
|
|
SOURCE_RE = re.compile(r'print\("v8-foozzie source: (.*)"\);')
|
2016-12-19 10:13:48 +00:00
|
|
|
|
2017-01-16 19:53:35 +00:00
|
|
|
# The number of hex digits used from the hash of the original source file path.
|
|
|
|
# Keep the number small to avoid duplicate explosion.
|
|
|
|
ORIGINAL_SOURCE_HASH_LENGTH = 3
|
|
|
|
|
|
|
|
# Placeholder string if no original source file could be determined.
|
|
|
|
ORIGINAL_SOURCE_DEFAULT = 'none'
|
|
|
|
|
2020-05-28 17:50:39 +00:00
|
|
|
# Placeholder string for failures from crash tests. If a failure is found with
|
|
|
|
# this signature, the matching sources should be moved to the mapping below.
|
|
|
|
ORIGINAL_SOURCE_CRASHTESTS = 'placeholder for CrashTests'
|
|
|
|
|
|
|
|
# Mapping from relative original source path (e.g. CrashTests/path/to/file.js)
|
|
|
|
# to a string key. Map to the same key for duplicate issues. The key should
|
|
|
|
# have more than 3 characters to not collide with other existing hashes.
|
|
|
|
# If a symptom from a particular original source file is known to map to a
|
|
|
|
# known failure, it can be added to this mapping. This should be done for all
|
|
|
|
# failures from CrashTests, as those by default map to the placeholder above.
|
|
|
|
KNOWN_FAILURES = {
|
|
|
|
# Foo.caller with asm.js: https://crbug.com/1042556
|
2020-07-22 19:15:14 +00:00
|
|
|
'CrashTests/4782147262545920/494.js': '.caller',
|
2020-07-03 07:38:22 +00:00
|
|
|
'CrashTests/5637524389167104/01457.js': '.caller',
|
2020-05-28 17:50:39 +00:00
|
|
|
'CrashTests/5703451898085376/02176.js': '.caller',
|
|
|
|
'CrashTests/4846282433495040/04342.js': '.caller',
|
2020-07-03 07:38:22 +00:00
|
|
|
'CrashTests/5712410200899584/04483.js': '.caller',
|
2020-07-22 19:15:14 +00:00
|
|
|
'v8/test/mjsunit/regress/regress-105.js': '.caller',
|
2020-05-28 17:50:39 +00:00
|
|
|
# Flaky issue that almost never repros.
|
|
|
|
'CrashTests/5694376231632896/1033966.js': 'flaky',
|
|
|
|
}
|
|
|
|
|
2017-02-02 11:32:52 +00:00
|
|
|
|
2019-11-13 14:30:54 +00:00
|
|
|
def infer_arch(d8):
|
|
|
|
"""Infer the V8 architecture from the build configuration next to the
|
|
|
|
executable.
|
|
|
|
"""
|
|
|
|
with open(os.path.join(os.path.dirname(d8), 'v8_build_config.json')) as f:
|
|
|
|
arch = json.load(f)['v8_current_cpu']
|
2019-11-15 08:54:43 +00:00
|
|
|
arch = 'ia32' if arch == 'x86' else arch
|
|
|
|
assert arch in SUPPORTED_ARCHS
|
|
|
|
return arch
|
|
|
|
|
|
|
|
|
|
|
|
class ExecutionArgumentsConfig(object):
|
|
|
|
def __init__(self, label):
|
|
|
|
self.label = label
|
|
|
|
|
|
|
|
def add_arguments(self, parser, default_config):
|
|
|
|
def add_argument(flag_template, help_template, **kwargs):
|
|
|
|
parser.add_argument(
|
|
|
|
flag_template % self.label,
|
|
|
|
help=help_template % self.label,
|
|
|
|
**kwargs)
|
|
|
|
|
|
|
|
add_argument(
|
|
|
|
'--%s-config',
|
|
|
|
'%s configuration',
|
|
|
|
default=default_config)
|
|
|
|
add_argument(
|
|
|
|
'--%s-config-extra-flags',
|
|
|
|
'additional flags passed to the %s run',
|
|
|
|
action='append',
|
|
|
|
default=[])
|
|
|
|
add_argument(
|
|
|
|
'--%s-d8',
|
|
|
|
'optional path to %s d8 executable, '
|
|
|
|
'default: bundled in the directory of this script',
|
2020-06-29 13:46:52 +00:00
|
|
|
default=DEFAULT_D8)
|
2019-11-15 08:54:43 +00:00
|
|
|
|
2021-05-17 13:29:26 +00:00
|
|
|
def make_options(self, options, default_config=None, default_d8=None):
|
2019-11-15 08:54:43 +00:00
|
|
|
def get(name):
|
|
|
|
return getattr(options, '%s_%s' % (self.label, name))
|
|
|
|
|
2020-06-29 18:33:42 +00:00
|
|
|
config = default_config or get('config')
|
2019-11-15 08:54:43 +00:00
|
|
|
assert config in CONFIGS
|
|
|
|
|
2021-05-17 13:29:26 +00:00
|
|
|
d8 = default_d8 or get('d8')
|
2019-11-15 08:54:43 +00:00
|
|
|
if not os.path.isabs(d8):
|
|
|
|
d8 = os.path.join(BASE_PATH, d8)
|
|
|
|
assert os.path.exists(d8)
|
|
|
|
|
|
|
|
flags = CONFIGS[config] + get('config_extra_flags')
|
|
|
|
|
|
|
|
RunOptions = namedtuple('RunOptions', ['arch', 'config', 'd8', 'flags'])
|
|
|
|
return RunOptions(infer_arch(d8), config, d8, flags)
|
2019-11-13 14:30:54 +00:00
|
|
|
|
|
|
|
|
2020-06-29 13:46:52 +00:00
|
|
|
class ExecutionConfig(object):
|
|
|
|
def __init__(self, options, label):
|
|
|
|
self.options = options
|
|
|
|
self.label = label
|
|
|
|
self.arch = getattr(options, label).arch
|
|
|
|
self.config = getattr(options, label).config
|
|
|
|
d8 = getattr(options, label).d8
|
|
|
|
flags = getattr(options, label).flags
|
|
|
|
self.command = Command(options, label, d8, flags)
|
|
|
|
|
2021-05-17 13:29:26 +00:00
|
|
|
# Options for a fallback configuration only exist when comparing
|
|
|
|
# different architectures.
|
|
|
|
fallback_label = label + '_fallback'
|
|
|
|
self.fallback = None
|
|
|
|
if getattr(options, fallback_label, None):
|
|
|
|
self.fallback = ExecutionConfig(options, fallback_label)
|
|
|
|
|
2020-06-29 13:46:52 +00:00
|
|
|
@property
|
|
|
|
def flags(self):
|
|
|
|
return self.command.flags
|
|
|
|
|
2020-11-27 12:35:26 +00:00
|
|
|
@property
|
|
|
|
def is_error_simulation(self):
|
|
|
|
return '--simulate-errors' in self.flags
|
|
|
|
|
2020-06-29 13:46:52 +00:00
|
|
|
|
2016-12-19 10:13:48 +00:00
|
|
|
def parse_args():
|
2019-11-15 08:54:43 +00:00
|
|
|
first_config_arguments = ExecutionArgumentsConfig('first')
|
|
|
|
second_config_arguments = ExecutionArgumentsConfig('second')
|
|
|
|
|
2016-12-19 10:13:48 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument(
|
|
|
|
'--random-seed', type=int, required=True,
|
|
|
|
help='random seed passed to both runs')
|
2019-02-28 11:22:50 +00:00
|
|
|
parser.add_argument(
|
2020-11-27 13:29:37 +00:00
|
|
|
'--skip-smoke-tests', default=False, action='store_true',
|
|
|
|
help='skip smoke tests for testing purposes')
|
2020-02-04 14:23:21 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--skip-suppressions', default=False, action='store_true',
|
|
|
|
help='skip suppressions to reproduce known issues')
|
2019-11-15 08:54:43 +00:00
|
|
|
|
|
|
|
# Add arguments for each run configuration.
|
2020-06-29 13:46:52 +00:00
|
|
|
first_config_arguments.add_arguments(parser, BASELINE_CONFIG)
|
|
|
|
second_config_arguments.add_arguments(parser, DEFAULT_CONFIG)
|
2019-11-15 08:54:43 +00:00
|
|
|
|
2017-01-10 17:18:59 +00:00
|
|
|
parser.add_argument('testcase', help='path to test case')
|
2016-12-19 10:13:48 +00:00
|
|
|
options = parser.parse_args()
|
|
|
|
|
|
|
|
# Ensure we have a test case.
|
|
|
|
assert (os.path.exists(options.testcase) and
|
|
|
|
os.path.isfile(options.testcase)), (
|
|
|
|
'Test case %s doesn\'t exist' % options.testcase)
|
|
|
|
|
2019-11-15 08:54:43 +00:00
|
|
|
options.first = first_config_arguments.make_options(options)
|
|
|
|
options.second = second_config_arguments.make_options(options)
|
2020-06-29 18:33:42 +00:00
|
|
|
options.default = second_config_arguments.make_options(
|
2021-05-17 13:29:26 +00:00
|
|
|
options, default_config=DEFAULT_CONFIG)
|
|
|
|
|
|
|
|
# Use fallback configurations only on diffrent architectures. In this
|
|
|
|
# case we are going to re-test against the first architecture.
|
|
|
|
if options.first.arch != options.second.arch:
|
|
|
|
options.second_fallback = second_config_arguments.make_options(
|
|
|
|
options, default_d8=options.first.d8)
|
|
|
|
options.default_fallback = second_config_arguments.make_options(
|
|
|
|
options, default_config=DEFAULT_CONFIG, default_d8=options.first.d8)
|
2019-11-13 14:30:54 +00:00
|
|
|
|
2020-06-22 16:35:23 +00:00
|
|
|
# Ensure we make a valid comparison.
|
2019-11-15 08:54:43 +00:00
|
|
|
if (options.first.d8 == options.second.d8 and
|
|
|
|
options.first.config == options.second.config):
|
2019-09-30 13:11:24 +00:00
|
|
|
parser.error('Need either executable or config difference.')
|
|
|
|
|
2016-12-19 10:13:48 +00:00
|
|
|
return options
|
|
|
|
|
|
|
|
|
2017-01-16 13:00:50 +00:00
|
|
|
def get_meta_data(content):
|
|
|
|
"""Extracts original-source-file paths from test case content."""
|
|
|
|
sources = []
|
|
|
|
for line in content.splitlines():
|
|
|
|
match = SOURCE_RE.match(line)
|
|
|
|
if match:
|
|
|
|
sources.append(match.group(1))
|
|
|
|
return {'sources': sources}
|
|
|
|
|
|
|
|
|
|
|
|
def content_bailout(content, ignore_fun):
|
|
|
|
"""Print failure state and return if ignore_fun matches content."""
|
|
|
|
bug = (ignore_fun(content) or '').strip()
|
2017-01-11 10:49:09 +00:00
|
|
|
if bug:
|
2020-06-27 17:45:53 +00:00
|
|
|
raise FailException(FAILURE_HEADER_TEMPLATE % dict(
|
2019-02-19 08:28:26 +00:00
|
|
|
configs='', source_key='', suppression=bug))
|
2016-12-19 10:13:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
def fail_bailout(output, ignore_by_output_fun):
|
|
|
|
"""Print failure state and return if ignore_by_output_fun matches output."""
|
|
|
|
bug = (ignore_by_output_fun(output.stdout) or '').strip()
|
|
|
|
if bug:
|
2020-06-27 17:45:53 +00:00
|
|
|
raise FailException(FAILURE_HEADER_TEMPLATE % dict(
|
2019-02-19 08:28:26 +00:00
|
|
|
configs='', source_key='', suppression=bug))
|
2016-12-19 10:13:48 +00:00
|
|
|
|
|
|
|
|
2020-06-27 17:45:53 +00:00
|
|
|
def format_difference(
|
2021-05-17 13:29:26 +00:00
|
|
|
first_config, second_config,
|
|
|
|
first_config_output, second_config_output,
|
|
|
|
difference, source_key=None, source=None):
|
2019-02-28 11:22:50 +00:00
|
|
|
# The first three entries will be parsed by clusterfuzz. Format changes
|
|
|
|
# will require changes on the clusterfuzz side.
|
2021-05-17 13:29:26 +00:00
|
|
|
source_key = source_key or cluster_failures(source)
|
2020-06-29 13:46:52 +00:00
|
|
|
first_config_label = '%s,%s' % (first_config.arch, first_config.config)
|
|
|
|
second_config_label = '%s,%s' % (second_config.arch, second_config.config)
|
2019-02-28 11:22:50 +00:00
|
|
|
source_file_text = SOURCE_FILE_TEMPLATE % source if source else ''
|
2020-03-28 12:45:36 +00:00
|
|
|
|
|
|
|
if PYTHON3:
|
|
|
|
first_stdout = first_config_output.stdout
|
|
|
|
second_stdout = second_config_output.stdout
|
|
|
|
else:
|
|
|
|
first_stdout = first_config_output.stdout.decode('utf-8', 'replace')
|
|
|
|
second_stdout = second_config_output.stdout.decode('utf-8', 'replace')
|
2020-06-17 08:55:22 +00:00
|
|
|
difference = difference.decode('utf-8', 'replace')
|
2020-03-28 12:45:36 +00:00
|
|
|
|
|
|
|
text = (FAILURE_TEMPLATE % dict(
|
2019-02-28 11:22:50 +00:00
|
|
|
configs='%s:%s' % (first_config_label, second_config_label),
|
|
|
|
source_file_text=source_file_text,
|
|
|
|
source_key=source_key,
|
|
|
|
suppression='', # We can't tie bugs to differences.
|
|
|
|
first_config_label=first_config_label,
|
|
|
|
second_config_label=second_config_label,
|
2020-06-29 13:46:52 +00:00
|
|
|
first_config_flags=' '.join(first_config.flags),
|
|
|
|
second_config_flags=' '.join(second_config.flags),
|
2020-03-28 12:45:36 +00:00
|
|
|
first_config_output=first_stdout,
|
|
|
|
second_config_output=second_stdout,
|
2019-02-28 11:22:50 +00:00
|
|
|
source=source,
|
2020-03-28 12:45:36 +00:00
|
|
|
difference=difference,
|
|
|
|
))
|
|
|
|
if PYTHON3:
|
2020-06-27 17:45:53 +00:00
|
|
|
return text
|
2020-03-28 12:45:36 +00:00
|
|
|
else:
|
2020-06-27 17:45:53 +00:00
|
|
|
return text.encode('utf-8', 'replace')
|
2019-02-28 11:22:50 +00:00
|
|
|
|
|
|
|
|
2020-05-28 17:50:39 +00:00
|
|
|
def cluster_failures(source, known_failures=None):
|
|
|
|
"""Returns a string key for clustering duplicate failures.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
source: The original source path where the failure happened.
|
|
|
|
known_failures: Mapping from original source path to failure key.
|
|
|
|
"""
|
|
|
|
known_failures = known_failures or KNOWN_FAILURES
|
|
|
|
# No source known. Typical for manually uploaded issues. This
|
|
|
|
# requires also manual issue creation.
|
|
|
|
if not source:
|
|
|
|
return ORIGINAL_SOURCE_DEFAULT
|
|
|
|
# Source is known to produce a particular failure.
|
|
|
|
if source in known_failures:
|
|
|
|
return known_failures[source]
|
|
|
|
# Subsume all other sources from CrashTests under one key. Otherwise
|
|
|
|
# failures lead to new crash tests which in turn lead to new failures.
|
|
|
|
if source.startswith('CrashTests'):
|
|
|
|
return ORIGINAL_SOURCE_CRASHTESTS
|
|
|
|
|
|
|
|
# We map all remaining failures to a short hash of the original source.
|
|
|
|
long_key = hashlib.sha1(source.encode('utf-8')).hexdigest()
|
|
|
|
return long_key[:ORIGINAL_SOURCE_HASH_LENGTH]
|
|
|
|
|
|
|
|
|
2021-05-17 13:29:26 +00:00
|
|
|
class RepeatedRuns(object):
|
|
|
|
"""Helper class for storing statistical data from repeated runs."""
|
|
|
|
def __init__(self, test_case, timeout, verbose):
|
|
|
|
self.test_case = test_case
|
|
|
|
self.timeout = timeout
|
|
|
|
self.verbose = verbose
|
|
|
|
|
|
|
|
# Stores if any run has crashed or was simulated.
|
|
|
|
self.has_crashed = False
|
|
|
|
self.simulated = False
|
|
|
|
|
|
|
|
def run(self, config):
|
|
|
|
comparison_output = config.command.run(
|
|
|
|
self.test_case, timeout=self.timeout, verbose=self.verbose)
|
|
|
|
self.has_crashed = self.has_crashed or comparison_output.HasCrashed()
|
|
|
|
self.simulated = self.simulated or config.is_error_simulation
|
|
|
|
return comparison_output
|
|
|
|
|
|
|
|
@property
|
|
|
|
def crash_state(self):
|
|
|
|
return '_simulated_crash_' if self.simulated else '_unexpected_crash_'
|
|
|
|
|
|
|
|
|
2020-06-29 18:33:42 +00:00
|
|
|
def run_comparisons(suppress, execution_configs, test_case, timeout,
|
2020-06-29 14:49:27 +00:00
|
|
|
verbose=True, ignore_crashes=True, source_key=None):
|
2020-06-29 18:33:42 +00:00
|
|
|
"""Runs different configurations and bails out on output difference.
|
2020-06-29 14:49:27 +00:00
|
|
|
|
|
|
|
Args:
|
|
|
|
suppress: The helper object for textual suppressions.
|
2020-06-29 18:33:42 +00:00
|
|
|
execution_configs: Two or more configurations to run. The first one will be
|
|
|
|
used as baseline to compare all others to.
|
2020-06-29 14:49:27 +00:00
|
|
|
test_case: The test case to run.
|
|
|
|
timeout: Timeout in seconds for one run.
|
|
|
|
verbose: Prints the executed commands.
|
|
|
|
ignore_crashes: Typically we ignore crashes during fuzzing as they are
|
2020-11-27 13:29:37 +00:00
|
|
|
frequent. However, when running smoke tests we should not crash
|
2020-06-29 14:49:27 +00:00
|
|
|
and immediately flag crashes as a failure.
|
|
|
|
source_key: A fixed source key. If not given, it will be inferred from the
|
|
|
|
output.
|
2020-06-27 17:45:53 +00:00
|
|
|
"""
|
2021-05-17 13:29:26 +00:00
|
|
|
runner = RepeatedRuns(test_case, timeout, verbose)
|
2020-06-27 17:45:53 +00:00
|
|
|
|
2020-06-29 18:33:42 +00:00
|
|
|
# Run the baseline configuration.
|
|
|
|
baseline_config = execution_configs[0]
|
2021-05-17 13:29:26 +00:00
|
|
|
baseline_output = runner.run(baseline_config)
|
2020-06-29 18:33:42 +00:00
|
|
|
|
|
|
|
# Iterate over the remaining configurations, run and compare.
|
|
|
|
for comparison_config in execution_configs[1:]:
|
2021-05-17 13:29:26 +00:00
|
|
|
comparison_output = runner.run(comparison_config)
|
2020-06-29 18:33:42 +00:00
|
|
|
difference, source = suppress.diff(baseline_output, comparison_output)
|
|
|
|
|
|
|
|
if difference:
|
|
|
|
# Only bail out due to suppressed output if there was a difference. If a
|
|
|
|
# suppression doesn't show up anymore in the statistics, we might want to
|
|
|
|
# remove it.
|
|
|
|
fail_bailout(baseline_output, suppress.ignore_by_output)
|
|
|
|
fail_bailout(comparison_output, suppress.ignore_by_output)
|
|
|
|
|
2021-05-17 13:29:26 +00:00
|
|
|
# Check if a difference also occurs with the fallback configuration and
|
|
|
|
# give it precedence. E.g. we always prefer x64 differences.
|
|
|
|
if comparison_config.fallback:
|
|
|
|
fallback_output = runner.run(comparison_config.fallback)
|
|
|
|
fallback_difference, fallback_source = suppress.diff(
|
|
|
|
baseline_output, fallback_output)
|
|
|
|
if fallback_difference:
|
|
|
|
fail_bailout(fallback_output, suppress.ignore_by_output)
|
|
|
|
source = fallback_source
|
|
|
|
comparison_config = comparison_config.fallback
|
|
|
|
comparison_output = fallback_output
|
|
|
|
difference = fallback_difference
|
|
|
|
|
2020-06-29 18:33:42 +00:00
|
|
|
raise FailException(format_difference(
|
2021-05-17 13:29:26 +00:00
|
|
|
baseline_config, comparison_config,
|
|
|
|
baseline_output, comparison_output,
|
|
|
|
difference, source_key, source))
|
2020-06-29 18:33:42 +00:00
|
|
|
|
2021-05-17 13:29:26 +00:00
|
|
|
if runner.has_crashed:
|
2020-06-29 14:49:27 +00:00
|
|
|
if ignore_crashes:
|
|
|
|
# Show if a crash has happened in one of the runs and no difference was
|
|
|
|
# detected. This is only for the statistics during experiments.
|
|
|
|
raise PassException('# V8 correctness - C-R-A-S-H')
|
|
|
|
else:
|
2020-11-27 13:29:37 +00:00
|
|
|
# Subsume simulated and unexpected crashes (e.g. during smoke tests)
|
2020-11-27 12:35:26 +00:00
|
|
|
# with one failure state.
|
2020-06-29 14:49:27 +00:00
|
|
|
raise FailException(FAILURE_HEADER_TEMPLATE % dict(
|
2021-05-17 13:29:26 +00:00
|
|
|
configs='', source_key='', suppression=runner.crash_state))
|
2020-06-27 17:45:53 +00:00
|
|
|
|
|
|
|
|
2016-12-19 10:13:48 +00:00
|
|
|
def main():
|
|
|
|
options = parse_args()
|
2020-06-27 22:38:25 +00:00
|
|
|
suppress = v8_suppressions.get_suppression(options.skip_suppressions)
|
2016-12-19 10:13:48 +00:00
|
|
|
|
2017-01-16 13:00:50 +00:00
|
|
|
# Static bailout based on test case content or metadata.
|
2020-03-28 12:45:36 +00:00
|
|
|
kwargs = {}
|
|
|
|
if PYTHON3:
|
|
|
|
kwargs['encoding'] = 'utf-8'
|
|
|
|
with open(options.testcase, 'r', **kwargs) as f:
|
2017-01-16 13:00:50 +00:00
|
|
|
content = f.read()
|
2020-06-27 17:45:53 +00:00
|
|
|
content_bailout(get_meta_data(content), suppress.ignore_by_metadata)
|
|
|
|
content_bailout(content, suppress.ignore_by_content)
|
|
|
|
|
2020-06-29 18:33:42 +00:00
|
|
|
# Prepare the baseline, default and a secondary configuration to compare to.
|
2021-05-17 13:29:26 +00:00
|
|
|
# The default (turbofan) takes precedence as many of the secondary configs
|
2020-06-29 18:33:42 +00:00
|
|
|
# are based on the turbofan config with additional parameters.
|
|
|
|
execution_configs = [
|
|
|
|
ExecutionConfig(options, 'first'),
|
|
|
|
ExecutionConfig(options, 'default'),
|
|
|
|
ExecutionConfig(options, 'second'),
|
|
|
|
]
|
2019-11-13 14:30:54 +00:00
|
|
|
|
2020-06-29 14:49:27 +00:00
|
|
|
# First, run some fixed smoke tests in all configs to ensure nothing
|
|
|
|
# is fundamentally wrong, in order to prevent bug flooding.
|
2020-11-27 13:29:37 +00:00
|
|
|
if not options.skip_smoke_tests:
|
2020-06-29 14:49:27 +00:00
|
|
|
run_comparisons(
|
2020-06-29 18:33:42 +00:00
|
|
|
suppress, execution_configs,
|
2020-11-27 13:29:37 +00:00
|
|
|
test_case=SMOKE_TESTS,
|
|
|
|
timeout=SMOKE_TEST_TIMEOUT_SEC,
|
2020-06-29 14:49:27 +00:00
|
|
|
verbose=False,
|
2020-11-27 13:29:37 +00:00
|
|
|
# Don't accept crashes during smoke tests. A crash would hint at
|
2020-06-29 14:49:27 +00:00
|
|
|
# a flag that might be incompatible or a broken test file.
|
|
|
|
ignore_crashes=False,
|
2020-11-27 13:29:37 +00:00
|
|
|
# Special source key for smoke tests so that clusterfuzz dedupes all
|
2020-06-29 14:49:27 +00:00
|
|
|
# cases on this in case it's hit.
|
2020-11-27 13:29:37 +00:00
|
|
|
source_key = 'smoke test failed',
|
2020-06-29 14:49:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Second, run all configs against the fuzz test case.
|
|
|
|
run_comparisons(
|
2020-06-29 18:33:42 +00:00
|
|
|
suppress, execution_configs,
|
2020-06-29 14:49:27 +00:00
|
|
|
test_case=options.testcase,
|
|
|
|
timeout=TEST_TIMEOUT_SEC,
|
|
|
|
)
|
|
|
|
|
|
|
|
# TODO(machenbach): Figure out if we could also return a bug in case
|
|
|
|
# there's no difference, but one of the line suppressions has matched -
|
|
|
|
# and without the match there would be a difference.
|
|
|
|
print('# V8 correctness - pass')
|
2016-12-19 10:13:48 +00:00
|
|
|
return RETURN_PASS
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
try:
|
|
|
|
result = main()
|
2020-06-27 17:45:53 +00:00
|
|
|
except FailException as e:
|
|
|
|
print(e.message)
|
|
|
|
result = RETURN_FAIL
|
|
|
|
except PassException as e:
|
|
|
|
print(e.message)
|
|
|
|
result = RETURN_PASS
|
2016-12-19 10:13:48 +00:00
|
|
|
except SystemExit:
|
|
|
|
# Make sure clusterfuzz reports internal errors and wrong usage.
|
|
|
|
# Use one label for all internal and usage errors.
|
2019-02-19 08:28:26 +00:00
|
|
|
print(FAILURE_HEADER_TEMPLATE % dict(
|
|
|
|
configs='', source_key='', suppression='wrong_usage'))
|
2016-12-20 09:33:55 +00:00
|
|
|
result = RETURN_FAIL
|
2017-02-13 07:51:24 +00:00
|
|
|
except MemoryError:
|
|
|
|
# Running out of memory happens occasionally but is not actionable.
|
2019-02-19 08:28:26 +00:00
|
|
|
print('# V8 correctness - pass')
|
2017-02-13 07:51:24 +00:00
|
|
|
result = RETURN_PASS
|
2016-12-19 10:13:48 +00:00
|
|
|
except Exception as e:
|
2019-02-19 08:28:26 +00:00
|
|
|
print(FAILURE_HEADER_TEMPLATE % dict(
|
|
|
|
configs='', source_key='', suppression='internal_error'))
|
|
|
|
print('# Internal error: %s' % e)
|
2016-12-19 10:13:48 +00:00
|
|
|
traceback.print_exc(file=sys.stdout)
|
2016-12-20 09:33:55 +00:00
|
|
|
result = RETURN_FAIL
|
2016-12-19 10:13:48 +00:00
|
|
|
|
|
|
|
sys.exit(result)
|