Skip to contentSkip to conversation

shell: Add support for runtime

PATCH In review Cyril Hrubis 3 participants 4 messages Nov 19, 2025 – Nov 24, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 shell: Add support for runtime

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.

---
 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
testcases/lib/.gitignore +1 -0
index 385f3c3ca..19d7c67bb 100644
@@ -25,3 +25,4 @@
 /tst_timeout_kill
 /tst_res_
 /tst_run_shell
+/tst_remaining_runtime
testcases/lib/Makefile +1 -1
index b3a9181c1..2309a42a3 100644
@@ -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
testcases/lib/tests/shell_loader_filesystems.sh +9 -0
index d584503ad..823ce1975 100755
@@ -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
testcases/lib/tst_remaining_runtime.c new file +26 -0
new file mode 100644
index 000000000..df383d346
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Cyril Hrubis <[email protected]>
+ */
+
+#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;
+}
testcases/lib/tst_run_shell.c +16 -0
index 7a446e004..91f34127d 100644
@@ -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;
Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by Li Wang on v1 1/1
#1 lore raw
Quoted 55 lines · Cyril Hrubis

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.

---
 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
testcases/lib/.gitignore +1 -0
index 385f3c3ca..19d7c67bb 100644
@@ -25,3 +25,4 @@
 /tst_timeout_kill
 /tst_res_
 /tst_run_shell
+/tst_remaining_runtime
testcases/lib/Makefile +0 -0
index b3a9181c1..2309a42a3 100644
@@ -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_\

testcases/lib/Makefile +1 -1
-                          tst_run_shell
+                          tst_run_shell tst_remaining_runtime
 
 include $(top_srcdir)/include/mk/generic_trunk_target.mk
testcases/lib/tests/shell_loader_filesystems.sh +1 -0
index d584503ad..823ce1975 100755
@@ -6,6 +6,7 @@
 # env
 # {
 #  "mount_device": true,
+#  "runtime": 10,
 #  "mntpoint": "ltp_mntpoint",
 #  "filesystems": [
 #   {
@@ -38,6 +39,14 @@ tst_test()
        else

testcases/lib/tests/shell_loader_filesystems.sh tst_test() · line 49

Quoted 10 lines
testcases/lib/tests/shell_loader_filesystems.sh +7 -0
                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

Quoted 50 lines
testcases/lib/tests/shell_loader_filesystems.sh +1 -0
+       fi
 }
 

. tst_run.sh

testcases/lib/tst_remaining_runtime.c new file +26 -0
new file mode 100644
index 000000000..df383d346
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Cyril Hrubis <[email protected]>
+ */
+
+#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;
+}
testcases/lib/tst_run_shell.c +1 -0
index 7a446e004..91f34127d 100644
@@ -60,6 +60,7 @@ enum test_attr_ids {
        MIN_CPUS,
        MIN_MEM_AVAIL,
        MIN_KVER,
+       MIN_RUNTIME,
        MIN_SWAP_AVAIL,
        MNTPOINT,
        MOUNT_DEVICE,

testcases/lib/tst_run_shell.c enum test_attr_ids { · line 79

Quoted 5 lines
testcases/lib/tst_run_shell.c +1 -0
@@ -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:

Quoted 58 lines
testcases/lib/tst_run_shell.c +0 -0
        SAVE_RESTORE,
        SKIP_FILESYSTEMS,

SKIP_IN_COMPAT,

testcases/lib/tst_run_shell.c +2 -0
@@ -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),

testcases/lib/tst_run_shell.c +6 -0
@@ -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");

testcases/lib/tst_run_shell.c +6 -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

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by
#2 lore raw

Hi Cyril, Li,

LGTM

Quoted 14 lines
Quoted 14 lines

+++ b/testcases/lib/tests/shell_loader_filesystems.sh

testcases/lib/tests/shell_loader_filesystems.sh +2 -0
@@ -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
+
Quoted 8 lines

testcases/lib/tests/shell_loader_filesystems.sh tst_test() · line 48

Quoted 6 lines
testcases/lib/tests/shell_loader_filesystems.sh +6 -0
+       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

Quoted 2 lines
Quoted 2 lines
testcases/lib/tests/shell_loader_filesystems.sh +1 -0
+       fi
 }

..

Quoted 18 lines
Quoted 10 lines

+++ b/testcases/lib/tst_run_shell.c

testcases/lib/tst_run_shell.c +1 -0
@@ -60,6 +60,7 @@ enum test_attr_ids {
        MIN_CPUS,
        MIN_MEM_AVAIL,
        MIN_KVER,
+       MIN_RUNTIME,
        MIN_SWAP_AVAIL,
        MNTPOINT,
        MOUNT_DEVICE,

testcases/lib/tst_run_shell.c enum test_attr_ids { · line 78

Quoted 4 lines
testcases/lib/tst_run_shell.c +1 -0
@@ -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?

Quoted 1 line

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

Quoted 4 lines

method (DEFAULT_TIMEOUT + tst_test->timeout).

Anyway, this patch itself looks good:

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
In reply to Li Wang via ltp

Hi!

Quoted 1 line

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.

Quoted 2 lines

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.

Quoted 2 lines

Anyway, this patch itself looks good:

Pushed, thanks.

Signature · 5 lines
Cyril Hrubis
[email protected]

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