Skip to content

Commit

Permalink
lib: TST_EXP_FAIL: Fix the *_ARR_() macros
Browse files Browse the repository at this point in the history
This is basically the same fix as:
d7e5e10 (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: 1cfe614 ("lib: TST_EXP_FAIL: Add array variants")
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reported-by: Wei Gao <wegao@suse.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
  • Loading branch information
metan-ucw committed Jan 17, 2024
1 parent 8674832 commit 009795a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions include/tst_test_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 009795a

Please sign in to comment.