From cf5e1b5d39ce6ea6a47dcd8db5b87b470cf437d1 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 24 Apr 2024 21:18:27 +0200 Subject: [PATCH] test: Skip meson integration tests if SYSTEMD_INTEGRATION_TESTS != 1 We cannot mark a test suite as excluded by default in meson. Instead, let's require that SYSTEMD_INTEGRATION_TESTS=1 and skip any integration test if it's not set. This is effectively the same as excluding it by default. If the integration-test option is enabled, we'll set the environment variable by default, just like we do with SYSTEMD_SLOW_TESTS and the slow-tests meson option. --- src/test/meson.build | 1 + test/README.testsuite | 8 ++-- test/integration-test-wrapper.py | 4 ++ test/meson.build | 74 +++++++++++++++----------------- 4 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/test/meson.build b/src/test/meson.build index 69b2b1e5878..a452021f626 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -15,6 +15,7 @@ test_env.set('SYSTEMD_LANGUAGE_FALLBACK_MAP', language_fallback_map) test_env.set('PATH', project_build_root + ':' + path) test_env.set('PROJECT_BUILD_ROOT', project_build_root) test_env.set('SYSTEMD_SLOW_TESTS', slow_tests ? '1' : '0') +test_env.set('SYSTEMD_INTEGRATION_TESTS', integration_tests ? '1' : '0') if efi_addon != '' test_env.set('EFI_ADDON', efi_addon) diff --git a/test/README.testsuite b/test/README.testsuite index 7dcb602e84f..91cafeb58e0 100644 --- a/test/README.testsuite +++ b/test/README.testsuite @@ -31,7 +31,7 @@ $ sudo make -C test/TEST-01-BASIC clean setup run To run the meson-based integration test config enable integration tests and options for required commands with the following: -$ meson configure build -Dintegration-tests=true -Dremote=enabled -Dopenssl=enabled -Dblkid=enabled -Dtpm2=enabled +$ meson configure build -Dremote=enabled -Dopenssl=enabled -Dblkid=enabled -Dtpm2=enabled Once enabled, first build the integration test image: @@ -39,18 +39,18 @@ $ meson compile -C build mkosi After the image has been built, the integration tests can be run with: -$ meson test -C build/ --suite integration-tests --num-processes "$(($(nproc) / 2))" +$ SYSTEMD_INTEGRATION_TESTS=1 meson test -C build/ --suite integration-tests --num-processes "$(($(nproc) / 2))" As usual, specific tests can be run in meson by appending the name of the test which is usually the name of the directory e.g. -$ meson test -C build/ -v TEST-01-BASIC +$ SYSTEMD_INTEGRATION_TESTS=1 meson test -C build/ -v TEST-01-BASIC Due to limitations in meson, the integration tests do not yet depend on the mkosi target, which means the mkosi target has to be manually rebuilt before running the integration tests. To rebuild the image and rerun a test, the following command can be used: -$ meson compile -C build mkosi && meson test -C build -v TEST-01-BASIC +$ meson compile -C build mkosi && SYSTEMD_INTEGRATION_TESTS=1 meson test -C build -v TEST-01-BASIC See `meson introspect build --tests` for a list of tests. diff --git a/test/integration-test-wrapper.py b/test/integration-test-wrapper.py index f3c7fe5b855..4465576c5bc 100755 --- a/test/integration-test-wrapper.py +++ b/test/integration-test-wrapper.py @@ -38,6 +38,10 @@ ExecStart=false def main(): + if not bool(int(os.getenv("SYSTEMD_INTEGRATION_TESTS", "0"))): + print("SYSTEMD_INTEGRATION_TESTS=1 not found in environment, skipping", file=sys.stderr) + exit(77) + parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--meson-source-dir', required=True, type=Path) parser.add_argument('--meson-build-dir', required=True, type=Path) diff --git a/test/meson.build b/test/meson.build index 8e0d11682ec..bd25e94276c 100644 --- a/test/meson.build +++ b/test/meson.build @@ -334,45 +334,39 @@ endif ############################################################ -if get_option('integration-tests') - if not mkosi.found() - error('Could not find mkosi which is required to run the integration tests') - endif - - integration_test_wrapper = find_program('integration-test-wrapper.py') - integration_tests = { - '01': 'TEST-01-BASIC', - '02': 'TEST-02-UNITTESTS', +integration_test_wrapper = find_program('integration-test-wrapper.py') +integration_tests = { + '01': 'TEST-01-BASIC', + '02': 'TEST-02-UNITTESTS', +} +foreach test_number, dirname : integration_tests + test_params = { + 'mkosi_args' : [], + 'timeout' : 600, } - foreach test_number, dirname : integration_tests - test_params = { - 'mkosi_args' : [], - 'timeout' : 600, - } - - # TODO: This fs.exists call isn't included in rebuild logic - # so if you add a new meson.build in a subdir - # you need to touch another build file to get it to reparse. - if fs.exists(dirname / 'meson.build') - subdir(dirname) - endif - args = [ - '--meson-source-dir', meson.project_source_root(), - '--meson-build-dir', meson.project_build_root(), - '--test-name', dirname, - '--test-number', test_number, - '--', - ] + test_params['mkosi_args'] - - # We don't explicitly depend on the "mkosi" target because that means the image is rebuilt - # on every "ninja -C build". Instead, the mkosi target has to be rebuilt manually before - # running the integration tests with mkosi. - test(dirname, - integration_test_wrapper, - env: test_env, - args : args, - timeout : test_params['timeout'], - suite : 'integration-tests') - endforeach -endif + # TODO: This fs.exists call isn't included in rebuild logic + # so if you add a new meson.build in a subdir + # you need to touch another build file to get it to reparse. + if fs.exists(dirname / 'meson.build') + subdir(dirname) + endif + + args = [ + '--meson-source-dir', meson.project_source_root(), + '--meson-build-dir', meson.project_build_root(), + '--test-name', dirname, + '--test-number', test_number, + '--', + ] + test_params['mkosi_args'] + + # We don't explicitly depend on the "mkosi" target because that means the image is rebuilt + # on every "ninja -C build". Instead, the mkosi target has to be rebuilt manually before + # running the integration tests with mkosi. + test(dirname, + integration_test_wrapper, + env: test_env, + args : args, + timeout : test_params['timeout'], + suite : 'integration-tests') +endforeach -- 2.47.3