Skip to contentSkip to conversation

tst_test_macros: Add TST_EXP_EQ_*() macros

PATCH In review Cyril Hrubis 2 participants 3 messages Feb 18, 2022 – Feb 21, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tst_test_macros: Add TST_EXP_EQ_*() macros

This is a family of macros to compare two values, so far long integers and size_t/ssize_t have been added but we can add anything else once needed as well.

The intended usage is:

...

        siginfo_t infop;

        TST_EXP_PASS(waitid(P_PGID, pid_group, &infop, WEXITED));

        TST_EXP_EQ_LI(infop.si_pid, pid_child);
        TST_EXP_EQ_LI(infop.si_status, 0);
        TST_EXP_EQ_LI(infop.si_signo, SIGCHLD);
        TST_EXP_EQ_LI(infop.si_code, CLD_EXITED);

...

And the output (with intentionaly wrong assertion for si_signo) looks like:

...
waitid05.c:34: TPASS: waitid(P_PGID, pid_group, &infop, WEXITED) passed waitid05.c:36: TPASS: infop.si_pid == pid_child (18443) waitid05.c:37: TPASS: infop.si_status == 0 (0) waitid05.c:38: TFAIL: infop.si_signo (17) != SIGHUP (1) waitid05.c:39: TPASS: infop.si_code == CLD_EXITED (1)
...

---
 include/tst_test_macros.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
include/tst_test_macros.h +25 -0
index 8893dbf0e..33f03e22f 100644
@@ -214,4 +214,29 @@ extern void *TST_RET_PTR;
 #define TST_EXP_EXPR(EXPR, FMT, ...)						\
 	tst_res_(__FILE__, __LINE__, (EXPR) ? TPASS : TFAIL, "Expect: " FMT, ##__VA_ARGS__);
 
+#define TST_EXP_EQ_(VAL_A, SVAL_A, VAL_B, SVAL_B, TYPE, PFS) do {\
+	TYPE tst_tmp_a__ = VAL_A; \
+	TYPE tst_tmp_b__ = VAL_B; \
+	if (tst_tmp_a__ == tst_tmp_b__) { \
+		tst_res_(__FILE__, __LINE__, TPASS, \
+			SVAL_A " == " SVAL_B " (" PFS ")", tst_tmp_a__); \
+	} else { \
+		tst_res_(__FILE__, __LINE__, TFAIL, \
+			SVAL_A " (" PFS ") != " SVAL_B " (" PFS ")", \
+			tst_tmp_a__, tst_tmp_b__); \
+	} \
+} while (0) \
+
+#define TST_EXP_EQ_LI(VAL_A, VAL_B) \
+		TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, long long, "%lli")
+
+#define TST_EXP_EQ_LU(VAL_A, VAL_B) \
+		TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, unsigned long long, "%llu")
+
+#define TST_EXP_EQ_SZ(VAL_A, VAL_B) \
+		TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, size_t, "%zu")
+
+#define TST_EXP_EQ_SSZ(VAL_A, VAL_B) \
+		TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, ssize_t, "%zi")
+
 #endif	/* TST_TEST_MACROS_H__ */
Signature · 5 lines
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hi!
I've added some docs to C API docs and pushed, thanks.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp