[LTP] [PATCH 05/19] tst_test_macros: Add TST_TOSTR macro

Petr Vorel pvorel@suse.cz
Tue May 3 16:38:02 CEST 2022


Hi Luke,

> Add the TST_TOSTR macro which uses a preprocessor trick to concetenate
> variables into strings.

> Useful when needing to create strings from other #define variables.

> Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
> ---
>  include/tst_test_macros.h | 3 +++
>  1 file changed, 3 insertions(+)

> diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
> index 2e7b7871c..f5d86c421 100644
> --- a/include/tst_test_macros.h
> +++ b/include/tst_test_macros.h
include/tst_common.h would be probably a better place.
Because tst_test_macros.h contains tests which call TEST() helpers.

> @@ -36,6 +36,9 @@ extern void *TST_RET_PTR;

>  #define TST_2_(_1, _2, ...) _2

> +#define _TST_TOSTR(STR) #STR
At least 3 tests have:
#define str(s) #s (or STR)

(testcases/network/stress/route/route-change-netlink.c
testcases/kernel/controllers/freezer/vfork.c
testcases/kernel/pty/pty04.c)

therefore IMHO it'd be better to define:
#define TST_STR(s) #s
#define TST_TOSTR(s) TST_STR(s)

> +#define TST_TOSTR(STR) _TST_TOSTR(STR)

Kind regards,
Petr


More information about the ltp mailing list