diff mbox series

[v5,07/10] tst_test.sh: Introduce TST_FS_TYPE_FUSE

Message ID 20220909141840.18327-8-pvorel@suse.cz
State Changes Requested
Headers show
Series shell: df01.sh: $TST_ALL_FILESYSTEMS (.all_filesystems) | expand

Commit Message

Petr Vorel Sept. 9, 2022, 2:18 p.m. UTC
Useful if tests need to grep on mount output (there is fuseblk instead
of expected filesystem).

Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 doc/shell-test-api.txt    |  2 ++
 testcases/lib/tst_test.sh | 14 +++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

Comments

Cyril Hrubis Sept. 12, 2022, 3:28 p.m. UTC | #1
Hi!
> @@ -307,6 +307,18 @@ tst_mount()
>  	if [ $ret -ne 0 ]; then
>  		tst_brk TBROK "Failed to mount device${mnt_err}: mount exit = $ret"
>  	fi
> +
> +	mnt_real="$(grep -E "$TST_MNTPOINT ($TST_FS_TYPE|fuseblk)" /proc/mounts | awk 'NR==1{print $3}')"
> +	case $mnt_real in
> +		'') tst_brk TBROK 'Failed to found filesystem type in /proc/mounts';;
> +		'fuseblk') TST_FS_TYPE_FUSE=1;;
> +		*)
> +			if [ "$mnt_real" != "$TST_FS_TYPE" ]; then
> +				tst_brk TBROK "$mnt_real: unsupported type in /proc/mounts"
> +			fi
> +			TST_FS_TYPE_FUSE=
> +		;;
> +		esac
>  }

I just wonder if this is worth being added to the test library just for
a single test. Or do you expect this to be usable in more than df01.sh?

Also maybe it would be a better as a function so that the code does not
run unconditionally on each tst_mount() call?
Petr Vorel Sept. 12, 2022, 8:04 p.m. UTC | #2
> Hi!
> > @@ -307,6 +307,18 @@ tst_mount()
> >  	if [ $ret -ne 0 ]; then
> >  		tst_brk TBROK "Failed to mount device${mnt_err}: mount exit = $ret"
> >  	fi
> > +
> > +	mnt_real="$(grep -E "$TST_MNTPOINT ($TST_FS_TYPE|fuseblk)" /proc/mounts | awk 'NR==1{print $3}')"
> > +	case $mnt_real in
> > +		'') tst_brk TBROK 'Failed to found filesystem type in /proc/mounts';;
> > +		'fuseblk') TST_FS_TYPE_FUSE=1;;
> > +		*)
> > +			if [ "$mnt_real" != "$TST_FS_TYPE" ]; then
> > +				tst_brk TBROK "$mnt_real: unsupported type in /proc/mounts"
> > +			fi
> > +			TST_FS_TYPE_FUSE=
> > +		;;
> > +		esac
> >  }

> I just wonder if this is worth being added to the test library just for
> a single test. Or do you expect this to be usable in more than df01.sh?
Well, the inspiration was the C API, which also allows to skip fuse.
But sure, I can handle it just in df01.sh, just let me know the result.

> Also maybe it would be a better as a function so that the code does not
> run unconditionally on each tst_mount() call?
Do you mean e.g. tst_is_fuse() and df01.sh would call it?

Kind regards,
Petr
Cyril Hrubis Sept. 13, 2022, 8:15 a.m. UTC | #3
Hi!
> > Also maybe it would be a better as a function so that the code does not
> > run unconditionally on each tst_mount() call?
> Do you mean e.g. tst_is_fuse() and df01.sh would call it?

Yes that looks slightly cleaner than adding another variable.
Petr Vorel Sept. 13, 2022, 8:37 a.m. UTC | #4
> Hi!
> > > Also maybe it would be a better as a function so that the code does not
> > > run unconditionally on each tst_mount() call?
> > Do you mean e.g. tst_is_fuse() and df01.sh would call it?

> Yes that looks slightly cleaner than adding another variable.
OK, I'll fix it in v7. I put it into tst_test.sh, but if you prefer to have this
function just in df01.sh (called as is_fuse) until anything else needs it that
would work for me as well.

Kind regards,
Petr
Petr Vorel Sept. 13, 2022, 2:30 p.m. UTC | #5
> Hi!
> > > Also maybe it would be a better as a function so that the code does not
> > > run unconditionally on each tst_mount() call?
> > Do you mean e.g. tst_is_fuse() and df01.sh would call it?

> Yes that looks slightly cleaner than adding another variable.
In the end I add custom code to df01.sh, that's really better until some other
test needs to detects fuse.

Kind regards,
Petr
diff mbox series

Patch

diff --git a/doc/shell-test-api.txt b/doc/shell-test-api.txt
index 18ed144a9..e16080061 100644
--- a/doc/shell-test-api.txt
+++ b/doc/shell-test-api.txt
@@ -210,6 +210,8 @@  simply by setting right '$TST_FOO'.
 | 'TST_DEVICE'             | Block device name for 'tst_mount' and 'tst_mkfs', see
                              https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#formatting-device-with-a-filesystem[Formatting device with a filesystem].
 | 'TST_FS_TYPE'            | Override the default filesystem to be used.
+| 'TST_FS_TYPE_FUSE'       | 1 if mounted 'TST_FS_TYPE' filesystem on
+                             'TST_DEVICE' device is FUSE.
 | 'TST_MNTPOINT'           | Holds path to mountpoint used in 'tst_mount', see
                              https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#formatting-device-with-a-filesystem[Formatting device with a filesystem].
 | 'TST_MNT_PARAMS'         | Extra mount params for 'tst_mount', see
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index 2937bd80c..78dbfc1ce 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -307,6 +307,18 @@  tst_mount()
 	if [ $ret -ne 0 ]; then
 		tst_brk TBROK "Failed to mount device${mnt_err}: mount exit = $ret"
 	fi
+
+	mnt_real="$(grep -E "$TST_MNTPOINT ($TST_FS_TYPE|fuseblk)" /proc/mounts | awk 'NR==1{print $3}')"
+	case $mnt_real in
+		'') tst_brk TBROK 'Failed to found filesystem type in /proc/mounts';;
+		'fuseblk') TST_FS_TYPE_FUSE=1;;
+		*)
+			if [ "$mnt_real" != "$TST_FS_TYPE" ]; then
+				tst_brk TBROK "$mnt_real: unsupported type in /proc/mounts"
+			fi
+			TST_FS_TYPE_FUSE=
+		;;
+		esac
 }
 
 tst_umount()
@@ -636,7 +648,7 @@  tst_run()
 			OPTS|USAGE|PARSE_ARGS|POS_ARGS);;
 			NEEDS_ROOT|NEEDS_TMPDIR|TMPDIR|NEEDS_DEVICE|DEVICE);;
 			NEEDS_CMDS|NEEDS_MODULE|MODPATH|DATAROOT);;
-			NEEDS_DRIVERS|FS_TYPE|MNTPOINT|MNT_PARAMS);;
+			NEEDS_DRIVERS|FS_TYPE|FS_TYPE_FUSE|MNTPOINT|MNT_PARAMS);;
 			NEEDS_KCONFIGS|NEEDS_KCONFIGS_IFS);;
 			IPV6|IPV6_FLAG|IPVER|TEST_DATA|TEST_DATA_IFS);;
 			RETRY_FUNC|RETRY_FN_EXP_BACKOFF|TIMEOUT);;