]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
TEST-22: add --dry-run calls
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 8 Dec 2023 09:17:04 +0000 (10:17 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 12 Feb 2024 12:34:32 +0000 (13:34 +0100)
aCdDefLprRwxXz are tested with --dry-run.
I added a primitive test of bc.
There were no tests for AhHt, and I didn't add those either.

test/units/testsuite-22.02.sh
test/units/testsuite-22.03.sh
test/units/testsuite-22.04.sh
test/units/testsuite-22.05.sh
test/units/testsuite-22.06.sh
test/units/testsuite-22.11.sh
test/units/testsuite-22.12.sh
test/units/testsuite-22.15.sh
test/units/testsuite-22.16.sh
test/units/testsuite-22.18.sh
test/units/testsuite-22.19.sh [new file with mode: 0755]

index b883a9672ecee03a65117e621a3a6786d046f1d5..f191ae3ee7c27f6e831cb0f154fb1b957560bd2d 100755 (executable)
@@ -14,6 +14,14 @@ mkdir  /tmp/{C,d,D,e}
 mkdir /tmp/d/2
 chmod 777 /tmp/d/2
 
+systemd-tmpfiles --dry-run --create - <<EOF
+d     /tmp/d/1    0755 daemon daemon - -
+d     /tmp/d/2    0755 daemon daemon - -
+EOF
+
+test ! -d /tmp/d/1
+test -d /tmp/d/2
+
 systemd-tmpfiles --create - <<EOF
 d     /tmp/d/1    0755 daemon daemon - -
 d     /tmp/d/2    0755 daemon daemon - -
@@ -104,6 +112,14 @@ chmod 755 /tmp/C/{1,2,3}-origin/f1
 mkdir /tmp/C/{2,3}
 touch /tmp/C/3/f1
 
+systemd-tmpfiles --dry-run --create - <<EOF
+C     /tmp/C/1    0755 daemon daemon - /tmp/C/1-origin
+C     /tmp/C/2    0755 daemon daemon - /tmp/C/2-origin
+EOF
+
+test ! -d /tmp/C/1
+test -d /tmp/C/2
+
 systemd-tmpfiles --create - <<EOF
 C     /tmp/C/1    0755 daemon daemon - /tmp/C/1-origin
 C     /tmp/C/2    0755 daemon daemon - /tmp/C/2-origin
index 6fce4c07053997756b143888264028c59972f490..d1584987551bd6fe2bbec9e12687bdd13f299aa2 100755 (executable)
@@ -12,6 +12,14 @@ touch /tmp/file-owned-by-root
 #
 # 'f'
 #
+systemd-tmpfiles --dry-run --create - <<EOF
+f     /tmp/f/1    0644 - - - -
+f     /tmp/f/2    0644 - - - This string should be written
+EOF
+
+test ! -e /tmp/f/1
+test ! -e /tmp/f/2
+
 systemd-tmpfiles --create - <<EOF
 f     /tmp/f/1    0644 - - - -
 f     /tmp/f/2    0644 - - - This string should be written
@@ -189,6 +197,11 @@ touch /tmp/w/overwritten
 touch /tmp/w/appended
 
 ### nop if the target does not exist.
+systemd-tmpfiles --dry-run --create - <<EOF
+w     /tmp/w/unexistent    0644 - - - new content
+EOF
+test ! -e /tmp/w/unexistent
+
 systemd-tmpfiles --create - <<EOF
 w     /tmp/w/unexistent    0644 - - - new content
 EOF
@@ -200,6 +213,12 @@ w     /tmp/w/unexistent    0644 - - - -
 EOF
 
 ### write into an empty file.
+systemd-tmpfiles --dry-run --create - <<EOF
+w     /tmp/w/overwritten    0644 - - - old content
+EOF
+test -f /tmp/w/overwritten
+test -z "$(< /tmp/w/overwritten)"
+
 systemd-tmpfiles --create - <<EOF
 w     /tmp/w/overwritten    0644 - - - old content
 EOF
@@ -207,6 +226,12 @@ test -f /tmp/w/overwritten
 test "$(< /tmp/w/overwritten)" = "old content"
 
 ### old content is overwritten
+systemd-tmpfiles --dry-run --create - <<EOF
+w     /tmp/w/overwritten    0644 - - - new content
+EOF
+test -f /tmp/w/overwritten
+test "$(< /tmp/w/overwritten)" = "old content"
+
 systemd-tmpfiles --create - <<EOF
 w     /tmp/w/overwritten    0644 - - - new content
 EOF
@@ -223,6 +248,10 @@ test -f /tmp/w/appended
 test "$(< /tmp/w/appended)" = "$(echo -ne '12\n3')"
 
 ### writing into an 'exotic' file should be allowed.
+systemd-tmpfiles --dry-run --create - <<EOF
+w     /dev/null    - - - - new content
+EOF
+
 systemd-tmpfiles --create - <<EOF
 w     /dev/null    - - - - new content
 EOF
index 7bf2b28edc08a715d423616254a713be101c97a1..2c0ffe32ae08819d73d4c2199d6f899ece042888 100755 (executable)
@@ -9,6 +9,12 @@ rm -fr /tmp/p
 mkdir  /tmp/p
 touch  /tmp/p/f1
 
+systemd-tmpfiles --dry-run --create - <<EOF
+p     /tmp/p/fifo1    0666 - - - -
+EOF
+
+test ! -p /tmp/p/fifo1
+
 systemd-tmpfiles --create - <<EOF
 p     /tmp/p/fifo1    0666 - - - -
 EOF
index cde9b5d61c7e2cbd0259b8f602444454c366a378..d78e7ee8d229d65575c51624f92e2844dfd6af50 100755 (executable)
@@ -12,6 +12,15 @@ mkdir  /tmp/{z,Z}
 mkdir /tmp/z/d{1,2}
 touch /tmp/z/f1 /tmp/z/d1/f11 /tmp/z/d2/f21
 
+systemd-tmpfiles --dry-run --create - <<EOF
+z     /tmp/z/f1    0755 daemon daemon - -
+z     /tmp/z/d1    0755 daemon daemon - -
+EOF
+
+test "$(stat -c %U /tmp/z/f1)" = "$USER"
+test "$(stat -c %U /tmp/z/d1)" = "$USER"
+test "$(stat -c %U /tmp/z/d1/f11)" = "$USER"
+
 systemd-tmpfiles --create - <<EOF
 z     /tmp/z/f1    0755 daemon daemon - -
 z     /tmp/z/d1    0755 daemon daemon - -
index f64a95ce1ac467effc246e7fe9ec520fee16b74c..45aea9c6b834f669a491f62a5cb06637287e4201 100755 (executable)
@@ -6,7 +6,14 @@ set -eux
 set -o pipefail
 
 test_snippet() {
-        systemd-tmpfiles "$@" - <<EOF
+    # First call with --dry-run to test the code paths
+    systemd-tmpfiles --dry-run "$@" - <<EOF
+d /var/tmp/foobar-test-06
+d /var/tmp/foobar-test-06/important
+R /var/tmp/foobar-test-06
+EOF
+
+    systemd-tmpfiles "$@" - <<EOF
 d /var/tmp/foobar-test-06
 d /var/tmp/foobar-test-06/important
 R /var/tmp/foobar-test-06
index deee6fe5d1cb112a4a62532cbefbb0f2d54a35db..6f75888adec7f6a45be68dc7f18186d967252155 100755 (executable)
@@ -12,6 +12,19 @@ mkdir  /tmp/x
 mkdir -p /tmp/x/{1,2}
 touch /tmp/x/1/{x1,x2} /tmp/x/2/{y1,y2} /tmp/x/{z1,z2}
 
+systemd-tmpfiles --clean --dry-run - <<EOF
+d /tmp/x - - - 0
+x /tmp/x/1
+EOF
+
+find /tmp/x | sort
+test -f /tmp/x/1/x1
+test -f /tmp/x/1/x2
+test -f /tmp/x/2/y1
+test -f /tmp/x/2/y2
+test -f /tmp/x/z1
+test -f /tmp/x/z2
+
 systemd-tmpfiles --clean - <<EOF
 d /tmp/x - - - 0
 x /tmp/x/1
@@ -34,6 +47,19 @@ test ! -f /tmp/x/z2
 mkdir -p /tmp/x/{1,2}
 touch /tmp/x/1/{x1,x2} /tmp/x/2/{y1,y2} /tmp/x/{z1,z2}
 
+systemd-tmpfiles --dry-run --clean - <<EOF
+d /tmp/x - - - 0
+X /tmp/x/1
+EOF
+
+find /tmp/x | sort
+test -f /tmp/x/1/x1
+test -f /tmp/x/1/x2
+test -f /tmp/x/2/y1
+test -f /tmp/x/2/y2
+test -f /tmp/x/z1
+test -f /tmp/x/z2
+
 systemd-tmpfiles --clean - <<EOF
 d /tmp/x - - - 0
 X /tmp/x/1
@@ -56,6 +82,20 @@ test ! -f /tmp/x/z2
 mkdir -p /tmp/x/{1,2}
 touch /tmp/x/1/{x1,x2} /tmp/x/2/{y1,y2} /tmp/x/{z1,z2}
 
+systemd-tmpfiles --dry-run --clean - <<EOF
+d /tmp/x - - - 0
+x /tmp/x/[1345]
+x /tmp/x/z*
+EOF
+
+find /tmp/x | sort
+test -f /tmp/x/1/x1
+test -f /tmp/x/1/x2
+test -f /tmp/x/2/y1
+test -f /tmp/x/2/y2
+test -f /tmp/x/z1
+test -f /tmp/x/z2
+
 systemd-tmpfiles --clean - <<EOF
 d /tmp/x - - - 0
 x /tmp/x/[1345]
@@ -79,6 +119,20 @@ test -f /tmp/x/z2
 mkdir -p /tmp/x/{1,2}
 touch /tmp/x/1/{x1,x2} /tmp/x/2/{y1,y2} /tmp/x/{z1,z2}
 
+systemd-tmpfiles --dry-run --clean - <<EOF
+d /tmp/x - - - 0
+X /tmp/x/[1345]
+X /tmp/x/?[12]
+EOF
+
+find /tmp/x | sort
+test -f /tmp/x/1/x1
+test -f /tmp/x/1/x2
+test -f /tmp/x/2/y1
+test -f /tmp/x/2/y2
+test -f /tmp/x/z1
+test -f /tmp/x/z2
+
 systemd-tmpfiles --clean - <<EOF
 d /tmp/x - - - 0
 X /tmp/x/[1345]
@@ -102,6 +156,19 @@ test -f /tmp/x/z2
 mkdir -p /tmp/x/{1,2}/a
 touch /tmp/x/1/a/{x1,x2} /tmp/x/2/a/{y1,y2}
 
+systemd-tmpfiles --dry-run --clean - <<EOF
+# x/X is not supposed to influence r
+x /tmp/x/1/a
+X /tmp/x/2/a
+r /tmp/x/1
+r /tmp/x/2
+EOF
+
+test -f /tmp/x/1/a/x1
+test -f /tmp/x/1/a/x2
+test -f /tmp/x/2/a/y1
+test -f /tmp/x/2/a/y2
+
 systemd-tmpfiles --clean - <<EOF
 # x/X is not supposed to influence r
 x /tmp/x/1/a
@@ -125,6 +192,18 @@ test -f /tmp/x/2/a/y2
 mkdir -p /tmp/x/{1,2}/a
 touch /tmp/x/1/a/{x1,x2} /tmp/x/2/a/{y1,y2}
 
+systemd-tmpfiles --dry-run --remove - <<EOF
+# Check that X is honoured below R
+X /tmp/x/1/a
+X /tmp/x/2/a
+R /tmp/x/1
+EOF
+
+test -f /tmp/x/1/a/x1
+test -f /tmp/x/1/a/x2
+test -f /tmp/x/2/a/y1
+test -f /tmp/x/2/a/y2
+
 systemd-tmpfiles --remove - <<EOF
 # Check that X is honoured below R
 X /tmp/x/1/a
@@ -146,6 +225,17 @@ test -f /tmp/x/2/a/y2
 
 touch /tmp/x/{11,22,33}
 
+systemd-tmpfiles --dry-run --remove - <<EOF
+# Check that X is honoured below R
+r /tmp/x/11
+R /tmp/x/22
+D /tmp/x/33
+EOF
+
+test -f /tmp/x/11
+test -f /tmp/x/22
+test -f /tmp/x/33
+
 systemd-tmpfiles --remove - <<EOF
 # Check that X is honoured below R
 r /tmp/x/11
index b8c4da8381cda74d239fef23015d6072c8c8dcd8..57788da906c4f62d7b2edfda780eff15309f076b 100755 (executable)
@@ -52,6 +52,16 @@ sleep 1
 touch /tmp/ageby/d{3,4}/f{2..4}
 
 # Check for cleanup of "f1" in each of "/tmp/d{1..4}".
+systemd-tmpfiles --dry-run --clean - <<-EOF
+d /tmp/ageby/d1 - - - a:1m -
+e /tmp/ageby/d2 - - - m:3m -
+D /tmp/ageby/d3 - - - c:2s -
+EOF
+
+for d in d{1..3}; do
+    test -f "/tmp/ageby/${d}/f1"
+done
+
 systemd-tmpfiles --clean - <<-EOF
 d /tmp/ageby/d1 - - - a:1m -
 e /tmp/ageby/d2 - - - m:3m -
index 6cbb498678d895c1012c9a9c64b9af9e24eadb4d..6ee0e6379160b4a3e0a291ff071cc64470cb7ecf 100755 (executable)
@@ -12,6 +12,12 @@ mkdir  /tmp/L
 home='/somewhere'
 dst='/tmp/L/1'
 src="$home"
+HOME="$home" \
+systemd-tmpfiles --dry-run --create - <<EOF
+L     $dst    - - - - %h
+EOF
+test ! -h "$dst"
+
 HOME="$home" \
 systemd-tmpfiles --create - <<EOF
 L     $dst    - - - - %h
@@ -25,6 +31,12 @@ home='/%U'
 src="/usr/share/factory$home"
 mkdir -p "$root$src"
 dst="$root$home"
+HOME="$home" \
+systemd-tmpfiles --create --dry-run --root="$root" - <<EOF
+L     %h    - - - -
+EOF
+test ! -h "$dst"
+
 HOME="$home" \
 systemd-tmpfiles --create --root="$root" - <<EOF
 L     %h    - - - -
index 555e07fec7532243af332eb1dfd92b639fc59781..3d3d0c88e7b6d7daa54f52359289937f1f70caba 100755 (executable)
@@ -12,6 +12,11 @@ rm -f /tmp/acl_exec
 touch /tmp/acl_exec
 
 # No ACL set yet
+systemd-tmpfiles --dry-run --create - <<EOF
+a /tmp/acl_exec - - - - u:root:rwX
+EOF
+assert_not_in 'user:root:rw-' "$(getfacl -Ec /tmp/acl_exec)"
+
 systemd-tmpfiles --create - <<EOF
 a /tmp/acl_exec - - - - u:root:rwX
 EOF
index 14e434fd14fd3b08d2145a0d5efd7daf0b3a22ab..5d24197c8137b32a5e8596a1e43092f1bca98e99 100755 (executable)
@@ -8,26 +8,27 @@ set -o pipefail
 
 export SYSTEMD_LOG_LEVEL=debug
 
-systemd-tmpfiles --create - <<EOF
+c='
 d /tmp/somedir
 f /tmp/somedir/somefile - - - - baz
-EOF
+'
 
+systemd-tmpfiles --create - <<<"$c"
 test -f /tmp/somedir/somefile
 grep -q baz /tmp/somedir/somefile
 
-systemd-tmpfiles --purge - <<EOF
-d /tmp/somedir
-f /tmp/somedir/somefile - - - - baz
-EOF
+systemd-tmpfiles --purge --dry-run - <<<"$c"
+test -f /tmp/somedir/somefile
+grep -q baz /tmp/somedir/somefile
 
+systemd-tmpfiles --purge - <<<"$c"
 test ! -f /tmp/somedir/somefile
 test ! -d /tmp/somedir/
 
-systemd-tmpfiles --create --purge - <<EOF
-d /tmp/somedir
-f /tmp/somedir/somefile - - - - baz
-EOF
+systemd-tmpfiles --create --purge --dry-run - <<<"$c"
+test ! -f /tmp/somedir/somefile
+test ! -d /tmp/somedir/
 
+systemd-tmpfiles --create --purge - <<<"$c"
 test -f /tmp/somedir/somefile
 grep -q baz /tmp/somedir/somefile
diff --git a/test/units/testsuite-22.19.sh b/test/units/testsuite-22.19.sh
new file mode 100755 (executable)
index 0000000..c5a0966
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+#
+# Tests for character and block device creation
+#
+set -eux
+set -o pipefail
+
+rm -rf /tmp/dev
+mkdir /tmp/dev
+
+# We are running tests in /tmp, which would normally be mounted nodev,
+# so we only try with --dry-run.
+
+systemd-tmpfiles --dry-run --create - <<EOF
+c /tmp/dev/char  - - - - 11:12
+b /tmp/dev/block - - - - 11:14
+EOF
+
+test ! -e /tmp/dev/char
+test ! -e /tmp/dev/block
+
+systemd-tmpfiles --dry-run --create - <<EOF
+c+ /tmp/dev/char  - - - - 11:12
+b+ /tmp/dev/block - - - - 11:14
+EOF
+
+test ! -e /tmp/dev/char
+test ! -e /tmp/dev/block