Skip to content

Commit aeded6b

Browse files
committed
test-fstab-generator: also test with SYSTEMD_IN_INITRD=no
1 parent 7f8c67c commit aeded6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+301
-10
lines changed

test/test-fstab-generator.sh

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ PATH=$PATH:/usr/sbin
2424
export SYSTEMD_FORCE_MEASURE=0
2525

2626
test_one() (
27-
local input out exp i j k dir fname expf
27+
local initrd input out exp i j k dir fname expf
2828

2929
input=${1?}
30+
initrd=${2?}
3031

31-
: "*** Running $input"
32+
: "*** Running $input (initrd=$initrd)"
3233

3334
out=$(mktemp --tmpdir --directory "test-fstab-generator.XXXXXXXXXX")
3435
# shellcheck disable=SC2064
@@ -38,17 +39,21 @@ test_one() (
3839
if [[ "${input##*/}" =~ swap ]] && systemd-detect-virt --container >/dev/null; then
3940
exp="${exp}.container"
4041
fi
42+
if [[ "$initrd" == no ]]; then
43+
exp="${exp}.sysroot"
44+
fi
4145

4246
if [[ "${input##*/}" =~ \.fstab\.input ]]; then
43-
SYSTEMD_LOG_LEVEL=debug SYSTEMD_IN_INITRD=yes SYSTEMD_SYSFS_CHECK=no SYSTEMD_PROC_CMDLINE="fstab=yes root=fstab" SYSTEMD_FSTAB="$input" SYSTEMD_SYSROOT_FSTAB="/dev/null" $generator "$out" "$out" "$out"
47+
SYSTEMD_LOG_LEVEL=debug SYSTEMD_IN_INITRD="$initrd" SYSTEMD_SYSFS_CHECK=no SYSTEMD_PROC_CMDLINE="fstab=yes root=fstab" SYSTEMD_FSTAB="$input" SYSTEMD_SYSROOT_FSTAB="/dev/null" $generator "$out" "$out" "$out"
4448
else
45-
SYSTEMD_LOG_LEVEL=debug SYSTEMD_IN_INITRD=yes SYSTEMD_SYSFS_CHECK=no SYSTEMD_PROC_CMDLINE="fstab=no $(cat "$input")" $generator "$out" "$out" "$out"
49+
SYSTEMD_LOG_LEVEL=debug SYSTEMD_IN_INITRD="$initrd" SYSTEMD_SYSFS_CHECK=no SYSTEMD_PROC_CMDLINE="fstab=no $(cat "$input")" $generator "$out" "$out" "$out"
4650
fi
4751

4852
# The option x-systemd.growfs creates symlink to system's [email protected] in .mount.wants directory.
53+
# Also, when $initrd is no, symlink to systemd-remount-fs.service is created.
4954
# The system that the test is currently running on may not have or may have outdated unit file.
5055
# Let's replace the symlink with an empty file.
51-
for i in "$out"/*/systemd-growfs@*.service; do
56+
for i in "$out"/*/systemd-growfs@*.service "$out"/local-fs.target.wants/systemd-remount-fs.service; do
5257
[[ -L "$i" ]] || continue
5358
rm "$i"
5459
touch "$i"
@@ -80,16 +85,21 @@ test_one() (
8085
fi
8186
done
8287

88+
# We do not store empty directory.
89+
if [[ -z "$(ls -A "$out")" && ! -d "$exp" ]]; then
90+
return 0
91+
fi
92+
8393
# We store empty files rather than dead symlinks, so that they don't get pruned when packaged up, so compare
8494
# the list of filenames rather than their content
8595
if ! diff -u <(find "$out" -printf '%P\n' | sort) <(find "$exp" -printf '%P\n' | sort); then
86-
: "**** Unexpected output for $input"
96+
: "**** Unexpected output for $input (initrd=$initrd)"
8797
return 1
8898
fi
8999

90100
# Check the main units.
91101
if ! diff -u "$out" "$exp"; then
92-
: "**** Unexpected output for $input"
102+
: "**** Unexpected output for $input (initrd=$initrd)"
93103
return 1
94104
fi
95105

@@ -106,14 +116,14 @@ test_one() (
106116
if [[ -L "$j" && ! -e "$j" ]]; then
107117
# For dead symlink, we store an empty file.
108118
if [[ ! -e "$expf" || -n "$(cat "$expf")" ]]; then
109-
: "**** Unexpected symlink $j created by $input"
119+
: "**** Unexpected symlink $j created by $input (initrd=$initrd)"
110120
return 1
111121
fi
112122
continue
113123
fi
114124

115125
if ! diff -u "$j" "$expf"; then
116-
: "**** Unexpected output in $j for $input"
126+
: "**** Unexpected output in $j for $input (initrd=$initrd)"
117127
return 1
118128
fi
119129
done
@@ -123,5 +133,6 @@ test_one() (
123133
)
124134

125135
for f in "$src"/test-*.input; do
126-
test_one "$f"
136+
test_one "$f" yes
137+
test_one "$f" no
127138
done
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../sysroot-usr.mount
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../sysroot.mount

test/test-fstab-generator/test-17-initrd-sysroot.fstab.expected.sysroot/local-fs.target.wants/systemd-remount-fs.service

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Automatically generated by systemd-fstab-generator
2+
3+
[Unit]
4+
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
5+
SourcePath=/etc/fstab
6+
Before=local-fs.target
7+
8+
9+
[Mount]
10+
What=/dev/sdx2
11+
Where=/sysroot/usr
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Automatically generated by systemd-fstab-generator
2+
3+
[Unit]
4+
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
5+
SourcePath=/etc/fstab
6+
Before=local-fs.target
7+
8+
9+
10+
11+
[Mount]
12+
What=/dev/sdx1
13+
Where=/sysroot
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../mnt-requiredby.mount
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../mnt-wantedby.mount
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Automatically generated by systemd-fstab-generator
2+
3+
[Unit]
4+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../mnt-after.mount

0 commit comments

Comments
 (0)