aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mtest.py
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2021-02-02 09:43:09 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2021-02-02 11:21:11 +0100
commit26a3148e19243ce2cc893aeec121e0afd8480f56 (patch)
tree2aae346a44296fca29cc2c04748e893563d04294 /mesonbuild/mtest.py
parent0aeb2074b9440a478aa2e94680649e690c0ee0d8 (diff)
downloadmeson-26a3148e19243ce2cc893aeec121e0afd8480f56.zip
meson-26a3148e19243ce2cc893aeec121e0afd8480f56.tar.gz
meson-26a3148e19243ce2cc893aeec121e0afd8480f56.tar.bz2
mtest: load build data early
This will be needed to exclude testsuites from test setups (which are stored in the build data). While at it, since a chdir is needed simplify a bit the loading of tests and benchmarks.
Diffstat (limited to 'mesonbuild/mtest.py')
-rw-r--r--mesonbuild/mtest.py44
1 files changed, 21 insertions, 23 deletions
diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py
index bbd3fd8..fc883f9 100644
--- a/mesonbuild/mtest.py
+++ b/mesonbuild/mtest.py
@@ -1114,22 +1114,6 @@ def check_testdata(objs: T.List[TestSerialisation]) -> T.List[TestSerialisation]
raise MesonVersionMismatchException(obj.version, coredata_version)
return objs
-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:
- objs = check_testdata(pickle.load(f))
- 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:
- objs = check_testdata(pickle.load(f))
- return objs
-
# Custom waiting primitives for asyncio
async def try_wait_one(*awaitables: T.Any, timeout: T.Optional[T.Union[int, float]]) -> None:
@@ -1441,10 +1425,19 @@ class TestHarness:
if namebase:
self.logfile_base += '-' + namebase.replace(' ', '_')
- if self.options.benchmark:
- self.tests = load_benchmarks(options.wd)
- else:
- self.tests = load_tests(options.wd)
+ startdir = os.getcwd()
+ try:
+ if self.options.wd:
+ os.chdir(self.options.wd)
+ self.build_data = build.load(os.getcwd())
+ if not self.options.setup:
+ self.options.setup = self.build_data.test_setup_default_name
+ if self.options.benchmark:
+ self.tests = self.load_tests('meson_benchmark_setup.dat')
+ else:
+ self.tests = self.load_tests('meson_test_setup.dat')
+ finally:
+ os.chdir(startdir)
ss = set()
for t in self.tests:
@@ -1452,6 +1445,14 @@ class TestHarness:
ss.add(s)
self.suites = list(ss)
+ def load_tests(self, file_name: str) -> T.List[TestSerialisation]:
+ datafile = Path('meson-private') / file_name
+ if not datafile.is_file():
+ raise TestException('Directory {!r} does not seem to be a Meson build directory.'.format(self.options.wd))
+ with datafile.open('rb') as f:
+ objs = check_testdata(pickle.load(f))
+ return objs
+
def __enter__(self) -> 'TestHarness':
return self
@@ -1489,8 +1490,6 @@ class TestHarness:
def get_test_runner(self, test: TestSerialisation) -> SingleTestRunner:
name = self.get_pretty_suite(test)
options = deepcopy(self.options)
- if not options.setup:
- options.setup = self.build_data.test_setup_default_name
if options.setup:
env = self.merge_suite_options(options, test)
else:
@@ -1599,7 +1598,6 @@ class TestHarness:
try:
if self.options.wd:
os.chdir(self.options.wd)
- self.build_data = build.load(os.getcwd())
runners = [self.get_test_runner(test) for test in tests]
self.duration_max_len = max([len(str(int(runner.timeout or 99)))
for runner in runners])