Re: [PATCH v2 2/2] test_macros: Add TST_EXP_PASS_OR_FAIL()

Cyril Hrubis <[email protected]>
Newsgroups gmane.linux.ltp
Message-ID <alDv2LPAshw48WBE@rei>
Hi!
>  #define TST_EXP_PASS(SCALL, ...)                                               \
> +	TST_EXP_PASS_(SCALL, #SCALL, ##__VA_ARGS__)
> +
> +#define TST_EXP_PASS_(SCALL, SSCALL, ...)                                      \
>  	do {                                                                   \
>  		TST_EXP_PASS_SILENT_(SCALL, #SCALL, ##__VA_ARGS__);            \
                                            ^
					    Here as well SSCALL
> @@ -366,6 +369,32 @@ extern int TST_PASS;
>  			TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
>  	} while (0)
>  
> +/**
> + * TST_EXP_PASS_OR_FAIL() - Test syscall and expect it to pass or fail with
> + * expected errno.
> + *
> + * @SCALL: Tested syscall.
> + * @ERRNO: Expected errno or 0.
> + * @...: A printf-like parameters.
> + *
> + * Expect to pass if ERRNO is 0 otherwise expect a failure with
> + * expected errno.
> + *
> + * Internally it uses TST_EXP_FAIL() and TST_EXP_PASS().
> + */
> +#define TST_EXP_PASS_OR_FAIL(SCALL, ERRNO, ...)                               \
> +	TST_EXP_PASS_OR_FAIL_(SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
> +
> +#define TST_EXP_PASS_OR_FAIL_(SCALL, SSCALL, ERRNO, ...)                      \

And here as well, no need for the indirection until we need to use
TST_EXP_PASS_OR_FAIL_ in another macro.

> +	({                                                                     \
> +		if (ERRNO)                                                     \
> +			TST_EXP_FAIL_(SCALL, SSCALL, ERRNO, ##__VA_ARGS__);    \
> +		else                                                           \
> +			TST_EXP_PASS_(SCALL, SSCALL, ##__VA_ARGS__);           \
> +		                                                               \
> +		TST_RET;                                                       \
> +	})
> +
>  /**
>   * TST_EXP_PASS_PTR_VOID() - Test syscall to return a valid pointer.
>   *
> diff --git a/lib/newlib_tests/test_macros03.c b/lib/newlib_tests/test_macros03.c
> index 19a0ad6fd3..2a281bafcd 100644
> --- a/lib/newlib_tests/test_macros03.c
> +++ b/lib/newlib_tests/test_macros03.c
> @@ -9,9 +9,11 @@
>  
>  #include "tst_test.h"
>  
> +#define ERR_ERRNO EINVAL
> +
>  static int fail_fn(void)
>  {
> -	errno = EINVAL;
> +	errno = ERR_ERRNO;
>  	return -1;
>  }
>  
> @@ -42,6 +44,11 @@ static void do_test(void)
>  	tst_res(TINFO, "TST_PASS = %i from TST_EXP_PASS_SILENT(pass_fn, ...)", TST_PASS);
>  	TST_EXP_PASS_SILENT(inval_ret_fn(), "inval_ret_fn()");
>  	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
> +
> +	tst_res(TINFO, "Testing TST_EXP_PASS_OR_FAIL() macro (pass)");
> +	TST_EXP_PASS_OR_FAIL(pass_fn(), 0, "pass_fn()");
> +	tst_res(TINFO, "Testing TST_EXP_PASS_OR_FAIL() macro (fail)");
> +	TST_EXP_PASS_OR_FAIL(fail_fn(), ERR_ERRNO, "fail_fn()");
>  }
>  
>  static struct tst_test test = {
> -- 
> 2.54.0
> 

-- 
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.