tests: make new -mount test more robust

This test failed on non-Linux systems:
- On Solaris 11, the output of the native df(1) tool has a different order,
  and hence the detection of a usable mount point for the test fails.
  Verify that df(1) is from GNU coreutils, or fall back to 'gdf',
  else skip the test.
- On a FreeBSD system where /home was a symlink to /usr/home, the code
  for finding a usable mount point failed, because the symlink itself
  is on the '/' file system.
  Ensure that the found mount point is identical to the original test
  directory like /home etc.

* tests/find/mount-vs-xdev.sh: Try harder to use a GNU df(1) tool.
Check whether the found mount point is identical to the original
directory name, thus avoiding symlinks.
This commit is contained in:
Bernhard Voelker 2026-01-05 18:25:08 +01:00
parent 3c2af8a185
commit ebea22e88b

View File

@ -19,9 +19,17 @@
. "${srcdir=.}/tests/init.sh"; fu_path_prepend_
print_ver_ find
# Require GNU df in getmntpoint.
for f in df gdf; do
# Find GNU df.
$f --version | grep GNU \
&& DF=$f
done
test "$DF" || skip_ "GNU df required."
getmntpoint () {
# Skip header line and print last field.
df "$1" | awk 'NR==2 {print $NF}'
$DF "$1" | awk 'NR==2 {print $NF}'
}
mnt_root=$( getmntpoint '/' ) \
@ -32,9 +40,10 @@ found=0
# Find a directory entry which is mounted (likely) from a different device
# than the '/' directory.
for m in /dev /home /proc /run /tmp; do
test -e "$m" \
test -d "$m" \
&& mnt_m=$( getmntpoint "$m" ) \
&& test "$mnt_root" != "$mnt_m" \
&& test "$m" = "$mnt_m" \
|| continue
found=1