Skip to content

Commit 1f6bd6e

Browse files
committed
tst_test.sh: Add $TST_ALL_FILESYSTEMS
$TST_ALL_FILESYSTEMS is shell API equivalent of .all_filesystems from C API. Improve also $TST_SKIP_FILESYSTEMS to behave like .skip_filesystems. Reviewed-by: Li Wang <[email protected]> Acked-by: Richard Palethorpe <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]> Signed-off-by: Petr Vorel <[email protected]>
1 parent 5fbc21e commit 1f6bd6e

File tree

2 files changed

+98
-48
lines changed

2 files changed

+98
-48
lines changed

doc/shell-test-api.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ simply by setting right '$TST_FOO'.
199199
[options="header"]
200200
|=============================================================================
201201
| Variable name | Action done
202+
| 'TST_ALL_FILESYSTEMS' | Testing on all available filesystems
203+
('tst_test.all_filesystems' equivalent).
204+
When 'TST_SKIP_FILESYSTEMS' any listed filesystem is not
205+
included in the resulting list of supported filesystems.
202206
| 'TST_DEV_EXTRA_OPTS' | Pass extra 'mkfs' options _after_ device name,
203207
to 'tst_mkfs', use with 'TST_FORMAT_DEVICE=1'.
204208
| 'TST_DEV_FS_OPTS' | Pass 'mkfs' options _before_ the device name,
@@ -209,7 +213,10 @@ simply by setting right '$TST_FOO'.
209213
Implies 'TST_NEEDS_DEVICE=1' (no need to set it).
210214
| 'TST_DEVICE' | Block device name for 'tst_mount' and 'tst_mkfs', see
211215
https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#formatting-device-with-a-filesystem[Formatting device with a filesystem].
212-
| 'TST_FS_TYPE' | Override the default filesystem to be used.
216+
| 'TST_FS_TYPE' | Override the default filesystem to be used. Also
217+
contains currently used filesystem during looping
218+
filesystems in 'TST_ALL_FILESYSTEMS=1'
219+
('tst_device->fs_type' equivalent).
213220
| 'TST_MNTPOINT' | Holds path to mountpoint used in 'tst_mount', see
214221
https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#formatting-device-with-a-filesystem[Formatting device with a filesystem].
215222
| 'TST_MNT_PARAMS' | Extra mount params for 'tst_mount', see

testcases/lib/tst_test.sh

Lines changed: 90 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ export TST_ITERATIONS=1
1717
export TST_TMPDIR_RHOST=0
1818
export TST_LIB_LOADED=1
1919

20-
if [ -z "$TST_FS_TYPE" ]; then
21-
export TST_FS_TYPE="${LTP_DEV_FS_TYPE:-ext2}"
22-
fi
23-
2420
. tst_ansi_color.sh
2521
. tst_security.sh
2622

@@ -33,17 +29,7 @@ _tst_do_exit()
3329
local ret=0
3430
TST_DO_EXIT=1
3531

36-
if [ -n "$TST_DO_CLEANUP" -a -n "$TST_CLEANUP" -a -z "$TST_NO_CLEANUP" ]; then
37-
if command -v $TST_CLEANUP >/dev/null 2>/dev/null; then
38-
$TST_CLEANUP
39-
else
40-
tst_res TWARN "TST_CLEANUP=$TST_CLEANUP declared, but function not defined (or cmd not found)"
41-
fi
42-
fi
43-
44-
if [ "$TST_MOUNT_FLAG" = 1 ]; then
45-
tst_umount
46-
fi
32+
[ "$TST_MOUNT_FLAG" = 1 ] && tst_umount
4733

4834
if [ "$TST_NEEDS_DEVICE" = 1 -a "$TST_DEVICE_FLAG" = 1 ]; then
4935
if ! tst_device release "$TST_DEVICE"; then
@@ -289,7 +275,7 @@ TST_CHECKPOINT_WAKE_AND_WAIT()
289275

290276
tst_mount()
291277
{
292-
local mnt_opt mnt_err
278+
local mnt_opt mnt_err mnt_real
293279

294280
if [ -n "$TST_FS_TYPE" ]; then
295281
mnt_opt="-t $TST_FS_TYPE"
@@ -480,6 +466,7 @@ LTPROOT Prefix for installed LTP (default: /opt/ltp)
480466
LTP_COLORIZE_OUTPUT Force colorized output behaviour (y/1 always, n/0: never)
481467
LTP_DEV Path to the block device to be used (for .needs_device)
482468
LTP_DEV_FS_TYPE Filesystem used for testing (default: ext2)
469+
LTP_SINGLE_FS_TYPE Testing only - specifies filesystem instead all supported (for TST_ALL_FILESYSTEMS=1)
483470
LTP_TIMEOUT_MUL Timeout multiplier (must be a number >=1, ceiled to int)
484471
TMPDIR Base directory for template directory (for .needs_tmpdir, default: /tmp)
485472
EOF
@@ -621,10 +608,41 @@ _tst_init_checkpoints()
621608
export LTP_IPC_PATH
622609
}
623610

611+
_prepare_device()
612+
{
613+
if [ "$TST_FORMAT_DEVICE" = 1 ]; then
614+
tst_device clear "$TST_DEVICE"
615+
tst_mkfs $TST_FS_TYPE $TST_DEV_FS_OPTS $TST_DEVICE $TST_DEV_EXTRA_OPTS
616+
fi
617+
618+
if [ "$TST_MOUNT_DEVICE" = 1 ]; then
619+
tst_mount
620+
TST_MOUNT_FLAG=1
621+
fi
622+
}
623+
624+
_tst_run_tcases_per_fs()
625+
{
626+
local fs
627+
local filesystems
628+
629+
filesystems="$(tst_supported_fs -s "$TST_SKIP_FILESYSTEMS")"
630+
if [ $? -ne 0 ]; then
631+
tst_brk TCONF "There are no supported filesystems or all skipped"
632+
fi
633+
634+
for fs in $filesystems; do
635+
tst_res TINFO "=== Testing on $fs ==="
636+
TST_FS_TYPE="$fs"
637+
_tst_run_iterations
638+
done
639+
}
640+
624641
tst_run()
625642
{
626643
local _tst_i
627644
local _tst_data
645+
local _tst_fs
628646
local _tst_max
629647
local _tst_name
630648
local _tst_pattern='[='\''"} \t\/:`$\;].*'
@@ -633,7 +651,7 @@ tst_run()
633651
if [ -n "$TST_TEST_PATH" ]; then
634652
for _tst_i in $(grep '^[^#]*\bTST_' "$TST_TEST_PATH" | sed "s/.*TST_//; s/$_tst_pattern//"); do
635653
case "$_tst_i" in
636-
DISABLE_APPARMOR|DISABLE_SELINUX);;
654+
ALL_FILESYSTEMS|DISABLE_APPARMOR|DISABLE_SELINUX);;
637655
SETUP|CLEANUP|TESTFUNC|ID|CNT|MIN_KVER);;
638656
OPTS|USAGE|PARSE_ARGS|POS_ARGS);;
639657
NEEDS_ROOT|NEEDS_TMPDIR|TMPDIR|NEEDS_DEVICE|DEVICE);;
@@ -679,16 +697,32 @@ tst_run()
679697
tst_brk TCONF "test requires kernel $TST_MIN_KVER+"
680698
fi
681699

682-
tst_supported_fs -s "$TST_SKIP_FILESYSTEMS" $TST_FS_TYPE
683-
ret=$?
684-
[ $ret -ne 0 ] && return $ret
685-
686-
_tst_setup_timer
700+
[ -n "$TST_NEEDS_MODULE" ] && tst_require_module "$TST_NEEDS_MODULE"
687701

688702
[ "$TST_MOUNT_DEVICE" = 1 ] && TST_FORMAT_DEVICE=1
689-
[ "$TST_FORMAT_DEVICE" = 1 ] && TST_NEEDS_DEVICE=1
703+
[ "$TST_FORMAT_DEVICE" = 1 -o "$TST_ALL_FILESYSTEMS" = 1 ] && TST_NEEDS_DEVICE=1
690704
[ "$TST_NEEDS_DEVICE" = 1 ] && TST_NEEDS_TMPDIR=1
691705

706+
if [ "$TST_ALL_FILESYSTEMS" != 1 ]; then
707+
if ! tst_supported_fs -s "$TST_SKIP_FILESYSTEMS" $TST_FS_TYPE > /dev/null; then
708+
tst_brk TCONF "$TST_FS_TYPE is skipped by the test"
709+
fi
710+
fi
711+
712+
if [ "$TST_NEEDS_DEVICE" = 1 ]; then
713+
TST_DEVICE=$(tst_device acquire)
714+
715+
if [ ! -b "$TST_DEVICE" -o $? -ne 0 ]; then
716+
unset TST_DEVICE
717+
tst_brk TBROK "Failed to acquire device"
718+
fi
719+
TST_DEVICE_FLAG=1
720+
721+
if [ -z "$TST_FS_TYPE" ]; then
722+
export TST_FS_TYPE="${LTP_DEV_FS_TYPE:-ext2}"
723+
fi
724+
fi
725+
692726
if [ "$TST_NEEDS_TMPDIR" = 1 ]; then
693727
if [ -z "$TMPDIR" ]; then
694728
export TMPDIR="/tmp"
@@ -699,35 +733,32 @@ tst_run()
699733
chmod 777 "$TST_TMPDIR"
700734

701735
TST_STARTWD=$(pwd)
702-
703736
cd "$TST_TMPDIR"
704737
fi
705738

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

711-
if [ ! -b "$TST_DEVICE" -o $? -ne 0 ]; then
712-
unset TST_DEVICE
713-
tst_brk TBROK "Failed to acquire device"
714-
fi
741+
TST_MNTPOINT="${TST_MNTPOINT:-$PWD/mntpoint}"
715742

716-
TST_DEVICE_FLAG=1
743+
if [ "$TST_ALL_FILESYSTEMS" = 1 ]; then
744+
_tst_run_tcases_per_fs
745+
else
746+
_tst_run_iterations
717747
fi
718748

719-
[ -n "$TST_NEEDS_MODULE" ] && tst_require_module "$TST_NEEDS_MODULE"
749+
_tst_do_exit
750+
}
720751

721-
if [ "$TST_FORMAT_DEVICE" = 1 ]; then
722-
tst_mkfs $TST_FS_TYPE $TST_DEV_FS_OPTS $TST_DEVICE $TST_DEV_EXTRA_OPTS
723-
fi
752+
_tst_run_iterations()
753+
{
754+
local _tst_i=$TST_ITERATIONS
755+
local _tst_j
724756

725-
if [ "$TST_MOUNT_DEVICE" = 1 ]; then
726-
tst_mount
727-
TST_MOUNT_FLAG=1
728-
fi
757+
[ "$TST_NEEDS_TMPDIR" = 1 ] && cd "$TST_TMPDIR"
729758

730-
[ -n "$TST_NEEDS_CHECKPOINTS" ] && _tst_init_checkpoints
759+
_prepare_device
760+
761+
_tst_setup_timer
731762

732763
if [ -n "$TST_SETUP" ]; then
733764
if command -v $TST_SETUP >/dev/null 2>/dev/null; then
@@ -739,20 +770,32 @@ tst_run()
739770
fi
740771

741772
#TODO check that test reports some results for each test function call
742-
while [ $TST_ITERATIONS -gt 0 ]; do
773+
while [ $_tst_i -gt 0 ]; do
743774
if [ -n "$TST_TEST_DATA" ]; then
744775
tst_require_cmds cut tr wc
745776
_tst_max=$(( $(echo $TST_TEST_DATA | tr -cd "$TST_TEST_DATA_IFS" | wc -c) +1))
746-
for _tst_i in $(seq $_tst_max); do
747-
_tst_data="$(echo "$TST_TEST_DATA" | cut -d"$TST_TEST_DATA_IFS" -f$_tst_i)"
777+
for _tst_j in $(seq $_tst_max); do
778+
_tst_data="$(echo "$TST_TEST_DATA" | cut -d"$TST_TEST_DATA_IFS" -f$_tst_j)"
748779
_tst_run_tests "$_tst_data"
749780
done
750781
else
751782
_tst_run_tests
752783
fi
753-
TST_ITERATIONS=$((TST_ITERATIONS-1))
784+
_tst_i=$((_tst_i-1))
754785
done
755-
_tst_do_exit
786+
787+
if [ -n "$TST_DO_CLEANUP" -a -n "$TST_CLEANUP" -a -z "$TST_NO_CLEANUP" ]; then
788+
if command -v $TST_CLEANUP >/dev/null 2>/dev/null; then
789+
$TST_CLEANUP
790+
else
791+
tst_res TWARN "TST_CLEANUP=$TST_CLEANUP declared, but function not defined (or cmd not found)"
792+
fi
793+
fi
794+
795+
if [ "$TST_MOUNT_FLAG" = 1 ]; then
796+
tst_umount
797+
TST_MOUNT_FLAG=
798+
fi
756799
}
757800

758801
_tst_run_tests()

0 commit comments

Comments
 (0)