Skip to contentSkip to conversation

include/tst_test_macros.h: Add TST_EXP_PID and TST_EXP_PID_SILENT macros

PATCH New [email protected] 2 participants 5 messages Apr 19, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 include/tst_test_macros.h: Add TST_EXP_PID and TST_EXP_PID_SILENT macros

From: Xiao Yang <[email protected]>

---
 include/tst_test_macros.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/tst_test_macros.h +11 -0
index 189891507..101ac2c87 100644
@@ -77,6 +77,17 @@ extern void *TST_RET_PTR;
 				#SCALL, ##__VA_ARGS__);                        \
 	} while (0)
 
+#define TST_EXP_PID_SILENT(SCALL, ...)	TST_EXP_FD_SILENT(SCALL, __VA_ARGS__)
+
+#define TST_EXP_PID(SCALL, ...)                                                \
+	do {                                                                   \
+		TST_EXP_PID_SILENT(SCALL, __VA_ARGS__);                        \
+									       \
+		if (TST_PASS)                                                  \
+			TST_MSGP_(TPASS, " returned pid %ld", TST_RET,         \
+				#SCALL, ##__VA_ARGS__);                        \
+	} while (0)
+
 #define TST_EXP_PASS_SILENT(SCALL, ...)                                        \
 	do {                                                                   \
 		TEST(SCALL);                                                   \
Signature · 1 line
2.26.2
#1 lore raw

PATCH v2 2/2 syscalls/{wait401.c, waitpid01.c}: Take use of TST_EXP_PID_SILENT()

From: Xiao Yang <[email protected]>

Also correct the name(waitpid=>wait4) in the output of wait401.

---

V1->V2:
Return immediately if TST_PASS == 0

 testcases/kernel/syscalls/wait4/wait401.c     | 10 ++++------
 testcases/kernel/syscalls/waitpid/waitpid01.c | 14 +++++++-------
 2 files changed, 11 insertions(+), 13 deletions(-)
testcases/kernel/syscalls/wait4/wait401.c +4 -6
index 07fb864f3..ab99891be 100644
@@ -29,17 +29,15 @@ static void run(void)
 		exit(0);
 	}
 
-	TEST(wait4(pid, &status, 0, &rusage));
-	if (TST_RET == -1) {
-		tst_res(TFAIL | TTERRNO, "wait4() failed");
+	TST_EXP_PID_SILENT(wait4(pid, &status, 0, &rusage), "wait4()");
+	if (!TST_PASS)
 		return;
-	}
 
 	if (TST_RET != pid) {
-		tst_res(TFAIL, "waitpid() returned wrong pid %li, expected %i",
+		tst_res(TFAIL, "wait4() returned wrong pid %li, expected %i",
 			TST_RET, pid);
 	} else {
-		tst_res(TPASS, "waitpid() returned correct pid %i", pid);
+		tst_res(TPASS, "wait4() returned correct pid %i", pid);
 	}
 
 	if (!WIFEXITED(status)) {
testcases/kernel/syscalls/waitpid/waitpid01.c +7 -7
index 6e03acef6..5a39a1107 100644
@@ -18,7 +18,7 @@
 
 static void run(void)
 {
-	pid_t pid, rpid;
+	pid_t pid;
 	int status;
 
 	pid = SAFE_FORK();
@@ -27,13 +27,13 @@ static void run(void)
 		exit(0);
 	}
 
-	rpid = waitpid(pid, &status, 0);
-	if (rpid < 0)
-		tst_brk(TBROK | TERRNO, "waitpid() failed");
+	TST_EXP_PID_SILENT(waitpid(pid, &status, 0));
+	if (!TST_PASS)
+		return;
 
-	if (rpid != pid) {
-		tst_res(TFAIL, "waitpid() returned wrong pid %i, expected %i",
-		        rpid, pid);
+	if (TST_RET != pid) {
+		tst_res(TFAIL, "waitpid() returned wrong pid %li, expected %i",
+			TST_RET, pid);
 	} else {
 		tst_res(TPASS, "waitpid() returned correct pid %i", pid);
 	}
Signature · 1 line
2.26.2
#3 lore raw

PATCH v2 1/2 include/tst_test_macros.h: Add TST_EXP_PID and TST_EXP_PID_SILENT macros

In reply to [email protected]

Hi!

Quoted 10 lines
---
 include/tst_test_macros.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/tst_test_macros.h +0 -0
index 189891507..101ac2c87 100644

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

Quoted 4 lines
include/tst_test_macros.h +1 -0
@@ -77,6 +77,17 @@ extern void *TST_RET_PTR;
 				#SCALL, ##__VA_ARGS__);                        \
 	} while (0)
 
+#define TST_EXP_PID_SILENT(SCALL, ...)	TST_EXP_FD_SILENT(SCALL, __VA_ARGS__)

Maybe we should rename the TST_EXP_FD_SILENT() to TST_EXP_POSITIVE() and then define both TST_EXP_PID_SILENT() and TST_EXP_FD_SILENT() based on TST_EXP_POSITIVE(), but that's very minor.

Looks good to me:

Quoted 15 lines
include/tst_test_macros.h +9 -0
+#define TST_EXP_PID(SCALL, ...)                                                \
+	do {                                                                   \
+		TST_EXP_PID_SILENT(SCALL, __VA_ARGS__);                        \
+									       \
+		if (TST_PASS)                                                  \
+			TST_MSGP_(TPASS, " returned pid %ld", TST_RET,         \
+				#SCALL, ##__VA_ARGS__);                        \
+	} while (0)
+
 #define TST_EXP_PASS_SILENT(SCALL, ...)                                        \
 	do {                                                                   \
 		TEST(SCALL);                                                   \
Signature · 1 line
2.26.2
Signature · 2 lines
Cyril Hrubis
[email protected]
author
#4 lore raw

PATCH v2 1/2 include/tst_test_macros.h: Add TST_EXP_PID and TST_EXP_PID_SILENT macros

Hi Cyril,

Thanks, pushed with your suggestion(use TST_EXP_POSITIVE).

Best Regards,

Xiao Yang

Quoted 7 lines · Cyril Hrubis

Maybe we should rename the TST_EXP_FD_SILENT() to TST_EXP_POSITIVE() and then define both TST_EXP_PID_SILENT() and TST_EXP_FD_SILENT() based on TST_EXP_POSITIVE(), but that's very minor.

Looks good to me: