tests: Reduce complexity of the run_tests signature

pull/8859/head
Daniel Mensinger 3 years ago
parent 99d3897caf
commit e1708d3de9
  1. 31
      run_project_tests.py
  2. 36
      run_single_test.py

@ -546,16 +546,17 @@ def detect_parameter_files(test: TestDef, test_build_dir: str) -> T.Tuple[Path,
return nativefile, crossfile
def run_test(test: TestDef, extra_args: T.List[str], compiler: str, backend: Backend,
flags: T.List[str], commands: T.Tuple[T.List[str], T.List[str], T.List[str], T.List[str]],
should_fail: str, use_tmp: bool) -> T.Optional[TestResult]:
def run_test(test: TestDef,
extra_args: T.List[str],
should_fail: str,
use_tmp: bool) -> T.Optional[TestResult]:
if test.skip:
return None
build_dir = create_deterministic_builddir(test, use_tmp)
try:
with TemporaryDirectoryWinProof(prefix='i ', dir=None if use_tmp else os.getcwd()) as install_dir:
try:
return _run_test(test, build_dir, install_dir, extra_args, compiler, backend, flags, commands, should_fail)
return _run_test(test, build_dir, install_dir, extra_args, should_fail)
except TestResult as r:
return r
finally:
@ -563,11 +564,11 @@ def run_test(test: TestDef, extra_args: T.List[str], compiler: str, backend: Bac
finally:
mesonlib.windows_proof_rmtree(build_dir)
def _run_test(test: TestDef, test_build_dir: str, install_dir: str,
extra_args: T.List[str], compiler: str, backend: Backend,
flags: T.List[str], commands: T.Tuple[T.List[str], T.List[str], T.List[str], T.List[str]],
def _run_test(test: TestDef,
test_build_dir: str,
install_dir: str,
extra_args: T.List[str],
should_fail: str) -> TestResult:
compile_commands, clean_commands, install_commands, uninstall_commands = commands
gen_start = time.time()
# Configure in-process
gen_args = [] # type: T.List[str]
@ -575,7 +576,7 @@ def _run_test(test: TestDef, test_build_dir: str, install_dir: str,
gen_args += ['--prefix', 'x:/usr'] if mesonlib.is_windows() else ['--prefix', '/usr']
if 'libdir' not in test.do_not_set_opts:
gen_args += ['--libdir', 'lib']
gen_args += [test.path.as_posix(), test_build_dir] + flags + extra_args
gen_args += [test.path.as_posix(), test_build_dir] + backend_flags + extra_args
nativefile, crossfile = detect_parameter_files(test, test_build_dir)
@ -678,7 +679,7 @@ def _run_test(test: TestDef, test_build_dir: str, install_dir: str,
testresult.add_step(BuildStep.install, '', '')
if not install_commands:
return testresult
install_msg = validate_install(test, Path(install_dir), compiler, builddata.environment)
install_msg = validate_install(test, Path(install_dir), host_c_compiler, builddata.environment)
if install_msg:
testresult.fail('\n' + install_msg)
return testresult
@ -1090,7 +1091,6 @@ def _run_tests(all_tests: T.List[T.Tuple[str, T.List[TestDef], bool]],
passing_tests = 0
failing_tests = 0
skipped_tests = 0
commands = (compile_commands, clean_commands, install_commands, uninstall_commands)
try:
# This fails in some CI environments for unknown reasons.
@ -1133,8 +1133,7 @@ def _run_tests(all_tests: T.List[T.Tuple[str, T.List[TestDef], bool]],
should_fail = name.split('warning-')[1]
t.skip = skipped or t.skip
result_future = executor.submit(run_test, t, extra_args + suite_args + t.args,
host_c_compiler, backend, backend_flags, commands, should_fail, use_tmp)
result_future = executor.submit(run_test, t, extra_args + suite_args + t.args, should_fail, use_tmp)
futures.append((testname, t, result_future))
for (testname, t, result_future) in futures:
sys.stdout.flush()
@ -1255,13 +1254,13 @@ def check_format() -> None:
continue
check_file(root / file)
def check_meson_commands_work(options: argparse.Namespace) -> None:
def check_meson_commands_work(use_tmpdir: bool, extra_args: T.List[str]) -> None:
global backend, compile_commands, test_commands, install_commands
testdir = PurePath('test cases', 'common', '1 trivial').as_posix()
meson_commands = mesonlib.python_command + [get_meson_script()]
with TemporaryDirectoryWinProof(prefix='b ', dir=None if options.use_tmpdir else '.') as build_dir:
with TemporaryDirectoryWinProof(prefix='b ', dir=None if use_tmpdir else '.') as build_dir:
print('Checking that configuring works...')
gen_cmd = meson_commands + [testdir, build_dir] + backend_flags + options.extra_args
gen_cmd = meson_commands + [testdir, build_dir] + backend_flags + extra_args
pc, o, e = Popen_safe(gen_cmd)
if pc.returncode != 0:
raise RuntimeError(f'Failed to configure {testdir!r}:\n{e}\n{o}')

@ -10,23 +10,16 @@ test, with all of the rules from the test.json file loaded.
import argparse
import pathlib
import shutil
import typing as T
from mesonbuild import environment
from mesonbuild import mlog
from mesonbuild import mesonlib
from run_project_tests import TestDef, load_test_json, run_test, BuildStep, skippable
from run_tests import get_backend_commands, guess_backend, get_fake_options
from run_project_tests import setup_commands, detect_system_compiler, print_tool_versions
if T.TYPE_CHECKING:
try:
from typing import Protocol
except ImportError:
# Mypy gets grump about this even though it's fine
from typing_extensions import Protocol # type: ignore
from run_project_tests import CompilerArgumentType
class ArgumentType(Protocol):
class ArgumentType(CompilerArgumentType):
"""Typing information for command line arguments."""
@ -40,26 +33,21 @@ def main() -> None:
parser.add_argument('case', type=pathlib.Path, help='The test case to run')
parser.add_argument('--subtest', type=int, action='append', dest='subtests', help='which subtests to run')
parser.add_argument('--backend', action='store', help="Which backend to use")
parser.add_argument('--cross-file', action='store', help='File describing cross compilation environment.')
parser.add_argument('--native-file', action='store', help='File describing native compilation environment.')
parser.add_argument('--use-tmpdir', action='store_true', help='Use tmp directory for temporary files.')
args = T.cast('ArgumentType', parser.parse_args())
setup_commands(args.backend)
detect_system_compiler(args)
print_tool_versions()
test = TestDef(args.case, args.case.stem, [])
tests = load_test_json(test, False)
if args.subtests:
tests = [t for i, t in enumerate(tests) if i in args.subtests]
with mesonlib.TemporaryDirectoryWinProof() as build_dir:
fake_opts = get_fake_options('/')
env = environment.Environment(None, build_dir, fake_opts)
try:
comp = env.compiler_from_language('c', mesonlib.MachineChoice.HOST).get_id()
except mesonlib.MesonException:
raise RuntimeError('Could not detect C compiler')
backend, backend_args = guess_backend(args.backend, shutil.which('msbuild'))
_cmds = get_backend_commands(backend, False)
commands = (_cmds[0], _cmds[1], _cmds[3], _cmds[4])
results = [run_test(t, t.args, comp, backend, backend_args, commands, '', True) for t in tests]
results = [run_test(t, t.args, '', True) for t in tests]
failed = False
for test, result in zip(tests, results):
if (result is None) or (('MESON_SKIP_TEST' in result.stdo) and (skippable(str(args.case.parent), test.path.as_posix()))):
@ -70,7 +58,7 @@ def main() -> None:
else:
msg = mlog.green('PASS:')
mlog.log(msg, test.display_name())
if result.msg and 'MESON_SKIP_TEST' not in result.stdo:
if result is not None and result.msg and 'MESON_SKIP_TEST' not in result.stdo:
mlog.log('reason:', result.msg)
if result.step is BuildStep.configure:
# For configure failures, instead of printing stdout,

Loading…
Cancel
Save