All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 0/4] shell: Add tst_mount() helper
@ 2019-03-14  9:49 Petr Vorel
  2019-03-14  9:49 ` [LTP] [PATCH v2 1/4] " Petr Vorel
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Petr Vorel @ 2019-03-14  9:49 UTC (permalink / raw)
  To: ltp

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(-)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2 1/4] shell: Add tst_mount() helper
  2019-03-14  9:49 [LTP] [PATCH v2 0/4] shell: Add tst_mount() helper Petr Vorel
@ 2019-03-14  9:49 ` Petr Vorel
  2019-03-14 11:15   ` Cyril Hrubis
  2019-03-14  9:49 ` [LTP] [PATCH v2 2/4] ima, commands/{df,mkfs}: Use tst_mount() Petr Vorel
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Petr Vorel @ 2019-03-14  9:49 UTC (permalink / raw)
  To: ltp

and TST_FS_TYPE, TST_MNTPOINT, TST_MNT_PARAMS variables.
TST_FS_TYPE is going to replace FS_TYPE in next commits.
+ document changes.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
[pvorel: Thanks Cyril to point out correct variable names]
Acked-by: Cyril Hrubis <chrubis@suse.cz>
---
 doc/test-writing-guidelines.txt | 12 ++++++++----
 testcases/lib/tst_test.sh       | 25 ++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt
index a5fe58960..d28728d10 100644
--- a/doc/test-writing-guidelines.txt
+++ b/doc/test-writing-guidelines.txt
@@ -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
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index f36051f55..8e7a5b6d6 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -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"
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2 2/4] ima, commands/{df,mkfs}: Use tst_mount()
  2019-03-14  9:49 [LTP] [PATCH v2 0/4] shell: Add tst_mount() helper Petr Vorel
  2019-03-14  9:49 ` [LTP] [PATCH v2 1/4] " Petr Vorel
@ 2019-03-14  9:49 ` Petr Vorel
  2019-03-14  9:49 ` [LTP] [PATCH v2 3/4] shell: Move mkfs.foo into tst_mkfs() Petr Vorel
  2019-03-14  9:49 ` [LTP] [PATCH v2 4/4] shell: Use $TST_FS_TYPE and $TST_DEVICE in tst_mkfs() Petr Vorel
  3 siblings, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2019-03-14  9:49 UTC (permalink / raw)
  To: ltp

to reduce duplicity.
That required to rename variable s/FS_TYPE/TST_FS_TYPE/.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
Acked-by: Cyril Hrubis <chrubis@suse.cz>
---
 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(-)

diff --git a/testcases/commands/df/df01.sh b/testcases/commands/df/df01.sh
index ecd66fbd6..5d9eda802 100755
--- a/testcases/commands/df/df01.sh
+++ b/testcases/commands/df/df01.sh
@@ -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()
diff --git a/testcases/commands/mkfs/mkfs01.sh b/testcases/commands/mkfs/mkfs01.sh
index 68d40830a..88f7f0baa 100755
--- a/testcases/commands/mkfs/mkfs01.sh
+++ b/testcases/commands/mkfs/mkfs01.sh
@@ -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()
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
index fe6098135..1ebd8484d 100644
--- a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
@@ -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()
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2 3/4] shell: Move mkfs.foo into tst_mkfs()
  2019-03-14  9:49 [LTP] [PATCH v2 0/4] shell: Add tst_mount() helper Petr Vorel
  2019-03-14  9:49 ` [LTP] [PATCH v2 1/4] " Petr Vorel
  2019-03-14  9:49 ` [LTP] [PATCH v2 2/4] ima, commands/{df,mkfs}: Use tst_mount() Petr Vorel
@ 2019-03-14  9:49 ` Petr Vorel
  2019-03-14  9:49 ` [LTP] [PATCH v2 4/4] shell: Use $TST_FS_TYPE and $TST_DEVICE in tst_mkfs() Petr Vorel
  3 siblings, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2019-03-14  9:49 UTC (permalink / raw)
  To: ltp

+ remove unused local ret variable.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
Acked-by: Cyril Hrubis <chrubis@suse.cz>
---
 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(-)

diff --git a/testcases/commands/df/df01.sh b/testcases/commands/df/df01.sh
index 5d9eda802..1ffecd2da 100755
--- a/testcases/commands/df/df01.sh
+++ b/testcases/commands/df/df01.sh
@@ -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}')
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
index 1ebd8484d..bfdcfaef7 100644
--- a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
@@ -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
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index 8e7a5b6d6..ecd162e60 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -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
 }
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2 4/4] shell: Use $TST_FS_TYPE and $TST_DEVICE in tst_mkfs()
  2019-03-14  9:49 [LTP] [PATCH v2 0/4] shell: Add tst_mount() helper Petr Vorel
                   ` (2 preceding siblings ...)
  2019-03-14  9:49 ` [LTP] [PATCH v2 3/4] shell: Move mkfs.foo into tst_mkfs() Petr Vorel
@ 2019-03-14  9:49 ` Petr Vorel
  3 siblings, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2019-03-14  9:49 UTC (permalink / raw)
  To: ltp

as default parameters.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
Acked-by: Cyril Hrubis <chrubis@suse.cz>
---
 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(-)

diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt
index d28728d10..73fc687d5 100644
--- a/doc/test-writing-guidelines.txt
+++ b/doc/test-writing-guidelines.txt
@@ -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
diff --git a/testcases/commands/df/df01.sh b/testcases/commands/df/df01.sh
index 1ffecd2da..9b0be76fe 100755
--- a/testcases/commands/df/df01.sh
+++ b/testcases/commands/df/df01.sh
@@ -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}')
 }
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
index bfdcfaef7..52551190a 100644
--- a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
@@ -53,7 +53,7 @@ mount_loop_device()
 {
 	local ret
 
-	tst_mkfs $TST_FS_TYPE $TST_DEVICE
+	tst_mkfs
 	tst_mount
 	cd $TST_MNTPOINT
 }
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index ecd162e60..af16ce1cf 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -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="$@"
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2 1/4] shell: Add tst_mount() helper
  2019-03-14  9:49 ` [LTP] [PATCH v2 1/4] " Petr Vorel
@ 2019-03-14 11:15   ` Cyril Hrubis
  2019-03-14 13:27     ` Petr Vorel
  0 siblings, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2019-03-14 11:15 UTC (permalink / raw)
  To: ltp

Hi!
> +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.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2 1/4] shell: Add tst_mount() helper
  2019-03-14 11:15   ` Cyril Hrubis
@ 2019-03-14 13:27     ` Petr Vorel
  0 siblings, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2019-03-14 13:27 UTC (permalink / raw)
  To: ltp

Hi Cyril,

> 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.

Thank for fixes, merged!


Kind regards,
Petr

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-03-14 13:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-14  9:49 [LTP] [PATCH v2 0/4] shell: Add tst_mount() helper Petr Vorel
2019-03-14  9:49 ` [LTP] [PATCH v2 1/4] " Petr Vorel
2019-03-14 11:15   ` Cyril Hrubis
2019-03-14 13:27     ` Petr Vorel
2019-03-14  9:49 ` [LTP] [PATCH v2 2/4] ima, commands/{df,mkfs}: Use tst_mount() Petr Vorel
2019-03-14  9:49 ` [LTP] [PATCH v2 3/4] shell: Move mkfs.foo into tst_mkfs() Petr Vorel
2019-03-14  9:49 ` [LTP] [PATCH v2 4/4] shell: Use $TST_FS_TYPE and $TST_DEVICE in tst_mkfs() Petr Vorel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.