diff mbox series

[v6,1/3] lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID}

Message ID 20240403032859.3826-2-wegao@suse.com
State Superseded
Headers show
Series lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID} | expand

Commit Message

Wei Gao April 3, 2024, 3:28 a.m. UTC
Signed-off-by: Wei Gao <wegao@suse.com>
---
 include/tst_test_macros.h        | 61 ++++++++++++++++++++++++++++++++
 lib/newlib_tests/.gitignore      |  1 +
 lib/newlib_tests/test_macros07.c | 61 ++++++++++++++++++++++++++++++++
 3 files changed, 123 insertions(+)
 create mode 100644 lib/newlib_tests/test_macros07.c

Comments

Cyril Hrubis April 4, 2024, 1:51 p.m. UTC | #1
Hi!
This one looks good, I would wote for merging it now, however the
subject suggests that the TST_EXP_PASS_PTR_* functions are implemented
here as well, which isn't the case.

So I propse to fix the subject to include only EXP_FAIL_ and merge this
then add the EXP_PASS_ variants in another patch.

With that:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz> for the whole patchset.
Petr Vorel April 4, 2024, 4:01 p.m. UTC | #2
Hi Cyril, Wei,

> Hi!
> This one looks good, I would wote for merging it now, however the
> subject suggests that the TST_EXP_PASS_PTR_* functions are implemented
> here as well, which isn't the case.

> So I propse to fix the subject to include only EXP_FAIL_ and merge this
> then add the EXP_PASS_ variants in another patch.

Sure, I'll fix that before merge.

BTW I fix that in the v6 patchset which I sent (and I Cc Wei and you) before Wei
sent his v6 (my only change was adding everything into test_macros02 and use
macros to shorten the code as more macros will be added to it in the future. I
suppose you prefer the original code as you acked this).

Kind regards,
Petr

[1] https://patchwork.ozlabs.org/project/ltp/patch/20240328162939.100872-2-pvorel@suse.cz/

> With that:

> Reviewed-by: Cyril Hrubis <chrubis@suse.cz> for the whole patchset.
Cyril Hrubis April 5, 2024, 8:53 a.m. UTC | #3
Hi!
> > This one looks good, I would wote for merging it now, however the
> > subject suggests that the TST_EXP_PASS_PTR_* functions are implemented
> > here as well, which isn't the case.
> 
> > So I propse to fix the subject to include only EXP_FAIL_ and merge this
> > then add the EXP_PASS_ variants in another patch.
> 
> Sure, I'll fix that before merge.
> 
> BTW I fix that in the v6 patchset which I sent (and I Cc Wei and you) before Wei
> sent his v6 (my only change was adding everything into test_macros02 and use
> macros to shorten the code as more macros will be added to it in the future. I
> suppose you prefer the original code as you acked this).

I'm simply lost in the number of iterations for this patch. Also I do
not think that reducing the duplication in the library test is that
important, but feel free to push that with my reviewed-by as well.
Petr Vorel April 5, 2024, 10:28 a.m. UTC | #4
> Hi!
> > > This one looks good, I would wote for merging it now, however the
> > > subject suggests that the TST_EXP_PASS_PTR_* functions are implemented
> > > here as well, which isn't the case.

> > > So I propse to fix the subject to include only EXP_FAIL_ and merge this
> > > then add the EXP_PASS_ variants in another patch.

> > Sure, I'll fix that before merge.

> > BTW I fix that in the v6 patchset which I sent (and I Cc Wei and you) before Wei
> > sent his v6 (my only change was adding everything into test_macros02 and use
> > macros to shorten the code as more macros will be added to it in the future. I
> > suppose you prefer the original code as you acked this).

> I'm simply lost in the number of iterations for this patch. Also I do
> not think that reducing the duplication in the library test is that
> important, but feel free to push that with my reviewed-by as well.

Thanks, merged with that extra commit.

Kind regards,
Petr
Cyril Hrubis April 5, 2024, 11:23 a.m. UTC | #5
Hi!
Also is anybody going to work on the PASS variant? Looks like the huge*
tests would need that...
Petr Vorel April 5, 2024, 2:03 p.m. UTC | #6
Hi Cyril, Wei,

merged with the cleanup commit before.

> Hi!
> Also is anybody going to work on the PASS variant? Looks like the huge*
> tests would need that...

@Wei I suppose you plan to work on it. If not, please let us know.

Kind regards,
Petr
Wei Gao April 7, 2024, 11:31 p.m. UTC | #7
On Fri, Apr 05, 2024 at 04:03:25PM +0200, Petr Vorel wrote:
> Hi Cyril, Wei,
> 
> merged with the cleanup commit before.
> 
> > Hi!
> > Also is anybody going to work on the PASS variant? Looks like the huge*
> > tests would need that...
> 
> @Wei I suppose you plan to work on it. If not, please let us know.
Sure, i will work on this.
> 
> Kind regards,
> Petr
diff mbox series

Patch

diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index 6a7bcdce5..eff3aef69 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -227,6 +227,41 @@  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, FAIL_PTR_VAL,                  \
+	ERRNOS, ERRNOS_CNT, ...)                                               \
+	do {                                                                   \
+		TESTPTR(SCALL);                                                \
+		                                                               \
+		TST_PASS = 0;                                                  \
+		                                                               \
+		if (TST_RET_PTR != FAIL_PTR_VAL) {                             \
+			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_PTR_(SCALL, SSCALL, FAIL_PTR_VAL,                         \
+	ERRNOS, ERRNOS_CNT, ...)                                               \
+	do {                                                                   \
+		TST_EXP_FAIL_SILENT_PTR_(SCALL, SSCALL, FAIL_PTR_VAL,          \
+	        ERRNOS, ERRNOS_CNT, ##__VA_ARGS__);                            \
+		if (TST_PASS)                                                  \
+			TST_MSG_(TPASS | TTERRNO, " ", SSCALL, ##__VA_ARGS__); \
+	} while (0)
+
+
 #define TST_EXP_FAIL_ARR_(SCALL, SSCALL, EXP_ERRS, EXP_ERRS_CNT, ...)          \
 	do {                                                                   \
 		TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, SSCALL,              \
@@ -258,6 +293,32 @@  const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
 		TST_EXP_FAIL2_ARR_(SCALL, #SCALL, EXP_ERRS,                    \
 		                  EXP_ERRS_CNT, ##__VA_ARGS__);
 
+#define TST_EXP_FAIL_PTR_NULL(SCALL, EXP_ERR, ...)                             \
+	do {                                                                   \
+		int tst_exp_err__ = EXP_ERR;                                   \
+		TST_EXP_FAIL_PTR_(SCALL, #SCALL, NULL,                         \
+			&tst_exp_err__, 1, ##__VA_ARGS__);                     \
+	} while (0)
+
+#define TST_EXP_FAIL_PTR_ARR_NULL(SCALL, EXP_ERRS, ...)                        \
+	do {                                                                   \
+		TST_EXP_FAIL_PTR_(SCALL, #SCALL, NULL,                         \
+			EXP_ERRS, ARRAY_SIZE(EXP_ERRS), ##__VA_ARGS__);        \
+	} while (0)
+
+#define TST_EXP_FAIL_PTR_VOID(SCALL, EXP_ERR, ...)                             \
+	do {                                                                   \
+		int tst_exp_err__ = EXP_ERR;                                   \
+		TST_EXP_FAIL_PTR_(SCALL, #SCALL, (void *)-1,                   \
+			&tst_exp_err__, 1, ##__VA_ARGS__);                     \
+	} while (0)
+
+#define TST_EXP_FAIL_PTR_ARR_VOID(SCALL, EXP_ERRS, ...)                        \
+	do {                                                                   \
+		TST_EXP_FAIL_PTR_(SCALL, #SCALL, (void *)-1,                   \
+			EXP_ERRS, ARRAY_SIZE(EXP_ERRS), ##__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 6d125f933..ed10d860a 100644
--- a/lib/newlib_tests/.gitignore
+++ b/lib/newlib_tests/.gitignore
@@ -41,6 +41,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..ac361fd8e
--- /dev/null
+++ b/lib/newlib_tests/test_macros07.c
@@ -0,0 +1,61 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2024 Wei Gao <wegao@suse.com>
+ */
+
+/*
+ * Test TST_EXP_FAIL_PTR_{NULL,VOID} and TST_EXP_FAIL_PTR_ARR{NULL,VOID} macro.
+ */
+
+#include "tst_test.h"
+
+static char *fail_fn_null(void)
+{
+	errno = EINVAL;
+	return NULL;
+}
+
+static char *fail_fn_void(void)
+{
+	errno = EINVAL;
+	return (void *)-1;
+}
+
+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_NULL macro");
+	TST_EXP_FAIL_PTR_NULL(fail_fn_null(), EINVAL, "fail_fn_null()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_FAIL_PTR_NULL(fail_fn_null(), ENOTTY, "fail_fn_null()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_FAIL_PTR_NULL(pass_fn(), ENOTTY, "pass_fn()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_FAIL_PTR_ARR_NULL(fail_fn_null(), exp_errs_pass, "fail_fn_null()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_FAIL_PTR_ARR_NULL(fail_fn_null(), exp_errs_fail, "fail_fn()_null");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+
+	tst_res(TINFO, "Testing TST_EXP_FAIL_PTR_VOID macro");
+	TST_EXP_FAIL_PTR_VOID(fail_fn_void(), EINVAL, "fail_fn_void()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_FAIL_PTR_VOID(fail_fn_void(), ENOTTY, "fail_fn_void()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_FAIL_PTR_VOID(pass_fn(), ENOTTY, "pass_fn()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_FAIL_PTR_ARR_VOID(fail_fn_void(), exp_errs_pass, "fail_fn_void()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_FAIL_PTR_ARR_VOID(fail_fn_void(), exp_errs_fail, "fail_fn()_void");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+};