[LTP] [PATCH v1 2/2] ioctl_loop01.c: Update to new .needs_cmds struct
Cyril Hrubis
chrubis@suse.cz
Fri Sep 26 11:32:19 CEST 2025
On Fri, Sep 26, 2025 at 08:50:12AM +0000, Wei Gao wrote:
> NOTE:This patchset is draft for review not final one.
> Since not include update .needs_cmds for all related testcases.
>
> Suggested-by: Cyril Hrubis <chrubis@suse.cz>
> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
> .../kernel/syscalls/ioctl/ioctl_loop01.c | 23 ++++++++-----------
> 1 file changed, 9 insertions(+), 14 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop01.c b/testcases/kernel/syscalls/ioctl/ioctl_loop01.c
> index c9137bf1e..a3f0857e3 100644
> --- a/testcases/kernel/syscalls/ioctl/ioctl_loop01.c
> +++ b/testcases/kernel/syscalls/ioctl/ioctl_loop01.c
> @@ -97,9 +97,10 @@ static void verify_ioctl_loop(void)
>
> static void setup(void)
> {
> - int ret;
> + parted_sup = tst_cmd_present(test.needs_cmds, "parted");
> +
> const char *const cmd_parted[] = {"parted", "-s", "test.img", "mklabel", "msdos", "mkpart",
> - "primary", "ext4", "1M", "10M", NULL};
> + "primary", "ext4", "1M", "10M", NULL};
>
> dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
> if (dev_num < 0)
> @@ -107,18 +108,8 @@ static void setup(void)
>
> tst_fill_file("test.img", 0, 1024 * 1024, 10);
>
> - ret = tst_cmd(cmd_parted, NULL, NULL, TST_CMD_PASS_RETVAL);
> - switch (ret) {
> - case 0:
> - parted_sup = 1;
> - break;
> - case 255:
> - tst_res(TCONF, "parted binary not installed or failed");
> - break;
> - default:
> - tst_res(TCONF, "parted exited with %i", ret);
> - break;
> - }
> + if (parted_sup)
> + SAFE_CMD(cmd_parted, NULL, NULL);
>
> sprintf(partscan_path, "/sys/block/loop%d/loop/partscan", dev_num);
> sprintf(autoclear_path, "/sys/block/loop%d/loop/autoclear", dev_num);
> @@ -152,5 +143,9 @@ static struct tst_test test = {
> {"linux-git", "6ac92fb5cdff"},
> {}
> },
> + .needs_cmds = (struct tst_cmd[]) {
> + {"parted", 0, 0},
No need to pass the zeros if we just initialize the cmd part. Also I
would use the named initializers as:
{.cmd = "parted", .optional = 1},
> + {}
> + },
> .needs_tmpdir = 1,
> };
> --
> 2.51.0
>
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list