[LTP] [PATCH v3 1/3] lib/tests: Add test for testing tst_res() flags

Petr Vorel pvorel@suse.cz
Thu Dec 14 00:40:44 CET 2023


> Hi!
> > +#define FLAG(x) .flag = x, .str = #x
> > +static struct tcase {
> > +	int flag;
> > +	const char *str;
> > +} tcases[] = {
> > +	{FLAG(TPASS)},
> > +	{FLAG(TFAIL)},
> > +	{FLAG(TBROK)},
> > +	{FLAG(TCONF)},
> > +	{FLAG(TWARN)},
> > +	{FLAG(TINFO)},
> > +};
> > +
> > +static void do_cleanup(void)
> > +{
> > +	tst_brk(TBROK, "TBROK message should be TWARN in cleanup");
> > +}
> > +
> > +static void do_test(unsigned int n)
> > +{
> > +	int flag = tcases[n].flag;
> > +	const char *str = tcases[n].str;
> > +
> > +	tst_res(flag, "%s message", str);
> > +
> > +	if (flag == TWARN || flag == TINFO)
> > +		tst_res(TPASS, "%s message is not a result", str);

> Maybe it would make sense the loop over the flags here instead, so that
> we don't have to produce second TPASS message.

I'm not sure if I follow you. I wanted to use the flag in tst_res(),
but for these two there would be tst_brk(TBROK) due missing result.

Kind regards,
Petr

> > +}
> > +
> > +static struct tst_test test = {
> > +	.test = do_test,
> > +	.tcnt = ARRAY_SIZE(tcases),
> > +	.cleanup = do_cleanup,
> > +};
> > -- 
> > 2.43.0


More information about the ltp mailing list