Skip to contentSkip to conversation

include/tst_test_macros.h: Add TST_EXP_{PASS, FD}_SILENT macros

PATCH New Xiao Yang 2 participants 8 messages Jan 12, 2021 – Jan 25, 2021

lore
Share & tools
lore

Xiao Yang

author
#0 lore raw

PATCH v3 1/3 include/tst_test_macros.h: Add TST_EXP_{PASS, FD}_SILENT macros

1) TST_EXP_{PASS,FD}_SILENT don't report TPASS when SCALL succeeds.
2) TST_EXP_{PASS,FD} calls TST_EXP_{PASS,FD}_SILENT and reports TPASS when SCALL succeeds.

---
 include/tst_test_macros.h | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)
include/tst_test_macros.h +18 -7
index 3016d95c2..92cb5c66b 100644
@@ -46,7 +46,7 @@ extern void *TST_RET_PTR;
 	tst_res_(__FILE__, __LINE__, RES, \
 		TST_FMT_(TST_2_(dummy, ##__VA_ARGS__, SCALL) FMT, __VA_ARGS__), PAR)
 
-#define TST_EXP_FD(SCALL, ...)                                                 \
+#define TST_EXP_FD_SILENT(SCALL, ...)                                          \
 	do {                                                                   \
 		TEST(SCALL);                                                   \
 		                                                               \
@@ -64,14 +64,20 @@ extern void *TST_RET_PTR;
 			break;                                                 \
 		}                                                              \
                                                                                \
-		TST_MSGP_(TPASS, " returned fd %ld", TST_RET,                  \
-		         #SCALL, ##__VA_ARGS__);                               \
-                                                                               \
 		TST_PASS = 1;                                                  \
                                                                                \
 	} while (0)
 
-#define TST_EXP_PASS(SCALL, ...)                                               \
+#define TST_EXP_FD(SCALL, ...)                                                 \
+	do {                                                                   \
+		TST_EXP_FD_SILENT(SCALL, __VA_ARGS__);                         \
+		                                                               \
+		if (TST_PASS)                                                  \
+			TST_MSGP_(TPASS, " returned fd %ld", TST_RET,          \
+				#SCALL, ##__VA_ARGS__);                        \
+	} while (0)
+
+#define TST_EXP_PASS_SILENT(SCALL, ...)                                        \
 	do {                                                                   \
 		TEST(SCALL);                                                   \
 		                                                               \
@@ -89,12 +95,17 @@ extern void *TST_RET_PTR;
 			break;                                                 \
 		}                                                              \
                                                                                \
-		TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);             \
-                                                                               \
 		TST_PASS = 1;                                                  \
                                                                                \
 	} while (0)
 
+#define TST_EXP_PASS(SCALL, ...)                                               \
+	do {                                                                   \
+		TST_EXP_PASS_SILENT(SCALL, __VA_ARGS__);                       \
+		                                                               \
+		if (TST_PASS)                                                  \
+			TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
+	} while (0)                                                            \
 
 #define TST_EXP_FAIL(SCALL, ERRNO, ...)                                        \
 	do {                                                                   \
Signature · 1 line
2.21.0
author
#1 lore raw

PATCH v3 1/3 include/tst_test_macros.h: Add TST_EXP_{PASS, FD}_SILENT macros

Hi Cyril,

If you have no objection, I will push the patchset after the new release. :-)

Best Regards?
Xiao Yang

Quoted 67 lines · Xiao Yang

1) TST_EXP_{PASS,FD}_SILENT don't report TPASS when SCALL succeeds.
2) TST_EXP_{PASS,FD} calls TST_EXP_{PASS,FD}_SILENT and reports TPASS when SCALL succeeds.

---
 include/tst_test_macros.h | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)
include/tst_test_macros.h +18 -7
index 3016d95c2..92cb5c66b 100644
@@ -46,7 +46,7 @@ extern void *TST_RET_PTR;
 	tst_res_(__FILE__, __LINE__, RES, \
 		TST_FMT_(TST_2_(dummy, ##__VA_ARGS__, SCALL) FMT, __VA_ARGS__), PAR)
 
-#define TST_EXP_FD(SCALL, ...)                                                 \
+#define TST_EXP_FD_SILENT(SCALL, ...)                                          \
 	do {                                                                   \
 		TEST(SCALL);                                                   \
 		                                                               \
@@ -64,14 +64,20 @@ extern void *TST_RET_PTR;
 			break;                                                 \
 		}                                                              \
                                                                                \
-		TST_MSGP_(TPASS, " returned fd %ld", TST_RET,                  \
-		         #SCALL, ##__VA_ARGS__);                               \
-                                                                               \
 		TST_PASS = 1;                                                  \
                                                                                \
 	} while (0)
 
-#define TST_EXP_PASS(SCALL, ...)                                               \
+#define TST_EXP_FD(SCALL, ...)                                                 \
+	do {                                                                   \
+		TST_EXP_FD_SILENT(SCALL, __VA_ARGS__);                         \
+		                                                               \
+		if (TST_PASS)                                                  \
+			TST_MSGP_(TPASS, " returned fd %ld", TST_RET,          \
+				#SCALL, ##__VA_ARGS__);                        \
+	} while (0)
+
+#define TST_EXP_PASS_SILENT(SCALL, ...)                                        \
 	do {                                                                   \
 		TEST(SCALL);                                                   \
 		                                                               \
@@ -89,12 +95,17 @@ extern void *TST_RET_PTR;
 			break;                                                 \
 		}                                                              \
                                                                                \
-		TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);             \
-                                                                               \
 		TST_PASS = 1;                                                  \
                                                                                \
 	} while (0)
 
+#define TST_EXP_PASS(SCALL, ...)                                               \
+	do {                                                                   \
+		TST_EXP_PASS_SILENT(SCALL, __VA_ARGS__);                       \
+		                                                               \
+		if (TST_PASS)                                                  \
+			TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
+	} while (0)                                                            \
 
 #define TST_EXP_FAIL(SCALL, ERRNO, ...)                                        \
 	do {                                                                   \
author
#2 lore raw

PATCH v3 2/3 syscalls/open01.c: Take use of TST_EXP_FD_SILENT

In reply to Xiao Yang

Current TST_EXP_FD macro reports the double passed for one subtest, for example:
--------------------------------------------
./open01
tst_test.c:1261: TINFO: Timeout per run is 0h 05m 00s open01.c:48: TPASS: open() with sticky bit returned fd 3 open01.c:59: TPASS: sticky bit is set as expected open01.c:48: TPASS: open() with sirectory bit returned fd 3 open01.c:59: TPASS: sirectory bit is set as expected

Summary:

passed   4
failed   0
broken   0
skipped  0

warnings 0
--------------------------------------------

It is just a minor cleanup rather than a fix.

---
 testcases/kernel/syscalls/open/open01.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/syscalls/open/open01.c +1 -1
index 2f0ad550a..baf73ab11 100644
@@ -45,7 +45,7 @@ static void verify_open(unsigned int n)
 	struct tcase *tc = &tcases[n];
 	struct stat buf;
 
-	TST_EXP_FD(open(tc->filename, tc->flag, tc->mode),
+	TST_EXP_FD_SILENT(open(tc->filename, tc->flag, tc->mode),
 	           "open() with %s", tc->desc);
 	if (!TST_PASS)
 		return;
Signature · 1 line
2.21.0
author
#3 lore raw

PATCH v3 3/3 syscalls: Take use of TST_EXP_PASS_SILENT

In reply to Xiao Yang

Current TST_EXP_PASS macro reports the double passed for
one subtest, for example:
--------------------------------------------
tst_test.c:1261: TINFO: Timeout per run is 0h 05m 00s access02.c:62: TPASS: access(file_f, F_OK) as root passed access02.c:141: TPASS: access(file_f, F_OK) as root behaviour is correct. access02.c:62: TPASS: access(file_f, F_OK) as nobody passed access02.c:141: TPASS: access(file_f, F_OK) as nobody behaviour is correct. access02.c:62: TPASS: access(file_r, R_OK) as root passed
...

Summary:

passed   32
failed   0
broken   0
skipped  0

warnings 0
--------------------------------------------

It is just a minor cleanup rather than a fix.

---
 testcases/kernel/syscalls/access/access02.c | 2 +-
 testcases/kernel/syscalls/bind/bind04.c     | 2 +-
 testcases/kernel/syscalls/bind/bind05.c     | 2 +-
 testcases/kernel/syscalls/brk/brk01.c       | 6 +++++-
 testcases/kernel/syscalls/capget/capget01.c | 4 +++-
 5 files changed, 11 insertions(+), 5 deletions(-)
testcases/kernel/syscalls/access/access02.c +1 -1
index ff3e7b6f4..bf636f9f4 100644
@@ -59,7 +59,7 @@ static void access_test(struct tcase *tc, const char *user)
 	struct stat stat_buf;
 	char command[64];
 
-	TST_EXP_PASS(access(tc->pathname, tc->mode),
+	TST_EXP_PASS_SILENT(access(tc->pathname, tc->mode),
 	             "access(%s, %s) as %s", tc->pathname, tc->name, user);
 
 	if (!TST_PASS)
testcases/kernel/syscalls/bind/bind04.c +1 -1
index 49e784ccd..de43b6c13 100644
@@ -118,7 +118,7 @@ static void test_bind(unsigned int n)
 	listen_sock = SAFE_SOCKET(tc->address->sa_family, tc->type,
 		tc->protocol);
 
-	TST_EXP_PASS(bind(listen_sock, tc->address, tc->addrlen), "bind()");
+	TST_EXP_PASS_SILENT(bind(listen_sock, tc->address, tc->addrlen), "bind()");
 
 	if (!TST_PASS) {
 		SAFE_CLOSE(listen_sock);
testcases/kernel/syscalls/bind/bind05.c +1 -1
index 3b384cf1b..c43593fe1 100644
@@ -131,7 +131,7 @@ static void test_bind(unsigned int n)
 	tst_res(TINFO, "Testing %s", tc->description);
 	sock = SAFE_SOCKET(tc->address->sa_family, tc->type, tc->protocol);
 
-	TST_EXP_PASS(bind(sock, tc->address, tc->addrlen), "bind()");
+	TST_EXP_PASS_SILENT(bind(sock, tc->address, tc->addrlen), "bind()");
 
 	if (!TST_PASS) {
 		SAFE_CLOSE(sock);
testcases/kernel/syscalls/brk/brk01.c +5 -1
index 3f8606375..a9b89bce5 100644
@@ -31,7 +31,9 @@ void verify_brk(void)
 		break;
 		}
 
-		TST_EXP_PASS(brk((void *)new_brk), "brk()");
+		TST_EXP_PASS_SILENT(brk((void *)new_brk), "brk()");
+		if (!TST_PASS)
+			return;
 
 		cur_brk = (uintptr_t)sbrk(0);
 
@@ -46,6 +48,8 @@ void verify_brk(void)
 		if (i % 3 == 0)
 			*((char *)cur_brk) = 0;
 	}
+
+	tst_res(TPASS, "brk() works fine");
 }
 
 static struct tst_test test = {
testcases/kernel/syscalls/capget/capget01.c +3 -1
index 6c17a7c7c..af088e2fc 100644
@@ -32,8 +32,10 @@ static void verify_capget(unsigned int n)
 	hdr->version = tc->version;
 	hdr->pid = pid;
 
-	TST_EXP_PASS(tst_syscall(__NR_capget, hdr, data),
+	TST_EXP_PASS_SILENT(tst_syscall(__NR_capget, hdr, data),
 	             "capget() with %s", tc->message);
+	if (!TST_PASS)
+		return;
 
 	if (data[0].effective & 1 << CAP_NET_RAW)
 		tst_res(TFAIL, "capget() gets CAP_NET_RAW unexpectedly in pE");
Signature · 1 line
2.21.0
#4 lore raw

PATCH v3 3/3 syscalls: Take use of TST_EXP_PASS_SILENT

Hi!

Quoted 6 lines
testcases/kernel/syscalls/capget/capget01.c +0 -0
index 6c17a7c7c..af088e2fc 100644
@@ -32,8 +32,10 @@ static void verify_capget(unsigned int n)
 	hdr->version = tc->version;

testcases/kernel/syscalls/capget/capget01.c static void verify_capget(unsigned int n) · line 41

Quoted 10 lines
testcases/kernel/syscalls/capget/capget01.c +3 -1
 	hdr->pid = pid;
 
-	TST_EXP_PASS(tst_syscall(__NR_capget, hdr, data),
+	TST_EXP_PASS_SILENT(tst_syscall(__NR_capget, hdr, data),
 	             "capget() with %s", tc->message);
+	if (!TST_PASS)
+		return;
 
 	if (data[0].effective & 1 << CAP_NET_RAW)
 		tst_res(TFAIL, "capget() gets CAP_NET_RAW unexpectedly in pE");

I do not agree with the change in the capget01 here since there are really two testcases there and the test was producing the same amount of TPASS messages before the change to the TST_EXP_PASS() as well.

Other than that the patchset is fine.

So with the capget change removed you can add my:

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#5 lore raw

PATCH v3 3/3 syscalls: Take use of TST_EXP_PASS_SILENT

Quoted 15 lines · Cyril Hrubis

Hi!

Quoted 14 lines
testcases/kernel/syscalls/capget/capget01.c +3 -1
index 6c17a7c7c..af088e2fc 100644
@@ -32,8 +32,10 @@ static void verify_capget(unsigned int n)
  	hdr->version = tc->version;
  	hdr->pid = pid;
 
-	TST_EXP_PASS(tst_syscall(__NR_capget, hdr, data),
+	TST_EXP_PASS_SILENT(tst_syscall(__NR_capget, hdr, data),
  	             "capget() with %s", tc->message);
+	if (!TST_PASS)
+		return;
 
Quoted 5 lines

testcases/kernel/syscalls/capget/capget01.c static void verify_capget(unsigned int n) · line 41

Quoted 2 lines
testcases/kernel/syscalls/capget/capget01.c +0 -0
  	if (data[0].effective&  1<<  CAP_NET_RAW)
  		tst_res(TFAIL, "capget() gets CAP_NET_RAW unexpectedly in pE");

I do not agree with the change in the capget01 here since there are really two testcases there and the test was producing the same amount of TPASS messages before the change to the TST_EXP_PASS() as well.

Hi Cyril,

Running capget01 with TST_EXP_PASS() shows:
--------------------------------------------------------
capget01.c:35: TPASS: capget() with LINUX_CAPABILITY_VERSION_1 passed capget01.c:41: TPASS: capget() doesn't get CAP_NET_RAW as expected in PE capget01.c:35: TPASS: capget() with LINUX_CAPABILITY_VERSION_2 passed capget01.c:41: TPASS: capget() doesn't get CAP_NET_RAW as expected in PE capget01.c:35: TPASS: capget() with LINUX_CAPABILITY_VERSION_3 passed capget01.c:41: TPASS: capget() doesn't get CAP_NET_RAW as expected in PE

Summary:
passed 6
--------------------------------------------------------

Running capget01 with TST_EXP_PASS_SILENT() shows:
--------------------------------------------------------
capget01.c:43: TPASS: capget() doesn't get CAP_NET_RAW as expected in PE capget01.c:43: TPASS: capget() doesn't get CAP_NET_RAW as expected in PE capget01.c:43: TPASS: capget() doesn't get CAP_NET_RAW as expected in PE

Summary:
passed 3
--------------------------------------------------------

If you want to keep two TPASS for a subtest, how about merging two TPASS into one? like this:
------------------------------------------------------------------------------------------
capget01.c:43: TPASS: capget() with LINUX_CAPABILITY_VERSION_1 doesn't get CAP_NET_RAW as expected in PE
capget01.c:43: TPASS: capget() with LINUX_CAPABILITY_VERSION_2 doesn't get CAP_NET_RAW as expected in PE
capget01.c:43: TPASS: capget() with LINUX_CAPABILITY_VERSION_3 doesn't get CAP_NET_RAW as expected in PE

Summary:
passed 3
------------------------------------------------------------------------------------------

BTW, I just want to avoid many TPASS for a subtest.

Best Regards,
Xiao Yang

Quoted 6 lines

Other than that the patchset is fine.

So with the capget change removed you can add my:

#6 lore raw

PATCH v3 3/3 syscalls: Take use of TST_EXP_PASS_SILENT

Hi!

Quoted 1 line

BTW, I just want to avoid many TPASS for a subtest.

Why? The capget01 clearly does two different tests per iteration.

There is absolutely no correlation between the number of TPASS test produces and the number of iteration test does.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#7 lore raw

PATCH v3 3/3 syscalls: Take use of TST_EXP_PASS_SILENT

Quoted 6 lines · Cyril Hrubis

Hi!

Quoted 1 line

BTW, I just want to avoid many TPASS for a subtest.

Why? The capget01 clearly does two different tests per iteration.

There is absolutely no correlation between the number of TPASS test produces and the number of iteration test does.

Hi Cyril,

I pushed the patchset without capget01 for now. But I think there is a whole test per iteration, like three steps:
1) Drop CAP_NET_RAW.
2) Get effective by specifying kernel revision.
3) Check that the effective doesn't include CAP_NET_RAW. Is it necessary for per steps to report TPASS? :-)

Best Regards,
Xiao Yang