From 1da030e6e1f8e488d292ef15ebf6b4eb78615aa6 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 2 Apr 2025 20:43:41 +0200 Subject: [PATCH 1/2] test: Unset JOURNAL_STREAM for integration test units We use StandardOutput=journal+console for integration test units to make sure the output from the test ends up on both the serial console and in the journal. Unfortunately this only works for messages written to stdout/stderr of the test service. All journal messages logged by systemd tools will only end up in the journal and not on the serial console. This makes test failures harder to debug than needed because developers have to fetch the journal to figure out the actual error that was logged by any systemd tool that failed when invoked from the integration test script. To fix this, let's unset $JOURNAL_STREAM for the integration test units. This forces all output to go through stdout, which will make journald forward it to the console and save it in the journal. --- test/test.service.in | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test.service.in b/test/test.service.in index 223df0399a..a2e60afa4d 100644 --- a/test/test.service.in +++ b/test/test.service.in @@ -10,3 +10,4 @@ ExecStart=@command@ Type=oneshot MemoryAccounting=@memory-accounting@ Environment=SYSTEMD_PAGER= @env@ +UnsetEnvironment=JOURNAL_STREAM From 48e19280b2e9d97e03821c8ecc85a55e745899f8 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 2 Apr 2025 21:58:59 +0200 Subject: [PATCH 2/2] test: Use test.service template for all integration tests Instead of having some tests have their own unit, let's make test.service.in generic enough so that it works for all integration tests. --- .../TEST-07-PID1/TEST-07-PID1.service | 15 ------- .../TEST-07-PID1/meson.build | 10 ++++- .../TEST-16-EXTEND-TIMEOUT.service | 21 ---------- .../TEST-16-EXTEND-TIMEOUT/meson.build | 15 ++++++- .../TEST-44-LOG-NAMESPACE.service | 10 ----- .../TEST-44-LOG-NAMESPACE/meson.build | 13 +++++- .../TEST-69-SHUTDOWN/TEST-69-SHUTDOWN.service | 11 ----- .../TEST-69-SHUTDOWN/meson.build | 4 +- .../TEST-82-SOFTREBOOT.service | 12 ------ .../TEST-82-SOFTREBOOT/meson.build | 10 ++++- test/integration-tests/meson.build | 9 ++-- test/meson.build | 42 +++++++++++-------- test/test.service.in | 2 + 13 files changed, 74 insertions(+), 100 deletions(-) delete mode 100644 test/integration-tests/TEST-07-PID1/TEST-07-PID1.service delete mode 100644 test/integration-tests/TEST-16-EXTEND-TIMEOUT/TEST-16-EXTEND-TIMEOUT.service delete mode 100644 test/integration-tests/TEST-44-LOG-NAMESPACE/TEST-44-LOG-NAMESPACE.service delete mode 100644 test/integration-tests/TEST-69-SHUTDOWN/TEST-69-SHUTDOWN.service delete mode 100644 test/integration-tests/TEST-82-SOFTREBOOT/TEST-82-SOFTREBOOT.service diff --git a/test/integration-tests/TEST-07-PID1/TEST-07-PID1.service b/test/integration-tests/TEST-07-PID1/TEST-07-PID1.service deleted file mode 100644 index f2c8697e5b..0000000000 --- a/test/integration-tests/TEST-07-PID1/TEST-07-PID1.service +++ /dev/null @@ -1,15 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-07-PID1 -Wants=basic.target multi-user.target -After=basic.target - -[Service] -Type=oneshot -ExecStartPre=rm -f /failed /testok -ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh -NotifyAccess=all -# Issue: https://github.com/systemd/systemd/issues/2691 -ExecStop=sh -c 'kill -SEGV $$$$' -RemainAfterExit=yes -TimeoutStopSec=270s diff --git a/test/integration-tests/TEST-07-PID1/meson.build b/test/integration-tests/TEST-07-PID1/meson.build index 3b31782108..678fc5f0ec 100644 --- a/test/integration-tests/TEST-07-PID1/meson.build +++ b/test/integration-tests/TEST-07-PID1/meson.build @@ -3,6 +3,14 @@ integration_tests += [ integration_test_template + { 'name' : fs.name(meson.current_source_dir()), - 'unit' : files('TEST-07-PID1.service'), + 'configuration' : integration_test_template['configuration'] + { + 'service' : integration_test_template['configuration']['service'] + { + 'NotifyAccess' : 'all', + # Issue: https://github.com/systemd/systemd/issues/2691 + 'ExecStop' : 'sh -c \'kill -SEGV $$$$\'', + 'RemainAfterExit' : 'yes', + 'TimeoutStopSec' : '270s', + }, + }, }, ] diff --git a/test/integration-tests/TEST-16-EXTEND-TIMEOUT/TEST-16-EXTEND-TIMEOUT.service b/test/integration-tests/TEST-16-EXTEND-TIMEOUT/TEST-16-EXTEND-TIMEOUT.service deleted file mode 100644 index 3189a2484a..0000000000 --- a/test/integration-tests/TEST-16-EXTEND-TIMEOUT/TEST-16-EXTEND-TIMEOUT.service +++ /dev/null @@ -1,21 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-16-EXTEND-TIMEOUT -# Testsuite: Assess all other testsuite-*.services worked as expected - -Wants=basic.target multi-user.target -After=basic.target - -Wants=success-all.service -Wants=success-start.service -Wants=success-runtime.service -Wants=success-stop.service -Wants=fail-start.service -Wants=fail-stop.service -Wants=fail-runtime.service -StopWhenUnneeded=yes - -[Service] -ExecStartPre=rm -f /failed /testok -Type=oneshot -ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh diff --git a/test/integration-tests/TEST-16-EXTEND-TIMEOUT/meson.build b/test/integration-tests/TEST-16-EXTEND-TIMEOUT/meson.build index e18b847471..a7eac125e3 100644 --- a/test/integration-tests/TEST-16-EXTEND-TIMEOUT/meson.build +++ b/test/integration-tests/TEST-16-EXTEND-TIMEOUT/meson.build @@ -3,7 +3,20 @@ integration_tests += [ integration_test_template + { 'name' : fs.name(meson.current_source_dir()), - 'unit' : files('TEST-16-EXTEND-TIMEOUT.service'), + 'configuration' : integration_test_template['configuration'] + { + 'unit' : integration_test_template['configuration']['unit'] + { + 'Wants' : ' '.join([ + 'success-all.service', + 'success-start.service', + 'success-runtime.service', + 'success-stop.service', + 'fail-start.service', + 'fail-stop.service', + 'fail-runtime.service', + ]), + 'StopWhenUnneeded' : 'yes', + }, + }, 'coredump-exclude-regex' : '/(bash|sleep)$', }, ] diff --git a/test/integration-tests/TEST-44-LOG-NAMESPACE/TEST-44-LOG-NAMESPACE.service b/test/integration-tests/TEST-44-LOG-NAMESPACE/TEST-44-LOG-NAMESPACE.service deleted file mode 100644 index bed66fa003..0000000000 --- a/test/integration-tests/TEST-44-LOG-NAMESPACE/TEST-44-LOG-NAMESPACE.service +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-44-LOG-NAMESPACE -Wants=basic.target multi-user.target systemd-journald@foobar.socket systemd-journald-varlink@foobar.socket -After=basic.target systemd-journald@foobar.socket systemd-journald-varlink@foobar.socket - -[Service] -ExecStartPre=rm -f /failed /testok -ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh -Type=oneshot diff --git a/test/integration-tests/TEST-44-LOG-NAMESPACE/meson.build b/test/integration-tests/TEST-44-LOG-NAMESPACE/meson.build index 555ba7befd..6a33a8bd18 100644 --- a/test/integration-tests/TEST-44-LOG-NAMESPACE/meson.build +++ b/test/integration-tests/TEST-44-LOG-NAMESPACE/meson.build @@ -3,6 +3,17 @@ integration_tests += [ integration_test_template + { 'name' : fs.name(meson.current_source_dir()), - 'unit' : files('TEST-44-LOG-NAMESPACE.service'), + 'configuration' : integration_test_template['configuration'] + { + 'unit' : integration_test_template['configuration']['unit'] + { + 'Wants' : ' '.join([ + 'systemd-journald@foobar.socket', + 'systemd-journald-varlink@foobar.socket', + ]), + 'After' : ' '.join([ + 'systemd-journald@foobar.socket', + 'systemd-journald-varlink@foobar.socket', + ]), + }, + }, }, ] diff --git a/test/integration-tests/TEST-69-SHUTDOWN/TEST-69-SHUTDOWN.service b/test/integration-tests/TEST-69-SHUTDOWN/TEST-69-SHUTDOWN.service deleted file mode 100644 index 7b47b61893..0000000000 --- a/test/integration-tests/TEST-69-SHUTDOWN/TEST-69-SHUTDOWN.service +++ /dev/null @@ -1,11 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-69-SHUTDOWN -Wants=basic.target multi-user.target -After=basic.target - -ConditionPathExists=/usr/bin/python3 - -[Service] -Type=oneshot -ExecStart=/usr/lib/systemd/tests/testdata/units/TEST-69-SHUTDOWN.py diff --git a/test/integration-tests/TEST-69-SHUTDOWN/meson.build b/test/integration-tests/TEST-69-SHUTDOWN/meson.build index c1b1ab557f..edc0abfb87 100644 --- a/test/integration-tests/TEST-69-SHUTDOWN/meson.build +++ b/test/integration-tests/TEST-69-SHUTDOWN/meson.build @@ -3,10 +3,8 @@ integration_tests += [ integration_test_template + { 'name' : fs.name(meson.current_source_dir()), - 'unit' : files('TEST-69-SHUTDOWN.service'), 'configuration' : integration_test_template['configuration'] + { - 'wants' : '@0@ systemd-user-sessions.service'.format(integration_test_template['configuration']['wants']), - 'after' : '@0@ systemd-user-sessions.service'.format(integration_test_template['configuration']['after']), + 'command' : '/usr/lib/systemd/tests/testdata/units/%N.py', }, }, ] diff --git a/test/integration-tests/TEST-82-SOFTREBOOT/TEST-82-SOFTREBOOT.service b/test/integration-tests/TEST-82-SOFTREBOOT/TEST-82-SOFTREBOOT.service deleted file mode 100644 index d9c4529412..0000000000 --- a/test/integration-tests/TEST-82-SOFTREBOOT/TEST-82-SOFTREBOOT.service +++ /dev/null @@ -1,12 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-82-SOFTREBOOT -DefaultDependencies=no -Wants=basic.target multi-user.target -After=basic.target - -[Service] -Type=oneshot -ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh -FileDescriptorStoreMax=3 -NotifyAccess=all diff --git a/test/integration-tests/TEST-82-SOFTREBOOT/meson.build b/test/integration-tests/TEST-82-SOFTREBOOT/meson.build index a7c1bf0bd5..3e3f7767c6 100644 --- a/test/integration-tests/TEST-82-SOFTREBOOT/meson.build +++ b/test/integration-tests/TEST-82-SOFTREBOOT/meson.build @@ -3,7 +3,15 @@ integration_tests += [ integration_test_template + { 'name' : fs.name(meson.current_source_dir()), - 'unit' : files('TEST-82-SOFTREBOOT.service'), + 'configuration' : integration_test_template['configuration'] + { + 'unit' : integration_test_template['configuration']['unit'] + { + 'DefaultDependencies' : 'no', + }, + 'service' : integration_test_template['configuration']['service'] + { + 'FileDescriptorStoreMax' : '3', + 'NotifyAccess' : 'all', + }, + }, 'cmdline' : ['systemd.set_credential=kernelcmdlinecred:uff'], 'storage' : 'persistent', 'vm' : true, diff --git a/test/integration-tests/meson.build b/test/integration-tests/meson.build index 3afbeac1e4..1980acc10c 100644 --- a/test/integration-tests/meson.build +++ b/test/integration-tests/meson.build @@ -15,6 +15,8 @@ integration_test_template = { 'wants' : 'multi-user.target user@4711.service', 'after' : 'user@4711.service', 'env' : {}, + 'service' : {}, + 'unit' : {}, }, 'cmdline' : [], 'credentials' : [], @@ -109,14 +111,9 @@ foreach integration_test : integration_tests '--exit-code', integration_test['exit-code'].to_string(), '--coredump-exclude-regex', integration_test['coredump-exclude-regex'], '--sanitizer-exclude-regex', integration_test['sanitizer-exclude-regex'], + '--unit', '@0@.service'.format(integration_test['name']) ] - if 'unit' in integration_test - integration_test_args += ['--unit', fs.name(integration_test['unit'])] - else - integration_test_args += ['--unit', '@0@.service'.format(integration_test['name'])] - endif - if integration_test['vm'] integration_test_args += ['--vm'] endif diff --git a/test/meson.build b/test/meson.build index b23553e34a..68bffdb282 100644 --- a/test/meson.build +++ b/test/meson.build @@ -283,27 +283,33 @@ endif if install_tests foreach integration_test : integration_tests - if 'unit' in integration_test - integration_test_unit = integration_test['unit'] - else - integration_test_unit_env = [] + integration_test_unit_env = [] + integration_test_extra_unit_properties = [] + integration_test_extra_service_properties = [] - foreach key, value : integration_test['configuration']['env'] - integration_test_unit_env += [f'@key@=@value@'] - endforeach + foreach key, value : integration_test['configuration']['env'] + integration_test_unit_env += [f'@key@=@value@'] + endforeach - integration_test_unit = configure_file( - input : 'test.service.in', - output : '@0@.service'.format(integration_test['name']), - configuration : integration_test['configuration'] + { - 'env' : ' '.join(integration_test_unit_env) - }, - ) - endif + foreach key, value : integration_test['configuration']['unit'] + integration_test_extra_unit_properties += [f'@key@=@value@'] + endforeach - if install_tests - install_data(integration_test_unit, install_dir : testdata_dir / 'units') - endif + foreach key, value : integration_test['configuration']['service'] + integration_test_extra_service_properties += [f'@key@=@value@'] + endforeach + + integration_test_unit = configure_file( + input : 'test.service.in', + output : '@0@.service'.format(integration_test['name']), + configuration : integration_test['configuration'] + { + 'env' : ' '.join(integration_test_unit_env), + 'unit' : '\n'.join(integration_test_extra_unit_properties), + 'service' : '\n'.join(integration_test_extra_service_properties), + }, + ) + + install_data(integration_test_unit, install_dir : testdata_dir / 'units') endforeach testdata_subdirs = [ diff --git a/test/test.service.in b/test/test.service.in index a2e60afa4d..0d0dccdb75 100644 --- a/test/test.service.in +++ b/test/test.service.in @@ -3,6 +3,7 @@ Description=%N Wants=basic.target network.target @wants@ After=basic.target network.target @after@ +@unit@ [Service] ExecStartPre=rm -f /failed /testok @@ -11,3 +12,4 @@ Type=oneshot MemoryAccounting=@memory-accounting@ Environment=SYSTEMD_PAGER= @env@ UnsetEnvironment=JOURNAL_STREAM +@service@