From: Frantisek Sumsal Date: Fri, 31 Mar 2023 16:42:38 +0000 (+0200) Subject: test: set ReadWritePaths= for test-.services when built w/ coverage X-Git-Tag: v254-rc1~836^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e660c590a5222bc72f7aea8912806aa48b0fb126;p=thirdparty%2Fsystemd.git test: set ReadWritePaths= for test-.services when built w/ coverage Let's make the dropin, to make the build dir writable for gcov, a bit more generic, so it can be used by all units starting with prefix test-. This should help with a bunch of recent reports about missing coverage I got, as well as with existing test units using DynamicUser=true. This might feel a bit like a magic trick from behind the curtains, but I want to touch the actual tests as little as possible, since it makes them unnecessarily messy (see the various workarounds for sanitizers), and the coverage reports are generated only in a specific CI job anyway. --- diff --git a/test/TEST-78-SIGQUEUE/test.sh b/test/TEST-78-SIGQUEUE/test.sh index 80ce7926ab1..61e8e7d1c42 100755 --- a/test/TEST-78-SIGQUEUE/test.sh +++ b/test/TEST-78-SIGQUEUE/test.sh @@ -3,8 +3,6 @@ set -e TEST_DESCRIPTION="Test queue signal logic" -# Ignore gcov complaints caused by DynamicUser=true -IGNORE_MISSING_COVERAGE=yes # shellcheck source=test/test-functions . "$TEST_BASE_DIR/test-functions" diff --git a/test/TEST-79-MEMPRESS/test.sh b/test/TEST-79-MEMPRESS/test.sh index 95c8581238f..4f9c896492e 100755 --- a/test/TEST-79-MEMPRESS/test.sh +++ b/test/TEST-79-MEMPRESS/test.sh @@ -3,8 +3,6 @@ set -e TEST_DESCRIPTION="Test Memory Pressure handling" -# Ignore gcov complaints caused by DynamicUser=true -IGNORE_MISSING_COVERAGE=yes # shellcheck source=test/test-functions . "$TEST_BASE_DIR/test-functions" diff --git a/test/test-functions b/test/test-functions index 1a4e42f575d..906cac8e80f 100644 --- a/test/test-functions +++ b/test/test-functions @@ -1240,11 +1240,14 @@ install_systemd() { mkdir -p "$initdir/etc/systemd/system/service.d/" echo -e "[Service]\nProtectSystem=no\nProtectHome=no\n" >"$initdir/etc/systemd/system/service.d/99-gcov-override.conf" # Similarly, set ReadWritePaths= to the $BUILD_DIR in the test image - # to make the coverage work with units utilizing DynamicUser=yes. Do - # this only for services from TEST-20, as setting this system-wide - # has many undesirable side-effects - mkdir -p "$initdir/etc/systemd/system/test20-.service.d/" - echo -e "[Service]\nReadWritePaths=${BUILD_DIR:?}\n" >"$initdir/etc/systemd/system/test20-.service.d/99-gcov-rwpaths-override.conf" + # to make the coverage work with units using DynamicUser=yes. Do this + # only for services with test- prefix, as setting this system-wide + # has many undesirable side-effects, as it creates its own namespace. + mkdir -p "$initdir/etc/systemd/system/test-.service.d/" + echo -e "[Service]\nReadWritePaths=${BUILD_DIR:?}\n" >"$initdir/etc/systemd/system/test-.service.d/99-gcov-rwpaths-override.conf" + # Ditto, but for the user daemon + mkdir -p "$initdir/etc/systemd/user/test-.service.d/" + echo -e "[Service]\nReadWritePaths=${BUILD_DIR:?}\n" >"$initdir/etc/systemd/user/test-.service.d/99-gcov-rwpaths-override.conf" fi # If we're built with -Dportabled=false, tests with systemd-analyze diff --git a/test/units/testsuite-19.sh b/test/units/testsuite-19.sh index 6ce6d3d4291..1e705ea72bf 100755 --- a/test/units/testsuite-19.sh +++ b/test/units/testsuite-19.sh @@ -7,37 +7,37 @@ test_scope_unpriv_delegation() { useradd test ||: trap "userdel -r test" RETURN - systemd-run --uid=test -p User=test -p Delegate=yes --slice workload.slice --unit workload0.scope --scope \ - test -w /sys/fs/cgroup/workload.slice/workload0.scope -a \ - -w /sys/fs/cgroup/workload.slice/workload0.scope/cgroup.procs -a \ - -w /sys/fs/cgroup/workload.slice/workload0.scope/cgroup.subtree_control + systemd-run --uid=test -p User=test -p Delegate=yes --slice workload.slice --unit test-workload0.scope --scope \ + test -w /sys/fs/cgroup/workload.slice/test-workload0.scope -a \ + -w /sys/fs/cgroup/workload.slice/test-workload0.scope/cgroup.procs -a \ + -w /sys/fs/cgroup/workload.slice/test-workload0.scope/cgroup.subtree_control } if grep -q cgroup2 /proc/filesystems ; then - systemd-run --wait --unit=test0.service -p "DynamicUser=1" -p "Delegate=" \ - test -w /sys/fs/cgroup/system.slice/test0.service/ -a \ - -w /sys/fs/cgroup/system.slice/test0.service/cgroup.procs -a \ - -w /sys/fs/cgroup/system.slice/test0.service/cgroup.subtree_control + systemd-run --wait --unit=test-0.service -p "DynamicUser=1" -p "Delegate=" \ + test -w /sys/fs/cgroup/system.slice/test-0.service/ -a \ + -w /sys/fs/cgroup/system.slice/test-0.service/cgroup.procs -a \ + -w /sys/fs/cgroup/system.slice/test-0.service/cgroup.subtree_control - systemd-run --wait --unit=test1.service -p "DynamicUser=1" -p "Delegate=memory pids" \ - grep -q memory /sys/fs/cgroup/system.slice/test1.service/cgroup.controllers + systemd-run --wait --unit=test-1.service -p "DynamicUser=1" -p "Delegate=memory pids" \ + grep -q memory /sys/fs/cgroup/system.slice/test-1.service/cgroup.controllers - systemd-run --wait --unit=test2.service -p "DynamicUser=1" -p "Delegate=memory pids" \ - grep -q pids /sys/fs/cgroup/system.slice/test2.service/cgroup.controllers + systemd-run --wait --unit=test-2.service -p "DynamicUser=1" -p "Delegate=memory pids" \ + grep -q pids /sys/fs/cgroup/system.slice/test-2.service/cgroup.controllers # "io" is not among the controllers enabled by default for all units, verify that grep -qv io /sys/fs/cgroup/system.slice/cgroup.controllers # Run a service with "io" enabled, and verify it works - systemd-run --wait --unit=test3.service -p "IOAccounting=yes" -p "Slice=system-foo-bar-baz.slice" \ - grep -q io /sys/fs/cgroup/system.slice/system-foo.slice/system-foo-bar.slice/system-foo-bar-baz.slice/test3.service/cgroup.controllers + systemd-run --wait --unit=test-3.service -p "IOAccounting=yes" -p "Slice=system-foo-bar-baz.slice" \ + grep -q io /sys/fs/cgroup/system.slice/system-foo.slice/system-foo-bar.slice/system-foo-bar-baz.slice/test-3.service/cgroup.controllers # We want to check if "io" is removed again from the controllers # list. However, PID 1 (rightfully) does this asynchronously. In order # to force synchronization on this, let's start a short-lived service # which requires PID 1 to refresh the cgroup tree, so that we can # verify that this all works. - systemd-run --wait --unit=test4.service true + systemd-run --wait --unit=test-4.service true # And now check again, "io" should have vanished grep -qv io /sys/fs/cgroup/system.slice/cgroup.controllers diff --git a/test/units/testsuite-20.sh b/test/units/testsuite-20.sh index 338769aacc5..0f8b2ea9286 100755 --- a/test/units/testsuite-20.sh +++ b/test/units/testsuite-20.sh @@ -13,8 +13,8 @@ INTERNALPID=$! disown # Start a test process outside of our own cgroup -systemd-run -p DynamicUser=1 --unit=test20-sleep.service /bin/sleep infinity -EXTERNALPID="$(systemctl show -P MainPID test20-sleep.service)" +systemd-run -p DynamicUser=1 --unit=test-sleep.service /bin/sleep infinity +EXTERNALPID="$(systemctl show -P MainPID test-sleep.service)" # Update our own main PID to the external test PID, this should work systemd-notify MAINPID="$EXTERNALPID" @@ -54,7 +54,7 @@ test "$(systemctl show -P MainPID testsuite-20.service)" -eq "$INTERNALPID" systemd-notify --uid=1000 MAINPID=$$ test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$ -cat >/tmp/test20-mainpid.sh </tmp/test-mainpid.sh </run/mainpidsh/pid EOF -chmod +x /tmp/test20-mainpid.sh +chmod +x /tmp/test-mainpid.sh -systemd-run --unit=test20-mainpidsh.service -p StandardOutput=tty -p StandardError=tty -p Type=forking -p RuntimeDirectory=mainpidsh -p PIDFile=/run/mainpidsh/pid /tmp/test20-mainpid.sh -test "$(systemctl show -P MainPID test20-mainpidsh.service)" -eq "$(cat /run/mainpidsh/pid)" +systemd-run --unit=test-mainpidsh.service -p StandardOutput=tty -p StandardError=tty -p Type=forking -p RuntimeDirectory=mainpidsh -p PIDFile=/run/mainpidsh/pid /tmp/test-mainpid.sh +test "$(systemctl show -P MainPID test-mainpidsh.service)" -eq "$(cat /run/mainpidsh/pid)" -cat >/tmp/test20-mainpid2.sh </tmp/test-mainpid2.sh </run/mainpidsh2/pid chown 1001:1001 /run/mainpidsh2/pid EOF -chmod +x /tmp/test20-mainpid2.sh +chmod +x /tmp/test-mainpid2.sh -systemd-run --unit=test20-mainpidsh2.service -p StandardOutput=tty -p StandardError=tty -p Type=forking -p RuntimeDirectory=mainpidsh2 -p PIDFile=/run/mainpidsh2/pid /tmp/test20-mainpid2.sh -test "$(systemctl show -P MainPID test20-mainpidsh2.service)" -eq "$(cat /run/mainpidsh2/pid)" +systemd-run --unit=test-mainpidsh2.service -p StandardOutput=tty -p StandardError=tty -p Type=forking -p RuntimeDirectory=mainpidsh2 -p PIDFile=/run/mainpidsh2/pid /tmp/test-mainpid2.sh +test "$(systemctl show -P MainPID test-mainpidsh2.service)" -eq "$(cat /run/mainpidsh2/pid)" -cat >/dev/shm/test20-mainpid3.sh </dev/shm/test-mainpid3.sh </etc/systemd/system/testservice.service </etc/systemd/system/test-service.service </etc/systemd/system/testservice.service </etc/systemd/system/test-service.service </etc/systemd/system/tmp-hoge.mount </etc/systemd/system/testservice.socket </etc/systemd/system/test-service.socket </testok diff --git a/test/units/testsuite-54.sh b/test/units/testsuite-54.sh index dd7e28392d2..43049dea508 100755 --- a/test/units/testsuite-54.sh +++ b/test/units/testsuite-54.sh @@ -10,6 +10,7 @@ systemd-run -p LoadCredential=passwd:/etc/passwd \ -p LoadCredential=shadow:/etc/shadow \ -p SetCredential=dog:wuff \ -p DynamicUser=1 \ + --unit=test-54-unpriv.service \ --wait \ --pipe \ cat '${CREDENTIALS_DIRECTORY}/passwd' '${CREDENTIALS_DIRECTORY}/shadow' '${CREDENTIALS_DIRECTORY}/dog' >/tmp/ts54-concat @@ -77,11 +78,13 @@ fi # Verify that the creds are immutable systemd-run -p LoadCredential=passwd:/etc/passwd \ -p DynamicUser=1 \ + --unit=test-54-immutable-touch.service \ --wait \ touch '${CREDENTIALS_DIRECTORY}/passwd' \ && { echo 'unexpected success'; exit 1; } systemd-run -p LoadCredential=passwd:/etc/passwd \ -p DynamicUser=1 \ + --unit=test-54-immutable-rm.service \ --wait \ rm '${CREDENTIALS_DIRECTORY}/passwd' \ && { echo 'unexpected success'; exit 1; } @@ -94,6 +97,7 @@ echo -n c >/tmp/ts54-creds/baz echo -n d >/tmp/ts54-creds/sub/qux systemd-run -p LoadCredential=cred:/tmp/ts54-creds \ -p DynamicUser=1 \ + --unit=test-54-dir.service \ --wait \ --pipe \ cat '${CREDENTIALS_DIRECTORY}/cred_foo' \