diff mbox series

[v2,3/6] tst_test.sh: Add $TST_FORMAT_DEVICE and related vars

Message ID 20220210162739.30159-4-pvorel@suse.cz
State Accepted
Headers show
Series Add TST_FORMAT_DEVICE support | expand

Commit Message

Petr Vorel Feb. 10, 2022, 4:27 p.m. UTC
i.e.: TST_DEV_EXTRA_OPTS, TST_DEV_FS_OPTS, TST_FS_TYPE
(to sync with C API).

NOTE: stop using pattern 'TST_NEEDS_FOO', sometimes 'NEEDS' just does
not fit to variable name.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 doc/shell-test-api.txt    | 31 +++++++++++++++++++++++++++++--
 testcases/lib/tst_test.sh |  6 ++++++
 2 files changed, 35 insertions(+), 2 deletions(-)

Comments

Yang Xu Feb. 11, 2022, 6:58 a.m. UTC | #1
Hi Petr
> +
> +[source,sh]
> +-------------------------------------------------------------------------------
> +TST_FORMAT_DEVICE=1
> +TST_DEV_FS_OPTS="-b 1024 -O quota"
> +TST_DEV_EXTRA_OPTS="5m"
> +TST_TESTFUNC=test
> +
> +test1()
A small nit, I prefer to use test name directly if we don't have several
sub test cases.

Best Regards
Yang Xu
> +{
> +	tst_res TPASS "device formatted"
> +}

> +-------------------------------------------------------------------------------
Petr Vorel Feb. 11, 2022, 7:15 a.m. UTC | #2
Hi Xu,
> Hi Petr
> > +
> > +[source,sh]
> > +-------------------------------------------------------------------------------
> > +TST_FORMAT_DEVICE=1
> > +TST_DEV_FS_OPTS="-b 1024 -O quota"
> > +TST_DEV_EXTRA_OPTS="5m"
> > +TST_TESTFUNC=test
> > +
> > +test1()
> A small nit, I prefer to use test name directly if we don't have several
> sub test cases.
Sure. Originally I had more tests there, using lsblk.
But I'll probably extend these tests to your suggestion in different mail.

Kind regards,
Petr

> Best Regards
> Yang Xu
> > +{
> > +	tst_res TPASS "device formatted"
> > +}

> > +-------------------------------------------------------------------------------
Cyril Hrubis March 11, 2022, 2:28 p.m. UTC | #3
Hi!
> ---
>  doc/shell-test-api.txt    | 31 +++++++++++++++++++++++++++++--
>  testcases/lib/tst_test.sh |  6 ++++++
>  2 files changed, 35 insertions(+), 2 deletions(-)
> 
> diff --git a/doc/shell-test-api.txt b/doc/shell-test-api.txt
> index a5974b4fad..5caa889c9e 100644
> --- a/doc/shell-test-api.txt
> +++ b/doc/shell-test-api.txt
> @@ -189,11 +189,20 @@ space as default value is used. Of course, it's possible to use separate functio
>  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  
>  Similarily to the C library various checks and preparations can be requested
> -simply by setting right '$TST_NEEDS_FOO'.
> +simply by setting right '$TST_FOO'.
>  
>  [options="header"]
>  |=============================================================================
>  | Variable name            | Action done
> +| '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,
> +|                          | to 'tst_mkfs', use with 'TST_FORMAT_DEVICE=1'.
> +| 'TST_FORMAT_DEVICE'      | Format a block device with a filesystem, see
> +|                          | https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#formatting-device-with-a-filesystem[Formatting device with a filesystem]

Hm, I guess that we already have a few absolute links in the docs to a
github.com wiki, but I do not like it that much. I guess that realtive
links does not work, right?

> +|                          | See also 'TST_DEV_EXTRA_OPTS', 'TST_DEV_FS_OPTS', 'TST_FS_TYPE'.
> +|                          | Implies 'TST_NEEDS_DEVICE=1' (no need to set it).
> +| 'TST_FS_TYPE'            | Override the default filesystem to be used.
>  | '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.
> @@ -495,7 +504,25 @@ tst_random 0 1000
>  Formatting device with a filesystem
>  +++++++++++++++++++++++++++++++++++
>  
> -The 'tst_mkfs' helper will format device with the filesystem.
> +'TST_FORMAT_DEVICE=1' can be used to format device before running the test.
> +Uses '$TST_FS_TYPE' (used filesystem, by default ext2), '$TST_DEVICE' (used
                              ^
			      I would removed this part and keep only
			      the (by default ext2)
> +block device, usually prepared by 'TST_NEEDS_DEVICE=1'), '$TST_DEV_FS_OPTS'

and rewrote this part no to be in the parentheses as:

'$TST_DEVICE' a block device to be formatted, usually prepared by the
library (TST_NEEDS_DEVICE=1 must be set).

> +('mkfs' options _before_ the device name) and '$TST_DEV_EXTRA_OPTS'
> +(extra 'mkfs' options _after_ the device name).

And remove the parentheses here as:

'$TST_DEV_FS_OPTS' a 'mkfs' options _before_ the device path and
'$TST_DEV_EXTRA_OPTS' extra 'mkfs'' options _after_ the device path.


Other than that and the test1() pointed out by Yang Xu:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Petr Vorel March 13, 2022, 9:48 p.m. UTC | #4
Hi Cyril,

> > +| 'TST_FORMAT_DEVICE'      | Format a block device with a filesystem, see
> > +|                          | https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#formatting-device-with-a-filesystem[Formatting device with a filesystem]

> Hm, I guess that we already have a few absolute links in the docs to a
> github.com wiki, but I do not like it that much. I guess that realtive
> links does not work, right?

AFAIK it does not in AsciiDoc format (not sure about other, but we don't want to
switch anyway). I guess I can keep it as we don't have any better solution,
right?

> > +|                          | See also 'TST_DEV_EXTRA_OPTS', 'TST_DEV_FS_OPTS', 'TST_FS_TYPE'.
> > +|                          | Implies 'TST_NEEDS_DEVICE=1' (no need to set it).
> > +| 'TST_FS_TYPE'            | Override the default filesystem to be used.
> >  | '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.
> > @@ -495,7 +504,25 @@ tst_random 0 1000
> >  Formatting device with a filesystem
> >  +++++++++++++++++++++++++++++++++++

> > -The 'tst_mkfs' helper will format device with the filesystem.
> > +'TST_FORMAT_DEVICE=1' can be used to format device before running the test.
> > +Uses '$TST_FS_TYPE' (used filesystem, by default ext2), '$TST_DEVICE' (used
>                               ^
> 			      I would removed this part and keep only
> 			      the (by default ext2)
> > +block device, usually prepared by 'TST_NEEDS_DEVICE=1'), '$TST_DEV_FS_OPTS'

> and rewrote this part no to be in the parentheses as:

> '$TST_DEVICE' a block device to be formatted, usually prepared by the
> library (TST_NEEDS_DEVICE=1 must be set).

> > +('mkfs' options _before_ the device name) and '$TST_DEV_EXTRA_OPTS'
> > +(extra 'mkfs' options _after_ the device name).

> And remove the parentheses here as:

> '$TST_DEV_FS_OPTS' a 'mkfs' options _before_ the device path and
> '$TST_DEV_EXTRA_OPTS' extra 'mkfs'' options _after_ the device path.

Agree with all of this.


> Other than that and the test1() pointed out by Yang Xu:
I suppose this is what you mean: s/test1/test/, right?

+++ doc/shell-test-api.txt
@@ -517,7 +517,7 @@ TST_DEV_FS_OPTS="-b 1024 -O quota"
 TST_DEV_EXTRA_OPTS="5m"
 TST_TESTFUNC=test

-test1()
+test()
 {
        tst_res TPASS "device formatted"
 }


> Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Thanks!

Kind regards,
Petr
diff mbox series

Patch

diff --git a/doc/shell-test-api.txt b/doc/shell-test-api.txt
index a5974b4fad..5caa889c9e 100644
--- a/doc/shell-test-api.txt
+++ b/doc/shell-test-api.txt
@@ -189,11 +189,20 @@  space as default value is used. Of course, it's possible to use separate functio
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 Similarily to the C library various checks and preparations can be requested
-simply by setting right '$TST_NEEDS_FOO'.
+simply by setting right '$TST_FOO'.
 
 [options="header"]
 |=============================================================================
 | Variable name            | Action done
+| '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,
+|                          | to 'tst_mkfs', use with 'TST_FORMAT_DEVICE=1'.
+| 'TST_FORMAT_DEVICE'      | Format a block device with a filesystem, see
+|                          | https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#formatting-device-with-a-filesystem[Formatting device with a filesystem]
+|                          | See also 'TST_DEV_EXTRA_OPTS', 'TST_DEV_FS_OPTS', 'TST_FS_TYPE'.
+|                          | Implies 'TST_NEEDS_DEVICE=1' (no need to set it).
+| 'TST_FS_TYPE'            | Override the default filesystem to be used.
 | '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.
@@ -495,7 +504,25 @@  tst_random 0 1000
 Formatting device with a filesystem
 +++++++++++++++++++++++++++++++++++
 
-The 'tst_mkfs' helper will format device with the filesystem.
+'TST_FORMAT_DEVICE=1' can be used to format device before running the test.
+Uses '$TST_FS_TYPE' (used filesystem, by default ext2), '$TST_DEVICE' (used
+block device, usually prepared by 'TST_NEEDS_DEVICE=1'), '$TST_DEV_FS_OPTS'
+('mkfs' options _before_ the device name) and '$TST_DEV_EXTRA_OPTS'
+(extra 'mkfs' options _after_ the device name).
+Library internally uses 'tst_mkfs' function, which can be used for more complex setup.
+
+[source,sh]
+-------------------------------------------------------------------------------
+TST_FORMAT_DEVICE=1
+TST_DEV_FS_OPTS="-b 1024 -O quota"
+TST_DEV_EXTRA_OPTS="5m"
+TST_TESTFUNC=test
+
+test1()
+{
+	tst_res TPASS "device formatted"
+}
+-------------------------------------------------------------------------------
 
 [source,sh]
 -------------------------------------------------------------------------------
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index 64e65f9f53..0968391984 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -616,6 +616,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);;
 			*) tst_res TWARN "Reserved variable TST_$_tst_i used!";;
 			esac
 		done
@@ -660,6 +661,7 @@  tst_run()
 
 	_tst_setup_timer
 
+	[ "$TST_FORMAT_DEVICE" = 1 ] && TST_NEEDS_DEVICE=1
 	[ "$TST_NEEDS_DEVICE" = 1 ] && TST_NEEDS_TMPDIR=1
 
 	if [ "$TST_NEEDS_TMPDIR" = 1 ]; then
@@ -691,6 +693,10 @@  tst_run()
 
 	[ -n "$TST_NEEDS_MODULE" ] && tst_require_module "$TST_NEEDS_MODULE"
 
+	if [ "$TST_FORMAT_DEVICE" = 1 ]; then
+		tst_mkfs $TST_FS_TYPE $TST_DEV_FS_OPTS $TST_DEVICE $TST_DEV_EXTRA_OPTS
+	fi
+
 	[ -n "$TST_NEEDS_CHECKPOINTS" ] && _tst_init_checkpoints
 
 	if [ -n "$TST_SETUP" ]; then