public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] shell: Add support for runtime
@ 2025-11-19  9:31 Cyril Hrubis
  2025-11-20  7:32 ` Li Wang via ltp
  0 siblings, 1 reply; 4+ messages in thread
From: Cyril Hrubis @ 2025-11-19  9:31 UTC (permalink / raw)
  To: ltp; +Cc: Piotr Kubaj

Adds support for "runtime" and "min_runtime" to the tst_run_shell as
well as new binary helper tst_remaining_runtime that calls the C
function of that name and prints the number into the stdout.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
CC: Piotr Kubaj <piotr.kubaj@intel.com>
---
 testcases/lib/.gitignore                      |  1 +
 testcases/lib/Makefile                        |  2 +-
 .../lib/tests/shell_loader_filesystems.sh     |  9 +++++++
 testcases/lib/tst_remaining_runtime.c         | 26 +++++++++++++++++++
 testcases/lib/tst_run_shell.c                 | 16 ++++++++++++
 5 files changed, 53 insertions(+), 1 deletion(-)
 create mode 100644 testcases/lib/tst_remaining_runtime.c

diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
index 385f3c3ca..19d7c67bb 100644
--- a/testcases/lib/.gitignore
+++ b/testcases/lib/.gitignore
@@ -25,3 +25,4 @@
 /tst_timeout_kill
 /tst_res_
 /tst_run_shell
+/tst_remaining_runtime
diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
index b3a9181c1..2309a42a3 100644
--- a/testcases/lib/Makefile
+++ b/testcases/lib/Makefile
@@ -17,6 +17,6 @@ MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
 			   tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill\
 			   tst_check_kconfigs tst_cgctl tst_fsfreeze tst_ns_create tst_ns_exec\
 			   tst_ns_ifmove tst_lockdown_enabled tst_secureboot_enabled tst_res_\
-			   tst_run_shell
+			   tst_run_shell tst_remaining_runtime
 
 include $(top_srcdir)/include/mk/generic_trunk_target.mk
diff --git a/testcases/lib/tests/shell_loader_filesystems.sh b/testcases/lib/tests/shell_loader_filesystems.sh
index d584503ad..823ce1975 100755
--- a/testcases/lib/tests/shell_loader_filesystems.sh
+++ b/testcases/lib/tests/shell_loader_filesystems.sh
@@ -6,6 +6,7 @@
 # env
 # {
 #  "mount_device": true,
+#  "runtime": 10,
 #  "mntpoint": "ltp_mntpoint",
 #  "filesystems": [
 #   {
@@ -38,6 +39,14 @@ tst_test()
 	else
 		tst_res TFAIL "Device not mounted!"
 	fi
+
+	RUNTIME=$(tst_remaining_runtime)
+
+	if [ "$RUNTIME" -ge 9 ]; then
+		tst_res TPASS "Remaining runtime $RUNTIME"
+	else
+		tst_res TFAIL "Remaning runtime $RUNTIME"
+	fi
 }
 
 . tst_run.sh
diff --git a/testcases/lib/tst_remaining_runtime.c b/testcases/lib/tst_remaining_runtime.c
new file mode 100644
index 000000000..df383d346
--- /dev/null
+++ b/testcases/lib/tst_remaining_runtime.c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+
+static void print_help(char *name)
+{
+	fprintf(stderr, "Usage: %s\n", name);
+}
+
+int main(int argc, char *argv[])
+{
+	if (argc > 1) {
+		print_help(argv[0]);
+		return 1;
+	}
+
+	tst_reinit();
+
+	printf("%u\n", tst_remaining_runtime());
+
+	return 0;
+}
diff --git a/testcases/lib/tst_run_shell.c b/testcases/lib/tst_run_shell.c
index 7a446e004..91f34127d 100644
--- a/testcases/lib/tst_run_shell.c
+++ b/testcases/lib/tst_run_shell.c
@@ -60,6 +60,7 @@ enum test_attr_ids {
 	MIN_CPUS,
 	MIN_MEM_AVAIL,
 	MIN_KVER,
+	MIN_RUNTIME,
 	MIN_SWAP_AVAIL,
 	MNTPOINT,
 	MOUNT_DEVICE,
@@ -74,6 +75,7 @@ enum test_attr_ids {
 	NEEDS_ROOT,
 	NEEDS_TMPDIR,
 	RESTORE_WALLCLOCK,
+	RUNTIME,
 	SAVE_RESTORE,
 	SKIP_FILESYSTEMS,
 	SKIP_IN_COMPAT,
@@ -93,6 +95,7 @@ static ujson_obj_attr test_attrs[] = {
 	UJSON_OBJ_ATTR_IDX(MIN_CPUS, "min_cpus", UJSON_INT),
 	UJSON_OBJ_ATTR_IDX(MIN_MEM_AVAIL, "min_mem_avail", UJSON_INT),
 	UJSON_OBJ_ATTR_IDX(MIN_KVER, "min_kver", UJSON_STR),
+	UJSON_OBJ_ATTR_IDX(MIN_RUNTIME, "min_runtime", UJSON_INT),
 	UJSON_OBJ_ATTR_IDX(MIN_SWAP_AVAIL, "min_swap_avail", UJSON_INT),
 	UJSON_OBJ_ATTR_IDX(MNTPOINT, "mntpoint", UJSON_STR),
 	UJSON_OBJ_ATTR_IDX(MOUNT_DEVICE, "mount_device", UJSON_BOOL),
@@ -107,6 +110,7 @@ static ujson_obj_attr test_attrs[] = {
 	UJSON_OBJ_ATTR_IDX(NEEDS_ROOT, "needs_root", UJSON_BOOL),
 	UJSON_OBJ_ATTR_IDX(NEEDS_TMPDIR, "needs_tmpdir", UJSON_BOOL),
 	UJSON_OBJ_ATTR_IDX(RESTORE_WALLCLOCK, "restore_wallclock", UJSON_BOOL),
+	UJSON_OBJ_ATTR_IDX(RUNTIME, "runtime", UJSON_INT),
 	UJSON_OBJ_ATTR_IDX(SAVE_RESTORE, "save_restore", UJSON_ARR),
 	UJSON_OBJ_ATTR_IDX(SKIP_FILESYSTEMS, "skip_filesystems", UJSON_ARR),
 	UJSON_OBJ_ATTR_IDX(SKIP_IN_COMPAT, "skip_in_compat", UJSON_BOOL),
@@ -421,6 +425,12 @@ static void parse_metadata(void)
 		case MIN_KVER:
 			test.min_kver = strdup(val.val_str);
 		break;
+		case MIN_RUNTIME:
+			if (val.val_int <= 0)
+				ujson_err(&reader, "Minimal runtime must be > 0");
+			else
+				test.min_runtime = val.val_int;
+		break;
 		case MIN_SWAP_AVAIL:
 			if (val.val_int <= 0)
 				ujson_err(&reader, "Minimal available swap size must be > 0");
@@ -469,6 +479,12 @@ static void parse_metadata(void)
 		case RESTORE_WALLCLOCK:
 			test.restore_wallclock = val.val_bool;
 		break;
+		case RUNTIME:
+			if (val.val_int <= 0)
+				ujson_err(&reader, "Runtime must be > 0");
+			else
+				test.runtime = val.val_int;
+		break;
 		case SAVE_RESTORE:
 			test.save_restore = parse_save_restore(&reader, &val);
 		break;
-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH] shell: Add support for runtime
  2025-11-19  9:31 [LTP] [PATCH] shell: Add support for runtime Cyril Hrubis
@ 2025-11-20  7:32 ` Li Wang via ltp
  2025-11-20 13:33   ` Petr Vorel
  2025-11-24 12:23   ` Cyril Hrubis
  0 siblings, 2 replies; 4+ messages in thread
From: Li Wang via ltp @ 2025-11-20  7:32 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

On Wed, Nov 19, 2025 at 5:30 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> Adds support for "runtime" and "min_runtime" to the tst_run_shell as
> well as new binary helper tst_remaining_runtime that calls the C
> function of that name and prints the number into the stdout.
>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> CC: Piotr Kubaj <piotr.kubaj@intel.com>
> ---
>  testcases/lib/.gitignore                      |  1 +
>  testcases/lib/Makefile                        |  2 +-
>  .../lib/tests/shell_loader_filesystems.sh     |  9 +++++++
>  testcases/lib/tst_remaining_runtime.c         | 26 +++++++++++++++++++
>  testcases/lib/tst_run_shell.c                 | 16 ++++++++++++
>  5 files changed, 53 insertions(+), 1 deletion(-)
>  create mode 100644 testcases/lib/tst_remaining_runtime.c
>
> diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
> index 385f3c3ca..19d7c67bb 100644
> --- a/testcases/lib/.gitignore
> +++ b/testcases/lib/.gitignore
> @@ -25,3 +25,4 @@
>  /tst_timeout_kill
>  /tst_res_
>  /tst_run_shell
> +/tst_remaining_runtime
> diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
> index b3a9181c1..2309a42a3 100644
> --- a/testcases/lib/Makefile
> +++ b/testcases/lib/Makefile
> @@ -17,6 +17,6 @@ MAKE_TARGETS          := tst_sleep tst_random
> tst_checkpoint tst_rod tst_kvcmp\
>                            tst_get_median tst_hexdump tst_get_free_pids
> tst_timeout_kill\
>                            tst_check_kconfigs tst_cgctl tst_fsfreeze
> tst_ns_create tst_ns_exec\
>                            tst_ns_ifmove tst_lockdown_enabled
> tst_secureboot_enabled tst_res_\
> -                          tst_run_shell
> +                          tst_run_shell tst_remaining_runtime
>
>  include $(top_srcdir)/include/mk/generic_trunk_target.mk
> diff --git a/testcases/lib/tests/shell_loader_filesystems.sh
> b/testcases/lib/tests/shell_loader_filesystems.sh
> index d584503ad..823ce1975 100755
> --- a/testcases/lib/tests/shell_loader_filesystems.sh
> +++ b/testcases/lib/tests/shell_loader_filesystems.sh
> @@ -6,6 +6,7 @@
>  # env
>  # {
>  #  "mount_device": true,
> +#  "runtime": 10,
>  #  "mntpoint": "ltp_mntpoint",
>  #  "filesystems": [
>  #   {
> @@ -38,6 +39,14 @@ tst_test()
>         else
>                 tst_res TFAIL "Device not mounted!"
>         fi
> +
> +       RUNTIME=$(tst_remaining_runtime)
> +
> +       if [ "$RUNTIME" -ge 9 ]; then
> +               tst_res TPASS "Remaining runtime $RUNTIME"
> +       else
> +               tst_res TFAIL "Remaning runtime $RUNTIME"
>

Typo ->  s/Remaning/Remaining



> +       fi
>  }
>
>  . tst_run.sh
> diff --git a/testcases/lib/tst_remaining_runtime.c
> b/testcases/lib/tst_remaining_runtime.c
> new file mode 100644
> index 000000000..df383d346
> --- /dev/null
> +++ b/testcases/lib/tst_remaining_runtime.c
> @@ -0,0 +1,26 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2025 Cyril Hrubis <chrubis@suse.cz>
> + */
> +
> +#define TST_NO_DEFAULT_MAIN
> +#include "tst_test.h"
> +
> +static void print_help(char *name)
> +{
> +       fprintf(stderr, "Usage: %s\n", name);
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +       if (argc > 1) {
> +               print_help(argv[0]);
> +               return 1;
> +       }
> +
> +       tst_reinit();
> +
> +       printf("%u\n", tst_remaining_runtime());
> +
> +       return 0;
> +}
> diff --git a/testcases/lib/tst_run_shell.c b/testcases/lib/tst_run_shell.c
> index 7a446e004..91f34127d 100644
> --- a/testcases/lib/tst_run_shell.c
> +++ b/testcases/lib/tst_run_shell.c
> @@ -60,6 +60,7 @@ enum test_attr_ids {
>         MIN_CPUS,
>         MIN_MEM_AVAIL,
>         MIN_KVER,
> +       MIN_RUNTIME,
>         MIN_SWAP_AVAIL,
>         MNTPOINT,
>         MOUNT_DEVICE,
> @@ -74,6 +75,7 @@ enum test_attr_ids {
>         NEEDS_ROOT,
>         NEEDS_TMPDIR,
>         RESTORE_WALLCLOCK,
> +       RUNTIME,
>

Do we need to add a flexible TIMEOUT in shell support as well?

The default TST_TIMEOUT in SHELL is 300, which is not consistent with C
method (DEFAULT_TIMEOUT + tst_test->timeout).

Anyway, this patch itself looks good:
Reviewed-by: Li Wang <liwang@redhat.com>




>         SAVE_RESTORE,
>         SKIP_FILESYSTEMS,
>         SKIP_IN_COMPAT,
> @@ -93,6 +95,7 @@ static ujson_obj_attr test_attrs[] = {
>         UJSON_OBJ_ATTR_IDX(MIN_CPUS, "min_cpus", UJSON_INT),
>         UJSON_OBJ_ATTR_IDX(MIN_MEM_AVAIL, "min_mem_avail", UJSON_INT),
>         UJSON_OBJ_ATTR_IDX(MIN_KVER, "min_kver", UJSON_STR),
> +       UJSON_OBJ_ATTR_IDX(MIN_RUNTIME, "min_runtime", UJSON_INT),
>         UJSON_OBJ_ATTR_IDX(MIN_SWAP_AVAIL, "min_swap_avail", UJSON_INT),
>         UJSON_OBJ_ATTR_IDX(MNTPOINT, "mntpoint", UJSON_STR),
>         UJSON_OBJ_ATTR_IDX(MOUNT_DEVICE, "mount_device", UJSON_BOOL),
> @@ -107,6 +110,7 @@ static ujson_obj_attr test_attrs[] = {
>         UJSON_OBJ_ATTR_IDX(NEEDS_ROOT, "needs_root", UJSON_BOOL),
>         UJSON_OBJ_ATTR_IDX(NEEDS_TMPDIR, "needs_tmpdir", UJSON_BOOL),
>         UJSON_OBJ_ATTR_IDX(RESTORE_WALLCLOCK, "restore_wallclock",
> UJSON_BOOL),
> +       UJSON_OBJ_ATTR_IDX(RUNTIME, "runtime", UJSON_INT),
>         UJSON_OBJ_ATTR_IDX(SAVE_RESTORE, "save_restore", UJSON_ARR),
>         UJSON_OBJ_ATTR_IDX(SKIP_FILESYSTEMS, "skip_filesystems",
> UJSON_ARR),
>         UJSON_OBJ_ATTR_IDX(SKIP_IN_COMPAT, "skip_in_compat", UJSON_BOOL),
> @@ -421,6 +425,12 @@ static void parse_metadata(void)
>                 case MIN_KVER:
>                         test.min_kver = strdup(val.val_str);
>                 break;
> +               case MIN_RUNTIME:
> +                       if (val.val_int <= 0)
> +                               ujson_err(&reader, "Minimal runtime must
> be > 0");
> +                       else
> +                               test.min_runtime = val.val_int;
> +               break;
>                 case MIN_SWAP_AVAIL:
>                         if (val.val_int <= 0)
>                                 ujson_err(&reader, "Minimal available swap
> size must be > 0");
> @@ -469,6 +479,12 @@ static void parse_metadata(void)
>                 case RESTORE_WALLCLOCK:
>                         test.restore_wallclock = val.val_bool;
>                 break;
> +               case RUNTIME:
> +                       if (val.val_int <= 0)
> +                               ujson_err(&reader, "Runtime must be > 0");
> +                       else
> +                               test.runtime = val.val_int;
> +               break;
>                 case SAVE_RESTORE:
>                         test.save_restore = parse_save_restore(&reader,
> &val);
>                 break;
> --
> 2.51.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>

-- 
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH] shell: Add support for runtime
  2025-11-20  7:32 ` Li Wang via ltp
@ 2025-11-20 13:33   ` Petr Vorel
  2025-11-24 12:23   ` Cyril Hrubis
  1 sibling, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2025-11-20 13:33 UTC (permalink / raw)
  To: Li Wang; +Cc: ltp

Hi Cyril, Li,

LGTM
Reviewed-by: Petr Vorel <pvorel@suse.cz>

> > +++ b/testcases/lib/tests/shell_loader_filesystems.sh
> > @@ -6,6 +6,7 @@
> >  # env
> >  # {
> >  #  "mount_device": true,
> > +#  "runtime": 10,
> >  #  "mntpoint": "ltp_mntpoint",
> >  #  "filesystems": [
> >  #   {
> > @@ -38,6 +39,14 @@ tst_test()
> >         else
> >                 tst_res TFAIL "Device not mounted!"
> >         fi
> > +
> > +       RUNTIME=$(tst_remaining_runtime)
> > +
> > +       if [ "$RUNTIME" -ge 9 ]; then
> > +               tst_res TPASS "Remaining runtime $RUNTIME"
> > +       else
> > +               tst_res TFAIL "Remaning runtime $RUNTIME"

> Typo ->  s/Remaning/Remaining

+1

> > +       fi
> >  }

..
> > +++ b/testcases/lib/tst_run_shell.c
> > @@ -60,6 +60,7 @@ enum test_attr_ids {
> >         MIN_CPUS,
> >         MIN_MEM_AVAIL,
> >         MIN_KVER,
> > +       MIN_RUNTIME,
> >         MIN_SWAP_AVAIL,
> >         MNTPOINT,
> >         MOUNT_DEVICE,
> > @@ -74,6 +75,7 @@ enum test_attr_ids {
> >         NEEDS_ROOT,
> >         NEEDS_TMPDIR,
> >         RESTORE_WALLCLOCK,
> > +       RUNTIME,


> Do we need to add a flexible TIMEOUT in shell support as well?

> The default TST_TIMEOUT in SHELL is 300, which is not consistent with C

300 s (5 min) is for tst_test.sh API. C API has 120 s (2 min), therefore that's
the default also for the shell loader API (the newest shell API).
And this specific test has 2 min 10 sec (due runtime 10).

The longer timeout is due Tumbleweed having CONFIG_FAULT_INJECTION, otherwise
it'd be 30 s (or 40 s for the test). I'm still not convinced that
CONFIG_FAULT_INJECTION itself should give 4x longer timeout for all
Tumbleweed/SLES testing. But that's something else, not relevant to the patch.

Kind regards,
Petr

> method (DEFAULT_TIMEOUT + tst_test->timeout).

> Anyway, this patch itself looks good:
> Reviewed-by: Li Wang <liwang@redhat.com>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH] shell: Add support for runtime
  2025-11-20  7:32 ` Li Wang via ltp
  2025-11-20 13:33   ` Petr Vorel
@ 2025-11-24 12:23   ` Cyril Hrubis
  1 sibling, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2025-11-24 12:23 UTC (permalink / raw)
  To: Li Wang; +Cc: ltp

Hi!
> Do we need to add a flexible TIMEOUT in shell support as well?

Well I guess that we will need timeout in the shell library eventually
as well, however for this patch I'm trying to keep the changes minimal
since threre is a test that needs this already.

> The default TST_TIMEOUT in SHELL is 300, which is not consistent with C
> method (DEFAULT_TIMEOUT + tst_test->timeout).

As explained by Peter the shell library with the C library loader has
exactly the same logic for runtime and timeout.

> Anyway, this patch itself looks good:
> Reviewed-by: Li Wang <liwang@redhat.com>

Pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

end of thread, other threads:[~2025-11-24 12:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-19  9:31 [LTP] [PATCH] shell: Add support for runtime Cyril Hrubis
2025-11-20  7:32 ` Li Wang via ltp
2025-11-20 13:33   ` Petr Vorel
2025-11-24 12:23   ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox