From: Wei Gao via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] Add TST_EXP_FAIL_PTR
Date: Wed, 17 Jan 2024 03:04:46 -0500 [thread overview]
Message-ID: <20240117080446.9663-1-wegao@suse.com> (raw)
In-Reply-To: <20240111012650.9731-1-wegao@suse.com>
Signed-off-by: Wei Gao <wegao@suse.com>
---
include/tst_test_macros.h | 41 +++++++++++++++++++++++++++++
lib/newlib_tests/.gitignore | 1 +
lib/newlib_tests/test_macros07.c | 44 ++++++++++++++++++++++++++++++++
3 files changed, 86 insertions(+)
create mode 100644 lib/newlib_tests/test_macros07.c
diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index 24fd324bf..409e6847c 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -227,6 +227,30 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
} \
} while (0)
+#define TST_EXP_FAIL_SILENT_PTR_(SCALL, SSCALL, ERRNOS, ERRNOS_CNT, ...) \
+ do { \
+ TESTPTR(SCALL); \
+ \
+ TST_PASS = 0; \
+ \
+ if (TST_RET_PTR) { \
+ TST_MSG_(TFAIL, " succeeded", SSCALL, ##__VA_ARGS__); \
+ break; \
+ } \
+ \
+ if (!tst_errno_in_set(TST_ERR, ERRNOS, ERRNOS_CNT)) { \
+ char tst_str_buf__[ERRNOS_CNT * 20]; \
+ TST_MSGP_(TFAIL | TTERRNO, " expected %s", \
+ tst_errno_names(tst_str_buf__, \
+ ERRNOS, ERRNOS_CNT), \
+ SSCALL, ##__VA_ARGS__); \
+ break; \
+ } \
+ \
+ TST_PASS = 1; \
+ \
+ } while (0)
+
#define TST_EXP_FAIL_ARR_(SCALL, EXP_ERRS, EXP_ERRS_CNT, ...) \
do { \
TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, #SCALL, \
@@ -258,6 +282,23 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
TST_EXP_FAIL2_ARR_(SCALL, EXP_ERRS, ARRAY_SIZE(EXP_ERRS), \
##__VA_ARGS__); \
+#define TST_EXP_FAIL_PTR(SCALL, EXP_ERR, ...) \
+ do { \
+ int tst_exp_err__ = EXP_ERR; \
+ TST_EXP_FAIL_SILENT_PTR_(SCALL, #SCALL, \
+ &tst_exp_err__, 1, ##__VA_ARGS__); \
+ if (TST_PASS) \
+ TST_MSG_(TPASS | TTERRNO, " ", #SCALL, ##__VA_ARGS__); \
+ } while (0)
+
+#define TST_EXP_FAIL_PTR_ARR(SCALL, EXP_ERRS, ...) \
+ do { \
+ TST_EXP_FAIL_SILENT_PTR_(SCALL, #SCALL, \
+ EXP_ERRS, ARRAY_SIZE(EXP_ERRS), ##__VA_ARGS__); \
+ if (TST_PASS) \
+ TST_MSG_(TPASS | TTERRNO, " ", #SCALL, ##__VA_ARGS__); \
+ } while (0)
+
#define TST_EXP_FAIL2(SCALL, EXP_ERR, ...) \
do { \
int tst_exp_err__ = EXP_ERR; \
diff --git a/lib/newlib_tests/.gitignore b/lib/newlib_tests/.gitignore
index a69b29e24..4f43899e5 100644
--- a/lib/newlib_tests/.gitignore
+++ b/lib/newlib_tests/.gitignore
@@ -40,6 +40,7 @@ test_macros03
test_macros04
test_macros05
test_macros06
+test_macros07
tst_fuzzy_sync01
tst_fuzzy_sync02
tst_fuzzy_sync03
diff --git a/lib/newlib_tests/test_macros07.c b/lib/newlib_tests/test_macros07.c
new file mode 100644
index 000000000..45bba8409
--- /dev/null
+++ b/lib/newlib_tests/test_macros07.c
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2024 Wei Gao <wegao@suse.com>
+ */
+
+/*
+ * Test TST_EXP_FAIL_PTR and TST_EXP_FAIL_PTR_ARR macro.
+ */
+
+#include "tst_test.h"
+
+static char *fail_fn(void)
+{
+ errno = EINVAL;
+ return NULL;
+}
+
+static char *pass_fn(void)
+{
+ return "pass";
+}
+
+static void do_test(void)
+{
+ const int exp_errs_pass[] = {ENOTTY, EINVAL};
+ const int exp_errs_fail[] = {ENOTTY, EISDIR};
+
+ tst_res(TINFO, "Testing TST_EXP_FAIL_PTR macro");
+ TST_EXP_FAIL_PTR(fail_fn(), EINVAL, "fail_fn()");
+ tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+ TST_EXP_FAIL_PTR(fail_fn(), ENOTTY, "fail_fn()");
+ tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+ TST_EXP_FAIL_PTR(pass_fn(), ENOTTY, "pass_fn()");
+ tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+ TST_EXP_FAIL_PTR_ARR(fail_fn(), exp_errs_pass, "fail_fn()");
+ tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+ TST_EXP_FAIL_PTR_ARR(fail_fn(), exp_errs_fail, "fail_fn()");
+ tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+
+}
+
+static struct tst_test test = {
+ .test_all = do_test,
+};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-01-17 8:05 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-11 1:26 [LTP] [PATCH v1] Add TST_EXP_FAIL_PTR Wei Gao via ltp
2024-01-16 17:49 ` Petr Vorel
2024-01-17 8:07 ` Wei Gao via ltp
2024-01-17 8:04 ` Wei Gao via ltp [this message]
2024-01-17 9:49 ` [LTP] [PATCH v2] " Petr Vorel
2024-01-30 12:21 ` Petr Vorel
2024-01-17 12:52 ` [LTP] [PATCH v3 0/2] lib: TST_EXP_FAIL_PTR Wei Gao via ltp
2024-01-17 12:52 ` [LTP] [PATCH v3 1/2] " Wei Gao via ltp
2024-01-23 8:45 ` Petr Vorel
2024-01-23 10:41 ` Cyril Hrubis
2024-01-30 12:20 ` Petr Vorel
2024-01-17 12:52 ` [LTP] [PATCH v3 2/2] getcwd01: Implement .test_variants Wei Gao via ltp
2024-01-23 9:45 ` Petr Vorel
2024-02-08 1:32 ` [LTP] [PATCH v4 0/3] lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID} Wei Gao via ltp
2024-02-08 1:32 ` [LTP] [PATCH v4 1/3] " Wei Gao via ltp
2024-03-20 10:47 ` Petr Vorel
2024-03-26 10:54 ` Cyril Hrubis
2024-02-08 1:32 ` [LTP] [PATCH v4 2/3] shmat02.c: Use TST_EXP_FAIL_PTR_VOID Wei Gao via ltp
2024-03-20 10:47 ` Petr Vorel
2024-02-08 1:32 ` [LTP] [PATCH v4 3/3] realpath01.c: use TST_EXP_FAIL_PTR_NULL Wei Gao via ltp
2024-03-20 10:47 ` Petr Vorel
2024-03-27 3:49 ` [LTP] [PATCH v5 0/3] lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID} Wei Gao via ltp
2024-03-27 3:49 ` [LTP] [PATCH v5 1/3] " Wei Gao via ltp
2024-03-28 11:29 ` Petr Vorel
2024-03-28 11:49 ` Petr Vorel
2024-03-28 11:57 ` Petr Vorel
2024-03-28 12:11 ` Petr Vorel
2024-03-27 3:49 ` [LTP] [PATCH v5 2/3] shmat02.c: Use TST_EXP_FAIL_PTR_VOID Wei Gao via ltp
2024-03-27 3:49 ` [LTP] [PATCH v5 3/3] realpath01.c: use TST_EXP_FAIL_PTR_NULL Wei Gao via ltp
2024-04-03 3:28 ` [LTP] [PATCH v6 0/3] lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID} Wei Gao via ltp
2024-04-03 3:28 ` [LTP] [PATCH v6 1/3] " Wei Gao via ltp
2024-04-04 13:51 ` Cyril Hrubis
2024-04-04 16:01 ` Petr Vorel
2024-04-05 8:53 ` Cyril Hrubis
2024-04-05 10:28 ` Petr Vorel
2024-04-05 11:23 ` Cyril Hrubis
2024-04-05 14:03 ` Petr Vorel
2024-04-07 23:31 ` Wei Gao via ltp
2024-04-03 3:28 ` [LTP] [PATCH v6 2/3] shmat02.c: Use TST_EXP_FAIL_PTR_VOID Wei Gao via ltp
2024-04-03 3:28 ` [LTP] [PATCH v6 3/3] realpath01.c: use TST_EXP_FAIL_PTR_NULL Wei Gao 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=20240117080446.9663-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