From 1570a90822941b3f0e6cc8efa50002eb528bee43 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Sun, 7 May 2017 11:15:40 +0530 Subject: [PATCH] project tests: Also regen before building This actually caught a cached-dependency related bug for me that the test-time regen did not. I also increased the ninja wait time to 1 second because that's actually how long you need to sleep to be guaranteed that a change will be detected. Must poke upstream about https://github.com/ninja-build/ninja/issues/371 --- run_project_tests.py | 10 +++++++--- run_tests.py | 8 ++++++++ run_unittests.py | 12 +++--------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/run_project_tests.py b/run_project_tests.py index 1abc19971..b8ef0e908 100755 --- a/run_project_tests.py +++ b/run_project_tests.py @@ -36,6 +36,7 @@ import concurrent.futures as conc import re from run_tests import get_backend_commands, get_backend_args_for_dir, Backend +from run_tests import ensure_backend_detects_changes class BuildStep(Enum): @@ -342,6 +343,10 @@ def _run_test(testdir, test_build_dir, install_dir, extra_args, compiler, backen return TestResult('Test that should have failed succeeded', BuildStep.configure, stdo, stde, mesonlog, gen_time) if returncode != 0: return TestResult('Generating the build system failed.', BuildStep.configure, stdo, stde, mesonlog, gen_time) + # Touch the meson.build file to force a regenerate so we can test that + # regeneration works before a build is run. + ensure_backend_detects_changes(backend) + os.utime(os.path.join(testdir, 'meson.build')) # Build with subprocess dir_args = get_backend_args_for_dir(backend, test_build_dir) build_start = time.time() @@ -356,9 +361,8 @@ def _run_test(testdir, test_build_dir, install_dir, extra_args, compiler, backen if pc.returncode != 0: return TestResult('Compiling source code failed.', BuildStep.build, stdo, stde, mesonlog, gen_time, build_time) # Touch the meson.build file to force a regenerate so we can test that - # regeneration works. We need to sleep for 0.2s because Ninja tracks mtimes - # at a low resolution: https://github.com/ninja-build/ninja/issues/371 - time.sleep(0.2) + # regeneration works after a build is complete. + ensure_backend_detects_changes(backend) os.utime(os.path.join(testdir, 'meson.build')) test_start = time.time() # Test in-process diff --git a/run_tests.py b/run_tests.py index d0a67e8df..a374839be 100755 --- a/run_tests.py +++ b/run_tests.py @@ -16,6 +16,7 @@ import os import sys +import time import shutil import subprocess import platform @@ -98,6 +99,13 @@ def get_backend_commands(backend, debug=False): raise AssertionError('Unknown backend: {!r}'.format(backend)) return cmd, clean_cmd, test_cmd, install_cmd, uninstall_cmd +def ensure_backend_detects_changes(backend): + # This is needed to increase the difference between build.ninja's + # timestamp and the timestamp of whatever you changed due to a Ninja + # bug: https://github.com/ninja-build/ninja/issues/371 + if backend is Backend.ninja: + time.sleep(1) + def get_fake_options(prefix): import argparse opts = argparse.Namespace() diff --git a/run_unittests.py b/run_unittests.py index d285e6a53..ed98cad6b 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -30,6 +30,7 @@ from mesonbuild.dependencies import PkgConfigDependency, ExternalProgram from run_tests import exe_suffix, get_fake_options, FakeEnvironment from run_tests import get_builddir_target_args, get_backend_commands, Backend +from run_tests import ensure_backend_detects_changes def get_soname(fname): @@ -355,13 +356,6 @@ class BasePlatformTests(unittest.TestCase): # XCode backend is untested with unit tests, help welcome! self.no_rebuild_stdout = 'UNKNOWN BACKEND {!r}'.format(self.backend.name) - def ensure_backend_detects_changes(self): - # This is needed to increase the difference between build.ninja's - # timestamp and the timestamp of whatever you changed due to a Ninja - # bug: https://github.com/ninja-build/ninja/issues/371 - if self.backend is Backend.ninja: - time.sleep(1) - def _print_meson_log(self): log = os.path.join(self.logdir, 'meson-log.txt') if not os.path.isfile(log): @@ -439,14 +433,14 @@ class BasePlatformTests(unittest.TestCase): def setconf(self, arg, will_build=True): if will_build: - self.ensure_backend_detects_changes() + ensure_backend_detects_changes(self.backend) self._run(self.mconf_command + [arg, self.builddir]) def wipe(self): shutil.rmtree(self.builddir) def utime(self, f): - self.ensure_backend_detects_changes() + ensure_backend_detects_changes(self.backend) os.utime(f) def get_compdb(self):