[LTP] [PATCH 0/2] lib: Add TINFO_WARN

Li Wang liwang@redhat.com
Fri Jun 21 15:22:53 CEST 2024


Hi All,

I come up with a way to define simple macros for all LTP print, especially
for TFAIL
we could make use of the GET_MACRO to select a specific macro implementation
based on the number of arguments provided to a variadic macro.

Something partly like:

--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -368,4 +368,28 @@ const char *tst_errno_names(char *buf, const int
*exp_errs, int exp_errs_cnt);
 #define TST_EXP_EQ_SSZ(VAL_A, VAL_B) \
                TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, ssize_t, "%zi")

+/*TST_RES*/
+#define TST_RES_TINFO(MESSAGE) \
+       tst_res(TINFO, MESSAGE);
+
+#define TST_RES_TWARN(MESSAGE) \
+       tst_res(TINFO, "WARNING "MESSAGE);
+
+#define TST_RES_TCONF(MESSAGE) \
+       tst_res(TCONF, MESSAGE);
+
+#define TST_RES_TPASS(MESSAGE) \
+       tst_res(TPASS, MESSAGE);
+
+#define TST_RES_TFAIL(...) \
+           GET_MACRO(__VA_ARGS__, TST_RES_FAIL2,
TST_RES_FAIL1)(__VA_ARGS__)
+
+#define GET_MACRO(_1, _2, NAME, ...) NAME
+
+#define TST_RES_FAIL1(MESSAGE) \
+           tst_res(TFAIL, MESSAGE)
+
+#define TST_RES_FAIL2(flag, MESSAGE) \
+           tst_res(TFAIL | flag, MESSAGE)
+
 #endif /* TST_TEST_MACROS_H__ */
diff --git a/lib/newlib_tests/tst_res_macros.c
b/lib/newlib_tests/tst_res_macros.c
new file mode 100644
index 000000000..e16f3cbba
--- /dev/null
+++ b/lib/newlib_tests/tst_res_macros.c
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2024 Li Wang <liwang@redhat.com>
+ */
+
+#include "tst_test.h"
+#include "tst_res_flags.h"
+#include "tst_test_macros.h"
+
+static void do_test(unsigned int i)
+{
+       TST_RES_TINFO("message");
+       TST_RES_TPASS("message");
+       TST_RES_TWARN("message");
+       TST_RES_TFAIL("message");
+       TST_RES_TFAIL(TERRNO, "message");
+       TST_RES_TFAIL(TTERRNO, "message");
+}
+
+static struct tst_test test = {
+       .test_all = do_test,
+};

>

-- 
Regards,
Li Wang


More information about the ltp mailing list