From: Cyril Hrubis <chrubis@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v1] Support return value in TST_* macros
Date: Wed, 26 Apr 2023 10:26:39 +0200 [thread overview]
Message-ID: <ZEjgPy7kJbUG4r1W@rei> (raw)
In-Reply-To: <20230426074950.8807-1-andrea.cervesato@suse.de>
Hi!
> include/tst_test_macros.h | 69 +++++++++++++++++++++++++++------------
> 1 file changed, 48 insertions(+), 21 deletions(-)
>
> diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
> index 231c04951..acc2d1bff 100644
> --- a/include/tst_test_macros.h
> +++ b/include/tst_test_macros.h
> @@ -74,45 +74,60 @@ extern void *TST_RET_PTR;
> } while (0)
>
> #define TST_EXP_POSITIVE(SCALL, ...) \
> - do { \
> + ({ \
> TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__); \
> \
> if (TST_PASS) { \
> TST_MSGP_(TPASS, " returned %ld", \
> TST_RET, #SCALL, ##__VA_ARGS__); \
> } \
> - } while (0)
> + \
> + TST_RET; \
> + })
>
> -#define TST_EXP_FD_SILENT(SCALL, ...) TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__)
> +#define TST_EXP_FD_SILENT(SCALL, ...) \
> + ({ \
> + TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__); \
> + TST_RET; \
> + })
It would prbably be easier to change the TST_EXP_POSITIVE_ to return a
value instead of changing all the macros that expand to
TST_EXP_POSITIVE_.
> #define TST_EXP_FD(SCALL, ...) \
> - do { \
> + ({ \
> TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__); \
> \
> if (TST_PASS) \
> TST_MSGP_(TPASS, " returned fd %ld", TST_RET, \
> #SCALL, ##__VA_ARGS__); \
> - } while (0)
> + \
> + TST_RET; \
> + })
>
> -#define TST_EXP_FD_OR_FAIL(SCALL, ERRNO, ...) \
> - do { \
> +#define TST_EXP_FD_OR_FAIL(SCALL, ERRNO, ...) \
> + ({ \
> if (ERRNO) \
> TST_EXP_FAIL(SCALL, ERRNO, ##__VA_ARGS__); \
> else \
> TST_EXP_FD(SCALL, ##__VA_ARGS__); \
> \
> - } while (0)
> + TST_RET; \
> + })
>
> -#define TST_EXP_PID_SILENT(SCALL, ...) TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__)
> +#define TST_EXP_PID_SILENT(SCALL, ...) \
> + ({ \
> + TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__); \
> + TST_RET; \
> + })
>
> #define TST_EXP_PID(SCALL, ...) \
> - do { \
> + ({ \
> TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__); \
> \
> if (TST_PASS) \
> TST_MSGP_(TPASS, " returned pid %ld", TST_RET, \
> #SCALL, ##__VA_ARGS__); \
> - } while (0)
> + \
> + TST_RET; \
> + })
>
> #define TST_EXP_VAL_SILENT_(SCALL, VAL, SSCALL, ...) \
> do { \
> @@ -128,18 +143,20 @@ extern void *TST_RET_PTR;
> \
> TST_PASS = 1; \
> \
> + TST_RET; \
> } while (0)
>
> #define TST_EXP_VAL_SILENT(SCALL, VAL, ...) TST_EXP_VAL_SILENT_(SCALL, VAL, #SCALL, ##__VA_ARGS__)
>
> #define TST_EXP_VAL(SCALL, VAL, ...) \
> - do { \
> + ({ \
> TST_EXP_VAL_SILENT_(SCALL, VAL, #SCALL, ##__VA_ARGS__); \
> \
> if (TST_PASS) \
> TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__); \
> - \
> - } while(0)
> + \
> + TST_RET; \
> + })
>
> #define TST_EXP_PASS_SILENT_(SCALL, SSCALL, ...) \
> do { \
> @@ -163,15 +180,21 @@ extern void *TST_RET_PTR;
> \
> } while (0)
>
> -#define TST_EXP_PASS_SILENT(SCALL, ...) TST_EXP_PASS_SILENT_(SCALL, #SCALL, ##__VA_ARGS__)
> +#define TST_EXP_PASS_SILENT(SCALL, ...) \
> + ({ \
> + TST_EXP_PASS_SILENT_(SCALL, #SCALL, ##__VA_ARGS__); \
> + TST_RET; \
> + })
Do we really need an return value from EXP_PASS and EXP_FAIL?
If TST_EXP_PASS_* does not break the test the return value was 0, if
TST_EXP_FAIL_* does not break the test, the return value was -1
> #define TST_EXP_PASS(SCALL, ...) \
> - do { \
> + ({ \
> TST_EXP_PASS_SILENT_(SCALL, #SCALL, ##__VA_ARGS__); \
> \
> if (TST_PASS) \
> TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__); \
> - } while (0) \
> + \
> + TST_RET; \
> + })
>
> #define TST_EXP_FAIL_SILENT_(PASS_COND, SCALL, SSCALL, ERRNO, ...) \
> do { \
> @@ -200,20 +223,24 @@ extern void *TST_RET_PTR;
> } while (0)
>
> #define TST_EXP_FAIL(SCALL, ERRNO, ...) \
> - do { \
> + ({ \
> TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, #SCALL, \
> ERRNO, ##__VA_ARGS__); \
> if (TST_PASS) \
> TST_MSG_(TPASS | TTERRNO, " ", #SCALL, ##__VA_ARGS__); \
> - } while (0)
> + \
> + TST_RET; \
> + })
>
> #define TST_EXP_FAIL2(SCALL, ERRNO, ...) \
> - do { \
> + ({ \
> TST_EXP_FAIL_SILENT_(TST_RET >= 0, SCALL, #SCALL, \
> ERRNO, ##__VA_ARGS__); \
> if (TST_PASS) \
> TST_MSG_(TPASS | TTERRNO, " ", #SCALL, ##__VA_ARGS__); \
> - } while (0)
> + \
> + TST_RET; \
> + })
>
> #define TST_EXP_FAIL_SILENT(SCALL, ERRNO, ...) \
> TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
> --
> 2.35.3
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2023-04-26 8:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-26 7:49 [LTP] [PATCH v1] Support return value in TST_* macros Andrea Cervesato
2023-04-26 8:26 ` Cyril Hrubis [this message]
2023-04-26 8:31 ` Andrea Cervesato via ltp
2023-04-26 8:38 ` Cyril Hrubis
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=ZEjgPy7kJbUG4r1W@rei \
--to=chrubis@suse.cz \
--cc=andrea.cervesato@suse.de \
--cc=ltp@lists.linux.it \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox