From 628effb3698e85e403351d2705d576cf4ee8c50c Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Tue, 23 Aug 2022 10:42:22 -0700 Subject: mtest: Run ninja build.ninja before loading tests When the build definition has changed since the last ninja invocation meson test operated on an outdated list of tests and their dependencies. That could lead to some tests not being run / not all dependencies being built. This was particularly confusing because the user would see the output of reconfiguration and rebuilding, and the next mtest invocation would have the updated configuration. One issue with this is that that we will now output more useless ninja output when nothing needs to be done (the "Entering directory" part is not repeated, as we happen to be in the build directory already). It likely is worth removing that output, perhaps by testing if anything needs to be done with ninja -n, but that seems better addressed separately. Fixes: #9852 --- mesonbuild/mtest.py | 10 ++++++++++ unittests/allplatformstests.py | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index ba9b06559..8b2382907 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -1560,6 +1560,16 @@ class TestHarness: startdir = os.getcwd() try: os.chdir(self.options.wd) + + # Before loading build / test data, make sure that the build + # configuration does not need to be regenerated. This needs to + # happen before rebuild_deps(), because we need the correct list of + # tests and their dependencies to compute + if not self.options.no_rebuild: + ret = subprocess.run(self.ninja + ['build.ninja']).returncode + if ret != 0: + raise TestException(f'Could not configure {self.options.wd!r}') + self.build_data = build.load(os.getcwd()) if not self.options.setup: self.options.setup = self.build_data.test_setup_default_name diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index 824d97b17..1b8ff85f2 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -793,6 +793,26 @@ class AllPlatformTests(BasePlatformTests): self.assertFailedTestCount(2, self.mtest_command + ['--no-suite', 'subprjfail:fail', '--no-suite', 'subprjmix:fail']) + def test_mtest_reconfigure(self): + if self.backend is not Backend.ninja: + raise SkipTest(f'mtest can\'t rebuild with {self.backend.name!r}') + + testdir = os.path.join(self.common_test_dir, '206 tap tests') + self.init(testdir) + self.utime(os.path.join(testdir, 'meson.build')) + o = self._run(self.mtest_command + ['--list']) + self.assertIn('Regenerating build files.', o) + self.assertIn('test_features / xfail', o) + o = self._run(self.mtest_command + ['--list']) + self.assertNotIn('Regenerating build files.', o) + # no real targets should have been built + tester = os.path.join(self.builddir, 'tester' + exe_suffix) + self.assertPathDoesNotExist(tester) + # check that we don't reconfigure if --no-rebuild is passed + self.utime(os.path.join(testdir, 'meson.build')) + o = self._run(self.mtest_command + ['--list', '--no-rebuild']) + self.assertNotIn('Regenerating build files.', o) + def test_build_by_default(self): testdir = os.path.join(self.common_test_dir, '129 build by default') self.init(testdir) -- cgit v1.2.3