tests: If filesystem is mounted with nodev opt skip CUSE chroot test

The CUSE TPM test will not work if the filesystem the test case runs
on is mounted with the 'nodev' option since the CUSE TPM can then
not use /tmp/.../dev/cuse.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
diff --git a/tests/test_tpm2_chroot_cuse b/tests/test_tpm2_chroot_cuse
index 33e9887..1d057dd 100755
--- a/tests/test_tpm2_chroot_cuse
+++ b/tests/test_tpm2_chroot_cuse
@@ -13,6 +13,11 @@
 	exit 77
 fi
 
+if [ -z "$(type -P df)" ]; then
+	echo "This test requires the 'df' tool."
+	exit 77
+fi
+
 ROOT=${abs_top_builddir:-$(dirname "$0")/..}
 TESTDIR=${abs_top_testdir:-$(dirname "$0")}
 
@@ -40,6 +45,21 @@
 
 for OPTION in --chroot -R; do
 	TPMDIR="$(mktemp -d)" || exit 1
+
+	# CUSE TPM will only work if the filesystem does not have 'nodev' option
+	mnt=$(df $TPMDIR | tail -n 1 | gawk '{print $1" "$6}')
+	if [ -z "${mnt}" ]; then
+		echo " Error: Could not determine filesystem and mount point of $TPMDIR"
+		exit 1
+	fi
+	nodev="$(grep -E "^${mnt} " /proc/mounts |
+		 gawk '{print ","$4","}' |
+		 grep ",nodev,")"
+	if [ -n "${nodev}" ]; then
+		echo " Error: '${mnt}' is mounted with nodev option. Skipping test."
+		exit 77
+	fi
+
 	mkdir $TPMDIR/dev
 	mknod -m 0666 $TPMDIR/dev/urandom c 1 9
 	mknod -m 0666 $TPMDIR/dev/cuse c 10 203