From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] tst_test_macros: Add TST_EXP_EQ_*() macros
Date: Fri, 18 Feb 2022 11:34:13 +0100 [thread overview]
Message-ID: <20220218103413.18540-1-chrubis@suse.cz> (raw)
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)
...
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
include/tst_test_macros.h | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index 8893dbf0e..33f03e22f 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -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__ */
--
2.34.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2022-02-18 10:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-18 10:34 Cyril Hrubis [this message]
2022-02-18 10:50 ` [LTP] [PATCH] tst_test_macros: Add TST_EXP_EQ_*() macros Petr Vorel
2022-02-21 16:00 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220218103413.18540-1-chrubis@suse.cz \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).