Skip to contentSkip to conversation

Add TST_EXP_FAIL_PTR

PATCH Superseded Wei Gao via ltp 3 participants 40 messages Jan 11, 2024 – Apr 7, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add TST_EXP_FAIL_PTR

---
 include/tst_test_macros.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

This is draft patch and should rebase after following patch merge.
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

include/tst_test_macros.h +28 -0
index 3f4f9f11d..6e45e0b27 100644
@@ -212,6 +212,26 @@ extern void *TST_RET_PTR;
 		}                                                              \
 	} while (0)
 
+#define TST_EXP_FAIL_SILENT_PTR_(SCALL, SSCALL, ERRNO, ...)             \
+	do {                                                                   \
+		TESTPTR(SCALL);                                                   \
+		                                                               \
+		TST_PASS = 0;                                                  \
+		                                                               \
+		if (TST_RET_PTR) {                                               \
+			TST_MSG_(TFAIL, " succeeded", SSCALL, ##__VA_ARGS__);  \
+		        break;                                                 \
+		}                                                              \
+		                                                               \
+		if (TST_ERR == (ERRNO)) {                                      \
+			TST_PASS = 1;                                          \
+		} else {                                                       \
+			TST_MSGP_(TFAIL | TTERRNO, " expected %s",             \
+				  tst_strerrno(ERRNO),                         \
+				  SSCALL, ##__VA_ARGS__);                      \
+		}                                                              \
+	} while (0)
+
 #define TST_EXP_FAIL(SCALL, ERRNO, ...)                                        \
 	do {                                                                   \
 		TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, #SCALL,              \
@@ -228,6 +248,14 @@ extern void *TST_RET_PTR;
 			TST_MSG_(TPASS | TTERRNO, " ", #SCALL, ##__VA_ARGS__); \
 	} while (0)
 
+#define TST_EXP_FAIL_PTR(SCALL, ERRNO, ...)                                        \
+	do {                                                                   \
+		TST_EXP_FAIL_SILENT_PTR_(SCALL, #SCALL,              \
+			ERRNO, ##__VA_ARGS__);                                 \
+		if (TST_PASS)                                                  \
+			TST_MSG_(TPASS | TTERRNO, " ", #SCALL, ##__VA_ARGS__); \
+	} while (0)
+
 #define TST_EXP_FAIL_SILENT(SCALL, ERRNO, ...) \
 	TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
 
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Wei,

Quoted 7 lines
---
 include/tst_test_macros.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

This is draft patch and should rebase after following patch merge.
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

Patch was accepted, please rebase. Also, please add at least one test which uses it.

Also, I wonder if we need TST_EXP_PASS_PTR().

Quoted 16 lines
include/tst_test_macros.h +8 -0
index 3f4f9f11d..6e45e0b27 100644
@@ -212,6 +212,26 @@ extern void *TST_RET_PTR;
 		}                                                              \
 	} while (0)
 
+#define TST_EXP_FAIL_SILENT_PTR_(SCALL, SSCALL, ERRNO, ...)             \
+	do {                                                                   \
+		TESTPTR(SCALL);                                                   \
+		                                                               \
+		TST_PASS = 0;                                                  \
+		                                                               \
+		if (TST_RET_PTR) {                                               \
+			TST_MSG_(TFAIL, " succeeded", SSCALL, ##__VA_ARGS__);  \

include/tst_test_macros.h extern void *TST_RET_PTR; · line 232

Quoted 10 lines
include/tst_test_macros.h +10 -0
+		        break;                                                 \
+		}                                                              \
+		                                                               \
+		if (TST_ERR == (ERRNO)) {                                      \
+			TST_PASS = 1;                                          \
+		} else {                                                       \
+			TST_MSGP_(TFAIL | TTERRNO, " expected %s",             \
+				  tst_strerrno(ERRNO),                         \
+				  SSCALL, ##__VA_ARGS__);                      \
+		}                                                              \

Maybe follow the pattern of already used tests (break saves else clause)?

 		if (TST_ERR != (ERRNO)) {                                      \
			TST_MSGP_(TFAIL | TTERRNO, " expected %s",             \
				  tst_strerrno(ERRNO),                         \
				  SSCALL, ##__VA_ARGS__);                      \
			break;                                                 \
		}                                                              \
                                                                               \
		TST_PASS = 1;                                                  \
Quoted 2 lines
include/tst_test_macros.h +2 -0
+	} while (0)
+
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
Quoted 7 lines · Petr Vorel

Hi Wei,

Quoted 4 lines
---
 include/tst_test_macros.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
Quoted 7 lines
Quoted 2 lines

This is draft patch and should rebase after following patch merge.
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

Patch was accepted, please rebase. Also, please add at least one test which uses it.

Also, I wonder if we need TST_EXP_PASS_PTR().

Sure, i can create another patch for TST_EXP_PASS_PTR.

Quoted 41 lines
Quoted 17 lines
include/tst_test_macros.h +8 -0
index 3f4f9f11d..6e45e0b27 100644
@@ -212,6 +212,26 @@ extern void *TST_RET_PTR;
 		}                                                              \
 	} while (0)
 
+#define TST_EXP_FAIL_SILENT_PTR_(SCALL, SSCALL, ERRNO, ...)             \
+	do {                                                                   \
+		TESTPTR(SCALL);                                                   \
+		                                                               \
+		TST_PASS = 0;                                                  \
+		                                                               \
+		if (TST_RET_PTR) {                                               \
+			TST_MSG_(TFAIL, " succeeded", SSCALL, ##__VA_ARGS__);  \

include/tst_test_macros.h extern void *TST_RET_PTR; · line 232

Quoted 10 lines
include/tst_test_macros.h +10 -0
+		        break;                                                 \
+		}                                                              \
+		                                                               \
+		if (TST_ERR == (ERRNO)) {                                      \
+			TST_PASS = 1;                                          \
+		} else {                                                       \
+			TST_MSGP_(TFAIL | TTERRNO, " expected %s",             \
+				  tst_strerrno(ERRNO),                         \
+				  SSCALL, ##__VA_ARGS__);                      \
+		}                                                              \

Maybe follow the pattern of already used tests (break saves else clause)?

 		if (TST_ERR != (ERRNO)) {                                      \
			TST_MSGP_(TFAIL | TTERRNO, " expected %s",             \
				  tst_strerrno(ERRNO),                         \
				  SSCALL, ##__VA_ARGS__);                      \
			break;                                                 \
		}                                                              \
                                                                               \
		TST_PASS = 1;                                                  \
Quoted 2 lines
include/tst_test_macros.h +2 -0
+	} while (0)
+
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

PATCH v2 1/1 Add TST_EXP_FAIL_PTR

In reply to Wei Gao via ltp
---
 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
include/tst_test_macros.h +41 -0
index 24fd324bf..409e6847c 100644
@@ -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;                                   \
lib/newlib_tests/.gitignore +1 -0
index a69b29e24..4f43899e5 100644
@@ -40,6 +40,7 @@ test_macros03
 test_macros04
 test_macros05
 test_macros06
+test_macros07
 tst_fuzzy_sync01
 tst_fuzzy_sync02
 tst_fuzzy_sync03
lib/newlib_tests/test_macros07.c new file +44 -0

44 lines not on this page · raw message

Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v2 1/1
#4 lore raw

Hi Wei,

subject should be: "lib: TST_EXP_{FAIL,PASS}_PTR"
(can be changed before merge)

Thanks for adding a library test.

If you send a patch for a test which actually uses these, we can merge it before the release. Otherwise I would wait for the merge after the release.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw
Quoted 3 lines

Hi Wei,

subject should be: "lib: TST_EXP_{FAIL,PASS}_PTR"

I'm sorry, I did not concentrate enough. It was supposed to be

"lib: Add TST_EXP_FAIL_PTR{,_ARR}"

Kind regards,
Petr

Quoted 11 lines

(can be changed before merge)

Thanks for adding a library test.

If you send a patch for a test which actually uses these, we can merge it before the release. Otherwise I would wait for the merge after the release.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

v3 cover lib: TST_EXP_FAIL_PTR

In reply to Wei Gao via ltp

Wei Gao (2):
lib: TST_EXP_FAIL_PTR
getcwd01: Implement .test_variants

 include/tst_test_macros.h                   | 41 +++++++++++
 lib/newlib_tests/.gitignore                 |  1 +
 lib/newlib_tests/test_macros07.c            | 44 ++++++++++++
 testcases/kernel/syscalls/getcwd/getcwd01.c | 80 +++++++++++++++------
 4 files changed, 146 insertions(+), 20 deletions(-)
 create mode 100644 lib/newlib_tests/test_macros07.c
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

PATCH v3 1/2 lib: TST_EXP_FAIL_PTR

---
 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
include/tst_test_macros.h +41 -0
index d2e50a219..5866d18b0 100644
@@ -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, SSCALL, EXP_ERRS, EXP_ERRS_CNT, ...)          \
 	do {                                                                   \
 		TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, SSCALL,              \
@@ -258,6 +282,23 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
 		TST_EXP_FAIL2_ARR_(SCALL, #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;                                   \
lib/newlib_tests/.gitignore +1 -0
index a69b29e24..4f43899e5 100644
@@ -40,6 +40,7 @@ test_macros03
 test_macros04
 test_macros05
 test_macros06
+test_macros07
 tst_fuzzy_sync01
 tst_fuzzy_sync02
 tst_fuzzy_sync03
lib/newlib_tests/test_macros07.c new file +44 -0

44 lines not on this page · raw message

Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v3 1/2
#8 lore raw

Re: [LTP] [PATCH v3 1/2] lib: TST_EXP_FAIL_PTR

Hi Wei,

thank you for sending rebased version.

You could have added my RBT (the code you added didn't change).

nit (I have suggested in v2): subject should be: "lib: TST_EXP_{FAIL,PASS}_PTR"

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw

Re: [LTP] [PATCH v3 1/2] lib: TST_EXP_FAIL_PTR

In reply to Wei Gao via ltp

Hi!

include/tst_test_macros.h const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt); · line 236

Quoted 7 lines
include/tst_test_macros.h +7 -0
+#define TST_EXP_FAIL_SILENT_PTR_(SCALL, SSCALL, ERRNOS, ERRNOS_CNT, ...)       \
+	do {                                                                   \
+		TESTPTR(SCALL);                                                \
+		                                                               \
+		TST_PASS = 0;                                                  \
+		                                                               \
+		if (TST_RET_PTR) {                                             \

Unfortunatelly there are two types of calls, one returns NULL on a failure and the second returns (void *)-1, from the top of my head these are mmap(), shmat() and possibly other memory related syscalls.

So I suppose that this macro needs another parameter for the actual value that is returned on a failure:

#define TST_EXP_FAIL_SILENT_PTR_(SCALL, SSCALL, FAIL_PTR_VAL, ERRNOS, ...)
	do {
		TESTPTR(SCALL);

		...

		if (TST_RET_PTR == FAILPTR_VAL) {
		...

The hard question is if we want to pass this parameter explicitly from the macros used by the tests, i.e. if each test would need to specify a FAIL_PTR_VAL or if we want to pass it in the macros, but that would mean that the number of macros will explode again and we would have to figure out a good names. So maybe it would be easier to pass them from each test.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw

Re: [LTP] [PATCH v3 1/2] lib: TST_EXP_FAIL_PTR

Hi Wei, Cyril,

Quoted 16 lines

Hi!

include/tst_test_macros.h const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt); · line 236

Quoted 7 lines
include/tst_test_macros.h +7 -0
+#define TST_EXP_FAIL_SILENT_PTR_(SCALL, SSCALL, ERRNOS, ERRNOS_CNT, ...)       \
+	do {                                                                   \
+		TESTPTR(SCALL);                                                \
+		                                                               \
+		TST_PASS = 0;                                                  \
+		                                                               \
+		if (TST_RET_PTR) {                                             \

Unfortunatelly there are two types of calls, one returns NULL on a failure and the second returns (void *)-1, from the top of my head these are mmap(), shmat() and possibly other memory related syscalls.

So I suppose that this macro needs another parameter for the actual value that is returned on a failure:

Quoted 8 lines
#define TST_EXP_FAIL_SILENT_PTR_(SCALL, SSCALL, FAIL_PTR_VAL, ERRNOS, ...)
	do {
		TESTPTR(SCALL);

		...

		if (TST_RET_PTR == FAILPTR_VAL) {
		...

+1

Quoted 6 lines

The hard question is if we want to pass this parameter explicitly from the macros used by the tests, i.e. if each test would need to specify a FAIL_PTR_VAL or if we want to pass it in the macros, but that would mean that the number of macros will explode again and we would have to figure out a good names. So maybe it would be easier to pass them from each test.

Names could be _NULL and _VOID, but I understand you want to limit number of macros.

Wei, I guess testcases/kernel/syscalls/realpath/realpath01.c could use TST_EXP_FAIL_PTR().

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#11 lore raw

PATCH v3 2/2 getcwd01: Implement .test_variants

In reply to Wei Gao via ltp
---
 testcases/kernel/syscalls/getcwd/getcwd01.c | 80 +++++++++++++++------
 1 file changed, 60 insertions(+), 20 deletions(-)

NOTE: Cyril give solution for run the test in a child and pass the test both on EFAULT and child being killed by SIGSEGV. But currently i have no idea how to do it since no SIGSEGV will hapeen if NULL buffer give to getcwd. This file just used for give a real user case for TST_EXP_FAIL_PTR.

testcases/kernel/syscalls/getcwd/getcwd01.c +60 -20
index 218bf4ef2..879c36206 100644
@@ -3,21 +3,34 @@
  * Copyright (c) International Business Machines Corp., 2001
  */
 
-/*
- * DESCRIPTION
+/*\
+ * [Description]
+ *
  * Testcase to test that getcwd(2) sets errno correctly.
- * 1) getcwd(2) fails if buf points to a bad address.
- * 2) getcwd(2) fails if the size is invalid.
- * 3) getcwd(2) fails if the size is set to 0.
- * 4) getcwd(2) fails if the size is set to 1.
- * 5) getcwd(2) fails if buf points to NULL and the size is set to 1.
+ *
+ * 1. getcwd(2) fails if buf points to a bad address.
+ * 2. getcwd(2) fails if the size is invalid.
+ * 3. getcwd(2) fails if the size is set to 0.
+ * 4. getcwd(2) fails if the size is set to 1.
+ * 5. getcwd(2) fails if buf points to NULL and the size is set to 1.
  *
  * Expected Result:
- * 1) getcwd(2) should return NULL and set errno to EFAULT.
- * 2) getcwd(2) should return NULL and set errno to EFAULT.
- * 3) getcwd(2) should return NULL and set errno to ERANGE.
- * 4) getcwd(2) should return NULL and set errno to ERANGE.
- * 5) getcwd(2) should return NULL and set errno to ERANGE.
+ *
+ * linux syscall
+ *
+ * 1. getcwd(2) should return NULL and set errno to EFAULT.
+ * 2. getcwd(2) should return NULL and set errno to EFAULT.
+ * 3. getcwd(2) should return NULL and set errno to ERANGE.
+ * 4. getcwd(2) should return NULL and set errno to ERANGE.
+ * 5. getcwd(2) should return NULL and set errno to ERANGE.
+ *
+ * glibc and uclibc{,-ng}.
+ *
+ * 1. getcwd(2) should return NULL and set errno to EFAULT.
+ * 2. getcwd(2) should return NULL and set errno to ENOMEM.
+ * 3. getcwd(2) should return NULL and set errno to EINVAL.
+ * 4. getcwd(2) should return NULL and set errno to ERANGE.
+ * 5. getcwd(2) should return NULL and set errno to ERANGE.
  */
 
 #include <errno.h>
@@ -32,23 +45,50 @@ static struct t_case {
 	char *buf;
 	size_t size;
 	int exp_err;
+	int exp_err_libc;
 } tcases[] = {
-	{(void *)-1, PATH_MAX, EFAULT},
-	{NULL, (size_t)-1, EFAULT},
-	{buffer, 0, ERANGE},
-	{buffer, 1, ERANGE},
-	{NULL, 1, ERANGE}
+	{(void *)-1, PATH_MAX, EFAULT, EFAULT},
+	{NULL, (size_t)-1, EFAULT, ENOMEM},
+	{buffer, 0, ERANGE, EINVAL},
+	{buffer, 1, ERANGE, ERANGE},
+	{NULL, 1, ERANGE, ERANGE},
 };
 
+static inline void tst_getcwd(char *buf, size_t size, int exp_err, int exp_err_libc)
+{
+
+	if (tst_variant == 0)
+		TST_EXP_FAIL2(tst_syscall(__NR_getcwd, buf, size), exp_err);
+	else
+		TST_EXP_FAIL_PTR(getcwd(buf, size), exp_err_libc);
+}
 
-static void verify_getcwd(unsigned int n)
+static void run(unsigned int n)
 {
 	struct t_case *tc = &tcases[n];
 
-	TST_EXP_FAIL2(tst_syscall(__NR_getcwd, tc->buf, tc->size), tc->exp_err);
+	/* https://github.com/linux-test-project/ltp/issues/1084 */
+#if !defined(__GLIBC__) && !defined(__ANDROID__)
+	if (tst_variant && !tc->buf) {
+		tst_res(TCONF, "NULL buffer test skipped on MUSL due different implementation");
+		return;
+	}
+#endif
+
+	tst_getcwd(tc->buf, tc->size, tc->exp_err, tc->exp_err_libc);
+}
+
+static void setup(void)
+{
+	if (tst_variant == 0)
+		tst_res(TINFO, "Testing getcwd with raw syscall");
+	else
+		tst_res(TINFO, "Testing getcwd with wrap syscall");
 }
 
 static struct tst_test test = {
+	.setup = setup,
 	.tcnt = ARRAY_SIZE(tcases),
-	.test = verify_getcwd
+	.test = run,
+	.test_variants = 2,
 };
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#12 lore raw

Re: [LTP] [PATCH v3 2/2] getcwd01: Implement .test_variants

Hi Wei,

Quoted 10 lines
---
 testcases/kernel/syscalls/getcwd/getcwd01.c | 80 +++++++++++++++------
 1 file changed, 60 insertions(+), 20 deletions(-)

NOTE: Cyril give solution for run the test in a child and pass the test both on EFAULT and child being killed by SIGSEGV. But currently i have no idea how to do it since no SIGSEGV will hapeen if NULL buffer give to getcwd. This file just used for give a real user case for TST_EXP_FAIL_PTR.

@Cyril, could you please point out test which uses similar approach? Maybe these?
testcases/kernel/syscalls/fstat/fstat03.c testcases/kernel/syscalls/ipc/shmat/shmat01.c testcases/kernel/syscalls/kill/kill11.c testcases/kernel/syscalls/setrlimit/setrlimit05.c

Or can the current approach be used?

Below only nits (formatting).

testcases/kernel/syscalls/getcwd/getcwd01.c line 3

Quoted 6 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +0 -0
index 218bf4ef2..879c36206 100644
@@ -3,21 +3,34 @@
  * Copyright (c) International Business Machines Corp., 2001

IBM in 2001 could be proud on this code :). There should have been some copyright, I would add:
* Copyright (c) Linux Test Project, 2002-2024

Quoted 10 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +5 -2
  */
 
-/*
- * DESCRIPTION
+/*\
+ * [Description]
+ *
  * Testcase to test that getcwd(2) sets errno correctly.
+ *
+ * 1. getcwd(2) fails if buf points to a bad address.

testcases/kernel/syscalls/getcwd/getcwd01.c line 21

Quoted 10 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +8 -0
+ * 2. getcwd(2) fails if the size is invalid.
+ * 3. getcwd(2) fails if the size is set to 0.
+ * 4. getcwd(2) fails if the size is set to 1.
+ * 5. getcwd(2) fails if buf points to NULL and the size is set to 1.
  *
  * Expected Result:
+ *
+ * linux syscall
+ *
+ * 1. getcwd(2) should return NULL and set errno to EFAULT.

I don't like repeating "getcwd(2) should return NULL and set errno to"

testcases/kernel/syscalls/getcwd/getcwd01.c line 27

Quoted 6 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +6 -0
+ * 2. getcwd(2) should return NULL and set errno to EFAULT.
+ * 3. getcwd(2) should return NULL and set errno to ERANGE.
+ * 4. getcwd(2) should return NULL and set errno to ERANGE.
+ * 5. getcwd(2) should return NULL and set errno to ERANGE.
+ *
+ * glibc and uclibc{,-ng}.

Although in the past LTP developers cared only about glibc, now we generally don't stick to any libc implementation. Thus it should be "libc syscall wrapper"

testcases/kernel/syscalls/getcwd/getcwd01.c line 34

Quoted 7 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +6 -0
+ *
+ * 1. getcwd(2) should return NULL and set errno to EFAULT.
+ * 2. getcwd(2) should return NULL and set errno to ENOMEM.
+ * 3. getcwd(2) should return NULL and set errno to EINVAL.
+ * 4. getcwd(2) should return NULL and set errno to ERANGE.
+ * 5. getcwd(2) should return NULL and set errno to ERANGE.
  */

How about to make it simple like this:
/*\
* [Description]
*
* Testcase to test that getcwd(2) returns NULL and sets errno correctly. *
* 1. getcwd(2) fails if buf points to a bad address (EFAULT).
* 2. getcwd(2) fails if the size is invalid (syscall: EFAULT, libc wrapper: ENOMEM).
* 3. getcwd(2) fails if the size is set to 0 (syscall: ERANGE, libc wrapper: EINVAL).
* 4. getcwd(2) fails if the size is set to 1 (ERANGE).
* 5. getcwd(2) fails if buf points to NULL and the size is set to 1 (ERANGE). */

Quoted 17 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +6 -5
 #include <errno.h>
@@ -32,23 +45,50 @@ static struct t_case {
 	char *buf;
 	size_t size;
 	int exp_err;
+	int exp_err_libc;
 } tcases[] = {
-	{(void *)-1, PATH_MAX, EFAULT},
-	{NULL, (size_t)-1, EFAULT},
-	{buffer, 0, ERANGE},
-	{buffer, 1, ERANGE},
-	{NULL, 1, ERANGE}
+	{(void *)-1, PATH_MAX, EFAULT, EFAULT},
+	{NULL, (size_t)-1, EFAULT, ENOMEM},
+	{buffer, 0, ERANGE, EINVAL},
+	{buffer, 1, ERANGE, ERANGE},
+	{NULL, 1, ERANGE, ERANGE},

testcases/kernel/syscalls/getcwd/getcwd01.c static struct t_case { · line 64

Quoted 10 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +8 -0
 };
 
+static inline void tst_getcwd(char *buf, size_t size, int exp_err, int exp_err_libc)
+{
+
+	if (tst_variant == 0)
+		TST_EXP_FAIL2(tst_syscall(__NR_getcwd, buf, size), exp_err);
+	else
+		TST_EXP_FAIL_PTR(getcwd(buf, size), exp_err_libc);
+}

+1

testcases/kernel/syscalls/getcwd/getcwd01.c static struct t_case { · line 70

Quoted 7 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +2 -2
-static void verify_getcwd(unsigned int n)
+static void run(unsigned int n)
 {
 	struct t_case *tc = &tcases[n];
 
-	TST_EXP_FAIL2(tst_syscall(__NR_getcwd, tc->buf, tc->size), tc->exp_err);
+	/* https://github.com/linux-test-project/ltp/issues/1084 */

IMHO this comment should go to the commit message.

testcases/kernel/syscalls/getcwd/getcwd01.c static struct t_case { · line 71

Quoted 1 line
testcases/kernel/syscalls/getcwd/getcwd01.c +1 -0
+#if !defined(__GLIBC__) && !defined(__ANDROID__)

I'll ask AOSP developers to check this.

Quoted 5 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +5 -0
+	if (tst_variant && !tc->buf) {
+		tst_res(TCONF, "NULL buffer test skipped on MUSL due different implementation");
+		return;
+	}
+#endif

testcases/kernel/syscalls/getcwd/getcwd01.c static struct t_case { · line 86

Quoted 10 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +10 -0
+
+	tst_getcwd(tc->buf, tc->size, tc->exp_err, tc->exp_err_libc);
+}
+
+static void setup(void)
+{
+	if (tst_variant == 0)
+		tst_res(TINFO, "Testing getcwd with raw syscall");
+	else
+		tst_res(TINFO, "Testing getcwd with wrap syscall");

"wrap syscall" => "libc syscall wrapper"

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#13 lore raw

v4 cover lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID}

In reply to Wei Gao via ltp

Wei Gao (3):
lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID}
shmat02.c: Use TST_EXP_FAIL_PTR_VOID
realpath01.c: use TST_EXP_FAIL_PTR_NULL

 include/tst_test_macros.h                     | 59 ++++++++++++++++++
 lib/newlib_tests/.gitignore                   |  1 +
 lib/newlib_tests/test_macros07.c              | 61 +++++++++++++++++++
 testcases/kernel/syscalls/ipc/shmat/shmat02.c | 15 +----
 .../kernel/syscalls/realpath/realpath01.c     | 11 +---
 5 files changed, 123 insertions(+), 24 deletions(-)
 create mode 100644 lib/newlib_tests/test_macros07.c
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#14 lore raw

PATCH v4 1/3 lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID}

---
 include/tst_test_macros.h        | 59 ++++++++++++++++++++++++++++++
 lib/newlib_tests/.gitignore      |  1 +
 lib/newlib_tests/test_macros07.c | 61 ++++++++++++++++++++++++++++++++
 3 files changed, 121 insertions(+)
 create mode 100644 lib/newlib_tests/test_macros07.c
include/tst_test_macros.h +59 -0
index d2e50a219..1f5b56d27 100644
@@ -227,6 +227,31 @@ 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_ARR_(SCALL, SSCALL, EXP_ERRS, EXP_ERRS_CNT, ...)          \
 	do {                                                                   \
 		TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, SSCALL,              \
@@ -258,6 +283,40 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
 		TST_EXP_FAIL2_ARR_(SCALL, #SCALL, EXP_ERRS,                    \
 		                  ARRAY_SIZE(EXP_ERRS), ##__VA_ARGS__);
 
+#define TST_EXP_FAIL_PTR_NULL(SCALL, EXP_ERR, ...)                             \
+	do {                                                                   \
+		int tst_exp_err__ = EXP_ERR;                                   \
+		TST_EXP_FAIL_SILENT_PTR_(SCALL, #SCALL, NULL,                  \
+			&tst_exp_err__, 1, ##__VA_ARGS__);                     \
+		if (TST_PASS)                                                  \
+			TST_MSG_(TPASS | TTERRNO, " ", #SCALL, ##__VA_ARGS__); \
+	} while (0)
+
+#define TST_EXP_FAIL_PTR_ARR_NULL(SCALL, EXP_ERRS, ...)                        \
+	do {                                                                   \
+		TST_EXP_FAIL_SILENT_PTR_(SCALL, #SCALL, NULL,                  \
+			EXP_ERRS, ARRAY_SIZE(EXP_ERRS), ##__VA_ARGS__);        \
+		if (TST_PASS)                                                  \
+			TST_MSG_(TPASS | TTERRNO, " ", #SCALL, ##__VA_ARGS__); \
+	} while (0)
+
+#define TST_EXP_FAIL_PTR_VOID(SCALL, EXP_ERR, ...)                             \
+	do {                                                                   \
+		int tst_exp_err__ = EXP_ERR;                                   \
+		TST_EXP_FAIL_SILENT_PTR_(SCALL, #SCALL, (void *)-1,            \
+			&tst_exp_err__, 1, ##__VA_ARGS__);                     \
+		if (TST_PASS)                                                  \
+			TST_MSG_(TPASS | TTERRNO, " ", #SCALL, ##__VA_ARGS__); \
+	} while (0)
+
+#define TST_EXP_FAIL_PTR_ARR_VOID(SCALL, EXP_ERRS, ...)                        \
+	do {                                                                   \
+		TST_EXP_FAIL_SILENT_PTR_(SCALL, #SCALL, (void *)-1,            \
+			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;                                   \
lib/newlib_tests/.gitignore +1 -0
index a69b29e24..4f43899e5 100644
@@ -40,6 +40,7 @@ test_macros03
 test_macros04
 test_macros05
 test_macros06
+test_macros07
 tst_fuzzy_sync01
 tst_fuzzy_sync02
 tst_fuzzy_sync03
lib/newlib_tests/test_macros07.c new file +61 -0

61 lines not on this page · raw message

Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v4 1/3
#15 lore raw

Re: [LTP] [PATCH v4 1/3] lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID}

Hi Wei,

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#16 lore raw

Re: [LTP] [PATCH v4 1/3] lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID}

In reply to Wei Gao via ltp

Hi!

Quoted 30 lines
include/tst_test_macros.h +25 -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_ARR_(SCALL, SSCALL, EXP_ERRS, EXP_ERRS_CNT, ...)          \
 	do {                                                                   \
 		TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, SSCALL,              \
@@ -258,6 +283,40 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
 		TST_EXP_FAIL2_ARR_(SCALL, #SCALL, EXP_ERRS,                    \

include/tst_test_macros.h const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt); · line 293

Quoted 10 lines
include/tst_test_macros.h +8 -0
 		                  ARRAY_SIZE(EXP_ERRS), ##__VA_ARGS__);
 
+#define TST_EXP_FAIL_PTR_NULL(SCALL, EXP_ERR, ...)                             \
+	do {                                                                   \
+		int tst_exp_err__ = EXP_ERR;                                   \
+		TST_EXP_FAIL_SILENT_PTR_(SCALL, #SCALL, NULL,                  \
+			&tst_exp_err__, 1, ##__VA_ARGS__);                     \
+		if (TST_PASS)                                                  \
+			TST_MSG_(TPASS | TTERRNO, " ", #SCALL, ##__VA_ARGS__); \
+	} while (0)

Given that the if (TST_PASS) message is same in all the cases we could as well add TST_EX_FAIL_PTR_() and simplify all the TST_EXP_FAIL_PTR_{NULL,ARR_NULL,VOID,ARR_VOID} to be build on the top of that.

Other than that it looks good.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#17 lore raw

PATCH v4 2/3 shmat02.c: Use TST_EXP_FAIL_PTR_VOID

In reply to Wei Gao via ltp
---
 testcases/kernel/syscalls/ipc/shmat/shmat02.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
testcases/kernel/syscalls/ipc/shmat/shmat02.c +1 -14
index 53cb6f542..3ad1fd08e 100644
@@ -44,20 +44,7 @@ static struct test_case_t {
 
 static void verify_shmat(struct test_case_t *tc)
 {
-	void *addr;
-
-	addr = shmat(*tc->shmid, *tc->shmaddr, 0);
-	if (addr != (void *)-1) {
-		tst_res(TFAIL, "shmat() succeeded unexpectedly");
-		return;
-	}
-
-	if (errno == tc->exp_err) {
-		tst_res(TPASS | TERRNO, "shmat() failed as expected");
-	} else {
-		tst_res(TFAIL | TERRNO, "shmat() failed unexpectedly, expected: %s",
-			tst_strerrno(tc->exp_err));
-	}
+	TST_EXP_FAIL_PTR_VOID(shmat(*tc->shmid, *tc->shmaddr, 0), tc->exp_err);
 }
 
 static void do_shmat(unsigned int n)
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v4 2/3
#18 lore raw

Re: [LTP] [PATCH v4 2/3] shmat02.c: Use TST_EXP_FAIL_PTR_VOID

Hi Wei,

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#19 lore raw

PATCH v4 3/3 realpath01.c: use TST_EXP_FAIL_PTR_NULL

In reply to Wei Gao via ltp
---
 testcases/kernel/syscalls/realpath/realpath01.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
testcases/kernel/syscalls/realpath/realpath01.c +1 -10
index c0381e9cb..c4c603609 100644
@@ -24,16 +24,7 @@ static void setup(void)
 
 static void run(void)
 {
-	TESTPTR(realpath(".", NULL));
-
-	if (TST_ERR != ENOENT) {
-		tst_res(TFAIL | TTERRNO, "returned unexpected errno");
-	} else	if (TST_RET_PTR != NULL) {
-		tst_res(TFAIL, "syscall didn't return NULL: '%s'",
-				(char *)TST_RET_PTR);
-	} else {
-		tst_res(TPASS, "bug not reproduced");
-	}
+	TST_EXP_FAIL_PTR_NULL(realpath(".", NULL), ENOENT);
 }
 
 static struct tst_test test = {
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v4 3/3
#20 lore raw

Re: [LTP] [PATCH v4 3/3] realpath01.c: use TST_EXP_FAIL_PTR_NULL

Hi Wei,

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#21 lore raw

v5 cover lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID}

In reply to Wei Gao via ltp

Wei Gao (3):
lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID}
shmat02.c: Use TST_EXP_FAIL_PTR_VOID
realpath01.c: use TST_EXP_FAIL_PTR_NULL

 include/tst_test_macros.h                     | 61 +++++++++++++++++++
 lib/newlib_tests/.gitignore                   |  1 +
 lib/newlib_tests/test_macros07.c              | 61 +++++++++++++++++++
 testcases/kernel/syscalls/ipc/shmat/shmat02.c | 15 +----
 .../kernel/syscalls/realpath/realpath01.c     | 11 +---
 5 files changed, 125 insertions(+), 24 deletions(-)
 create mode 100644 lib/newlib_tests/test_macros07.c
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#22 lore raw

PATCH v5 1/3 lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID}

---
 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
include/tst_test_macros.h +61 -0
index d2e50a219..c70cad2f4 100644
@@ -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,                    \
 		                  ARRAY_SIZE(EXP_ERRS), ##__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;                                   \
lib/newlib_tests/.gitignore +1 -0
index a69b29e24..4f43899e5 100644
@@ -40,6 +40,7 @@ test_macros03
 test_macros04
 test_macros05
 test_macros06
+test_macros07
 tst_fuzzy_sync01
 tst_fuzzy_sync02
 tst_fuzzy_sync03
lib/newlib_tests/test_macros07.c new file +61 -0

61 lines not on this page · raw message

Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#23 lore raw

Re: [LTP] [PATCH v5 1/3] lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID}

Hi Wei,

lib/newlib_tests/test_macros07.c

Quoted 2 lines
lib/newlib_tests/test_macros07.c new file +0 -0

nit: Instead of creating a new test I would add it to existing test_macros02.c (it would reduce some duplicity).

Also having exp_errs_pass[] and exp_errs_fail[] static and put testing all 4 macros into it's own functions, I'll send a suggestion shortly.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#24 lore raw

Re: [LTP] [PATCH v5 1/3] lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID}

In reply to Wei Gao via ltp

Hi Wei,

Quoted 54 lines
lib/newlib_tests/test_macros07.c new file +51 -0
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2024 Wei Gao <[email protected]>
+ */
+
+/*
+ * 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()");

lib/newlib_tests/test_macros07.c line 61

Quoted 10 lines
lib/newlib_tests/test_macros07.c new file +10 -0
+	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,
+};

How about extend test_macros02.c (add testing macro, renaming functions to avoid clash, add inval_ret_fn_char() which was missing in your version):

static int fail_fn(void)

{
	errno = EINVAL;
	return -1;
}

static int pass_fn(void)

{
	return 0;
}

static int inval_ret_fn(void)

{
	return 42;
}

static char *fail_fn_null(void)

{
	errno = EINVAL;
	return NULL;
}

static char *fail_fn_void(void)

{
	errno = EINVAL;
	return (void *)-1;
}

static char *inval_ret_fn_char(void)

{
	return (void *)-1;
}

static char *pass_fn_char(void)

{
	return "pass";
}
#define TEST_MACRO(macro, macro_arr, fail_fn, pass_fn, inval_fn) \
	do {                                                                   \
		tst_res(TINFO, "Testing macro macro"); \
		macro(fail_fn(), EINVAL, "fail_fn()"); \
		tst_res(TINFO, "TST_PASS = %i", TST_PASS); \
		macro(fail_fn(), ENOTTY, "fail_fn()"); \
		tst_res(TINFO, "TST_PASS = %i", TST_PASS); \
		macro(pass_fn(), ENOTTY, "pass_fn()"); \
		tst_res(TINFO, "TST_PASS = %i", TST_PASS); \
		macro(inval_fn(), ENOTTY, "inval_fn()"); \
		tst_res(TINFO, "TST_PASS = %i", TST_PASS); \
		macro_arr(fail_fn(), exp_errs_pass, "fail_fn()"); \
		tst_res(TINFO, "TST_PASS = %i", TST_PASS); \
		macro_arr(fail_fn(), exp_errs_fail, "fail_fn()"); \
		tst_res(TINFO, "TST_PASS = %i", TST_PASS); \
	} while (0)

static void do_test(void)
{

	const int exp_errs_pass[] = {ENOTTY, EINVAL};
	const int exp_errs_fail[] = {ENOTTY, EISDIR};

	TEST_MACRO(TST_EXP_FAIL, TST_EXP_FAIL_ARR, fail_fn, pass_fn, inval_ret_fn);
	TEST_MACRO(TST_EXP_FAIL2, TST_EXP_FAIL2_ARR, fail_fn, pass_fn, inval_ret_fn);
	TEST_MACRO(TST_EXP_FAIL_PTR_NULL, TST_EXP_FAIL_PTR_ARR_NULL, fail_fn_null,
			   pass_fn_char, inval_ret_fn_char);
	TEST_MACRO(TST_EXP_FAIL_PTR_VOID, TST_EXP_FAIL_PTR_ARR_VOID, fail_fn_void,
			   pass_fn_char, inval_ret_fn_char);
}

static struct tst_test test = {
.test_all = do_test,
};

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#25 lore raw

Re: [LTP] [PATCH v5 1/3] lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID}

Hi Wei,

Quoted 1 line

Hi Wei,

...

Quoted 8 lines
#define TEST_MACRO(macro, macro_arr, fail_fn, pass_fn, inval_fn) \
	do {                                                                   \
		tst_res(TINFO, "Testing macro macro"); \
		macro(fail_fn(), EINVAL, "fail_fn()"); \
		tst_res(TINFO, "TST_PASS = %i", TST_PASS); \
		macro(fail_fn(), ENOTTY, "fail_fn()"); \
		tst_res(TINFO, "TST_PASS = %i", TST_PASS); \
		macro(pass_fn(), ENOTTY, "pass_fn()"); \
Quoted 8 lines
		tst_res(TINFO, "TST_PASS = %i", TST_PASS); \
		macro(inval_fn(), ENOTTY, "inval_fn()"); \
		tst_res(TINFO, "TST_PASS = %i", TST_PASS); \
		macro_arr(fail_fn(), exp_errs_pass, "fail_fn()"); \
		tst_res(TINFO, "TST_PASS = %i", TST_PASS); \
		macro_arr(fail_fn(), exp_errs_fail, "fail_fn()"); \
		tst_res(TINFO, "TST_PASS = %i", TST_PASS); \
	} while (0)

Actually this (print real function with #macro and #macro_arr, 2x skip message parameter (to test also macro without error parameter):

#define TEST_MACRO(macro, macro_arr, fail_fn, pass_fn, inval_fn) \
	do {                                                                   \
		tst_res(TINFO, "Testing " #macro " macro"); \
		macro(fail_fn(), EINVAL, #fail_fn"()"); \
		tst_res(TINFO, "TST_PASS = %i", TST_PASS); \
		macro(fail_fn(), ENOTTY); /* skip msg parameter */ \
		tst_res(TINFO, "TST_PASS = %i", TST_PASS); \
		macro(pass_fn(), ENOTTY, #pass_fn"()"); \
		tst_res(TINFO, "TST_PASS = %i", TST_PASS); \
		macro(inval_fn(), ENOTTY, #inval_fn"()"); \
		tst_res(TINFO, "TST_PASS = %i", TST_PASS); \
		macro_arr(fail_fn(), exp_errs_pass, #fail_fn"()"); \
		tst_res(TINFO, "TST_PASS = %i", TST_PASS); \
		macro_arr(fail_fn(), exp_errs_fail); /* skip msg parameter */ \
		tst_res(TINFO, "TST_PASS = %i", TST_PASS); \
	} while (0)

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#26 lore raw

Re: [LTP] [PATCH v5 1/3] lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID}

In reply to Wei Gao via ltp

Hi Wei,

...

Quoted 8 lines

#define TST_EXP_FAIL_ARR_(SCALL, SSCALL, EXP_ERRS, EXP_ERRS_CNT, ...) \

include/tst_test_macros.h +1 -0
 	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,                    \
 		                  ARRAY_SIZE(EXP_ERRS), ##__VA_ARGS__);
 
+#define TST_EXP_FAIL_PTR_NULL(SCALL, EXP_ERR, ...)                             \

include/tst_test_macros.h const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt); · line 306

Quoted 10 lines
include/tst_test_macros.h +10 -0
+	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__);        \

FYI I send a patch [1] (Cyril's suggestion) replacing ARRAY_SIZE() with just size parameter. I.e. moving ARRAY_SIZE() to the caller. This allows to use array of expected errnos more flexibly, e.g. fanotify14 [2].

Could you please send another version, which will be based on my v3 patchset or just wait before it's merged and rebase?

Kind regards,
Petr

[1] https://lore.kernel.org/ltp/[email protected]/
[2] https://lore.kernel.org/ltp/[email protected]/
[3] https://patchwork.ozlabs.org/project/ltp/list/?series=400495

Quoted 15 lines
include/tst_test_macros.h +15 -0
+	} 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)
+
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#27 lore raw

PATCH v5 2/3 shmat02.c: Use TST_EXP_FAIL_PTR_VOID

In reply to Wei Gao via ltp
---
 testcases/kernel/syscalls/ipc/shmat/shmat02.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
testcases/kernel/syscalls/ipc/shmat/shmat02.c +1 -14
index 53cb6f542..3ad1fd08e 100644
@@ -44,20 +44,7 @@ static struct test_case_t {
 
 static void verify_shmat(struct test_case_t *tc)
 {
-	void *addr;
-
-	addr = shmat(*tc->shmid, *tc->shmaddr, 0);
-	if (addr != (void *)-1) {
-		tst_res(TFAIL, "shmat() succeeded unexpectedly");
-		return;
-	}
-
-	if (errno == tc->exp_err) {
-		tst_res(TPASS | TERRNO, "shmat() failed as expected");
-	} else {
-		tst_res(TFAIL | TERRNO, "shmat() failed unexpectedly, expected: %s",
-			tst_strerrno(tc->exp_err));
-	}
+	TST_EXP_FAIL_PTR_VOID(shmat(*tc->shmid, *tc->shmaddr, 0), tc->exp_err);
 }
 
 static void do_shmat(unsigned int n)
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#28 lore raw

PATCH v5 3/3 realpath01.c: use TST_EXP_FAIL_PTR_NULL

In reply to Wei Gao via ltp
---
 testcases/kernel/syscalls/realpath/realpath01.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
testcases/kernel/syscalls/realpath/realpath01.c +1 -10
index c0381e9cb..c4c603609 100644
@@ -24,16 +24,7 @@ static void setup(void)
 
 static void run(void)
 {
-	TESTPTR(realpath(".", NULL));
-
-	if (TST_ERR != ENOENT) {
-		tst_res(TFAIL | TTERRNO, "returned unexpected errno");
-	} else	if (TST_RET_PTR != NULL) {
-		tst_res(TFAIL, "syscall didn't return NULL: '%s'",
-				(char *)TST_RET_PTR);
-	} else {
-		tst_res(TPASS, "bug not reproduced");
-	}
+	TST_EXP_FAIL_PTR_NULL(realpath(".", NULL), ENOENT);
 }
 
 static struct tst_test test = {
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#29 lore raw

v6 cover lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID}

In reply to Wei Gao via ltp

Wei Gao (3):
lib: TST_EXP_{FAIL,PASS}_PTR_{NULL,VOID}
shmat02.c: Use TST_EXP_FAIL_PTR_VOID
realpath01.c: use TST_EXP_FAIL_PTR_NULL

 include/tst_test_macros.h                     | 61 +++++++++++++++++++
 lib/newlib_tests/.gitignore                   |  1 +
 lib/newlib_tests/test_macros07.c              | 61 +++++++++++++++++++
 testcases/kernel/syscalls/ipc/shmat/shmat02.c | 15 +----
 .../kernel/syscalls/realpath/realpath01.c     | 11 +---
 5 files changed, 125 insertions(+), 24 deletions(-)
 create mode 100644 lib/newlib_tests/test_macros07.c
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#30 lore raw

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

---
 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
include/tst_test_macros.h +61 -0
index 6a7bcdce5..eff3aef69 100644
@@ -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;                                   \
lib/newlib_tests/.gitignore +1 -0
index 6d125f933..ed10d860a 100644
@@ -41,6 +41,7 @@ test_macros03
 test_macros04
 test_macros05
 test_macros06
+test_macros07
 tst_fuzzy_sync01
 tst_fuzzy_sync02
 tst_fuzzy_sync03
lib/newlib_tests/test_macros07.c new file +61 -0

61 lines not on this page · raw message

Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v6 1/3
#31 lore raw

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

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:

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#32 lore raw

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

Hi Cyril, Wei,

Quoted 7 lines

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/[email protected]/

Quoted 3 lines

With that:

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#33 lore raw

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

Hi!

Quoted 7 lines
Quoted 6 lines

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.

Quoted 6 lines

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.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#34 lore raw

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

Quoted 10 lines

Hi!

Quoted 8 lines
Quoted 6 lines

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.

Quoted 8 lines
Quoted 4 lines

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

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#35 lore raw

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

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

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#36 lore raw

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

Hi Cyril, Wei,

merged with the cleanup commit before.

Quoted 3 lines

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

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#37 lore raw

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

Quoted 9 lines · Petr Vorel

Hi Cyril, Wei,

merged with the cleanup commit before.

Quoted 3 lines

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.

Quoted 3 lines

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#38 lore raw

PATCH v6 2/3 shmat02.c: Use TST_EXP_FAIL_PTR_VOID

In reply to Wei Gao via ltp
---
 testcases/kernel/syscalls/ipc/shmat/shmat02.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
testcases/kernel/syscalls/ipc/shmat/shmat02.c +1 -14
index 53cb6f542..3ad1fd08e 100644
@@ -44,20 +44,7 @@ static struct test_case_t {
 
 static void verify_shmat(struct test_case_t *tc)
 {
-	void *addr;
-
-	addr = shmat(*tc->shmid, *tc->shmaddr, 0);
-	if (addr != (void *)-1) {
-		tst_res(TFAIL, "shmat() succeeded unexpectedly");
-		return;
-	}
-
-	if (errno == tc->exp_err) {
-		tst_res(TPASS | TERRNO, "shmat() failed as expected");
-	} else {
-		tst_res(TFAIL | TERRNO, "shmat() failed unexpectedly, expected: %s",
-			tst_strerrno(tc->exp_err));
-	}
+	TST_EXP_FAIL_PTR_VOID(shmat(*tc->shmid, *tc->shmaddr, 0), tc->exp_err);
 }
 
 static void do_shmat(unsigned int n)
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#39 lore raw

PATCH v6 3/3 realpath01.c: use TST_EXP_FAIL_PTR_NULL

In reply to Wei Gao via ltp
---
 include/tst_test_macros.h                       |  8 ++++----
 lib/newlib_tests/test_macros07.c                |  8 ++++----
 testcases/kernel/syscalls/realpath/realpath01.c | 11 +----------
 3 files changed, 9 insertions(+), 18 deletions(-)
include/tst_test_macros.h +4 -4
index eff3aef69..88c329333 100644
@@ -300,10 +300,10 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
 			&tst_exp_err__, 1, ##__VA_ARGS__);                     \
 	} while (0)
 
-#define TST_EXP_FAIL_PTR_ARR_NULL(SCALL, EXP_ERRS, ...)                        \
+#define TST_EXP_FAIL_PTR_ARR_NULL(SCALL, EXP_ERRS, EXP_ERRS_CNT, ...)          \
 	do {                                                                   \
 		TST_EXP_FAIL_PTR_(SCALL, #SCALL, NULL,                         \
-			EXP_ERRS, ARRAY_SIZE(EXP_ERRS), ##__VA_ARGS__);        \
+			EXP_ERRS, EXP_ERRS_CNT, ##__VA_ARGS__);                \
 	} while (0)
 
 #define TST_EXP_FAIL_PTR_VOID(SCALL, EXP_ERR, ...)                             \
@@ -313,10 +313,10 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
 			&tst_exp_err__, 1, ##__VA_ARGS__);                     \
 	} while (0)
 
-#define TST_EXP_FAIL_PTR_ARR_VOID(SCALL, EXP_ERRS, ...)                        \
+#define TST_EXP_FAIL_PTR_ARR_VOID(SCALL, EXP_ERRS, EXP_ERRS_CNT, ...)          \
 	do {                                                                   \
 		TST_EXP_FAIL_PTR_(SCALL, #SCALL, (void *)-1,                   \
-			EXP_ERRS, ARRAY_SIZE(EXP_ERRS), ##__VA_ARGS__);        \
+			EXP_ERRS, EXP_ERRS_CNT, ##__VA_ARGS__);                \
 	} while (0)
 
 #define TST_EXP_FAIL2(SCALL, EXP_ERR, ...)                                     \
lib/newlib_tests/test_macros07.c +4 -4
index ac361fd8e..6015988cf 100644
@@ -38,9 +38,9 @@ static void do_test(void)
 	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_EXP_FAIL_PTR_ARR_NULL(fail_fn_null(), exp_errs_pass, ARRAY_SIZE(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_EXP_FAIL_PTR_ARR_NULL(fail_fn_null(), exp_errs_fail, ARRAY_SIZE(exp_errs_fail), "fail_fn()_null");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
 
 	tst_res(TINFO, "Testing TST_EXP_FAIL_PTR_VOID macro");
@@ -50,9 +50,9 @@ static void do_test(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_EXP_FAIL_PTR_ARR_VOID(fail_fn_void(), exp_errs_pass, ARRAY_SIZE(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_EXP_FAIL_PTR_ARR_VOID(fail_fn_void(), exp_errs_fail, ARRAY_SIZE(exp_errs_fail), "fail_fn()_void");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
 }
 
testcases/kernel/syscalls/realpath/realpath01.c +1 -10
index c0381e9cb..c4c603609 100644
@@ -24,16 +24,7 @@ static void setup(void)
 
 static void run(void)
 {
-	TESTPTR(realpath(".", NULL));
-
-	if (TST_ERR != ENOENT) {
-		tst_res(TFAIL | TTERRNO, "returned unexpected errno");
-	} else	if (TST_RET_PTR != NULL) {
-		tst_res(TFAIL, "syscall didn't return NULL: '%s'",
-				(char *)TST_RET_PTR);
-	} else {
-		tst_res(TPASS, "bug not reproduced");
-	}
+	TST_EXP_FAIL_PTR_NULL(realpath(".", NULL), ENOENT);
 }
 
 static struct tst_test test = {
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp