Skip to content

Commit 39a2844

Browse files
coolgwpevik
authored andcommitted
lib: Add support option for .needs_cmds
Link: https://lore.kernel.org/ltp/20260109061716.20258-2-wegao@suse.com/ Suggested-by: Cyril Hrubis <chrubis@suse.cz> Reviewed-by: Cyril Hrubis <chrubis@suse.cz> Reviewed-by: Petr Vorel <pvorel@suse.cz> Signed-off-by: Wei Gao <wegao@suse.com>
1 parent 22adea2 commit 39a2844

27 files changed

Lines changed: 155 additions & 87 deletions

include/tst_cmd.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ enum tst_cmd_flags {
1919
TST_CMD_TCONF_ON_MISSING = 2,
2020
};
2121

22+
/**
23+
* struct tst_cmd - Provides details about a command struct needed by LTP test.
24+
* @cmd: The name of the command.
25+
* @optional: A flag indicating if the command is optional.
26+
* @present: A flag indicating if the command was found at runtime. This is an output
27+
* parameter, set by the LTP library during the test setup.
28+
*/
29+
struct tst_cmd {
30+
const char *cmd;
31+
unsigned int optional:1;
32+
unsigned int present:1;
33+
};
34+
2235
int tst_cmd_fds_(void (cleanup_fn)(void),
2336
const char *const argv[],
2437
int stdout_fd,

include/tst_test.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ struct tst_fs {
526526
*
527527
* @tags: A {} terminated array of test tags. See :ref:`struct tst_tag` for details.
528528
*
529-
* @needs_cmds: A NULL terminated array of commands required for the test to run.
529+
* @needs_cmds: A NULL terminated array of :ref:`struct tst_cmd` required for the test to run.
530530
*
531531
* @needs_cgroup_ver: If set the test will run only if the specified cgroup
532532
* version is present on the system.
@@ -619,7 +619,7 @@ struct tst_fs {
619619

620620
const struct tst_tag *tags;
621621

622-
const char *const *needs_cmds;
622+
struct tst_cmd *needs_cmds;
623623

624624
const enum tst_cg_ver needs_cgroup_ver;
625625

lib/newlib_tests/tst_needs_cmds01.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ static void do_test(void)
1212

1313
static struct tst_test test = {
1414
.test_all = do_test,
15-
.needs_cmds = (const char *[]) {
16-
"mkfs.ext4",
17-
"mkfs.ext4 >= 1.0.0",
18-
"mkfs.ext4 <= 2.0.0",
19-
"mkfs.ext4 != 2.0.0",
20-
"mkfs.ext4 > 1.0.0",
21-
"mkfs.ext4 < 2.0.0",
22-
NULL
15+
.needs_cmds = (struct tst_cmd[]) {
16+
{.cmd = "mkfs.ext4", .optional = 1},
17+
{.cmd = "mkfs.ext4 >= 1.0.0", .optional = 0},
18+
{.cmd = "mkfs.ext4 <= 2.0.0"},
19+
{.cmd = "mkfs.ext4 != 2.0.0"},
20+
{.cmd = "mkfs.ext4 > 1.0.0"},
21+
{.cmd = "mkfs.ext4 < 2.0.0"},
22+
{}
2323
}
2424
};

lib/newlib_tests/tst_needs_cmds02.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ static void do_test(void)
1616

1717
static struct tst_test test = {
1818
.test_all = do_test,
19-
.needs_cmds = (const char *[]) {
20-
"mkfs.ext45 >= 1.43.0",
21-
NULL
19+
.needs_cmds = (struct tst_cmd[]) {
20+
{.cmd = "mkfs.ext45 >= 1.43.0"},
21+
{}
2222
}
2323
};

lib/newlib_tests/tst_needs_cmds03.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ static void do_test(void)
1616

1717
static struct tst_test test = {
1818
.test_all = do_test,
19-
.needs_cmds = (const char *[]) {
20-
"mkfs.ext4 ! 1.43.0",
21-
NULL
19+
.needs_cmds = (struct tst_cmd[]) {
20+
{.cmd = "mkfs.ext4 ! 1.43.0"},
21+
{}
2222
}
2323
};

lib/newlib_tests/tst_needs_cmds04.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ static void do_test(void)
1616

1717
static struct tst_test test = {
1818
.test_all = do_test,
19-
.needs_cmds = (const char *[]) {
20-
"mkfs.ext4 > 1.43",
21-
NULL
19+
.needs_cmds = (struct tst_cmd[]) {
20+
{.cmd = "mkfs.ext4 > 1.43"},
21+
{}
2222
}
2323
};

lib/newlib_tests/tst_needs_cmds05.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ static void do_test(void)
1616

1717
static struct tst_test test = {
1818
.test_all = do_test,
19-
.needs_cmds = (const char *[]) {
20-
"mkfs.ext4 > 1.43.0-1",
21-
NULL
19+
.needs_cmds = (struct tst_cmd[]) {
20+
{.cmd = "mkfs.ext4 > 1.43.0-1"},
21+
{}
2222
}
2323
};

lib/newlib_tests/tst_needs_cmds06.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ static void do_test(void)
1616

1717
static struct tst_test test = {
1818
.test_all = do_test,
19-
.needs_cmds = (const char *[]) {
20-
"mkfs.ext4 > 1.43.0 2",
21-
NULL
19+
.needs_cmds = (struct tst_cmd[]) {
20+
{.cmd = "mkfs.ext4 > 1.43.0 2"},
21+
{}
2222
}
2323
};

lib/newlib_tests/tst_needs_cmds07.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ static void do_test(void)
1616

1717
static struct tst_test test = {
1818
.test_all = do_test,
19-
.needs_cmds = (const char *[]) {
20-
"mkfs.ext45",
21-
NULL
19+
.needs_cmds = (struct tst_cmd[]) {
20+
{.cmd = "mkfs.ext45"},
21+
{}
2222
}
2323
};

lib/newlib_tests/tst_needs_cmds08.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ static void do_test(void)
1818

1919
static struct tst_test test = {
2020
.test_all = do_test,
21-
.needs_cmds = (const char *[]) {
22-
"mkfs.xfs",
23-
"mkfs.xfs >= 4.20.0",
24-
NULL
21+
.needs_cmds = (struct tst_cmd[]) {
22+
{.cmd = "mkfs.xfs"},
23+
{.cmd = "mkfs.xfs >= 4.20.0"},
24+
{}
2525
}
2626
};

0 commit comments

Comments
 (0)