diff mbox series

lib: TST_EXP_FAIL: Fix the *_ARR_() macros

Message ID 20240117101801.12536-1-chrubis@suse.cz
State Accepted
Headers show
Series lib: TST_EXP_FAIL: Fix the *_ARR_() macros | expand

Commit Message

Cyril Hrubis Jan. 17, 2024, 10:18 a.m. UTC
This is basically the same fix as:
d7e5e102364b (tst_test_macros.h: fix "too many arguments")

The point is that the SCALL parameter has to be stringified in the first
pass otherwise it ends up expandend and as long as it contains coma the
number of parameters will increase breaking the printf() formatting
again.

Fixes: #1120

Fixes: 1cfe61428982 ("lib: TST_EXP_FAIL: Add array variants")
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 include/tst_test_macros.h | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

Comments

Petr Vorel Jan. 17, 2024, 11:07 a.m. UTC | #1
Hi Cyril,

> This is basically the same fix as:
> d7e5e102364b (tst_test_macros.h: fix "too many arguments")

> The point is that the SCALL parameter has to be stringified in the first
> pass otherwise it ends up expandend and as long as it contains coma the
> number of parameters will increase breaking the printf() formatting
> again.

> Fixes: #1120

> Fixes: 1cfe61428982 ("lib: TST_EXP_FAIL: Add array variants")

Reported-by: Wei Gao <wegao@suse.com>
(missing credit)

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Thanks quick fix, please merge!
I'm sorry, I haven't noticed the problem. tst_test_macros.h is getting quite
complex, maybe we should add some comments into the header.

Kind regards,
Petr
Cyril Hrubis Jan. 17, 2024, 11:41 a.m. UTC | #2
Hi!
> I'm sorry, I haven't noticed the problem. tst_test_macros.h is getting quite
> complex, maybe we should add some comments into the header.

Pushed, thanks.

I guess that ideal fix would be comparing the output from the newlib
TST_EXP_* tescases with expected output. That would actually catch most
of the bugs introduced in there.
Petr Vorel Jan. 17, 2024, 11:44 a.m. UTC | #3
> Hi!
> > I'm sorry, I haven't noticed the problem. tst_test_macros.h is getting quite
> > complex, maybe we should add some comments into the header.

> Pushed, thanks.

> I guess that ideal fix would be comparing the output from the newlib
> TST_EXP_* tescases with expected output. That would actually catch most
> of the bugs introduced in there.

I've had it on my TODO list, hope to get to it sometimes in February.

Kind regards,
Petr
diff mbox series

Patch

diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index 24fd324bf..d2e50a219 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -227,41 +227,41 @@  const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
 		}                                                              \
 	} while (0)
 
-#define TST_EXP_FAIL_ARR_(SCALL, EXP_ERRS, EXP_ERRS_CNT, ...)                  \
+#define TST_EXP_FAIL_ARR_(SCALL, SSCALL, EXP_ERRS, EXP_ERRS_CNT, ...)          \
 	do {                                                                   \
-		TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, #SCALL,              \
+		TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, SSCALL,              \
 			EXP_ERRS, EXP_ERRS_CNT, ##__VA_ARGS__);                \
 		if (TST_PASS)                                                  \
-			TST_MSG_(TPASS | TTERRNO, " ", #SCALL, ##__VA_ARGS__); \
+			TST_MSG_(TPASS | TTERRNO, " ", SSCALL, ##__VA_ARGS__); \
 	} while (0)
 
 #define TST_EXP_FAIL(SCALL, EXP_ERR, ...)                                      \
 	do {                                                                   \
 		int tst_exp_err__ = EXP_ERR;                                   \
-		TST_EXP_FAIL_ARR_(SCALL, &tst_exp_err__, 1,                    \
+		TST_EXP_FAIL_ARR_(SCALL, #SCALL, &tst_exp_err__, 1,            \
                                   ##__VA_ARGS__);                              \
 	} while (0)
 
 #define TST_EXP_FAIL_ARR(SCALL, EXP_ERRS, ...)                                 \
-		TST_EXP_FAIL_ARR_(SCALL, EXP_ERRS, ARRAY_SIZE(EXP_ERRS),       \
-                                  ##__VA_ARGS__);                              \
+		TST_EXP_FAIL_ARR_(SCALL, #SCALL, EXP_ERRS,                     \
+				  ARRAY_SIZE(EXP_ERRS), ##__VA_ARGS__);
 
-#define TST_EXP_FAIL2_ARR_(SCALL, EXP_ERRS, EXP_ERRS_CNT, ...)                 \
+#define TST_EXP_FAIL2_ARR_(SCALL, SSCALL, EXP_ERRS, EXP_ERRS_CNT, ...)         \
 	do {                                                                   \
-		TST_EXP_FAIL_SILENT_(TST_RET >= 0, SCALL, #SCALL,              \
+		TST_EXP_FAIL_SILENT_(TST_RET >= 0, SCALL, SSCALL,              \
 			EXP_ERRS, EXP_ERRS_CNT, ##__VA_ARGS__);                \
 		if (TST_PASS)                                                  \
-			TST_MSG_(TPASS | TTERRNO, " ", #SCALL, ##__VA_ARGS__); \
+			TST_MSG_(TPASS | TTERRNO, " ", SSCALL, ##__VA_ARGS__); \
 	} while (0)
 
 #define TST_EXP_FAIL2_ARR(SCALL, EXP_ERRS, ...)                                \
-		TST_EXP_FAIL2_ARR_(SCALL, EXP_ERRS, ARRAY_SIZE(EXP_ERRS),      \
-                                  ##__VA_ARGS__);                              \
+		TST_EXP_FAIL2_ARR_(SCALL, #SCALL, EXP_ERRS,                    \
+		                  ARRAY_SIZE(EXP_ERRS), ##__VA_ARGS__);
 
 #define TST_EXP_FAIL2(SCALL, EXP_ERR, ...)                                     \
 	do {                                                                   \
 		int tst_exp_err__ = EXP_ERR;                                   \
-		TST_EXP_FAIL2_ARR_(SCALL, &tst_exp_err__, 1,                   \
+		TST_EXP_FAIL2_ARR_(SCALL, #SCALL, &tst_exp_err__, 1,           \
                                   ##__VA_ARGS__);                              \
 	} while (0)