[LTP] [PATCH v7 3/4] ioctl_loop01.c: Add new support .needs_cmds

Wei Gao wegao@suse.com
Sat Jan 17 14:16:01 CET 2026


On Fri, Jan 16, 2026 at 09:25:05PM +0800, Li Wang wrote:
> >         TST_ASSERT_INT(partscan_path, 0);
> >         TST_ASSERT_INT(autoclear_path, 0);
> >         TST_ASSERT_STR(backing_path, backing_file_path);
> > @@ -114,10 +97,23 @@ static void verify_ioctl_loop(void)
> >
> >  static void setup(void)
> >  {
> > +       parted_sup = tst_cmd_present("parted");
> 
> 
> In the logic of tst_test.c, there already did check and store the
> value in tst_test->needs_cmds.present, so why here do the check
> seperately again?
> 
> +               struct tst_cmd *pcmd = tst_test->needs_cmds;
> +               while (pcmd->cmd) {
> +                       pcmd->present = tst_check_cmd(pcmd->cmd,
> !pcmd->optional) ? 1 : 0;
> +                       pcmd++;
> +               }
> 
Let me clarify, and please correct me if I’m mistaken :)
tst_cmd_present not do tst_check_cmd again but just go through list find
specific cmd such as "parted" present status.
> 
> > +       const char *const cmd_parted[] = {"parted", "-s", dev_path, "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);
> > +
> > +       tst_attach_device(dev_path, "test.img");
> > +       attach_flag = 1;
> > +
> > +       if (parted_sup)
> 
> Can we just reuse the 'tst_test->needs_cmds.present' result?
> 
You cannot access tst_test->needs_cmds.present directly as if it were a single variable, 
because needs_cmds is an array (a list) of structures. To get the status of a specific command 
like "parted", you must iterate through that list to find the entry matching that name.
> > +               SAFE_CMD(cmd_parted, NULL, NULL);
> 
> 
> -- 
> Regards,
> Li Wang
> 


More information about the ltp mailing list