shell: Add tst_mount() helper
v2 cover shell: Add tst_mount() helper
Hi,
just single change in tst_mount(): it does not require $TST_FS_TYPE any more (it's optional). This was required by mkfs01.sh which has it's first run in runtest/commands without specifying filesystem. I guess this is valid testcase (testing some obscure fs e.g. some FUSE) which is not in runtest/commands + it also tests mkfs itself.
Kind regards,
Petr
Petr Vorel (4):
shell: Add tst_mount() helper
ima, commands/{df,mkfs}: Use tst_mount()
shell: Move mkfs.foo into tst_mkfs()
shell: Use $TST_FS_TYPE and $TST_DEVICE in tst_mkfs()
doc/test-writing-guidelines.txt | 16 +++++++--- testcases/commands/df/df01.sh | 28 +++------------- testcases/commands/mkfs/mkfs01.sh | 27 ++++------------ .../security/integrity/ima/tests/ima_setup.sh | 14 +++----- testcases/lib/tst_test.sh | 32 ++++++++++++++++--- 5 files changed, 56 insertions(+), 61 deletions(-)
Signature · 1 line
2.21.0
PATCH v2 1/4 shell: Add tst_mount() helper
and TST_FS_TYPE, TST_MNTPOINT, TST_MNT_PARAMS variables. TST_FS_TYPE is going to replace FS_TYPE in next commits.
+ document changes.
--- doc/test-writing-guidelines.txt | 12 ++++++++---- testcases/lib/tst_test.sh | 25 ++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 5 deletions(-)
doc/test-writing-guidelines.txt +8 -4
@@ -2034,12 +2034,16 @@ The 'tst_mkfs' helper will format device with the filesystem. tst_mkfs ext2 $TST_DEVICE ------------------------------------------------------------------------------- -Umounting filesystems -+++++++++++++++++++++ +Mounting and unmounting filesystems ++++++++++++++++++++++++++++++++++++ + +The 'tst_mount' and 'tst_umount' helpers are a safe way to mount/umount a filesystem. -The 'tst_umount' helper is a safe way to umount a filesystem. +The 'tst_mount' mounts '$TST_DEVICE' of '$TST_FS_TYPE' (optional) to '$TST_MNTPOINT', +using optional '$TST_MNT_PARAMS'. It creates before mounting the '$TST_MNTPOINT' +directory if not exists and fails if mounting was unsuccessful. -If the path passed to the function is not mounted (present in '/proc/mounts') +If the path passed to the 'tst_umount' is not mounted (present in '/proc/mounts') it's noop. Otherwise it retries to umount the filesystem a few times on a failure, which
testcases/lib/tst_test.sh +24 -1
@@ -235,6 +235,28 @@ TST_RTNL_CHK() tst_brk TBROK "$@ failed: $output" } +tst_mount() +{ + local mnt_opt mnt_err + + if [ -n "$TST_FS_TYPE" ]; then + mnt_opt="-t $TST_FS_TYPE" + mnt_err=" $TST_FS_TYPE type" + fi + + ROD_SILENT mkdir -p $TST_MNTPOINT + mount $mnt_opt $TST_DEVICE $TST_MNTPOINT $TST_MNT_PARAMS + local ret=$? + + if [ $ret -eq 32 ]; then + tst_brk TCONF "Cannot mount${mnt_err}, missing driver?" + fi + + if [ $ret -ne 0 ]; then + tst_brk TBROK "Failed to mount device${mnt_err}: mount exit = $ret" + fi +} + tst_umount() { local device="$1"
@@ -401,7 +423,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);; + NEEDS_DRIVERS|FS_TYPE|MNTPOINT|MNT_PARAMS);; IPV6|IPVER|TEST_DATA|TEST_DATA_IFS);; RETRY_FUNC|RETRY_FN_EXP_BACKOFF);; NET_MAX_PKT);;
@@ -462,6 +484,7 @@ tst_run() cd "$TST_TMPDIR" fi + TST_MNTPOINT="${TST_MNTPOINT:-mntpoint}" if [ "$TST_NEEDS_DEVICE" = 1 ]; then if [ -z ${TST_TMPDIR} ]; then tst_brk TBROK "Use TST_NEEDS_TMPDIR must be set for TST_NEEDS_DEVICE"
Signature · 1 line
2.21.0
PATCH v2 1/4 shell: Add tst_mount() helper
Hi!
doc/test-writing-guidelines.txt The 'tst_mkfs' helper will format device with the filesystem. · line 2044
Quoted 9 lines
doc/test-writing-guidelines.txt +7
-1+Mounting and unmounting filesystems ++++++++++++++++++++++++++++++++++++ + +The 'tst_mount' and 'tst_umount' helpers are a safe way to mount/umount a filesystem. -The 'tst_umount' helper is a safe way to umount a filesystem. +The 'tst_mount' mounts '$TST_DEVICE' of '$TST_FS_TYPE' (optional) to '$TST_MNTPOINT', +using optional '$TST_MNT_PARAMS'. It creates before mounting the '$TST_MNTPOINT' +directory if not exists and fails if mounting was unsuccessful.
The last nit is this piece of docummentation.
- The last sentence is missing subject, generally the sentence does not make much sense
- We should document that TST_MNTPOINT defaults to mntpoint
So it should be something as:
The 'tst_mount' mounts '$TST_DEVICE' of '$TST_FS_TYPE' (optional) to '$TST_MNTPOINT' (defaults to mntpoint), optionally using the '$TST_MNT_PARAMS'. The '$TST_MNTPOINT' directory is created if it didn't exist prior to the function call.
Otherwise it all looks fine, acked with a change to this docs.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/4 shell: Add tst_mount() helper
Hi Cyril,
Quoted 8 lines
The last nit is this piece of docummentation.
- The last sentence is missing subject, generally the sentence does not make much sense
- We should document thatTST_MNTPOINTdefaults to mntpointSo it should be something as:
Quoted 7 lines
The '
tst_mount' mounts '$TST_DEVICE' of '$TST_FS_TYPE' (optional) to '$TST_MNTPOINT' (defaults to mntpoint), optionally using the '$TST_MNT_PARAMS'. The '$TST_MNTPOINT' directory is created if it didn't exist prior to the function call.Otherwise it all looks fine, acked with a change to this docs.
Thank for fixes, merged!
Kind regards,
Petr
PATCH v2 2/4 ima, commands/{df,mkfs}: Use tst_mount()
In reply to Petr Vorelto reduce duplicity.
That required to rename variable s/FS_TYPE/TST_FS_TYPE/.
--- testcases/commands/df/df01.sh | 26 +++++------------- testcases/commands/mkfs/mkfs01.sh | 27 +++++-------------- .../security/integrity/ima/tests/ima_setup.sh | 15 ++++------- 3 files changed, 19 insertions(+), 49 deletions(-)
testcases/commands/df/df01.sh +7 -19
@@ -40,41 +40,29 @@ OPTIONS EOF } -FS_TYPE=ext2 +TST_FS_TYPE=ext2 parse_args() { - FS_TYPE="$2" + TST_FS_TYPE="$2" } setup() { local ret - if [ -n "$FS_TYPE" ]; then - tst_test_cmds mkfs.${FS_TYPE} - fi - - tst_mkfs ${FS_TYPE} ${TST_DEVICE} - - ROD_SILENT mkdir -p mntpoint - - mount ${TST_DEVICE} mntpoint - ret=$? - if [ $ret -eq 32 ]; then - tst_brk TCONF "Cannot mount ${FS_TYPE}, missing driver?" - fi - - if [ $ret -ne 0 ]; then - tst_brk TBROK "Failed to mount device: mount exit = $ret" + if [ -n "$TST_FS_TYPE" ]; then + tst_test_cmds mkfs.${TST_FS_TYPE} fi + tst_mkfs $TST_FS_TYPE $TST_DEVICE + tst_mount DF_FS_TYPE=$(mount | grep "$TST_DEVICE" | awk '{print $5}') } cleanup() { - tst_umount ${TST_DEVICE} + tst_umount $TST_DEVICE } df_test()
testcases/commands/mkfs/mkfs01.sh +7 -20
@@ -42,31 +42,18 @@ EOF parse_args() { - FS_TYPE="$2" + TST_FS_TYPE="$2" } setup() { - if [ -n "$FS_TYPE" ]; then - tst_test_cmds mkfs.${FS_TYPE} + if [ -n "$TST_FS_TYPE" ]; then + tst_test_cmds mkfs.${TST_FS_TYPE} fi ROD_SILENT mkdir -p mntpoint } -mkfs_mount() -{ - mount ${TST_DEVICE} mntpoint - local ret=$? - if [ $ret -eq 32 ]; then - tst_brk TCONF "Cannot mount ${FS_TYPE}, missing driver?" - fi - - if [ $ret -ne 0 ]; then - tst_brk TBROK "Failed to mount device: mount exit = $ret" - fi -} - mkfs_verify_type() { if [ -z "$1" ]; then
@@ -82,7 +69,7 @@ mkfs_verify_type() mkfs_verify_size() { - mkfs_mount + tst_mount local blocknum=`df -P -B 1k mntpoint | tail -n1 | awk '{print $2}'` tst_umount "$TST_DEVICE"
@@ -171,17 +158,17 @@ mkfs_test() test1() { - mkfs_test "" "$FS_TYPE" "" "$TST_DEVICE" + mkfs_test "" "$TST_FS_TYPE" "" "$TST_DEVICE" } test2() { - mkfs_test "" "$FS_TYPE" "" "$TST_DEVICE" "16000" + mkfs_test "" "$TST_FS_TYPE" "" "$TST_DEVICE" "16000" } test3() { - mkfs_test "" "$FS_TYPE" "-c" "$TST_DEVICE" + mkfs_test "" "$TST_FS_TYPE" "-c" "$TST_DEVICE" } test4()
testcases/kernel/security/integrity/ima/tests/ima_setup.sh +5 -10
@@ -28,7 +28,7 @@ TST_NEEDS_ROOT=1 SYSFS="/sys" UMOUNT= -FS_TYPE="ext3" +TST_FS_TYPE="ext3" mount_helper() {
@@ -53,15 +53,10 @@ mount_loop_device() { local ret - tst_test_cmds mkfs.$FS_TYPE - tst_mkfs $FS_TYPE $TST_DEVICE - ROD_SILENT mkdir -p mntpoint - mount ${TST_DEVICE} mntpoint - ret=$? - if [ $ret -ne 0 ]; then - tst_brk TBROK "failed to mount device (mount exit = $ret)" - fi - cd mntpoint + tst_test_cmds mkfs.$TST_FS_TYPE + tst_mkfs $TST_FS_TYPE $TST_DEVICE + tst_mount + cd $TST_MNTPOINT } print_ima_config()
Signature · 1 line
2.21.0
PATCH v2 3/4 shell: Move mkfs.foo into tst_mkfs()
In reply to Petr Vorel+ remove unused local ret variable.
--- testcases/commands/df/df01.sh | 6 ------ testcases/kernel/security/integrity/ima/tests/ima_setup.sh | 1 - testcases/lib/tst_test.sh | 3 ++- 3 files changed, 2 insertions(+), 8 deletions(-)
testcases/commands/df/df01.sh +0 -6
@@ -49,12 +49,6 @@ parse_args() setup() { - local ret - - if [ -n "$TST_FS_TYPE" ]; then - tst_test_cmds mkfs.${TST_FS_TYPE} - fi - tst_mkfs $TST_FS_TYPE $TST_DEVICE tst_mount DF_FS_TYPE=$(mount | grep "$TST_DEVICE" | awk '{print $5}')
testcases/kernel/security/integrity/ima/tests/ima_setup.sh +0 -1
@@ -53,7 +53,6 @@ mount_loop_device() { local ret - tst_test_cmds mkfs.$TST_FS_TYPE tst_mkfs $TST_FS_TYPE $TST_DEVICE tst_mount cd $TST_MNTPOINT
testcases/lib/tst_test.sh +2 -1
@@ -299,8 +299,9 @@ tst_mkfs() tst_brk TBROK "No device specified" fi - tst_res TINFO "Formatting $device with $fs_type extra opts='$fs_opts'" + tst_test_cmds mkfs.$fs_type + tst_res TINFO "Formatting $device with $fs_type extra opts='$fs_opts'" ROD_SILENT mkfs.$fs_type $fs_opts $device }
Signature · 1 line
2.21.0
PATCH v2 4/4 shell: Use $TST_FS_TYPE and $TST_DEVICE in tst_mkfs()
In reply to Petr Vorelas default parameters.
--- doc/test-writing-guidelines.txt | 4 ++++ testcases/commands/df/df01.sh | 2 +- testcases/kernel/security/integrity/ima/tests/ima_setup.sh | 2 +- testcases/lib/tst_test.sh | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-)
doc/test-writing-guidelines.txt +4 -0
@@ -2032,6 +2032,10 @@ The 'tst_mkfs' helper will format device with the filesystem. ------------------------------------------------------------------------------- # format test device with ext2 tst_mkfs ext2 $TST_DEVICE +# default params are $TST_FS_TYPE $TST_DEVICE +tst_mkfs +# optional parameters +tst_mkfs ext4 /dev/device -T largefile ------------------------------------------------------------------------------- Mounting and unmounting filesystems
testcases/commands/df/df01.sh +1 -1
@@ -49,7 +49,7 @@ parse_args() setup() { - tst_mkfs $TST_FS_TYPE $TST_DEVICE + tst_mkfs tst_mount DF_FS_TYPE=$(mount | grep "$TST_DEVICE" | awk '{print $5}') }
testcases/kernel/security/integrity/ima/tests/ima_setup.sh +1 -1
@@ -53,7 +53,7 @@ mount_loop_device() { local ret - tst_mkfs $TST_FS_TYPE $TST_DEVICE + tst_mkfs tst_mount cd $TST_MNTPOINT }
testcases/lib/tst_test.sh +2 -2
@@ -286,8 +286,8 @@ tst_umount() tst_mkfs() { - local fs_type=$1 - local device=$2 + local fs_type=${1:-$TST_FS_TYPE} + local device=${2:-$TST_DEVICE} shift 2 local fs_opts="$@"
Signature · 1 line
2.21.0