[LTP] [PATCH v2 1/2] test macros: Fix TST_EXP_FD_OR_FAIL()

Cyril Hrubis chrubis@suse.cz
Fri Jul 10 15:09:18 CEST 2026


Hi!
> diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
> index f06c8aeb77..e18f1d33f3 100644
> --- a/include/tst_test_macros.h
> +++ b/include/tst_test_macros.h
> @@ -8,6 +8,12 @@
>   * DOC: tst_test_macros.h -- helpers for testing syscalls
>   */
>  
> +/*
> + * NOTE: for all TST_EXP_*() macros SCALL in first macro needs to be stringified
> + * otherwise constants in syscalls will be evaluated (e.g. O_RDONLY becomes 0).
> + * That is the reason for underscore variants (e.g. TST_EXP_FAIL_()).
> + */
> +
>  #ifndef TST_TEST_MACROS_H__
>  #define TST_TEST_MACROS_H__
>  
> @@ -149,7 +155,10 @@ extern int TST_PASS;
>   * This is a variant of the TST_EXP_POSITIVE() for a more specific case that
>   * the returned value is a file descriptor.
>   */
> -#define TST_EXP_FD(SCALL, ...)                                                 \
> +#define TST_EXP_FD(SCALL, ...)                                  \
> +	TST_EXP_FD_(SCALL, #SCALL, ##__VA_ARGS__)
> +
> +#define TST_EXP_FD_(SCALL, SSCALL, ...)                                     \
>  	({                                                                     \
>  		TST_EXP_POSITIVE__(SCALL, #SCALL, ##__VA_ARGS__);              \
                                           ^
					   SSCALL
> @@ -174,11 +183,14 @@ extern int TST_PASS;
>   * Internally it uses TST_EXP_FAIL() and TST_EXP_FD().
>   */
>  #define TST_EXP_FD_OR_FAIL(SCALL, ERRNO, ...)                                  \
> -	({                                                                     \
> +	TST_EXP_FD_OR_FAIL_(SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
> +
> +#define TST_EXP_FD_OR_FAIL_(SCALL, SSCALL, ERRNO, ...)                 \
> +	({                                                                 \

This indirection is not needed as long as TST_EXP_FD_OR_FAIL() is not
called from other macros.

>  		if (ERRNO)                                                     \
> -			TST_EXP_FAIL(SCALL, ERRNO, ##__VA_ARGS__);             \
> +			TST_EXP_FAIL_(SCALL, SSCALL, ERRNO, ##__VA_ARGS__);    \
>  		else                                                           \
> -			TST_EXP_FD(SCALL, ##__VA_ARGS__);                      \
> +			TST_EXP_FD_(SCALL, SSCALL, ##__VA_ARGS__);             \
>  		                                                               \
>  		TST_RET;                                                       \
>  	})
> @@ -488,10 +500,13 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
>   * printed by the pass or fail tst_res() calls. If omitted the first parameter
>   * is converted to a string and used instead.
>   */
> -#define TST_EXP_FAIL(SCALL, EXP_ERR, ...)                                      \
> +#define TST_EXP_FAIL(SCALL, EXP_ERR, ...) \
> +	TST_EXP_FAIL_(SCALL, #SCALL, EXP_ERR, ##__VA_ARGS__)
> +
> +#define TST_EXP_FAIL_(SCALL, SSCALL, EXP_ERR, ...) \
>  	do {                                                                   \
>  		int tst_exp_err__ = EXP_ERR;                                   \
> -		TST_EXP_FAIL_ARR_(SCALL, #SCALL, &tst_exp_err__, 1,            \
> +		TST_EXP_FAIL_ARR_(SCALL, SSCALL, &tst_exp_err__, 1,            \
>                                    ##__VA_ARGS__);                              \
>  	} while (0)
>  
> -- 
> 2.54.0
> 

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list