Skip to content

Commit 710653d

Browse files
committed
test: Use meson add_test_setup() instead of environment variables
We add a default test setup that excludes the integration-tests suite so that the integration tests don't run by default. This allows us to get rid of $SYSTEMD_INTEGRATION_TESTS. Then, we add two extra setups: 'integration' and 'shell'. The 'integration' setup does not exclude the integration-tests suite, and so can be used to run the integration tests. The 'shell' setup does the same, but additionally sets $TEST_SHELL=1, allowing to get rid of $TEST_SHELL in the docs.
1 parent d9826d3 commit 710653d

File tree

8 files changed

+31
-39
lines changed

8 files changed

+31
-39
lines changed

.github/workflows/coverage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ jobs:
9090
sudo mkosi sandbox -- \
9191
meson setup \
9292
--buildtype=debugoptimized \
93-
-Dintegration-tests=true \
9493
build
9594
9695
- name: Build image
@@ -120,7 +119,8 @@ jobs:
120119
meson test \
121120
-C build \
122121
--no-rebuild \
123-
--suite integration-tests \
122+
--setup=integration \
123+
--suite=integration-tests \
124124
--print-errorlogs \
125125
--no-stdsplit \
126126
--num-processes "$(($(nproc) - 1))" \

.github/workflows/mkosi.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ jobs:
197197
sudo mkosi sandbox -- \
198198
meson setup \
199199
--buildtype=debugoptimized \
200-
-Dintegration-tests=true \
201200
-Dbpf-framework=disabled \
202201
build
203202
@@ -233,7 +232,8 @@ jobs:
233232
meson test \
234233
-C build \
235234
--no-rebuild \
236-
--suite integration-tests \
235+
--setup=integration \
236+
--suite=integration-tests \
237237
--print-errorlogs \
238238
--no-stdsplit \
239239
--num-processes "$(($(nproc) - 1))" \

meson.build

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ project('systemd', 'c',
1313
meson_version : '>= 0.62.0',
1414
)
1515

16+
add_test_setup(
17+
'default',
18+
exclude_suites : ['integration-tests'],
19+
is_default : true,
20+
)
21+
1622
project_major_version = meson.project_version().split('.')[0].split('~')[0]
1723
if meson.project_version().contains('.')
1824
project_minor_version = meson.project_version().split('.')[-1].split('~')[0]
@@ -339,7 +345,6 @@ meson_build_sh = find_program('tools/meson-build.sh')
339345
want_tests = get_option('tests')
340346
want_slow_tests = want_tests != 'false' and get_option('slow-tests')
341347
want_fuzz_tests = want_tests != 'false' and get_option('fuzz-tests')
342-
want_integration_tests = want_tests != 'false' and get_option('integration-tests')
343348
install_tests = want_tests != 'false' and get_option('install-tests')
344349

345350
if add_languages('cpp', native : false, required : fuzzer_build)
@@ -2661,10 +2666,6 @@ endif
26612666
#####################################################################
26622667

26632668
mkosi = find_program('mkosi', required : false)
2664-
if want_integration_tests and not mkosi.found()
2665-
error('Could not find mkosi which is required to run the integration tests')
2666-
endif
2667-
26682669
mkosi_depends = public_programs
26692670

26702671
foreach executable : ['systemd-journal-remote', 'systemd-sbsign', 'systemd-keyutil']

meson_options.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ option('install-tests', type : 'boolean', value : false,
509509
description : 'install test executables')
510510
option('log-message-verification', type : 'feature', deprecated : { 'true' : 'enabled', 'false' : 'disabled' },
511511
description : 'do fake printf() calls to verify format strings')
512-
option('integration-tests', type : 'boolean', value : false,
512+
option('integration-tests', type : 'boolean', value : false, deprecated : true,
513513
description : 'run the integration tests')
514514

515515
option('ok-color', type : 'combo',

test/integration-tests/README.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ directory (`OutputDirectory=`) to point to the other directory using `mkosi/mkos
3838
After the image has been built, the integration tests can be run with:
3939

4040
```shell
41-
$ env SYSTEMD_INTEGRATION_TESTS=1 mkosi -f sandbox -- meson test -C build --suite integration-tests --num-processes "$(($(nproc) / 4))"
41+
$ mkosi -f sandbox -- meson test -C build --setup=integration --suite integration-tests --num-processes "$(($(nproc) / 4))"
4242
```
4343

4444
As usual, specific tests can be run in meson by appending the name of the test
4545
which is usually the name of the directory e.g.
4646

4747
```shell
48-
$ env SYSTEMD_INTEGRATION_TESTS=1 mkosi -f sandbox -- meson test -C build -v TEST-01-BASIC
48+
$ mkosi -f sandbox -- meson test -C build --setup=integration -v TEST-01-BASIC
4949
```
5050

5151
See `mkosi -f sandbox -- meson introspect build --tests` for a list of tests.
@@ -55,7 +55,7 @@ To interactively debug a failing integration test, the `--interactive` option
5555
newer:
5656

5757
```shell
58-
$ env SYSTEMD_INTEGRATION_TESTS=1 mkosi -f sandbox -- meson test -C build -i TEST-01-BASIC
58+
$ mkosi -f sandbox -- meson test -C build --setup=integration -i TEST-01-BASIC
5959
```
6060

6161
Due to limitations in meson, the integration tests do not yet depend on the
@@ -64,7 +64,7 @@ running the integration tests. To rebuild the image and rerun a test, the
6464
following command can be used:
6565

6666
```shell
67-
$ mkosi -f sandbox -- meson compile -C build mkosi && env SYSTEMD_INTEGRATION_TESTS=1 mkosi -f sandbox -- meson test -C build -v TEST-01-BASIC
67+
$ mkosi -f sandbox -- meson compile -C build mkosi && mkosi -f sandbox -- meson test -C build --setup=integration -v TEST-01-BASIC
6868
```
6969

7070
The integration tests use the same mkosi configuration that's used when you run
@@ -78,7 +78,7 @@ To iterate on an integration test, let's first get a shell in the integration te
7878
the following:
7979

8080
```shell
81-
$ mkosi -f sandbox -- meson compile -C build mkosi && env SYSTEMD_INTEGRATION_TESTS=1 TEST_SHELL=1 mkosi -f sandbox -- meson test -C build -i TEST-01-BASIC
81+
$ mkosi -f sandbox -- meson compile -C build mkosi && mkosi -f sandbox -- meson test -C build --setup=shell -i TEST-01-BASIC
8282
```
8383

8484
This will get us a shell in the integration test environment after booting the machine without running the
@@ -107,7 +107,7 @@ re-running the test will first install the new packages we just built, make a ne
107107
the test again. You can keep running the loop of `mkosi -R`, `systemctl soft-reboot` and
108108
`systemctl start ...` until the changes to the integration test are working.
109109

110-
If you're debugging a failing integration test (running `meson test --interactive` without `TEST_SHELL`),
110+
If you're debugging a failing integration test (running `meson test --interactive`),
111111
there's no need to run `systemctl start ...`, running `systemctl soft-reboot` on its own is sufficient to
112112
rerun the test.
113113

@@ -120,10 +120,6 @@ rerun the test.
120120
`TEST_NO_KVM=1`: Disable qemu KVM auto-detection (may be necessary when you're
121121
trying to run the *vanilla* qemu and have both qemu and qemu-kvm installed)
122122

123-
`TEST_SHELL=1`: Configure the machine to be more *user-friendly* for
124-
interactive debugging (e.g. by setting a usable default terminal, suppressing
125-
the shutdown after the test, etc.).
126-
127123
`TEST_MATCH_SUBTEST=subtest`: If the test makes use of `run_subtests` use this
128124
variable to provide a POSIX extended regex to run only subtests matching the
129125
expression.

test/integration-tests/integration-test-wrapper.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def statfs(path: Path) -> str:
361361

362362
def main() -> None:
363363
parser = argparse.ArgumentParser(description=__doc__)
364-
parser.add_argument('--mkosi', required=True)
364+
parser.add_argument('--mkosi', default=None)
365365
parser.add_argument('--meson-source-dir', required=True, type=Path)
366366
parser.add_argument('--meson-build-dir', required=True, type=Path)
367367
parser.add_argument('--name', required=True)
@@ -379,6 +379,12 @@ def main() -> None:
379379
parser.add_argument('mkosi_args', nargs='*')
380380
args = parser.parse_args()
381381

382+
if not args.mkosi:
383+
args.mkosi = shutil.which('mkosi')
384+
if not args.mkosi:
385+
print('Could not find mkosi which is required to run the integration tests', file=sys.stderr)
386+
sys.exit(1)
387+
382388
# The meson source directory can either be the top-level repository directory or the
383389
# test/integration-tests/standalone subdirectory in the repository directory. The mkosi configuration
384390
# will always be a parent directory of one of these directories and at most 4 levels upwards, so don't
@@ -395,13 +401,6 @@ def main() -> None:
395401
)
396402
exit(1)
397403

398-
if not bool(int(os.getenv('SYSTEMD_INTEGRATION_TESTS', '0'))):
399-
print(
400-
f'SYSTEMD_INTEGRATION_TESTS=1 not found in environment, skipping {args.name}',
401-
file=sys.stderr,
402-
)
403-
exit(77)
404-
405404
if args.slow and not bool(int(os.getenv('SYSTEMD_SLOW_TESTS', '0'))):
406405
print(
407406
f'SYSTEMD_SLOW_TESTS=1 not found in environment, skipping {args.name}',

test/integration-tests/meson.build

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# SPDX-License-Identifier: LGPL-2.1-or-later
22

3+
# We'd give these more descriptive names but only alphanumeric characters are allowed.
4+
add_test_setup('integration')
5+
add_test_setup('shell', env : {'TEST_SHELL' : '1'})
6+
37
integration_test_wrapper = find_program('integration-test-wrapper.py')
48
integration_tests = []
59
integration_test_template = {
@@ -129,11 +133,11 @@ foreach integration_test : integration_tests
129133
integration_test_args += ['--skip']
130134
endif
131135

132-
if not mkosi.found()
133-
continue
136+
if mkosi.found()
137+
integration_test_args += ['--mkosi', mkosi.full_path()]
134138
endif
135139

136-
integration_test_args += ['--mkosi', mkosi.full_path(), '--']
140+
integration_test_args += ['--']
137141

138142
if integration_test['cmdline'].length() > 0
139143
integration_test_args += [
@@ -151,19 +155,12 @@ foreach integration_test : integration_tests
151155

152156
integration_test_args += integration_test['mkosi-args']
153157

154-
integration_test_env = {}
155-
156-
if want_integration_tests
157-
integration_test_env += {'SYSTEMD_INTEGRATION_TESTS': '1'}
158-
endif
159-
160158
# We don't explicitly depend on the "mkosi" target because that means the image is rebuilt on every
161159
# "ninja -C build". Instead, the mkosi target has to be rebuilt manually before running the
162160
# integration tests with mkosi.
163161
test(
164162
integration_test['name'],
165163
integration_test_wrapper,
166-
env : integration_test_env,
167164
args : integration_test_args,
168165
timeout : integration_test['timeout'],
169166
priority : integration_test['priority'],

test/integration-tests/standalone/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ project('systemd-testsuite',
1616

1717
fs = import('fs')
1818
mkosi = find_program('mkosi', required : true)
19-
want_integration_tests = true
2019

2120
# meson refuses .. in subdir() so we use a symlink to trick it into accepting it anyway.
2221
subdir('integration-tests')

0 commit comments

Comments
 (0)