From: Wake Liu via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] tst_test_macros: Avoid re-evaluating arguments in TST_EXP_{EQ, LE}_*()
Date: Fri, 13 Nov 2026 13:41:13 +0000 [thread overview]
Message-ID: <20261113134113.2822581-1-wakel@google.com> (raw)
Commit 1759ad9f3f0b ("Add silent macros for TST_EXP_EQ_*") split the
TPASS message out of TST_EXP_EQ_SILENT_() and printed VAL_A directly in
TST_EXP_EQ_LI(), TST_EXP_EQ_LU(), TST_EXP_EQ_SZ() and TST_EXP_EQ_SSZ()
because tst_tmp_a__ was no longer in scope. As a result, VAL_A is
evaluated a second time whenever the check passes. Commit 1b0395338108
("tst_test_macros: Add TST_EXP_LE_LU*()") followed the same pattern and
evaluates both VAL_A and VAL_B a second time on TPASS.
When an argument has side effects, the test executes it twice on
success. For example, stream04 calls:
TST_EXP_EQ_LI(fwrite(data, 1, DATASIZE, stream), DATASIZE);
which writes DATASIZE (27) bytes twice into the file, and epoll_wait06
calls:
TST_EXP_EQ_LI(SAFE_EPOLL_WAIT(epfd, &evt_receive, 1, 0), 1);
where the first call consumes the edge-triggered event and the second
call in the TPASS message returns 0, printing:
TPASS: SAFE_EPOLL_WAIT(epfd, &evt_receive, 1, 0) == 1 (0)
The first commit also passed size_t instead of ssize_t to
TST_EXP_EQ_SILENT_() in TST_EXP_EQ_SSZ().
Pass a SILENT parameter to TST_EXP_EQ_() and TST_EXP_LE_() so the TPASS
message is emitted inside the same block using tst_tmp_a__ and
tst_tmp_b__, and fix the type in TST_EXP_EQ_SSZ() to ssize_t.
Fixes: 1759ad9f3f0b ("Add silent macros for TST_EXP_EQ_*")
Fixes: 1b0395338108 ("tst_test_macros: Add TST_EXP_LE_LU*()")
Signed-off-by: Wake Liu <wakel@google.com>
---
include/tst_test_macros.h | 89 +++++++++++++--------------------------
1 file changed, 29 insertions(+), 60 deletions(-)
diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index fcecf7f82..53f6c1e80 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -759,33 +759,37 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
tst_res_(__FILE__, __LINE__, (EXPR) ? TPASS : TFAIL, "Expect: " \
TST_FMT_(TST_2_(dummy, ##__VA_ARGS__, #EXPR), __VA_ARGS__));
-#define TST_EXP_EQ_SILENT_(VAL_A, SVAL_A, VAL_B, SVAL_B, TYPE, PFS) do { \
+#define TST_EXP_EQ_(VAL_A, SVAL_A, VAL_B, SVAL_B, TYPE, PFS, SILENT) do { \
TYPE tst_tmp_a__ = VAL_A; \
TYPE tst_tmp_b__ = VAL_B; \
\
- TST_PASS = 0; \
+ TST_PASS = tst_tmp_a__ == tst_tmp_b__; \
\
- if (tst_tmp_a__ != tst_tmp_b__) { \
+ if (!TST_PASS) { \
tst_res_(__FILE__, __LINE__, TFAIL, \
SVAL_A " (" PFS ") != " SVAL_B " (" PFS ")", \
tst_tmp_a__, tst_tmp_b__); \
- } else { \
- TST_PASS = 1; \
+ } else if (!(SILENT)) { \
+ tst_res_(__FILE__, __LINE__, TPASS, \
+ SVAL_A " == " SVAL_B " (" PFS ")", \
+ tst_tmp_a__); \
} \
} while (0)
-#define TST_EXP_LE_SILENT_(VAL_A, SVAL_A, VAL_B, SVAL_B, TYPE, PFS) do { \
+#define TST_EXP_LE_(VAL_A, SVAL_A, VAL_B, SVAL_B, TYPE, PFS, SILENT) do { \
TYPE tst_tmp_a__ = VAL_A; \
TYPE tst_tmp_b__ = VAL_B; \
\
- TST_PASS = 0; \
+ TST_PASS = tst_tmp_a__ <= tst_tmp_b__; \
\
- if (tst_tmp_a__ > tst_tmp_b__) { \
+ if (!TST_PASS) { \
tst_res_(__FILE__, __LINE__, TFAIL, \
SVAL_A " (" PFS ") > " SVAL_B " (" PFS ")", \
tst_tmp_a__, tst_tmp_b__); \
- } else { \
- TST_PASS = 1; \
+ } else if (!(SILENT)) { \
+ tst_res_(__FILE__, __LINE__, TPASS, \
+ SVAL_A " <= " SVAL_B " (" PFS " <= " PFS ")", \
+ tst_tmp_a__, tst_tmp_b__); \
} \
} while (0)
@@ -797,15 +801,8 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
*
* Reports a pass if A <= B and a fail otherwise.
*/
-#define TST_EXP_LE_LU(VAL_A, VAL_B) do { \
- TST_EXP_LE_SILENT_(VAL_A, #VAL_A, VAL_B, #VAL_B, unsigned long long, "%llu"); \
- \
- if (TST_PASS) { \
- tst_res_(__FILE__, __LINE__, TPASS, \
- #VAL_A " <= " #VAL_B " (%llu <= %llu)", \
- (unsigned long long)VAL_A, (unsigned long long)VAL_B); \
- } \
-} while (0)
+#define TST_EXP_LE_LU(VAL_A, VAL_B) \
+ TST_EXP_LE_(VAL_A, #VAL_A, VAL_B, #VAL_B, unsigned long long, "%llu", 0)
/**
* TST_EXP_LE_LU_SILENT() - Compare two unsigned long long values, silent variant.
@@ -817,7 +814,7 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
* success, only prints :c:enum:`TFAIL <tst_res_flags>` on failure.
*/
#define TST_EXP_LE_LU_SILENT(VAL_A, VAL_B) \
- TST_EXP_LE_SILENT_(VAL_A, #VAL_A, VAL_B, #VAL_B, unsigned long long, "%llu")
+ TST_EXP_LE_(VAL_A, #VAL_A, VAL_B, #VAL_B, unsigned long long, "%llu", 1)
/**
* TST_EXP_EQ_LI() - Compare two long long values.
@@ -827,15 +824,8 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
*
* Reports a pass if values are equal and a fail otherwise.
*/
-#define TST_EXP_EQ_LI(VAL_A, VAL_B) do { \
- TST_EXP_EQ_SILENT_(VAL_A, #VAL_A, VAL_B, #VAL_B, long long, "%lli"); \
- \
- if (TST_PASS) { \
- tst_res_(__FILE__, __LINE__, TPASS, \
- #VAL_A " == " #VAL_B " (%lli)", \
- (long long)VAL_A); \
- } \
-} 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", 0)
/**
* TST_EXP_EQ_LI_SILENT() - Compare two long long values, silent variant.
@@ -847,7 +837,7 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
* success, only prints :c:enum:`TFAIL <tst_res_flags>` on failure.
*/
#define TST_EXP_EQ_LI_SILENT(VAL_A, VAL_B) \
- TST_EXP_EQ_SILENT_(VAL_A, #VAL_A, VAL_B, #VAL_B, long long, "%lli")
+ TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, long long, "%lli", 1)
/**
* TST_EXP_EQ_LU() - Compare two unsigned long long values.
@@ -857,15 +847,8 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
*
* Reports a pass if values are equal and a fail otherwise.
*/
-#define TST_EXP_EQ_LU(VAL_A, VAL_B) do { \
- TST_EXP_EQ_SILENT_(VAL_A, #VAL_A, VAL_B, #VAL_B, unsigned long long, "%llu"); \
- \
- if (TST_PASS) { \
- tst_res_(__FILE__, __LINE__, TPASS, \
- #VAL_A " == " #VAL_B " (%llu)", \
- (unsigned long long)VAL_A); \
- } \
-} while (0)
+#define TST_EXP_EQ_LU(VAL_A, VAL_B) \
+ TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, unsigned long long, "%llu", 0)
/**
* TST_EXP_EQ_LU_SILENT() - Compare two unsigned long long values, silent variant.
@@ -877,7 +860,7 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
* success, only prints :c:enum:`TFAIL <tst_res_flags>` on failure.
*/
#define TST_EXP_EQ_LU_SILENT(VAL_A, VAL_B) \
- TST_EXP_EQ_SILENT_(VAL_A, #VAL_A, VAL_B, #VAL_B, unsigned long long, "%llu")
+ TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, unsigned long long, "%llu", 1)
/**
* TST_EXP_EQ_SZ() - Compare two size_t values.
@@ -887,15 +870,8 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
*
* Reports a pass if values are equal and a fail otherwise.
*/
-#define TST_EXP_EQ_SZ(VAL_A, VAL_B) do { \
- TST_EXP_EQ_SILENT_(VAL_A, #VAL_A, VAL_B, #VAL_B, size_t, "%zu"); \
- \
- if (TST_PASS) { \
- tst_res_(__FILE__, __LINE__, TPASS, \
- #VAL_A " == " #VAL_B " (%zu)", \
- (size_t)VAL_A); \
- } \
-} while (0)
+#define TST_EXP_EQ_SZ(VAL_A, VAL_B) \
+ TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, size_t, "%zu", 0)
/**
* TST_EXP_EQ_SZ_SILENT() - Compare two size_t values, silent variant.
@@ -907,7 +883,7 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
* success, only prints :c:enum:`TFAIL <tst_res_flags>` on failure.
*/
#define TST_EXP_EQ_SZ_SILENT(VAL_A, VAL_B) \
- TST_EXP_EQ_SILENT_(VAL_A, #VAL_A, VAL_B, #VAL_B, size_t, "%zu")
+ TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, size_t, "%zu", 1)
/**
* TST_EXP_EQ_SSZ() - Compare two ssize_t values.
@@ -917,15 +893,8 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
*
* Reports a pass if values are equal and a fail otherwise.
*/
-#define TST_EXP_EQ_SSZ(VAL_A, VAL_B) do { \
- TST_EXP_EQ_SILENT_(VAL_A, #VAL_A, VAL_B, #VAL_B, size_t, "%zi"); \
- \
- if (TST_PASS) { \
- tst_res_(__FILE__, __LINE__, TPASS, \
- #VAL_A " == " #VAL_B " (%zi)", \
- (ssize_t)VAL_A); \
- } \
-} while (0)
+#define TST_EXP_EQ_SSZ(VAL_A, VAL_B) \
+ TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, ssize_t, "%zi", 0)
/**
* TST_EXP_EQ_SSZ_SILENT() - Compare two ssize_t values, silent variant.
@@ -937,7 +906,7 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
* success, only prints :c:enum:`TFAIL <tst_res_flags>` on failure.
*/
#define TST_EXP_EQ_SSZ_SILENT(VAL_A, VAL_B) \
- TST_EXP_EQ_SILENT_(VAL_A, #VAL_A, VAL_B, #VAL_B, ssize_t, "%zi")
+ TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, ssize_t, "%zi", 1)
/**
* TST_EXP_EQ_STR() - Compare two strings.
base-commit: 5f4d6908fa7d48842f151b18ed4d8a9a76258cd5
--
2.56.0.611.g1030f0b940-goog
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2026-11-13 13:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 13:41 Wake Liu via ltp [this message]
2026-11-24 8:42 ` [LTP] [PATCH] tst_test_macros: Avoid re-evaluating arguments in TST_EXP_{EQ, LE}_*() Wake Liu via ltp
2026-11-24 15:53 ` 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=20261113134113.2822581-1-wakel@google.com \
--to=ltp@lists.linux.it \
--cc=wakel@google.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.