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.
This commit is contained in:
Daan De Meyer 2024-04-24 21:18:27 +02:00
parent ff4fe9dee2
commit cf5e1b5d39
4 changed files with 42 additions and 43 deletions

View file

@ -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)

View file

@ -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.

View file

@ -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)

View file

@ -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')
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,
}
# 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
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,
}
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']
# 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
# 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