Skip to content

Commit 69b28f1

Browse files
committed
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. Signed-off-by: Cyril Hrubis <[email protected]> Reviewed-by: Li Wang <[email protected]> Reviewed-by: Petr Vorel <[email protected]>
1 parent d77e692 commit 69b28f1

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

testcases/lib/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525
/tst_timeout_kill
2626
/tst_res_
2727
/tst_run_shell
28+
/tst_remaining_runtime

testcases/lib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ MAKE_TARGETS := tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
1717
tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill\
1818
tst_check_kconfigs tst_cgctl tst_fsfreeze tst_ns_create tst_ns_exec\
1919
tst_ns_ifmove tst_lockdown_enabled tst_secureboot_enabled tst_res_\
20-
tst_run_shell
20+
tst_run_shell tst_remaining_runtime
2121

2222
include $(top_srcdir)/include/mk/generic_trunk_target.mk

testcases/lib/tests/shell_loader_filesystems.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# env
77
# {
88
# "mount_device": true,
9+
# "runtime": 10,
910
# "mntpoint": "ltp_mntpoint",
1011
# "filesystems": [
1112
# {
@@ -38,6 +39,14 @@ tst_test()
3839
else
3940
tst_res TFAIL "Device not mounted!"
4041
fi
42+
43+
RUNTIME=$(tst_remaining_runtime)
44+
45+
if [ "$RUNTIME" -ge 9 ]; then
46+
tst_res TPASS "Remaining runtime $RUNTIME"
47+
else
48+
tst_res TFAIL "Remaoning runtime $RUNTIME"
49+
fi
4150
}
4251

4352
. tst_run.sh
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Copyright (c) 2025 Cyril Hrubis <[email protected]>
4+
*/
5+
6+
#define TST_NO_DEFAULT_MAIN
7+
#include "tst_test.h"
8+
9+
static void print_help(char *name)
10+
{
11+
fprintf(stderr, "Usage: %s\n", name);
12+
}
13+
14+
int main(int argc, char *argv[])
15+
{
16+
if (argc > 1) {
17+
print_help(argv[0]);
18+
return 1;
19+
}
20+
21+
tst_reinit();
22+
23+
printf("%u\n", tst_remaining_runtime());
24+
25+
return 0;
26+
}

testcases/lib/tst_run_shell.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ enum test_attr_ids {
6060
MIN_CPUS,
6161
MIN_MEM_AVAIL,
6262
MIN_KVER,
63+
MIN_RUNTIME,
6364
MIN_SWAP_AVAIL,
6465
MNTPOINT,
6566
MOUNT_DEVICE,
@@ -74,6 +75,7 @@ enum test_attr_ids {
7475
NEEDS_ROOT,
7576
NEEDS_TMPDIR,
7677
RESTORE_WALLCLOCK,
78+
RUNTIME,
7779
SAVE_RESTORE,
7880
SKIP_FILESYSTEMS,
7981
SKIP_IN_COMPAT,
@@ -93,6 +95,7 @@ static ujson_obj_attr test_attrs[] = {
9395
UJSON_OBJ_ATTR_IDX(MIN_CPUS, "min_cpus", UJSON_INT),
9496
UJSON_OBJ_ATTR_IDX(MIN_MEM_AVAIL, "min_mem_avail", UJSON_INT),
9597
UJSON_OBJ_ATTR_IDX(MIN_KVER, "min_kver", UJSON_STR),
98+
UJSON_OBJ_ATTR_IDX(MIN_RUNTIME, "min_runtime", UJSON_INT),
9699
UJSON_OBJ_ATTR_IDX(MIN_SWAP_AVAIL, "min_swap_avail", UJSON_INT),
97100
UJSON_OBJ_ATTR_IDX(MNTPOINT, "mntpoint", UJSON_STR),
98101
UJSON_OBJ_ATTR_IDX(MOUNT_DEVICE, "mount_device", UJSON_BOOL),
@@ -107,6 +110,7 @@ static ujson_obj_attr test_attrs[] = {
107110
UJSON_OBJ_ATTR_IDX(NEEDS_ROOT, "needs_root", UJSON_BOOL),
108111
UJSON_OBJ_ATTR_IDX(NEEDS_TMPDIR, "needs_tmpdir", UJSON_BOOL),
109112
UJSON_OBJ_ATTR_IDX(RESTORE_WALLCLOCK, "restore_wallclock", UJSON_BOOL),
113+
UJSON_OBJ_ATTR_IDX(RUNTIME, "runtime", UJSON_INT),
110114
UJSON_OBJ_ATTR_IDX(SAVE_RESTORE, "save_restore", UJSON_ARR),
111115
UJSON_OBJ_ATTR_IDX(SKIP_FILESYSTEMS, "skip_filesystems", UJSON_ARR),
112116
UJSON_OBJ_ATTR_IDX(SKIP_IN_COMPAT, "skip_in_compat", UJSON_BOOL),
@@ -421,6 +425,12 @@ static void parse_metadata(void)
421425
case MIN_KVER:
422426
test.min_kver = strdup(val.val_str);
423427
break;
428+
case MIN_RUNTIME:
429+
if (val.val_int <= 0)
430+
ujson_err(&reader, "Minimal runtime must be > 0");
431+
else
432+
test.min_runtime = val.val_int;
433+
break;
424434
case MIN_SWAP_AVAIL:
425435
if (val.val_int <= 0)
426436
ujson_err(&reader, "Minimal available swap size must be > 0");
@@ -469,6 +479,12 @@ static void parse_metadata(void)
469479
case RESTORE_WALLCLOCK:
470480
test.restore_wallclock = val.val_bool;
471481
break;
482+
case RUNTIME:
483+
if (val.val_int <= 0)
484+
ujson_err(&reader, "Runtime must be > 0");
485+
else
486+
test.runtime = val.val_int;
487+
break;
472488
case SAVE_RESTORE:
473489
test.save_restore = parse_save_restore(&reader, &val);
474490
break;

0 commit comments

Comments
 (0)