diff mbox series

[v2,05/18] tst_test_macros: Add TST_TO_STR and TST_STR macro

Message ID a84f4b5177545cb10912c325f23175662a921396.1658433280.git.luke.nowakowskikrijger@canonical.com
State Accepted
Headers show
Series Expand Cgroup lib and modify controller tests | expand

Commit Message

Luke Nowakowski-Krijger July 21, 2022, 8:52 p.m. UTC
Add the TST_TO_STR macro which uses a preprocessor trick to concetenate
variables into strings.

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

Also define TST_STR as an intermediate macro that could be used when
defining string literals.

Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
---
v2: Change names to TST_STR and TST_TO_STR
Treat TST_STR as its own macro because it could be useful. 

 include/tst_test_macros.h | 3 +++
 1 file changed, 3 insertions(+)

Comments

Petr Vorel July 26, 2022, 2:44 p.m. UTC | #1
Hi all,

>  include/tst_test_macros.h | 3 +++
...
> +#define TST_STR(s) #s
> +#define TST_TO_STR(s) TST_STR(s)

NOTE: I changed before merging TST_STR to TST_TO_STR_ as Cyril requested [1].
I'm sorry I forget to update git commit message.

Kind regards,
Petr

[1] https://lore.kernel.org/ltp/YnPSgLxK2jUGndIv@yuki/
diff mbox series

Patch

diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index 2e7b7871c..58b965f78 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -36,6 +36,9 @@  extern void *TST_RET_PTR;
 
 #define TST_2_(_1, _2, ...) _2
 
+#define TST_STR(s) #s
+#define TST_TO_STR(s) TST_STR(s)
+
 #define TST_FMT_(FMT, _1, ...) FMT, ##__VA_ARGS__
 
 #define TST_MSG_(RES, FMT, SCALL, ...) \