Commit 0281df04 authored by Liviu Rau's avatar Liviu Rau Committed by V8 LUCI CQ

[test] Refactor testrunner (1)

Bringing test closer together

Bug: v8:12785
Change-Id: I2eed79fd3b1bda210b1f58b341422fc0c6435bfd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3678210Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Commit-Queue: Liviu Rau <liviurau@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80887}
parent 2c99b26d
......@@ -13,14 +13,7 @@ import shlex
import sys
import traceback
# Add testrunner to the path.
sys.path.insert(
0,
os.path.dirname(
os.path.dirname(os.path.abspath(__file__))))
from os.path import dirname as up
from testrunner.local import command
from testrunner.local import testsuite
......@@ -34,12 +27,6 @@ from testrunner.testproc.timeout import TimeoutProc
from testrunner.testproc import util
BASE_DIR = (
os.path.dirname(
os.path.dirname(
os.path.dirname(
os.path.abspath(__file__)))))
DEFAULT_OUT_GN = 'out.gn'
# Map of test name synonyms to lists of test suites. Should be ordered by
......@@ -268,7 +255,8 @@ def _do_load_build_config(outdir, verbose=False):
class BaseTestRunner(object):
def __init__(self, basedir=None):
self.basedir = basedir or BASE_DIR
self.v8_root = up(up(up(__file__)))
self.basedir = basedir or self.v8_root
self.outdir = None
self.build_config = None
self.mode_options = None
......
......@@ -8,7 +8,7 @@ import random
import sys
# Adds testrunner to the path hence it has to be imported at the beggining.
from . import base_runner
from testrunner import base_runner
from testrunner.local import utils
......
......@@ -60,11 +60,6 @@ GC_STRESS_FLAGS = ['--gc-interval=500', '--stress-compaction',
RANDOM_GC_STRESS_FLAGS = ['--random-gc-interval=5000',
'--stress-compaction-random']
PREDICTABLE_WRAPPER = os.path.join(
base_runner.BASE_DIR, 'tools', 'predictable_wrapper.py')
class StandardTestRunner(base_runner.BaseTestRunner):
def __init__(self, *args, **kwargs):
super(StandardTestRunner, self).__init__(*args, **kwargs)
......@@ -150,6 +145,9 @@ class StandardTestRunner(base_runner.BaseTestRunner):
parser.add_option('--report', default=False, action='store_true',
help='Print a summary of the tests to be run')
def _predictable_wrapper(self):
return os.path.join(self.v8_root, 'tools', 'predictable_wrapper.py')
def _process_options(self, options):
if options.sancov_dir:
self.sancov_dir = options.sancov_dir
......@@ -198,7 +196,7 @@ class StandardTestRunner(base_runner.BaseTestRunner):
options.extra_flags.append('--no-inline-new')
# Add predictable wrapper to command prefix.
options.command_prefix = (
[sys.executable, PREDICTABLE_WRAPPER] + options.command_prefix)
[sys.executable, self._predictable_wrapper()] + options.command_prefix)
# TODO(machenbach): Figure out how to test a bigger subset of variants on
# msan.
......
......@@ -22,16 +22,22 @@ import contextlib
import json
import os
import shutil
import subprocess
import sys
import tempfile
import unittest
from io import StringIO
TOOLS_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TOOLS_ROOT = os.path.dirname(
os.path.dirname(os.path.abspath(__file__)))
sys.path.append(TOOLS_ROOT)
from testrunner import standard_runner
from testrunner import num_fuzzer
from testrunner.local import command
from testrunner.local import pool
TEST_DATA_ROOT = os.path.join(TOOLS_ROOT, 'unittests', 'testdata')
RUN_TESTS_PY = os.path.join(TOOLS_ROOT, 'run-tests.py')
Result = collections.namedtuple(
'Result', ['stdout', 'stderr', 'returncode'])
......@@ -143,13 +149,6 @@ class SystemTest(unittest.TestCase):
cls._cov.start()
except ImportError:
print('Running without python coverage.')
sys.path.append(TOOLS_ROOT)
global standard_runner
from testrunner import standard_runner
global num_fuzzer
from testrunner import num_fuzzer
from testrunner.local import command
from testrunner.local import pool
command.setup_testing()
pool.setup_testing()
......
......@@ -19,9 +19,15 @@ import mock
# Requires python-coverage and python-mock. Native python coverage
# version >= 3.7.1 should be installed to get the best speed.
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
RUN_PERF = os.path.join(BASE_DIR, 'run_perf.py')
TEST_DATA = os.path.join(BASE_DIR, 'unittests', 'testdata')
TOOLS_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, TOOLS_ROOT)
import run_perf
from testrunner.local import command
from testrunner.objects.output import Output, NULL_OUTPUT
RUN_PERF = os.path.join(TOOLS_ROOT, 'run_perf.py')
TEST_DATA = os.path.join(TOOLS_ROOT, 'unittests', 'testdata')
TEST_WORKSPACE = os.path.join(tempfile.gettempdir(), 'test-v8-run-perf')
......@@ -120,12 +126,6 @@ V8_GENERIC_JSON = {
class UnitTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
sys.path.insert(0, BASE_DIR)
import run_perf
global run_perf
def testBuildDirectory(self):
base_path = os.path.join(TEST_DATA, 'builddirs', 'dir1', 'out')
expected_path = os.path.join(base_path, 'build')
......@@ -136,14 +136,9 @@ class UnitTest(unittest.TestCase):
class PerfTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
sys.path.insert(0, BASE_DIR)
cls._cov = coverage.coverage(
include=([os.path.join(BASE_DIR, 'run_perf.py')]))
include=([os.path.join(TOOLS_ROOT, 'run_perf.py')]))
cls._cov.start()
import run_perf
from testrunner.local import command
from testrunner.objects.output import Output, NULL_OUTPUT
global command, run_perf, Output, NULL_OUTPUT
@classmethod
def tearDownClass(cls):
......@@ -192,7 +187,7 @@ class PerfTest(unittest.TestCase):
build_dir = 'Release' if on_bots else 'x64.release'
out_dirs = ['out', 'out-secondary']
return_values = [
os.path.join(os.path.dirname(BASE_DIR), out, build_dir)
os.path.join(os.path.dirname(TOOLS_ROOT), out, build_dir)
for out in out_dirs
]
mock.patch.object(
......@@ -256,7 +251,7 @@ class PerfTest(unittest.TestCase):
self.assertListEqual(errors, self._LoadResults()['errors'])
def _VerifyMock(self, binary, *args, **kwargs):
shell = os.path.join(os.path.dirname(BASE_DIR), binary)
shell = os.path.join(os.path.dirname(TOOLS_ROOT), binary)
command.Command.assert_called_with(
cmd_prefix=[],
shell=shell,
......@@ -269,7 +264,7 @@ class PerfTest(unittest.TestCase):
for arg, actual in zip(args, command.Command.call_args_list):
expected = {
'cmd_prefix': [],
'shell': os.path.join(os.path.dirname(BASE_DIR), arg[0]),
'shell': os.path.join(os.path.dirname(TOOLS_ROOT), arg[0]),
'args': list(arg[1:]),
'timeout': kwargs.get('timeout', 60),
'handle_sigterm': True,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment