From: Lennart Poettering Date: Wed, 3 May 2023 13:05:12 +0000 (+0200) Subject: test: add integration test for soft reboots incl. fdstore passing X-Git-Tag: v254-rc1~298^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=093d5456588004f5b710ae03c74c695e9f2b527d;p=thirdparty%2Fsystemd.git test: add integration test for soft reboots incl. fdstore passing --- diff --git a/test/TEST-82-SOFTREBOOT/Makefile b/test/TEST-82-SOFTREBOOT/Makefile new file mode 120000 index 00000000000..e9f93b1104c --- /dev/null +++ b/test/TEST-82-SOFTREBOOT/Makefile @@ -0,0 +1 @@ +../TEST-01-BASIC/Makefile \ No newline at end of file diff --git a/test/TEST-82-SOFTREBOOT/test.sh b/test/TEST-82-SOFTREBOOT/test.sh new file mode 100755 index 00000000000..9d88c94fb7e --- /dev/null +++ b/test/TEST-82-SOFTREBOOT/test.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -e + +TEST_DESCRIPTION="Test Soft-Rebooting" + +# shellcheck source=test/test-functions +. "$TEST_BASE_DIR/test-functions" + +test_append_files() { + local workspace="${1:?}" + # prevent shutdown in test suite, the expect script does that manually. + mkdir -p "${workspace:?}/etc/systemd/system/end.service.d" + cat >"$workspace/etc/systemd/system/end.service.d/99-override.conf" <"$T" + systemd-notify --fd=3 --pid=parent 3<"$T" + rm "$T" + + # Check that the surviving service is still around + test "$(systemctl show -P ActiveState testsuite-82-survive.service)" = "active" + test "$(systemctl show -P ActiveState testsuite-82-nosurvive.service)" != "active" + + # Test that we really are in the new overlayfs root fs + read -r x "$T" + systemd-notify --fd=3 --pid=parent 3<"$T" + rm "$T" + + # Check that the surviving service is still around + test "$(systemctl show -P ActiveState testsuite-82-survive.service)" = "active" + test "$(systemctl show -P ActiveState testsuite-82-nosurvive.service)" != "active" + + # This time we test the /run/nextroot/ root switching logic. (We synthesize a new rootfs from the old via overlayfs) + mkdir -p /run/nextroot /tmp/nextroot-lower /original-root + mount -t tmpfs tmpfs /tmp/nextroot-lower + echo miep >/tmp/nextroot-lower/lower + mount -t overlay nextroot /run/nextroot -o lowerdir=/:/tmp/nextroot-lower,ro + + # Bind our current root into the target so that we later can return to it + mount --bind / /run/nextroot/original-root + + # Now issue the soft reboot. We should be right back soon. + touch /run/testsuite82.touch2 + systemctl --no-block soft-reboot + + # Now block until the soft-boot killing spree kills us + exec sleep infinity +else + # This is the first boot + systemd-notify --status="First Boot" + + # Let's upload an fd to the fdstore, so that we can verify fdstore passing works correcly + T="/dev/shm/fdstore.$RANDOM" + echo "wuffwuff" >"$T" + systemd-notify --fd=3 --pid=parent 3<"$T" + rm "$T" + + # Create a script that can survive the soft reboot by ignoring SIGTERM (we + # do this instead of the argv[0][0] = '@' thing because that's so hard to + # do from a shell + T="/dev/shm/survive-$RANDOM.sh" + cat >$T </testok + +systemctl --no-block poweroff + +exit 0