All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Wei Gao <wegao@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v1] lib: Add TST_EXP_PASS_PTR_{NULL,VOID} macros
Date: Wed, 17 Apr 2024 10:31:08 +0200	[thread overview]
Message-ID: <20240417083108.GC681570@pevik> (raw)
In-Reply-To: <20240415025100.2103-1-wegao@suse.com>

Hi Wei,

> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
>  include/tst_test_macros.h               | 41 +++++++++++++++++++++++++
>  testcases/kernel/syscalls/sbrk/sbrk01.c |  7 +----

I would split sbrk01 change into separate commit (generally it's better to
separate library change). And you can add also sbrk02.

I tried to find test which could use TST_EXP_PASS_PTR_NULL(), but haven't found
any. Do we need it?

>  2 files changed, 42 insertions(+), 6 deletions(-)

> diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
> index 22b39fb14..2668758fb 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,25 @@ 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, ...)                                      \
> +       do {                                                                    \
> +               TST_EXP_PASS_PTR_(SCALL, #SCALL, NULL, ##__VA_ARGS__);          \
> +       } while (0)
> +
> +#define TST_EXP_PASS_PTR_VOID(SCALL, ...)                                      \
> +       do {                                                                    \
> +               TST_EXP_PASS_PTR_(SCALL, #SCALL, (void *)-1, ##__VA_ARGS__);    \
> +       } while (0)

do { } while is not needed, maybe just (not an error, just code simplification):

#define TST_EXP_PASS_PTR_NULL(SCALL, ...)                                      \
       TST_EXP_PASS_PTR_(SCALL, #SCALL, NULL, ##__VA_ARGS__)

#define TST_EXP_PASS_PTR_VOID(SCALL, ...)                                      \
       TST_EXP_PASS_PTR_(SCALL, #SCALL, (void *)-1, ##__VA_ARGS__)

Also, the same applies to TST_EXP_FAIL_PTR_NULL_ARR() and
TST_EXP_FAIL_PTR_VOID_ARR().

> +
>  /*
>   * Returns true if err is in the exp_err array.
>   */
> diff --git a/testcases/kernel/syscalls/sbrk/sbrk01.c b/testcases/kernel/syscalls/sbrk/sbrk01.c
> index bb78d9a7b..2d2244a35 100644
> --- a/testcases/kernel/syscalls/sbrk/sbrk01.c
> +++ b/testcases/kernel/syscalls/sbrk/sbrk01.c
> @@ -26,12 +26,7 @@ static void run(unsigned int i)
>  {
>  	struct tcase *tc = &tcases[i];

> -	TESTPTR(sbrk(tc->increment));
> -
> -	if (TST_RET_PTR == (void *) -1)
> -		tst_res(TFAIL | TTERRNO, "sbrk(%ld) failed", tc->increment);
> -	else
> -		tst_res(TPASS, "sbrk(%ld) returned %p", tc->increment, TST_RET_PTR);
> +	TST_EXP_PASS_PTR_VOID(sbrk(tc->increment), "sbrk(%ld) returned %p", tc->increment, TST_RET_PTR);
Too long line, it's be better to split.

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2024-04-17  8:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-15  2:51 [LTP] [PATCH v1] lib: Add TST_EXP_PASS_PTR_{NULL,VOID} macros Wei Gao via ltp
2024-04-17  8:31 ` Petr Vorel [this message]
2024-04-25  2:03 ` [LTP] [PATCH v2 0/3] " Wei Gao via ltp
2024-04-25  2:03   ` [LTP] [PATCH v2 1/3] " Wei Gao via ltp
2024-04-25 11:40     ` [LTP] [PATCH v2 1/3] lib: Add TST_EXP_PASS_PTR_{NULL, VOID} macros Petr Vorel
2024-04-29 17:51       ` Avinesh Kumar
2024-04-25  2:03   ` [LTP] [PATCH v2 2/3] sbrk01.c: Use TST_EXP_PASS_PTR_VOID Wei Gao via ltp
2024-04-25 11:42     ` Petr Vorel
2024-04-25  2:03   ` [LTP] [PATCH v2 3/3] sbrk02.c: Use TST_EXP_FAIL_PTR_VOID Wei Gao via ltp
2024-04-25 11:44     ` Petr Vorel
2025-01-14 13:42   ` [LTP] [PATCH v2 0/3] lib: Add TST_EXP_PASS_PTR_{NULL, VOID} macros Andrea Cervesato via ltp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240417083108.GC681570@pevik \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=wegao@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.