From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 1/2] Add TST_ASSERT_SYSCALL*() macros
Date: Thu, 5 Mar 2020 18:42:05 +0100 [thread overview]
Message-ID: <20200305174205.GA29517@dell5510> (raw)
In-Reply-To: <20200305151459.30341-1-mdoucha@suse.cz>
Hi Martin,
> These macros take care of the standard return value checking boilerplate
> in cases where the test cannot continue after error.
> - TST_ASSERT_SYSCALL() calls tst_brk() if retval != 0
> - TST_ASSERT_SYSCALL_FD() calls tst_brk() if retval < 0
Reviewed-by: Petr Vorel <pvorel@suse.cz>
What I like on these macros (besides DRY) is that it really shows the test, not
the library, see
before:
tst_safe_timerfd.c:21: BROK: timerfd01.c:89 timerfd_create(CLOCK_MONOTONIC) failed: EINVAL (22)
after:
timerfd01.c:89: BROK: timerfd_create(CLOCK_MONOTONIC) failed: EINVAL (22)
> +/* assert that syscall returned only 0 and nothing else */
> +#define TST_ASSERT_SYSCALL(SCALL) \
> + TST_ASSERT_SYSCALL_IMPL(SCALL, __FILE__, __LINE__, #SCALL)
> +
> +#define TST_ASSERT_SYSCALL_IMPL(SCALL, FILENAME, LINENO, CALLSTR, ...) \
> + ({ \
> + int _tst_ret; \
> + errno = 0; \
> + _tst_ret = SCALL; \
> + if (_tst_ret == -1) { \
> + int _tst_ttype = errno == ENOTSUP ? TCONF : TBROK; \
> + tst_brk_(FILENAME, LINENO, _tst_ttype | TERRNO, \
> + CALLSTR " failed", ##__VA_ARGS__); \
> + } \
> + if (_tst_ret != 0) { \
> + tst_brk_(FILENAME, LINENO, TBROK | TERRNO, \
> + CALLSTR " returned invalid value %d", \
> + ##__VA_ARGS__, _tst_ret); \
> + } \
> + _tst_ret; \
> + })
> +
> +/*
> + * assert that syscall returned any non-negative value (e.g. valid file
> + * descriptor)
> + */
> +#define TST_ASSERT_SYSCALL_FD(SCALL) \
> + TST_ASSERT_SYSCALL_FD_IMPL(SCALL, __FILE__, __LINE__, #SCALL)
> +
> +#define TST_ASSERT_SYSCALL_FD_IMPL(SCALL, FILENAME, LINENO, CALLSTR, ...) \
> + ({ \
> + int _tst_ret; \
> + errno = 0; \
> + _tst_ret = SCALL; \
> + if (_tst_ret == -1) { \
> + int _tst_ttype = errno == ENOTSUP ? TCONF : TBROK; \
> + tst_brk_(FILENAME, LINENO, _tst_ttype | TERRNO, \
> + CALLSTR " failed", ##__VA_ARGS__); \
> + } \
> + if (_tst_ret < 0) { \
> + tst_brk_(FILENAME, LINENO, TBROK | TERRNO, \
> + CALLSTR " returned invalid value %d", \
> + ##__VA_ARGS__, _tst_ret); \
> + } \
> + _tst_ret; \
> + })
I'd consider to add single implementation, which would be influenced with flags
Something like
if ((flags & TST_ASSERT_LT_0) && _tst_ret < 0 || _tst_ret != 0) \
But maybe some people will not like degreased readability with macro,
and using flags would make it even a bit harder to read.
Kind regards,
Petr
next prev parent reply other threads:[~2020-03-05 17:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-05 15:14 [LTP] [PATCH v2 1/2] Add TST_ASSERT_SYSCALL*() macros Martin Doucha
2020-03-05 15:14 ` [LTP] [PATCH v2 2/2] Reimplement TST_SAFE_TIMERFD_*() using TST_ASSERT_SYSCALL*() Martin Doucha
2020-03-05 15:20 ` Cyril Hrubis
2020-03-05 17:50 ` Petr Vorel
2020-03-05 17:42 ` Petr Vorel [this message]
2020-03-05 17:53 ` [LTP] [PATCH v2 1/2] Add TST_ASSERT_SYSCALL*() macros Cyril Hrubis
2020-03-05 19:36 ` Petr Vorel
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=20200305174205.GA29517@dell5510 \
--to=pvorel@suse.cz \
--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