[LTP] [PATCH v2 1/3] lib: Add TST_EXP_PASS_PTR_{NULL, VOID} macros

Petr Vorel pvorel@suse.cz
Thu Apr 25 13:40:13 CEST 2024


Hi Wei,

> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
>  include/tst_test_macros.h | 45 +++++++++++++++++++++++++++++++++------
>  1 file changed, 39 insertions(+), 6 deletions(-)

> diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
> index 22b39fb14..1fb133dd3 100644
> --- a/include/tst_test_macros.h
> +++ b/include/tst_test_macros.h
> @@ -178,6 +178,28 @@ extern void *TST_RET_PTR;
>                                                                                 \
>  	} while (0)

> +#define TST_EXP_PASS_SILENT_PTR_(SCALL, SSCALL, FAIL_PTR_VAL, ...)             \
> +	do {                                                                   \
> +		TESTPTR(SCALL);                                                \
> +		                                                               \
> +		TST_PASS = 0;                                                  \
> +		                                                               \
> +		if (TST_RET_PTR == FAIL_PTR_VAL) {                             \
> +			TST_MSG_(TFAIL | TTERRNO, " failed",                   \
> +			         SSCALL, ##__VA_ARGS__);                       \
> +		        break;                                                 \
> +		}                                                              \
> +		                                                               \
> +		if (TST_RET != 0) {                                            \
> +			TST_MSGP_(TFAIL | TTERRNO, " invalid retval %ld",      \
> +			          TST_RET, SSCALL, ##__VA_ARGS__);             \
> +			break;                                                 \
> +		}                                                              \
> +                                                                               \
> +		TST_PASS = 1;                                                  \
> +                                                                               \
> +	} while (0)
> +
>  #define TST_EXP_PASS_SILENT(SCALL, ...) TST_EXP_PASS_SILENT_(SCALL, #SCALL, ##__VA_ARGS__)

>  #define TST_EXP_PASS(SCALL, ...)                                               \
> @@ -188,6 +210,21 @@ extern void *TST_RET_PTR;
>  			TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
>  	} while (0)                                                            \

> +#define TST_EXP_PASS_PTR_(SCALL, SSCALL, FAIL_PTR_VAL, ...)                    \
> +	do {                                                                   \
> +		TST_EXP_PASS_SILENT_PTR_(SCALL, SSCALL,                        \
> +					FAIL_PTR_VAL, ##__VA_ARGS__);          \
> +		                                                               \
> +		if (TST_PASS)                                                  \
> +			TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
> +	} while (0)
> +
> +#define TST_EXP_PASS_PTR_NULL(SCALL, ...)                                      \
> +               TST_EXP_PASS_PTR_(SCALL, #SCALL, NULL, ##__VA_ARGS__);

I'm still not sure whether add TST_EXP_PASS_PTR_NULL, which is not used.
I wonder what others think (it can be removed before merge).

> +
> +#define TST_EXP_PASS_PTR_VOID(SCALL, ...)                                      \
> +               TST_EXP_PASS_PTR_(SCALL, #SCALL, (void *)-1, ##__VA_ARGS__);
> +
>  /*
>   * Returns true if err is in the exp_err array.
>   */
> @@ -301,10 +338,8 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
>  	} while (0)

>  #define TST_EXP_FAIL_PTR_NULL_ARR(SCALL, EXP_ERRS, EXP_ERRS_CNT, ...)      \
> -	do {                                                                   \
>  		TST_EXP_FAIL_PTR_(SCALL, #SCALL, NULL,                         \
> -			EXP_ERRS, EXP_ERRS_CNT, ##__VA_ARGS__);        \
> -	} while (0)
> +			EXP_ERRS, EXP_ERRS_CNT, ##__VA_ARGS__);
+1

>  #define TST_EXP_FAIL_PTR_VOID(SCALL, EXP_ERR, ...)                         \
>  	do {                                                                   \
> @@ -314,10 +349,8 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
>  	} while (0)

>  #define TST_EXP_FAIL_PTR_VOID_ARR(SCALL, EXP_ERRS, EXP_ERRS_CNT, ...)      \
> -	do {                                                                   \
>  		TST_EXP_FAIL_PTR_(SCALL, #SCALL, (void *)-1,                   \
> -			EXP_ERRS, EXP_ERRS_CNT, ##__VA_ARGS__);        \
> -	} while (0)
> +			EXP_ERRS, EXP_ERRS_CNT, ##__VA_ARGS__);
+1

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

Kind regards,
Petr

>  #define TST_EXP_FAIL2(SCALL, EXP_ERR, ...)                                     \
>  	do {                                                                   \


More information about the ltp mailing list