From fb7099c6cf5a7ad43da1ad83c28567ecfb70809f Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Tue, 8 Sep 2020 19:05:50 +0530 Subject: mtest: Check version in the test data after loading Same as coredata.dat and build.dat loading. Also, do not assert if things change. Raise the appropriate exception. Fixes https://github.com/mesonbuild/meson/issues/7613 --- mesonbuild/mtest.py | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'mesonbuild/mtest.py') diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index 86d7384..c452254 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -41,6 +41,8 @@ import xml.etree.ElementTree as et 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 @@ -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('', 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('', coredata_version) + for i in objs: + if not isinstance(i, TestSerialisation): + raise MesonVersionMismatchException('', 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('', coredata_version) + for i in objs: + if not isinstance(i, TestSerialisation): + raise MesonVersionMismatchException('', coredata_version) + check_obj_major_version(objs) + return objs class SingleTestRunner: -- cgit v1.1