]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: skip Protect{Home,System}= tests with coverage builds
authorFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 19 Oct 2023 13:13:07 +0000 (15:13 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 19 Oct 2023 17:03:57 +0000 (18:03 +0100)
With coverage builds we disable Protect{Home,System}= via a service.d
dropin in /etc, which has, unfortunately, higher priority than our
transient systemd-run stuff. Let's just skip the affected tests in that
case instead of making the test setup even more complicated.

test/units/testsuite-07.exec-context.sh

index ccda8639e69ed9e3bd7ffa0829213adf42960434..de9edd7640bff0424aaebc3786b4bafbb5bf1a8f 100755 (executable)
@@ -23,25 +23,31 @@ proc_supports_option() {
     return $ec
 }
 
-systemd-run --wait --pipe -p ProtectSystem=yes \
-    bash -xec "test ! -w /usr; test ! -w /boot; test -w /etc; test -w /var"
-systemd-run --wait --pipe -p ProtectSystem=full \
-    bash -xec "test ! -w /usr; test ! -w /boot; test ! -w /etc; test -w /var"
-systemd-run --wait --pipe -p ProtectSystem=strict \
-    bash -xec "test ! -w /; test ! -w /etc; test ! -w /var; test -w /dev; test -w /proc"
-systemd-run --wait --pipe -p ProtectSystem=no \
-    bash -xec "test -w /; test -w /etc; test -w /var; test -w /dev; test -w /proc"
+# In coverage builds we disable ProtectSystem= and ProtectHome= via a service.d
+# dropin in /etc. This dropin has, unfortunately, higher priority than
+# the transient stuff from systemd-run. Let's just skip the following tests
+# in that case instead of complicating the test setup even more */
+if [[ -z "${COVERAGE_BUILD_DIR:-}" ]]; then
+    systemd-run --wait --pipe -p ProtectSystem=yes \
+        bash -xec "test ! -w /usr; test ! -w /boot; test -w /etc; test -w /var"
+    systemd-run --wait --pipe -p ProtectSystem=full \
+        bash -xec "test ! -w /usr; test ! -w /boot; test ! -w /etc; test -w /var"
+    systemd-run --wait --pipe -p ProtectSystem=strict \
+        bash -xec "test ! -w /; test ! -w /etc; test ! -w /var; test -w /dev; test -w /proc"
+    systemd-run --wait --pipe -p ProtectSystem=no \
+        bash -xec "test -w /; test -w /etc; test -w /var; test -w /dev; test -w /proc"
 
-MARK="$(mktemp /root/.exec-context.XXX)"
-systemd-run --wait --pipe -p ProtectHome=yes \
-    bash -xec "test ! -w /home; test ! -w /root; test ! -w /run/user; test ! -e $MARK"
-systemd-run --wait --pipe -p ProtectHome=read-only \
-    bash -xec "test ! -w /home; test ! -w /root; test ! -w /run/user; test -e $MARK"
-systemd-run --wait --pipe -p ProtectHome=tmpfs \
-    bash -xec "test -w /home; test -w /root; test -w /run/user; test ! -e $MARK"
-systemd-run --wait --pipe -p ProtectHome=no \
-    bash -xec "test -w /home; test -w /root; test -w /run/user; test -e $MARK"
-rm -f "$MARK"
+    MARK="$(mktemp /root/.exec-context.XXX)"
+    systemd-run --wait --pipe -p ProtectHome=yes \
+        bash -xec "test ! -w /home; test ! -w /root; test ! -w /run/user; test ! -e $MARK"
+    systemd-run --wait --pipe -p ProtectHome=read-only \
+        bash -xec "test ! -w /home; test ! -w /root; test ! -w /run/user; test -e $MARK"
+    systemd-run --wait --pipe -p ProtectHome=tmpfs \
+        bash -xec "test -w /home; test -w /root; test -w /run/user; test ! -e $MARK"
+    systemd-run --wait --pipe -p ProtectHome=no \
+        bash -xec "test -w /home; test -w /root; test -w /run/user; test -e $MARK"
+    rm -f "$MARK"
+fi
 
 if proc_supports_option "hidepid=off"; then
     systemd-run --wait --pipe -p ProtectProc=noaccess -p User=testuser \