mtest: Chdir into the build directory before running tests with -C

When `ninja -C builddir/ test` is run, ninja will change into the build
dir before starting, but `meson test -C builddir/` does not. This is
important because meson does not use (for good reasons) absolute paths,
which means if a test case needs to be passed as an argument a file name
that is part of the build process, it will be relative builddir. Without
changing into the builddir the path will not exist (or worse, point at
the wrong thing), and test will not behave as intended.

To fix this mtest will change directory before starting tests, and will
change back after all tests have been finished.

Fixes #2710
pull/2411/merge
Dylan Baker 7 years ago committed by Jussi Pakkanen
parent cabbb30ab4
commit d573a29bda
  1. 54
      mesonbuild/mtest.py

@ -482,35 +482,41 @@ TIMEOUT: %4d
numlen = len('%d' % len(tests)) numlen = len('%d' % len(tests))
self.open_log_files() self.open_log_files()
wrap = self.get_wrapper() wrap = self.get_wrapper()
startdir = os.getcwd()
if self.options.wd:
os.chdir(self.options.wd)
for _ in range(self.options.repeat): try:
for i, test in enumerate(tests): for _ in range(self.options.repeat):
visible_name = self.get_pretty_suite(test) for i, test in enumerate(tests):
visible_name = self.get_pretty_suite(test)
if self.options.gdb:
test.timeout = None if self.options.gdb:
test.timeout = None
if not test.is_parallel or self.options.gdb:
self.drain_futures(futures) if not test.is_parallel or self.options.gdb:
futures = [] self.drain_futures(futures)
res = self.run_single_test(wrap, test) futures = []
self.print_stats(numlen, tests, visible_name, res, i) res = self.run_single_test(wrap, test)
else: self.print_stats(numlen, tests, visible_name, res, i)
if not executor: else:
executor = conc.ThreadPoolExecutor(max_workers=self.options.num_processes) if not executor:
f = executor.submit(self.run_single_test, wrap, test) executor = conc.ThreadPoolExecutor(max_workers=self.options.num_processes)
futures.append((f, numlen, tests, visible_name, i)) f = executor.submit(self.run_single_test, wrap, test)
futures.append((f, numlen, tests, visible_name, i))
if self.options.repeat > 1 and self.fail_count:
break
if self.options.repeat > 1 and self.fail_count: if self.options.repeat > 1 and self.fail_count:
break break
if self.options.repeat > 1 and self.fail_count:
break
self.drain_futures(futures) self.drain_futures(futures)
self.print_summary() self.print_summary()
self.print_collected_logs() self.print_collected_logs()
if self.logfilename: if self.logfilename:
print('Full log written to %s' % self.logfilename) print('Full log written to %s' % self.logfilename)
finally:
os.chdir(startdir)
def drain_futures(self, futures): def drain_futures(self, futures):
for i in futures: for i in futures:

Loading…
Cancel
Save