[LTP] [PATCH 1/1] tst_test: Fix tests using device without .filesystems

Petr Vorel pvorel@suse.cz
Tue Jul 9 13:18:47 CEST 2024


Hi Cyril,

> Hi!
> > diff --git a/lib/tst_test.c b/lib/tst_test.c
> > index b49c248ae..6d258cd28 100644
> > --- a/lib/tst_test.c
> > +++ b/lib/tst_test.c
> > @@ -1355,8 +1355,11 @@ static void do_setup(int argc, char *argv[])

> >  		tdev.fs_type = default_fs_type();

> > -		if (!tst_test->all_filesystems && count_fs_descs() == 1)
> > -			prepare_device(&tst_test->filesystems[0]);
> > +		if (!tst_test->all_filesystems && count_fs_descs() <= 1) {
> > +			prepare_device(tst_test->filesystems ?
> > +				       &tst_test->filesystems[0] :
> > +				       &(struct tst_fs){.type = tdev.fs_type});

> Another option would be to change prepare_device() so that it works fine
> with NULL tst_fs pointer, then we could simply do:

> 	prepare_device(tst_test->filesystems);


> And for that we would have to do something like this:

> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index b49c248ae..ec6deea9b 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -1101,6 +1101,9 @@ static void prepare_device(struct tst_fs *fs)
>  {
>         const char *mnt_data;
>         char buf[1024];
> +       struct tst_fs dummy = {};
> +
> +       fs = fs ? &dummy : fs;

This looks more elegant, but I get coredump.
I also think you need to have count_fs_descs() <= 1 and maybe define fs_type
(not sure about it).

Feel free to post v2.

Kind regards,
Petr

>         const char *const extra[] = {fs->mkfs_size_opt, NULL};


> > +		}
> >  	}

> >  	if (tst_test->needs_overlay && !tst_test->mount_device)
> > -- 
> > 2.45.2


More information about the ltp mailing list