shell: Add support for runtime
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
@@ -25,3 +25,4 @@ /tst_timeout_kill /tst_res_ /tst_run_shell +/tst_remaining_runtime
testcases/lib/Makefile +1 -1
@@ -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
@@ -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
@@ -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
@@ -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
Quoted 55 lines · Cyril Hrubis
Adds support for "runtime" and "
min_runtime" to thetst_run_shellas well as new binary helpertst_remaining_runtimethat calls the C function of that name and prints the number into the stdout.Signed-off-by Cyril Hrubis <[email protected]>CC Piotr Kubaj <[email protected]>--- 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.ctestcases/lib/.gitignore +1
-0@@ -25,3 +25,4 @@ /tst_timeout_kill /tst_res_ /tst_run_shell +/tst_remaining_runtimetestcases/lib/Makefile +0
-0@@ -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_enabledtst_res_\testcases/lib/Makefile +1
-1- tst_run_shell + tst_run_shell tst_remaining_runtime include $(top_srcdir)/include/mk/generic_trunk_target.mktestcases/lib/tests/shell_loader_filesystems.sh +1
-0@@ -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
-0tst_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.shtestcases/lib/tst_remaining_runtime.c new file +26
-0@@ -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@@ -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
-0SAVE_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
Petr Vorel
Reviewed-byHi Cyril, Li,
LGTM
Quoted 14 lines
Quoted 14 lines
+++
b/testcases/lib/tests/shell_loader_filesystems.shtestcases/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.ctestcases/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_TIMEOUTin 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:
Reviewed-by Li Wang <[email protected]>
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/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_TIMEOUTin 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:
Reviewed-by Li Wang <[email protected]>
Pushed, thanks.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp