From: Wei Gao via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v1] lib: Add TST_EXP_PASS_PTR_{NULL,VOID} macros
Date: Sun, 14 Apr 2024 22:51:00 -0400 [thread overview]
Message-ID: <20240415025100.2103-1-wegao@suse.com> (raw)
Signed-off-by: Wei Gao <wegao@suse.com>
---
include/tst_test_macros.h | 41 +++++++++++++++++++++++++
testcases/kernel/syscalls/sbrk/sbrk01.c | 7 +----
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)
+
/*
* 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);
}
static struct tst_test test = {
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2024-04-15 2:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-15 2:51 Wei Gao via ltp [this message]
2024-04-17 8:31 ` [LTP] [PATCH v1] lib: Add TST_EXP_PASS_PTR_{NULL,VOID} macros Petr Vorel
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
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=20240415025100.2103-1-wegao@suse.com \
--to=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).