[LTP] [PATCH v3 2/4] ioctl_loop01.c: Update to new .needs_cmds struct
Wei Gao
wegao@suse.com
Fri Oct 10 08:45:48 CEST 2025
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Wei Gao <wegao@suse.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
---
.../kernel/syscalls/ioctl/ioctl_loop01.c | 28 +++++++++----------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop01.c b/testcases/kernel/syscalls/ioctl/ioctl_loop01.c
index cb1b506d2..fe62e7e5a 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_loop01.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_loop01.c
@@ -78,21 +78,7 @@ static void check_loop_value(int set_flag, int get_flag, int autoclear_field)
static void verify_ioctl_loop(void)
{
- int ret;
- const char *const cmd_parted[] = {"parted", "-s", dev_path, "mklabel", "msdos", "mkpart",
- "primary", "ext4", "1M", "10M", NULL};
-
- tst_fill_file("test.img", 0, 1024 * 1024, 10);
tst_attach_device(dev_path, "test.img");
-
- ret = tst_cmd(cmd_parted, NULL, NULL, TST_CMD_PASS_RETVAL);
- if (!ret)
- parted_sup = 1;
- else if (ret == 255)
- tst_res(TCONF, "parted binary not installed or failed");
- else
- tst_res(TCONF, "parted exited with %i", ret);
-
attach_flag = 1;
TST_ASSERT_INT(partscan_path, 0);
@@ -112,10 +98,20 @@ static void verify_ioctl_loop(void)
static void setup(void)
{
+ parted_sup = tst_cmd_present("parted");
+
+ const char *const cmd_parted[] = {"parted", "-s", "test.img", "mklabel", "msdos", "mkpart",
+ "primary", "ext4", "1M", "10M", NULL};
+
dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
if (dev_num < 0)
tst_brk(TBROK, "Failed to find free loop device");
+ tst_fill_file("test.img", 0, 1024 * 1024, 10);
+
+ 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);
sprintf(backing_path, "/sys/block/loop%d/loop/backing_file", dev_num);
@@ -148,5 +144,9 @@ static struct tst_test test = {
{"linux-git", "6ac92fb5cdff"},
{}
},
+ .needs_cmds = (struct tst_cmd[]) {
+ {.cmd = "parted", .optional = 1},
+ {}
+ },
.needs_tmpdir = 1,
};
--
2.51.0
More information about the ltp
mailing list