2022-01-06 14:12:27 +03:00
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
2023-07-26 00:30:37 +03:00
set -eux
2023-05-11 21:54:13 +03:00
shopt -s nullglob
shopt -s globstar
2022-01-06 14:12:27 +03:00
2023-07-26 00:30:37 +03:00
if [ [ -n " ${ 1 :- } " ] ] ; then
2022-01-06 14:12:27 +03:00
generator = $1
elif [ [ -x /usr/lib/systemd/system-generators/systemd-fstab-generator ] ] ; then
generator = /usr/lib/systemd/system-generators/systemd-fstab-generator
elif [ [ -x /lib/systemd/system-generators/systemd-fstab-generator ] ] ; then
generator = /lib/systemd/system-generators/systemd-fstab-generator
else
exit 1
fi
src = " $( dirname " $0 " ) /testdata/test-fstab-generator "
test: fstab-generator: adjust PATH for fsck
fsck(8) is located in /usr/sib/ on Debian sid:
stdout:
*** Running /home/christian/Coding/workspaces/systemd/test/testdata/test-fstab-generator/test-01-dev-nfs.input
*** Running /home/christian/Coding/workspaces/systemd/test/testdata/test-fstab-generator/test-02-dhcp.input
*** Running /home/christian/Coding/workspaces/systemd/test/testdata/test-fstab-generator/test-03-dhcp6.input
*** Running /home/christian/Coding/workspaces/systemd/test/testdata/test-fstab-generator/test-04-nfs.input
*** Running /home/christian/Coding/workspaces/systemd/test/testdata/test-fstab-generator/test-05-nfs4.input
*** Running /home/christian/Coding/workspaces/systemd/test/testdata/test-fstab-generator/test-06-ipv4.input
*** Running /home/christian/Coding/workspaces/systemd/test/testdata/test-fstab-generator/test-07-ipv6.input
*** Running /home/christian/Coding/workspaces/systemd/test/testdata/test-fstab-generator/test-08-implicit-nfs.input
*** Running /home/christian/Coding/workspaces/systemd/test/testdata/test-fstab-generator/test-09-cifs.input
*** Running /home/christian/Coding/workspaces/systemd/test/testdata/test-fstab-generator/test-10-iscsi.input
*** Running /home/christian/Coding/workspaces/systemd/test/testdata/test-fstab-generator/test-11-live.input
*** Running /home/christian/Coding/workspaces/systemd/test/testdata/test-fstab-generator/test-12-dev-sdx.input
--- /dev/fd/63 2022-11-04 15:39:13.131532174 +0100
+++ /dev/fd/62 2022-11-04 15:39:13.131532174 +0100
@@ -6,3 +6,4 @@
initrd-usr-fs.target.requires
initrd-usr-fs.target.requires/sysroot.mount
sysroot.mount
+systemd-fsck-root.service
**** Unexpected output for /home/christian/Coding/workspaces/systemd/test/testdata/test-fstab-generator/test-12-dev-sdx.input
stderr:
Skipping root directory handling, as root on NFS was requested.
Skipping root directory handling, as root on NFS was requested.
Skipping root directory handling, as root on NFS was requested.
Skipping root directory handling, as root on NFS was requested.
Skipping root directory handling, as root on NFS was requested.
Skipping root directory handling, as root on NFS was requested.
Skipping root directory handling, as root on NFS was requested.
Skipping root directory handling, as root on NFS was requested.
Skipping root directory handling, as root on CIFS was requested.
Skipping root directory handling, as root on iSCSI was requested.
Skipping root directory handling, as root on live image was requested.
Found entry what=/dev/sdx1 where=/sysroot type=n/a opts=ro
Checking was requested for /dev/sdx1, but the fsck command does not exist.
2022-11-04 17:48:50 +03:00
# fsck(8) is located in /usr/sbin on Debian
PATH = $PATH :/usr/sbin
2023-05-30 23:53:43 +03:00
# systemd-pcrfs@.service could be enabled or not, depending on the host state
# of the host system. Override the measurement to avoid the issue.
export SYSTEMD_FORCE_MEASURE = 0
2023-07-26 00:30:37 +03:00
test_one( ) (
2023-07-26 01:04:48 +03:00
local initrd input out exp i j k dir fname expf
2023-07-26 00:30:37 +03:00
input = ${ 1 ? }
2023-07-26 01:04:48 +03:00
initrd = ${ 2 ? }
2023-07-26 00:30:37 +03:00
2023-07-26 01:04:48 +03:00
: " *** Running $input (initrd= $initrd ) "
2023-07-26 00:30:37 +03:00
out = $( mktemp --tmpdir --directory "test-fstab-generator.XXXXXXXXXX" )
# shellcheck disable=SC2064
trap " rm -rf ' $out ' " EXIT INT QUIT PIPE
exp = " ${ input %.input } .expected "
if [ [ " ${ input ##*/ } " = ~ swap ] ] && systemd-detect-virt --container >/dev/null; then
exp = " ${ exp } .container "
fi
2023-07-26 01:04:48 +03:00
if [ [ " $initrd " = = no ] ] ; then
exp = " ${ exp } .sysroot "
fi
2023-07-26 00:30:37 +03:00
if [ [ " ${ input ##*/ } " = ~ \. fstab\. input ] ] ; then
2023-07-26 01:04:48 +03:00
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 "
2023-07-26 00:30:37 +03:00
else
2023-07-26 01:04:48 +03:00
SYSTEMD_LOG_LEVEL = debug SYSTEMD_IN_INITRD = " $initrd " SYSTEMD_SYSFS_CHECK = no SYSTEMD_PROC_CMDLINE = " fstab=no $( cat " $input " ) " $generator " $out " " $out " " $out "
2023-07-26 00:30:37 +03:00
fi
# The option x-systemd.growfs creates symlink to system's systemd-growfs@.service in .mount.wants directory.
2023-07-26 01:04:48 +03:00
# Also, when $initrd is no, symlink to systemd-remount-fs.service is created.
2023-07-26 00:30:37 +03:00
# The system that the test is currently running on may not have or may have outdated unit file.
# Let's replace the symlink with an empty file.
2023-07-26 01:04:48 +03:00
for i in " $out " /*/systemd-growfs@*.service " $out " /local-fs.target.wants/systemd-remount-fs.service; do
2023-07-26 00:30:37 +03:00
[ [ -L " $i " ] ] || continue
rm " $i "
touch " $i "
done
if [ [ " ${ input ##*/ } " = ~ \. fstab\. input ] ] ; then
for i in " $out " /*.{ automount,mount,swap} ; do
sed -i -e 's:SourcePath=.*$:SourcePath=/etc/fstab:' " $i "
2023-05-19 03:31:51 +03:00
done
2023-07-26 00:30:37 +03:00
fi
# .deb packager seems to dislike files named with backslash. So, as a workaround, we store files
# without backslash in .expected.
for i in " $out " /**/*\\ *.{ mount,swap} ; do
k = " ${ i // \\ / } "
if [ [ " $i " != " $k " ] ] ; then
if [ [ -f " $i " ] ] ; then
mv " $i " " $k "
elif [ [ -L " $i " ] ] ; then
dest = $( readlink " $i " )
rm " $i "
ln -s " ${ dest // \\ / } " " $k "
fi
2022-01-06 14:12:27 +03:00
fi
2023-07-26 00:30:37 +03:00
done
2023-07-26 01:04:48 +03:00
# We do not store empty directory.
if [ [ -z " $( ls -A " $out " ) " && ! -d " $exp " ] ] ; then
return 0
fi
2023-07-26 00:30:37 +03:00
# We store empty files rather than dead symlinks, so that they don't get pruned when packaged up, so compare
# the list of filenames rather than their content
if ! diff -u <( find " $out " -printf '%P\n' | sort) <( find " $exp " -printf '%P\n' | sort) ; then
2023-07-26 01:04:48 +03:00
: " **** Unexpected output for $input (initrd= $initrd ) "
2023-07-26 00:30:37 +03:00
return 1
fi
# Check the main units.
if ! diff -u " $out " " $exp " ; then
2023-07-26 01:04:48 +03:00
: " **** Unexpected output for $input (initrd= $initrd ) "
2023-07-26 00:30:37 +03:00
return 1
fi
# Also check drop-ins.
for i in " $out " /*; do
[ [ -d " $i " ] ] || continue
dir = " ${ i ##*/ } "
for j in " $i " /*; do
fname = " ${ j ##*/ } "
expf = " $exp / $dir / $fname "
if [ [ -L " $j " && ! -e " $j " ] ] ; then
# For dead symlink, we store an empty file.
if [ [ ! -e " $expf " || -n " $( cat " $expf " ) " ] ] ; then
2023-07-26 01:04:48 +03:00
: " **** Unexpected symlink $j created by $input (initrd= $initrd ) "
2023-07-26 00:30:37 +03:00
return 1
2023-05-11 21:55:46 +03:00
fi
2023-07-26 00:30:37 +03:00
continue
2023-05-11 21:55:46 +03:00
fi
2023-07-26 00:30:37 +03:00
if ! diff -u " $j " " $expf " ; then
2023-07-26 01:04:48 +03:00
: " **** Unexpected output in $j for $input (initrd= $initrd ) "
2023-07-26 00:30:37 +03:00
return 1
fi
done
done
2023-05-11 21:54:13 +03:00
2023-07-26 00:30:37 +03:00
return 0
)
2023-05-11 21:54:13 +03:00
2023-07-26 00:30:37 +03:00
for f in " $src " /test-*.input; do
2023-10-25 19:52:11 +03:00
# If /mnt is a symlink, then the expected output from this
# test scenario will not match the actual output
if test " $f " = " $src /test-18-options.fstab.input " -a " $( readlink /mnt) " != "/mnt"
then
echo " Skip $f because /mnt is a symlink "
continue
fi
2023-07-26 01:04:48 +03:00
test_one " $f " yes
test_one " $f " no
2022-01-06 14:12:27 +03:00
done