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

Cyril Hrubis chrubis@suse.cz
Wed Dec 13 20:04:11 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.

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

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list