Skip to contentSkip to conversation

unshare01: add EINVAL check

PATCH In review lufei 2 participants 2 messages Mar 12, 2025 – Mar 13, 2025

lore
Share & tools
lore

lufei

author
#0 lore raw

PATCH 1/1 unshare01: add EINVAL check

---
 testcases/kernel/syscalls/unshare/unshare01.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
testcases/kernel/syscalls/unshare/unshare01.c +14 -5
index 6e6315b11..ce1ed2e14 100644
@@ -28,21 +28,30 @@
 #include "config.h"
 
 #ifdef HAVE_UNSHARE
+#define INV_FLAG 0x0123
+
 
 static struct test_case_t {
 	int mode;
 	const char *desc;
+	const int eno;
 } tc[] = {
-	{CLONE_FILES,	"CLONE_FILES"},
-	{CLONE_FS,	"CLONE_FS"},
-	{CLONE_NEWNS,	"CLONE_NEWNS"},
+	{CLONE_FILES,	"CLONE_FILES",	0},
+	{CLONE_FS,	"CLONE_FS",	0},
+	{CLONE_NEWNS,	"CLONE_NEWNS",	0},
+	{INV_FLAG,	"INV_FLAG",	EINVAL},
 };
 
 static void run(unsigned int i)
 {
 	pid_t pid = SAFE_FORK();
-	if (pid == 0)
-		TST_EXP_PASS(unshare(tc[i].mode), "unshare(%s)", tc[i].desc);
+
+	if (pid == 0) {
+		if (tc[i].eno)
+			TST_EXP_FAIL(unshare(tc[i].mode), tc[i].eno, "unshare(%s)", tc[i].desc);
+		else
+			TST_EXP_PASS(unshare(tc[i].mode), "unshare(%s)", tc[i].desc);
+	}
 }
 
 static struct tst_test test = {
Signature · 5 lines
2.39.3


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

Hi lufei,

Please next time have a look on other tests, if the same thing is already being tested or not. EINVAL is already tested in unshare02.c (as -1).

That's why is this patch not needed (if really high value should be tested, which I don't think so, it should be in unshare02.c).

Also, we try to not mixing positive tests (e.g. CLONE_FILES) with negative ones (e.g. EINVAL), we put negative to separate test.

Quoted 9 lines
---
 testcases/kernel/syscalls/unshare/unshare01.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
testcases/kernel/syscalls/unshare/unshare01.c +0 -0
index 6e6315b11..ce1ed2e14 100644

testcases/kernel/syscalls/unshare/unshare01.c line 37

Quoted 10 lines
testcases/kernel/syscalls/unshare/unshare01.c +3 -0
@@ -28,21 +28,30 @@
 #include "config.h"
 
 #ifdef HAVE_UNSHARE
+#define INV_FLAG 0x0123
+
 
 static struct test_case_t {
 	int mode;
 	const char *desc;
+	const int eno;

nit: "eno" is not much descriptive, we usually use exp_errno.

Kind regards,
Petr

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