[LTP] [PATCH] unshare01: add EINVAL check

lufei lufei@uniontech.com
Wed Mar 12 10:28:09 CET 2025


---
 testcases/kernel/syscalls/unshare/unshare01.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/testcases/kernel/syscalls/unshare/unshare01.c b/testcases/kernel/syscalls/unshare/unshare01.c
index 6e6315b11..ce1ed2e14 100644
--- a/testcases/kernel/syscalls/unshare/unshare01.c
+++ b/testcases/kernel/syscalls/unshare/unshare01.c
@@ -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 = {
-- 
2.39.3



More information about the ltp mailing list