2016-12-19 10:13:48 +00:00
|
|
|
# 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.
|
|
|
|
|
|
|
|
# Fork from commands.py and output.py in v8 test driver.
|
|
|
|
|
2019-11-14 14:56:02 +00:00
|
|
|
import os
|
2016-12-19 10:13:48 +00:00
|
|
|
import signal
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
from threading import Event, Timer
|
|
|
|
|
2019-11-14 14:56:02 +00:00
|
|
|
import v8_fuzz_config
|
|
|
|
|
|
|
|
# List of default flags passed to each d8 run.
|
|
|
|
DEFAULT_FLAGS = [
|
|
|
|
'--correctness-fuzzer-suppressions',
|
|
|
|
'--expose-gc',
|
|
|
|
'--allow-natives-syntax',
|
|
|
|
'--invoke-weak-callbacks',
|
|
|
|
'--omit-quit',
|
|
|
|
'--es-staging',
|
|
|
|
'--wasm-staging',
|
|
|
|
'--no-wasm-async-compilation',
|
|
|
|
'--suppress-asm-messages',
|
|
|
|
]
|
|
|
|
|
|
|
|
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
|
|
# List of files passed to each d8 run before the testcase.
|
|
|
|
DEFAULT_FILES = [
|
|
|
|
os.path.join(BASE_PATH, 'v8_mock.js'),
|
|
|
|
os.path.join(BASE_PATH, 'v8_suppressions.js'),
|
|
|
|
]
|
|
|
|
|
|
|
|
# Architecture-specific mock file
|
|
|
|
ARCH_MOCKS = os.path.join(BASE_PATH, 'v8_mock_archs.js')
|
|
|
|
|
|
|
|
# Timeout in seconds for one d8 run.
|
|
|
|
TIMEOUT = 3
|
|
|
|
|
|
|
|
|
|
|
|
def _startup_files(options):
|
|
|
|
"""Default files and optional architecture-specific mock file."""
|
|
|
|
files = DEFAULT_FILES[:]
|
2019-11-15 08:54:43 +00:00
|
|
|
if options.first.arch != options.second.arch:
|
2019-11-14 14:56:02 +00:00
|
|
|
files.append(ARCH_MOCKS)
|
|
|
|
return files
|
|
|
|
|
|
|
|
|
|
|
|
class Command(object):
|
|
|
|
"""Represents a configuration for running V8 multiple times with certain
|
|
|
|
flags and files.
|
|
|
|
"""
|
|
|
|
def __init__(self, options, label, executable, config_flags):
|
|
|
|
self.label = label
|
|
|
|
self.executable = executable
|
|
|
|
self.config_flags = config_flags
|
|
|
|
self.common_flags = DEFAULT_FLAGS[:]
|
|
|
|
self.common_flags.extend(['--random-seed', str(options.random_seed)])
|
|
|
|
|
|
|
|
self.files = _startup_files(options)
|
|
|
|
|
|
|
|
def run(self, testcase, verbose=False):
|
|
|
|
"""Run the executable with a specific testcase."""
|
|
|
|
args = [self.executable] + self.flags + self.files + [testcase]
|
|
|
|
if verbose:
|
|
|
|
print('# Command line for %s comparison:' % self.label)
|
|
|
|
print(' '.join(args))
|
|
|
|
if self.executable.endswith('.py'):
|
|
|
|
# Wrap with python in tests.
|
|
|
|
args = [sys.executable] + args
|
|
|
|
return Execute(
|
|
|
|
args,
|
|
|
|
cwd=os.path.dirname(os.path.abspath(testcase)),
|
|
|
|
timeout=TIMEOUT,
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def flags(self):
|
|
|
|
return self.common_flags + self.config_flags
|
|
|
|
|
2016-12-19 10:13:48 +00:00
|
|
|
|
|
|
|
class Output(object):
|
|
|
|
def __init__(self, exit_code, timed_out, stdout, pid):
|
|
|
|
self.exit_code = exit_code
|
|
|
|
self.timed_out = timed_out
|
|
|
|
self.stdout = stdout
|
|
|
|
self.pid = pid
|
|
|
|
|
|
|
|
def HasCrashed(self):
|
|
|
|
# Timed out tests will have exit_code -signal.SIGTERM.
|
|
|
|
if self.timed_out:
|
|
|
|
return False
|
|
|
|
return (self.exit_code < 0 and
|
|
|
|
self.exit_code != -signal.SIGABRT)
|
|
|
|
|
|
|
|
def HasTimedOut(self):
|
|
|
|
return self.timed_out
|
|
|
|
|
|
|
|
|
|
|
|
def Execute(args, cwd, timeout=None):
|
|
|
|
popen_args = [c for c in args if c != ""]
|
|
|
|
try:
|
|
|
|
process = subprocess.Popen(
|
|
|
|
args=popen_args,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.STDOUT,
|
|
|
|
cwd=cwd
|
|
|
|
)
|
|
|
|
except Exception as e:
|
|
|
|
sys.stderr.write("Error executing: %s\n" % popen_args)
|
|
|
|
raise e
|
|
|
|
|
|
|
|
timeout_event = Event()
|
|
|
|
|
|
|
|
def kill_process():
|
|
|
|
timeout_event.set()
|
|
|
|
try:
|
|
|
|
process.kill()
|
|
|
|
except OSError:
|
|
|
|
sys.stderr.write('Error: Process %s already ended.\n' % process.pid)
|
|
|
|
|
|
|
|
timer = Timer(timeout, kill_process)
|
|
|
|
timer.start()
|
|
|
|
stdout, _ = process.communicate()
|
|
|
|
timer.cancel()
|
|
|
|
|
|
|
|
return Output(
|
|
|
|
process.returncode,
|
|
|
|
timeout_event.is_set(),
|
|
|
|
stdout.decode('utf-8', 'replace').encode('utf-8'),
|
|
|
|
process.pid,
|
|
|
|
)
|