Skip to content

Commit

Permalink
mtest: Check version in the test data after loading
Browse files Browse the repository at this point in the history
Same as coredata.dat and build.dat loading. Also, do not assert if
things change. Raise the appropriate exception.

Fixes mesonbuild#7613
  • Loading branch information
nirbheek committed Sep 9, 2020
1 parent 4c2d0eb commit c2d2dce
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
7 changes: 4 additions & 3 deletions mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ def __init__(self, name: str, project: str, suite: str, fname: T.List[str],
env: build.EnvironmentVariables, should_fail: bool,
timeout: T.Optional[int], workdir: T.Optional[str],
extra_paths: T.List[str], protocol: TestProtocol, priority: int,
cmd_is_built: bool,
depends: T.List[str]):
cmd_is_built: bool, depends: T.List[str], version: str):
self.name = name
self.project_name = project
self.suite = suite
Expand All @@ -143,6 +142,7 @@ def __init__(self, name: str, project: str, suite: str, fname: T.List[str],
self.needs_exe_wrapper = needs_exe_wrapper
self.cmd_is_built = cmd_is_built
self.depends = depends
self.version = version


def get_backend_from_name(backend: str, build: T.Optional[build.Build] = None, interpreter: T.Optional['Interpreter'] = None) -> T.Optional['Backend']:
Expand Down Expand Up @@ -864,7 +864,8 @@ def create_test_serialisation(self, tests: T.List['Test']) -> T.List[TestSeriali
t.should_fail, t.timeout, t.workdir,
extra_paths, t.protocol, t.priority,
isinstance(exe, build.Executable),
[x.get_id() for x in depends])
[x.get_id() for x in depends],
self.environment.coredata.version)
arr.append(ts)
return arr

Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
_T = T.TypeVar('_T')

class MesonVersionMismatchException(MesonException):
'''Build directory generated with Meson version incompatible with current version'''
'''Build directory generated with Meson version is incompatible with current version'''
def __init__(self, old_version: str, current_version: str) -> None:
super().__init__('Build directory has been generated with Meson version {}, '
'which is incompatible with current version {}.'
'which is incompatible with the current version {}.'
.format(old_version, current_version))
self.old_version = old_version
self.current_version = current_version
Expand Down
37 changes: 27 additions & 10 deletions mesonbuild/mtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
from . import build
from . import environment
from . import mlog
from .coredata import major_versions_differ, MesonVersionMismatchException
from .coredata import version as coredata_version
from .dependencies import ExternalProgram
from .mesonlib import MesonException, get_wine_shortpath, split_args, join_args
from .backend.backends import TestProtocol, TestSerialisation
Expand Down Expand Up @@ -574,27 +576,42 @@ def write_json_log(jsonlogfile: T.TextIO, test_name: str, result: TestRun) -> No
def run_with_mono(fname: str) -> bool:
return fname.endswith('.exe') and not (is_windows() or is_cygwin())

def check_obj_major_version(objs: T.List[TestSerialisation]) -> None:
if not objs:
return
obj = objs[0]
if not hasattr(obj, 'version'):
raise MesonVersionMismatchException('<unknown>', coredata_version)
if major_versions_differ(obj.version, coredata_version):
raise MesonVersionMismatchException(obj.version, coredata_version)

def load_benchmarks(build_dir: str) -> T.List[TestSerialisation]:
datafile = Path(build_dir) / 'meson-private' / 'meson_benchmark_setup.dat'
if not datafile.is_file():
raise TestException('Directory {!r} does not seem to be a Meson build directory.'.format(build_dir))
with datafile.open('rb') as f:
obj = pickle.load(f)
assert isinstance(obj, list)
for i in obj:
assert isinstance(i, TestSerialisation)
return obj
objs = pickle.load(f)
if not isinstance(objs, list):
raise MesonVersionMismatchException('<unknown>', coredata_version)
for i in objs:
if not isinstance(i, TestSerialisation):
raise MesonVersionMismatchException('<unknown>', coredata_version)
check_obj_major_version(objs)
return objs

def load_tests(build_dir: str) -> T.List[TestSerialisation]:
datafile = Path(build_dir) / 'meson-private' / 'meson_test_setup.dat'
if not datafile.is_file():
raise TestException('Directory {!r} does not seem to be a Meson build directory.'.format(build_dir))
with datafile.open('rb') as f:
obj = pickle.load(f)
assert isinstance(obj, list)
for i in obj:
assert isinstance(i, TestSerialisation)
return obj
objs = pickle.load(f)
if not isinstance(objs, list):
raise MesonVersionMismatchException('<unknown>', coredata_version)
for i in objs:
if not isinstance(i, TestSerialisation):
raise MesonVersionMismatchException('<unknown>', coredata_version)
check_obj_major_version(objs)
return objs


class SingleTestRunner:
Expand Down

0 comments on commit c2d2dce

Please sign in to comment.