2022-06-09 22:03:49

by Petr Vorel

[permalink] [raw]
Subject: [PATCH 0/9] shell: nfs: $TST_ALL_FILESYSTEMS (.all_filesystems)

Hi,

this is quite ready $TST_ALL_FILESYSTEMS (i.e. support for LTP shell API
to run test on all available filesystems, equivalent of .all_filesystems
in C API). It's used in NFS tests, where I have questions (RFC).

As it uses testcases/lib/tst_supported_fs.c binary it supports the same
features as C API:
* detect supported filesystems
* run only on single filesystem with $LTP_SINGLE_FS_TYPE (debugging)

825e10a91 ("Skip tmpfs in all-filesystem shell tests")


TODO API:
* filtering filesystems when test does not run on certain filesystem
* (i.e. nfs01.sh on vfat) with $TST_SKIP_FILESYSTEMS (equivalent of
skip_filesystems variable in C API)
* testcases/lib/tst_supported_fs.c skips tmpfs by default since
825e10a91 ("Skip tmpfs in all-filesystem shell tests"). After
implementing $TST_SKIP_FILESYSTEMS it could be removed.

TODO NFS tests:
* Do not require restart NFS server (otherwise legacy testcases/lib/daemonlib.sh
would have to be used)

Comments are welcome.

Code is also at: https://github.com/pevik/ltp/tree/shell/all_filesystems.v2

Kind regards,
Petr

Petr Vorel (9):
tst_test.sh: Add $TST_MOUNT_DEVICE
df01.sh: Use TST_MOUNT_DEVICE=1
tst_test.sh: allow ' in pattern for allowed variables
shell: Add test for TST_MOUNT_DEVICE=1
tst_test.sh: Add $TST_ALL_FILESYSTEMS
tst_device: Remove unnecessary braces
tst_device: Add clear command
shell: Add test for TST_ALL_FILESYSTEMS=1
nfs: Use TST_ALL_FILESYSTEMS=1

doc/shell-test-api.txt | 3 +
lib/newlib_tests/shell/tst_all_filesystems.sh | 27 +++++
lib/newlib_tests/shell/tst_mount_device.sh | 21 ++++
testcases/commands/df/df01.sh | 5 +-
testcases/lib/tst_device.c | 25 ++++-
testcases/lib/tst_test.sh | 104 ++++++++++++------
testcases/network/nfs/nfs_stress/nfs_lib.sh | 25 +++--
7 files changed, 159 insertions(+), 51 deletions(-)
create mode 100755 lib/newlib_tests/shell/tst_all_filesystems.sh
create mode 100755 lib/newlib_tests/shell/tst_mount_device.sh

--
2.36.1


2022-06-09 22:04:37

by Petr Vorel

[permalink] [raw]
Subject: [PATCH v2 3/9] tst_test.sh: allow ' in pattern for allowed variables

to allow using '... $TST_FOO'

i.e. without filtering '
EXPECT_PASS "grep '$TST_MNTPOINT $TST_FS_TYPE' /proc/mounts"
would produce warning:
tst_mount_device 1 TWARN: Reserved variable TST_FS_TYPE' used!
because sed filters it as: FS_TYPE'

Will be needed for next commit.

Signed-off-by: Petr Vorel <[email protected]>
---
testcases/lib/tst_test.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index 740115385..f9ff9bcb4 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -621,7 +621,7 @@ tst_run()
local _tst_name

if [ -n "$TST_TEST_PATH" ]; then
- for _tst_i in $(grep '^[^#]*\bTST_' "$TST_TEST_PATH" | sed 's/.*TST_//; s/[="} \t\/:`].*//'); do
+ for _tst_i in $(grep '^[^#]*\bTST_' "$TST_TEST_PATH" | sed 's/.*TST_//; s/[='\''"} \t\/:`].*//'); do
case "$_tst_i" in
DISABLE_APPARMOR|DISABLE_SELINUX);;
SETUP|CLEANUP|TESTFUNC|ID|CNT|MIN_KVER);;
--
2.36.1

2022-06-09 22:04:37

by Petr Vorel

[permalink] [raw]
Subject: [PATCH v2 2/9] df01.sh: Use TST_MOUNT_DEVICE=1

Reviewed-by: Cyril Hrubis <[email protected]>
Signed-off-by: Petr Vorel <[email protected]>
---
testcases/commands/df/df01.sh | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/testcases/commands/df/df01.sh b/testcases/commands/df/df01.sh
index f74032c96..976e205bf 100755
--- a/testcases/commands/df/df01.sh
+++ b/testcases/commands/df/df01.sh
@@ -1,19 +1,19 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (c) 2015 Fujitsu Ltd.
+# Copyright (c) 2018-2022 Petr Vorel <[email protected]>
# Author: Zhang Jin <[email protected]>
#
# Test df command with some basic options.

TST_CNT=12
TST_SETUP=setup
-TST_CLEANUP=tst_umount
TST_TESTFUNC=test
TST_OPTS="f:"
TST_USAGE=usage
TST_PARSE_ARGS=parse_args
TST_NEEDS_ROOT=1
-TST_FORMAT_DEVICE=1
+TST_MOUNT_DEVICE=1

usage()
{
@@ -34,7 +34,6 @@ parse_args()

setup()
{
- tst_mount
DF_FS_TYPE=$(mount | grep "$TST_DEVICE" | awk 'NR==1{print $5}')
}

--
2.36.1

2022-06-09 22:04:46

by Petr Vorel

[permalink] [raw]
Subject: [PATCH v2 6/9] tst_device: Remove unnecessary braces

to keep checkpatch.pl happy.

Signed-off-by: Petr Vorel <[email protected]>
---
testcases/lib/tst_device.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/testcases/lib/tst_device.c b/testcases/lib/tst_device.c
index 2a3ab1222..d6b74a5ff 100644
--- a/testcases/lib/tst_device.c
+++ b/testcases/lib/tst_device.c
@@ -40,11 +40,10 @@ static int acquire_device(int argc, char *argv[])
}
}

- if (argc >= 4) {
+ if (argc >= 4)
device = tst_acquire_loop_device(size, argv[3]);
- } else {
+ else
device = tst_acquire_device__(size);
- }

if (!device)
return 1;
--
2.36.1

2022-06-09 22:04:46

by Petr Vorel

[permalink] [raw]
Subject: [PATCH v2 7/9] tst_device: Add clear command

clearing block device will be needed for TST_ALL_FILESYSTEMS
implementation in shell API. Now we clear device during acquire,
but we will reuse this device for each tested filesystem, thus we need a
separate command for it.

Signed-off-by: Petr Vorel <[email protected]>
---
testcases/lib/tst_device.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/testcases/lib/tst_device.c b/testcases/lib/tst_device.c
index d6b74a5ff..45f77a38b 100644
--- a/testcases/lib/tst_device.c
+++ b/testcases/lib/tst_device.c
@@ -18,8 +18,10 @@ static struct tst_test test = {

static void print_help(void)
{
- fprintf(stderr, "\nUsage: tst_device acquire [size [filename]]\n");
- fprintf(stderr, " or: tst_device release /path/to/device\n\n");
+ fprintf(stderr, "\nUsage:\n");
+ fprintf(stderr, "tst_device acquire [size [filename]]\n");
+ fprintf(stderr, "tst_device release /path/to/device\n");
+ fprintf(stderr, "tst_device clear /path/to/device\n\n");
}

static int acquire_device(int argc, char *argv[])
@@ -72,6 +74,17 @@ static int release_device(int argc, char *argv[])
return tst_detach_device(argv[2]);
}

+static int clear_device(int argc, char *argv[])
+{
+ if (argc != 3)
+ return 1;
+
+ if (tst_clear_device(argv[2]))
+ return 1;
+
+ return 0;
+}
+
int main(int argc, char *argv[])
{
/*
@@ -94,6 +107,9 @@ int main(int argc, char *argv[])
} else if (!strcmp(argv[1], "release")) {
if (release_device(argc, argv))
goto help;
+ } else if (!strcmp(argv[1], "clear")) {
+ if (clear_device(argc, argv))
+ goto help;
} else {
fprintf(stderr, "ERROR: Invalid COMMAND '%s'\n", argv[1]);
goto help;
--
2.36.1

2022-06-09 22:04:53

by Petr Vorel

[permalink] [raw]
Subject: [PATCH v2 8/9] shell: Add test for TST_ALL_FILESYSTEMS=1

Unfortunately GitHub Actions don't have loop devices, thus cannot be run
in CI:

tst_format_device 1 TINFO: timeout per run is 0h 5m 0s
/__w/ltp/ltp/lib/tst_device.c:139: TINFO: No free devices found

Reviewed-by: Cyril Hrubis <[email protected]>
Signed-off-by: Petr Vorel <[email protected]>
---
lib/newlib_tests/shell/tst_all_filesystems.sh | 27 +++++++++++++++++++
testcases/lib/tst_test.sh | 2 +-
2 files changed, 28 insertions(+), 1 deletion(-)
create mode 100755 lib/newlib_tests/shell/tst_all_filesystems.sh

diff --git a/lib/newlib_tests/shell/tst_all_filesystems.sh b/lib/newlib_tests/shell/tst_all_filesystems.sh
new file mode 100755
index 000000000..8509a7481
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_all_filesystems.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 Petr Vorel <[email protected]>
+
+TST_ALL_FILESYSTEMS=1
+TST_TESTFUNC=test
+TST_CNT=2
+
+test1()
+{
+ tst_res TPASS "device using filesystem"
+}
+
+test2()
+{
+ local pattern
+
+
+ if [ "$TST_FS_TYPE" = "exfat" -o "$TST_FS_TYPE" = "ntfs" ]; then
+ pattern="|fuseblk"
+ fi
+
+ EXPECT_PASS "grep -E '$TST_MNTPOINT ($TST_FS_TYPE${pattern})' /proc/mounts"
+}
+
+. tst_test.sh
+tst_run
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index d96ce3448..27f698dab 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -603,7 +603,7 @@ _tst_init_checkpoints()
_prepare_device()
{
if [ "$TST_FORMAT_DEVICE" = 1 ]; then
- tst_clear_device $TST_DEVICE
+ tst_device clear "$TST_DEVICE"
tst_mkfs $TST_FS_TYPE $TST_DEV_FS_OPTS $TST_DEVICE $TST_DEV_EXTRA_OPTS
fi

--
2.36.1

2022-06-09 22:05:06

by Petr Vorel

[permalink] [raw]
Subject: [PATCH v2 5/9] tst_test.sh: Add $TST_ALL_FILESYSTEMS

Signed-off-by: Petr Vorel <[email protected]>
---
doc/shell-test-api.txt | 1 +
testcases/lib/tst_test.sh | 106 ++++++++++++++++++++++++--------------
2 files changed, 69 insertions(+), 38 deletions(-)

diff --git a/doc/shell-test-api.txt b/doc/shell-test-api.txt
index 65444541e..93073be13 100644
--- a/doc/shell-test-api.txt
+++ b/doc/shell-test-api.txt
@@ -199,6 +199,7 @@ simply by setting right '$TST_FOO'.
[options="header"]
|=============================================================================
| Variable name | Action done
+| 'TST_ALL_FILESYSTEMS' | Testing on all available filesystems (tst_test.all_filesystems equivalent).
| 'TST_DEV_EXTRA_OPTS' | Pass extra 'mkfs' options _after_ device name,
to 'tst_mkfs', use with 'TST_FORMAT_DEVICE=1'.
| 'TST_DEV_FS_OPTS' | Pass 'mkfs' options _before_ the device name,
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index f9ff9bcb4..d96ce3448 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -28,23 +28,12 @@ fi
trap "tst_brk TBROK 'test interrupted'" INT
trap "unset _tst_setup_timer_pid; tst_brk TBROK 'test terminated'" TERM

+# FIXME: debug called more times => check things moved out of it
_tst_do_exit()
{
local ret=0
TST_DO_EXIT=1

- if [ -n "$TST_DO_CLEANUP" -a -n "$TST_CLEANUP" -a -z "$TST_NO_CLEANUP" ]; then
- if command -v $TST_CLEANUP >/dev/null 2>/dev/null; then
- $TST_CLEANUP
- else
- tst_res TWARN "TST_CLEANUP=$TST_CLEANUP declared, but function not defined (or cmd not found)"
- fi
- fi
-
- if [ "$TST_MOUNT_FLAG" = 1 ]; then
- tst_umount
- fi
-
if [ "$TST_NEEDS_DEVICE" = 1 -a "$TST_DEVICE_FLAG" = 1 ]; then
if ! tst_device release "$TST_DEVICE"; then
tst_res TWARN "Failed to release device '$TST_DEVICE'"
@@ -61,8 +50,6 @@ _tst_do_exit()
rm $LTP_IPC_PATH
fi

- _tst_cleanup_timer
-
if [ $TST_FAIL -gt 0 ]; then
ret=$((ret|1))
fi
@@ -613,17 +600,41 @@ _tst_init_checkpoints()
export LTP_IPC_PATH
}

+_prepare_device()
+{
+ if [ "$TST_FORMAT_DEVICE" = 1 ]; then
+ tst_clear_device $TST_DEVICE
+ tst_mkfs $TST_FS_TYPE $TST_DEV_FS_OPTS $TST_DEVICE $TST_DEV_EXTRA_OPTS
+ fi
+
+ if [ "$TST_MOUNT_DEVICE" = 1 ]; then
+ tst_mount
+ TST_MOUNT_FLAG=1
+ fi
+}
+
+_tst_run_tcases_per_fs()
+{
+ for _tst_fs in $(tst_supported_fs); do
+ tst_res TINFO "Testing on $_tst_fs"
+ TST_FS_TYPE="$_tst_fs"
+ _prepare_device
+ _tst_run_iterations
+ done
+}
+
tst_run()
{
local _tst_i
local _tst_data
+ local _tst_fs
local _tst_max
local _tst_name

if [ -n "$TST_TEST_PATH" ]; then
for _tst_i in $(grep '^[^#]*\bTST_' "$TST_TEST_PATH" | sed 's/.*TST_//; s/[='\''"} \t\/:`].*//'); do
case "$_tst_i" in
- DISABLE_APPARMOR|DISABLE_SELINUX);;
+ ALL_FILESYSTEMS|DISABLE_APPARMOR|DISABLE_SELINUX);;
SETUP|CLEANUP|TESTFUNC|ID|CNT|MIN_KVER);;
OPTS|USAGE|PARSE_ARGS|POS_ARGS);;
NEEDS_ROOT|NEEDS_TMPDIR|TMPDIR|NEEDS_DEVICE|DEVICE);;
@@ -668,12 +679,23 @@ tst_run()
tst_brk TCONF "test requires kernel $TST_MIN_KVER+"
fi

- _tst_setup_timer
+ [ -n "$TST_NEEDS_MODULE" ] && tst_require_module "$TST_NEEDS_MODULE"

+ [ "$TST_ALL_FILESYSTEMS" = 1 ] && TST_MOUNT_DEVICE=1
[ "$TST_MOUNT_DEVICE" = 1 ] && TST_FORMAT_DEVICE=1
[ "$TST_FORMAT_DEVICE" = 1 ] && TST_NEEDS_DEVICE=1
[ "$TST_NEEDS_DEVICE" = 1 ] && TST_NEEDS_TMPDIR=1

+ if [ "$TST_NEEDS_DEVICE" = 1 ]; then
+ TST_DEVICE=$(tst_device acquire)
+
+ if [ ! -b "$TST_DEVICE" -o $? -ne 0 ]; then
+ unset TST_DEVICE
+ tst_brk TBROK "Failed to acquire device"
+ fi
+ TST_DEVICE_FLAG=1
+ fi
+
if [ "$TST_NEEDS_TMPDIR" = 1 ]; then
if [ -z "$TMPDIR" ]; then
export TMPDIR="/tmp"
@@ -684,35 +706,30 @@ tst_run()
chmod 777 "$TST_TMPDIR"

TST_STARTWD=$(pwd)
-
cd "$TST_TMPDIR"
fi

- TST_MNTPOINT="${TST_MNTPOINT:-$PWD/mntpoint}"
- if [ "$TST_NEEDS_DEVICE" = 1 ]; then
-
- TST_DEVICE=$(tst_device acquire)
+ [ -n "$TST_NEEDS_CHECKPOINTS" ] && _tst_init_checkpoints

- if [ ! -b "$TST_DEVICE" -o $? -ne 0 ]; then
- unset TST_DEVICE
- tst_brk TBROK "Failed to acquire device"
- fi
+ TST_MNTPOINT="${TST_MNTPOINT:-$PWD/mntpoint}"
+ [ -z "$TST_ALL_FILESYSTEMS" ] && _prepare_device

- TST_DEVICE_FLAG=1
+ if [ -n "$TST_ALL_FILESYSTEMS" ]; then
+ _tst_run_tcases_per_fs
+ else
+ _tst_run_iterations
fi

- [ -n "$TST_NEEDS_MODULE" ] && tst_require_module "$TST_NEEDS_MODULE"
+ _tst_do_exit
+}

- if [ "$TST_FORMAT_DEVICE" = 1 ]; then
- tst_mkfs $TST_FS_TYPE $TST_DEV_FS_OPTS $TST_DEVICE $TST_DEV_EXTRA_OPTS
- fi
+_tst_run_iterations()
+{
+ local _tst_i=$TST_ITERATIONS

- if [ "$TST_MOUNT_DEVICE" = 1 ]; then
- tst_mount
- TST_MOUNT_FLAG=1
- fi
+ [ "$TST_NEEDS_TMPDIR" = 1 ] && cd "$TST_TMPDIR"

- [ -n "$TST_NEEDS_CHECKPOINTS" ] && _tst_init_checkpoints
+ _tst_setup_timer

if [ -n "$TST_SETUP" ]; then
if command -v $TST_SETUP >/dev/null 2>/dev/null; then
@@ -724,7 +741,7 @@ tst_run()
fi

#TODO check that test reports some results for each test function call
- while [ $TST_ITERATIONS -gt 0 ]; do
+ while [ $_tst_i -gt 0 ]; do
if [ -n "$TST_TEST_DATA" ]; then
tst_require_cmds cut tr wc
_tst_max=$(( $(echo $TST_TEST_DATA | tr -cd "$TST_TEST_DATA_IFS" | wc -c) +1))
@@ -735,9 +752,22 @@ tst_run()
else
_tst_run_tests
fi
- TST_ITERATIONS=$((TST_ITERATIONS-1))
+ _tst_i=$((_tst_i-1))
done
- _tst_do_exit
+
+ if [ -n "$TST_DO_CLEANUP" -a -n "$TST_CLEANUP" -a -z "$TST_NO_CLEANUP" ]; then
+ if command -v $TST_CLEANUP >/dev/null 2>/dev/null; then
+ $TST_CLEANUP
+ else
+ tst_res TWARN "TST_CLEANUP=$TST_CLEANUP declared, but function not defined (or cmd not found)"
+ fi
+ fi
+
+ if [ "$TST_MOUNT_FLAG" = 1 ]; then
+ tst_umount
+ fi
+
+ _tst_cleanup_timer
}

_tst_run_tests()
--
2.36.1

2022-06-09 22:05:20

by Petr Vorel

[permalink] [raw]
Subject: [PATCH v2 1/9] tst_test.sh: Add $TST_MOUNT_DEVICE

Reviewed-by: Cyril Hrubis <[email protected]>
Signed-off-by: Petr Vorel <[email protected]>
---
doc/shell-test-api.txt | 2 ++
testcases/lib/tst_test.sh | 12 +++++++++++-
2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/doc/shell-test-api.txt b/doc/shell-test-api.txt
index df5ebbdf0..65444541e 100644
--- a/doc/shell-test-api.txt
+++ b/doc/shell-test-api.txt
@@ -214,6 +214,8 @@ simply by setting right '$TST_FOO'.
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
https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#formatting-device-with-a-filesystem[Formatting device with a filesystem].
+| 'TST_MOUNT_DEVICE' | Mount device, see
+ https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#mounting-and-unmounting-filesystems[Mounting and unmounting filesystems].
| 'TST_NEEDS_ROOT' | Exit the test with 'TCONF' unless executed under root.
Alternatively the 'tst_require_root' command can be used.
| 'TST_NEEDS_TMPDIR' | Create test temporary directory and cd into it.
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index c6e0752f3..740115385 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -41,6 +41,10 @@ _tst_do_exit()
fi
fi

+ if [ "$TST_MOUNT_FLAG" = 1 ]; then
+ tst_umount
+ fi
+
if [ "$TST_NEEDS_DEVICE" = 1 -a "$TST_DEVICE_FLAG" = 1 ]; then
if ! tst_device release "$TST_DEVICE"; then
tst_res TWARN "Failed to release device '$TST_DEVICE'"
@@ -632,7 +636,7 @@ tst_run()
NET_SKIP_VARIABLE_INIT|NEEDS_CHECKPOINTS);;
CHECKPOINT_WAIT|CHECKPOINT_WAKE);;
CHECKPOINT_WAKE2|CHECKPOINT_WAKE_AND_WAIT);;
- DEV_EXTRA_OPTS|DEV_FS_OPTS|FORMAT_DEVICE);;
+ DEV_EXTRA_OPTS|DEV_FS_OPTS|FORMAT_DEVICE|MOUNT_DEVICE);;
*) tst_res TWARN "Reserved variable TST_$_tst_i used!";;
esac
done
@@ -666,6 +670,7 @@ tst_run()

_tst_setup_timer

+ [ "$TST_MOUNT_DEVICE" = 1 ] && TST_FORMAT_DEVICE=1
[ "$TST_FORMAT_DEVICE" = 1 ] && TST_NEEDS_DEVICE=1
[ "$TST_NEEDS_DEVICE" = 1 ] && TST_NEEDS_TMPDIR=1

@@ -702,6 +707,11 @@ tst_run()
tst_mkfs $TST_FS_TYPE $TST_DEV_FS_OPTS $TST_DEVICE $TST_DEV_EXTRA_OPTS
fi

+ if [ "$TST_MOUNT_DEVICE" = 1 ]; then
+ tst_mount
+ TST_MOUNT_FLAG=1
+ fi
+
[ -n "$TST_NEEDS_CHECKPOINTS" ] && _tst_init_checkpoints

if [ -n "$TST_SETUP" ]; then
--
2.36.1

2022-06-09 22:05:20

by Petr Vorel

[permalink] [raw]
Subject: [PATCH v2 4/9] shell: Add test for TST_MOUNT_DEVICE=1

Unfortunately GitHub Actions don't have loop devices, thus cannot be run
in CI:

tst_format_device 1 TINFO: timeout per run is 0h 5m 0s
/__w/ltp/ltp/lib/tst_device.c:139: TINFO: No free devices found

Reviewed-by: Cyril Hrubis <[email protected]>
Signed-off-by: Petr Vorel <[email protected]>
---
lib/newlib_tests/shell/tst_mount_device.sh | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100755 lib/newlib_tests/shell/tst_mount_device.sh

diff --git a/lib/newlib_tests/shell/tst_mount_device.sh b/lib/newlib_tests/shell/tst_mount_device.sh
new file mode 100755
index 000000000..c8f185626
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_mount_device.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 Petr Vorel <[email protected]>
+
+TST_MOUNT_DEVICE=1
+TST_FS_TYPE=ext4
+TST_TESTFUNC=test
+TST_CNT=2
+
+test1()
+{
+ EXPECT_PASS "cd $TST_MNTPOINT"
+}
+
+test2()
+{
+ EXPECT_PASS "grep '$TST_MNTPOINT $TST_FS_TYPE' /proc/mounts"
+}
+
+. tst_test.sh
+tst_run
--
2.36.1

2022-06-09 22:05:27

by Petr Vorel

[permalink] [raw]
Subject: [RFC][PATCH v2 9/9] nfs: Use TST_ALL_FILESYSTEMS=1

Signed-off-by: Petr Vorel <[email protected]>
---
Hi NFS developers,

your comments are welcome. This is an effort how to support NFS tests on
all filesystems available on SUT. Using $TST_MNTPOINT means test run in
loop, each time different filesystem is used. It's implemented via
formatted loop device (the same way as in LTP C API).

Code is also at: https://github.com/pevik/ltp/tree/shell/all_filesystems.v2

But this requires restarting NFS server (otherwise legacy testcases/lib/daemonlib.sh
would have to be used), which is IMHO not optimal.

Without that (or only run 'systemctl reload nfs-server' or exportfs -r
on remote side) it cannot be umounted after testing - debugging with
fuser, code at:
https://github.com/pevik/ltp/commit/3656d035d43445a107154ef397ef1db2fad2c4f0

The problem is that loop device is still referenced by nfs server and
thus cannot be unmounted. Can this be somehow fixed? Is it even wanted
to have tests on loop device (the only reasonable way to support more
filesystems)? Also tests will run much longer (we could filter out some
filesystems not supported, if there are any).

# LTP_SINGLE_FS_TYPE=ext2 PATH="/opt/ltp/testcases/bin:$PATH" nfs07.sh -v 3 -t tcp -i3
## NOTE: testing itself is OK
nfs07 1 TINFO: initialize 'lhost' 'ltp_ns_veth2' interface
nfs07 1 TINFO: add local addr 10.0.0.2/24
nfs07 1 TINFO: add local addr fd00:1:1:1::2/64
nfs07 1 TINFO: initialize 'rhost' 'ltp_ns_veth1' interface
nfs07 1 TINFO: add remote addr 10.0.0.1/24
nfs07 1 TINFO: add remote addr fd00:1:1:1::1/64
nfs07 1 TINFO: Network config (local -- remote):
nfs07 1 TINFO: ltp_ns_veth2 -- ltp_ns_veth1
nfs07 1 TINFO: 10.0.0.2/24 -- 10.0.0.1/24
nfs07 1 TINFO: fd00:1:1:1::2/64 -- fd00:1:1:1::1/64
tst_device.c:89: TINFO: Found free device 0 '/dev/loop0'
tst_supported_fs_types.c:148: TINFO: WARNING: testing only ext2
tst_supported_fs_types.c:89: TINFO: Kernel supports ext2
tst_supported_fs_types.c:51: TINFO: mkfs.ext2 does exist
nfs07 1 TINFO: Testing on ext2
nfs07 1 TINFO: Formatting ext2 with opts='/dev/loop0'
nfs07 1 TINFO: timeout per run is 0h 5m 0s
nfs07 1 TINFO: mount.nfs: (linux nfs-utils 2.6.1)
nfs07 1 TINFO: setup NFSv3, socket type tcp
nfs07 1 TINFO: Mounting NFS: mount -v -t nfs -o proto=tcp,vers=3 10.0.0.2:/tmp/LTP_nfs07.A3PIB82iUv/mntpoint/3/tcp /tmp/LTP_nfs07.A3PIB82iUv/mntpoint/3/0
nfs07 1 TPASS: All files and directories were correctly listed
nfs07 2 TPASS: All files and directories were correctly listed
nfs07 3 TPASS: All files and directories were correctly listed
nfs07 4 TINFO: Cleaning up testcase

## DEBUGGING CODE in nfs_cleanup()
nfs07 4 TINFO: fuser -mv /tmp/LTP_nfs07.P1XS9smc5w ($TST_TMPDIR)
USER PID ACCESS COMMAND
/tmp/LTP_nfs07.P1XS9smc5w:
root kernel mount /tmp
root 2125 ..c.. tst_timeout_kil
nfs07 4 TINFO: fuser -mv /tmp/LTP_nfs07.P1XS9smc5w/mntpoint ($TST_MNTPOINT)
USER PID ACCESS COMMAND
/tmp/LTP_nfs07.P1XS9smc5w/mntpoint:
root kernel mount /tmp/LTP_nfs07.P1XS9smc5w/mntpoint
nfs07 4 TINFO: fuser -mv /tmp/LTP_nfs07.P1XS9smc5w/mntpoint/3/0
USER PID ACCESS COMMAND
/tmp/LTP_nfs07.P1XS9smc5w/mntpoint/3/0:
root kernel mount /tmp/LTP_nfs07.P1XS9smc5w/mntpoint/3/0

## from nfs_cleanup()
## grep -q "$local_dir" /proc/mounts && umount $local_dir
nfs07 4 TINFO: umount /tmp/LTP_nfs07.P1XS9smc5w/mntpoint/3/0
umount: /tmp/LTP_nfs07.P1XS9smc5w/mntpoint: target is busy.

## The rest is not relevant as the problem is above
## tst_umount from tst_test.sh trying hard to umount
nfs07 4 TINFO: umount(/tmp/LTP_nfs07.P1XS9smc5w/mntpoint) failed, try 1 ...
nfs07 4 TINFO: Likely gvfsd-trash is probing newly mounted fs, kill it to speed up tests.
umount: /tmp/LTP_nfs07.P1XS9smc5w/mntpoint: target is busy.
nfs07 4 TINFO: umount(/tmp/LTP_nfs07.P1XS9smc5w/mntpoint) failed, try 2 ...
nfs07 4 TINFO: Likely gvfsd-trash is probing newly mounted fs, kill it to speed up tests.
...
nfs07 4 TINFO: umount(/tmp/LTP_nfs07.P1XS9smc5w/mntpoint) failed, try 50 ...
nfs07 4 TINFO: Likely gvfsd-trash is probing newly mounted fs, kill it to speed up tests.
nfs07 4 TWARN: Failed to umount(/tmp/LTP_nfs07.P1XS9smc5w/mntpoint) after 50 retries

## if ! tst_device release "$TST_DEVICE"; then in _tst_do_exit() in tst_test.sh
tst_device.c:255: TWARN: ioctl(/dev/loop1, LOOP_CLR_FD, 0) no ENXIO for too long

Usage
tst_device acquire [size [filename]]
tst_device release /path/to/device

tst_device clear /path/to/device

## rm -r "$TST_TMPDIR" in _tst_do_exit() in tst_test.sh
nfs07 4 TWARN: Failed to release device '/dev/loop1'
rm: cannot remove '/tmp/LTP_nfs07.P1XS9smc5w/mntpoint': Device or resource busy
rm: cannot remove '/tmp/LTP_nfs07.P1XS9smc5w/mntpoint': Device or resource busy
nfs07 4 TINFO: AppArmor enabled, this may affect test results
nfs07 4 TINFO: it can be disabled with TST_DISABLE_APPARMOR=1 (requires super/root)
nfs07 4 TINFO: loaded AppArmor profiles: none

Kind regards,
Petr

testcases/network/nfs/nfs_stress/nfs_lib.sh | 25 ++++++++++++---------
1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/testcases/network/nfs/nfs_stress/nfs_lib.sh b/testcases/network/nfs/nfs_stress/nfs_lib.sh
index af7d46a21..a6557177b 100644
--- a/testcases/network/nfs/nfs_stress/nfs_lib.sh
+++ b/testcases/network/nfs/nfs_stress/nfs_lib.sh
@@ -28,7 +28,7 @@ NFS_PARSE_ARGS_CALLER="$TST_PARSE_ARGS"
TST_OPTS="v:t:$TST_OPTS"
TST_PARSE_ARGS=nfs_parse_args
TST_USAGE=nfs_usage
-TST_NEEDS_TMPDIR=1
+TST_ALL_FILESYSTEMS=1
TST_NEEDS_ROOT=1
TST_NEEDS_CMDS="$TST_NEEDS_CMDS mount exportfs mount.nfs"
TST_SETUP="${TST_SETUP:-nfs_setup}"
@@ -63,7 +63,7 @@ nfs_get_remote_path()
done

v=${1:-$v}
- echo "$TST_TMPDIR/$v/$type"
+ echo "$TST_MNTPOINT/$v/$type"
}

nfs_server_udp_enabled()
@@ -162,8 +162,8 @@ nfs_setup()
tst_brk TCONF "UDP support disabled on NFS server"
fi

- local_dir="$TST_TMPDIR/$i/$n"
- remote_dir="$TST_TMPDIR/$i/$type"
+ local_dir="$TST_MNTPOINT/$i/$n"
+ remote_dir="$TST_MNTPOINT/$i/$type"
mkdir -p $local_dir

nfs_setup_server $(($$ + n))
@@ -174,7 +174,7 @@ nfs_setup()
done

if [ "$n" -eq 1 ]; then
- cd ${VERSION}/0
+ cd $TST_MNTPOINT/$VERSION/0
fi
}

@@ -190,19 +190,22 @@ nfs_cleanup()

local n=0
for i in $VERSION; do
- local_dir="$TST_TMPDIR/$i/$n"
- grep -q "$local_dir" /proc/mounts && umount $local_dir
+ type=$(get_socket_type $n)
+ remote_dir="$TST_MNTPOINT/$i/$type"
+ tst_rhost_run -c "test -d $remote_dir && exportfs -u *:$remote_dir"
+ tst_rhost_run -c "test -d $remote_dir && rm -rf $remote_dir"
n=$(( n + 1 ))
done

n=0
for i in $VERSION; do
- type=$(get_socket_type $n)
- remote_dir="$TST_TMPDIR/$i/$type"
- tst_rhost_run -c "test -d $remote_dir && exportfs -u *:$remote_dir"
- tst_rhost_run -c "test -d $remote_dir && rm -rf $remote_dir"
+ local_dir="$TST_MNTPOINT/$i/$n"
+
+ grep -q "$local_dir" /proc/mounts && umount $local_dir
n=$(( n + 1 ))
done
+
+ systemctl restart nfs-server
}

. tst_net.sh
--
2.36.1

2022-06-17 13:54:38

by Cyril Hrubis

[permalink] [raw]
Subject: Re: [LTP] [PATCH v2 5/9] tst_test.sh: Add $TST_ALL_FILESYSTEMS

Hi!
> +_tst_run_iterations()
> +{
> + local _tst_i=$TST_ITERATIONS
>
> - if [ "$TST_MOUNT_DEVICE" = 1 ]; then
> - tst_mount
> - TST_MOUNT_FLAG=1
> - fi
> + [ "$TST_NEEDS_TMPDIR" = 1 ] && cd "$TST_TMPDIR"
>
> - [ -n "$TST_NEEDS_CHECKPOINTS" ] && _tst_init_checkpoints
> + _tst_setup_timer
>
> if [ -n "$TST_SETUP" ]; then
> if command -v $TST_SETUP >/dev/null 2>/dev/null; then
> @@ -724,7 +741,7 @@ tst_run()
> fi
>
> #TODO check that test reports some results for each test function call
> - while [ $TST_ITERATIONS -gt 0 ]; do
> + while [ $_tst_i -gt 0 ]; do
> if [ -n "$TST_TEST_DATA" ]; then
> tst_require_cmds cut tr wc
> _tst_max=$(( $(echo $TST_TEST_DATA | tr -cd "$TST_TEST_DATA_IFS" | wc -c) +1))
> @@ -735,9 +752,22 @@ tst_run()
> else
> _tst_run_tests
> fi
> - TST_ITERATIONS=$((TST_ITERATIONS-1))
> + _tst_i=$((_tst_i-1))
> done
> - _tst_do_exit
> +
> + if [ -n "$TST_DO_CLEANUP" -a -n "$TST_CLEANUP" -a -z "$TST_NO_CLEANUP" ]; then
> + if command -v $TST_CLEANUP >/dev/null 2>/dev/null; then
> + $TST_CLEANUP
> + else
> + tst_res TWARN "TST_CLEANUP=$TST_CLEANUP declared, but function not defined (or cmd not found)"
> + fi
> + fi
> +
> + if [ "$TST_MOUNT_FLAG" = 1 ]; then
> + tst_umount
> + fi
> +
> + _tst_cleanup_timer

Generally the code looks good, there is still a minor difference between
C API and this changes though. As we do call the _tst_cleanup_timer at
the end of this function the script runs without a timeout for a short
while (which includes tst_mkfs call).

I guess that instead of stopping the timer at the end of the
_tst_run_iterations() we can simply reset it (on the top of this patch):

diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index d96ce3448..f5af4c214 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -50,6 +50,8 @@ _tst_do_exit()
rm $LTP_IPC_PATH
fi

+ _tst_cleanup_timer
+
if [ $TST_FAIL -gt 0 ]; then
ret=$((ret|1))
fi
@@ -552,6 +554,12 @@ _tst_setup_timer()
done
}

+_tst_reset_timer()
+{
+ _tst_cleanup_timer
+ _tst_setup_timer
+}
+
tst_require_root()
{
if [ "$(id -ru)" != 0 ]; then
@@ -665,6 +673,8 @@ tst_run()
tst_brk TBROK "Number of iterations (-i) must be >= 0"
fi

+ _tst_setup_timer
+
[ "$TST_NEEDS_ROOT" = 1 ] && tst_require_root

[ "$TST_DISABLE_APPARMOR" = 1 ] && tst_disable_apparmor
@@ -729,8 +739,6 @@ _tst_run_iterations()

[ "$TST_NEEDS_TMPDIR" = 1 ] && cd "$TST_TMPDIR"

- _tst_setup_timer
-
if [ -n "$TST_SETUP" ]; then
if command -v $TST_SETUP >/dev/null 2>/dev/null; then
TST_DO_CLEANUP=1
@@ -767,7 +775,7 @@ _tst_run_iterations()
tst_umount
fi

- _tst_cleanup_timer
+ _tst_reset_timer
}


--
Cyril Hrubis
[email protected]

2022-06-17 14:03:36

by Cyril Hrubis

[permalink] [raw]
Subject: Re: [LTP] [PATCH v2 7/9] tst_device: Add clear command

Hi!
Looks good, but should go before the "add: $TST_ALL_FILESYSTEMS" right?

Reviewed-by: Cyril Hrubis <[email protected]>

--
Cyril Hrubis
[email protected]

2022-06-17 14:09:39

by Petr Vorel

[permalink] [raw]
Subject: Re: [LTP] [PATCH v2 5/9] tst_test.sh: Add $TST_ALL_FILESYSTEMS

Hi Cyril,

> Generally the code looks good, there is still a minor difference between
> C API and this changes though. As we do call the _tst_cleanup_timer at
> the end of this function the script runs without a timeout for a short
> while (which includes tst_mkfs call).

> I guess that instead of stopping the timer at the end of the
> _tst_run_iterations() we can simply reset it (on the top of this patch):

Good catch, thanks for providing a patch.
LGTM, I'll have a deeper look later.

Kind regards,
Petr

2022-06-17 14:50:35

by Cyril Hrubis

[permalink] [raw]
Subject: Re: [LTP] [RFC][PATCH v2 9/9] nfs: Use TST_ALL_FILESYSTEMS=1

Hi!
> +
> + systemctl restart nfs-server

I wonder do we stil have to care for systems without systemd?

We do have daemonlib.sh in LTP that has restart_daemon() function that
branches to systemctl|service|/etc/init.d/ that is used by a few tests.

--
Cyril Hrubis
[email protected]

2022-07-11 15:05:04

by Petr Vorel

[permalink] [raw]
Subject: Re: [PATCH v2 4/9] shell: Add test for TST_MOUNT_DEVICE=1

Hi all,

FYI merged up to this patch, the rest (the actual $TST_ALL_FILESYSTEMS)
will go in v3.

Kind regards,
Petr

2022-07-11 15:09:12

by Petr Vorel

[permalink] [raw]
Subject: Re: [LTP] [RFC][PATCH v2 9/9] nfs: Use TST_ALL_FILESYSTEMS=1

Hi all,

> > + systemctl restart nfs-server

> I wonder do we stil have to care for systems without systemd?
That'd be a question for embedded people. I myself wonder if they all moved to
systemd. But at least Alpine and Buildroot distros allow to use Busybox as init,
thus I'd still care.

> We do have daemonlib.sh in LTP that has restart_daemon() function that
> branches to systemctl|service|/etc/init.d/ that is used by a few tests.
That's exactly what I'm planning to use.

Kind regards,
Petr

2022-08-04 07:13:21

by Petr Vorel

[permalink] [raw]
Subject: Re: [PATCH v2 5/9] tst_test.sh: Add $TST_ALL_FILESYSTEMS

Hi all,

I wonder if we want to sort filesystems:

-for _tst_fs in $(tst_supported_fs); do
+for _tst_fs in $(tst_supported_fs | sort); do

or even -u (as uniq).

Martin used it in testcases/misc/lvm/prepare_lvm.sh, but IMHO it should not be
needed: looping over fs_type_whitelist() should be always the same.

FS_LIST=`tst_supported_fs | sort -u`

Therefore I'd remove it (don't use unnecessary dependencies - be nice for people
with minimal environment):

Kind regards,
Petr