[LTP] [PATCH] shell: Add support for runtime

Cyril Hrubis chrubis@suse.cz
Wed Nov 19 10:31:20 CET 2025


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



More information about the ltp mailing list