All of lore.kernel.org
 help / color / mirror / Atom feed
From: lufei <lufei@uniontech.com>
To: ltp@lists.linux.it
Cc: lufei <lufei@uniontech.com>
Subject: [LTP] [PATCH] syscalls/unshare: New test: CLONE_NEWNS unshares fs info
Date: Wed, 23 Apr 2025 12:46:01 +0800	[thread overview]
Message-ID: <20250423044601.9320-1-lufei@uniontech.com> (raw)

Add test case unshare04, to verify unshare(CLONE_NEWNS) also unshares
filesystem information.

Signed-off-by: lufei <lufei@uniontech.com>
---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/unshare/.gitignore  |  1 +
 testcases/kernel/syscalls/unshare/unshare04.c | 69 +++++++++++++++++++
 3 files changed, 71 insertions(+)
 create mode 100644 testcases/kernel/syscalls/unshare/unshare04.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 844ae7a13..57338297a 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1725,6 +1725,7 @@ unlinkat01 unlinkat01
 unshare01 unshare01
 unshare02 unshare02
 unshare03 unshare03
+unshare04 unshare04
 
 #
 # These tests require an unmounted block device
diff --git a/testcases/kernel/syscalls/unshare/.gitignore b/testcases/kernel/syscalls/unshare/.gitignore
index e5b5c261d..b1206e452 100644
--- a/testcases/kernel/syscalls/unshare/.gitignore
+++ b/testcases/kernel/syscalls/unshare/.gitignore
@@ -1,3 +1,4 @@
 /unshare01
 /unshare02
 /unshare03
+/unshare04
diff --git a/testcases/kernel/syscalls/unshare/unshare04.c b/testcases/kernel/syscalls/unshare/unshare04.c
new file mode 100644
index 000000000..0bbb9d19d
--- /dev/null
+++ b/testcases/kernel/syscalls/unshare/unshare04.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 lufei <lufei@uniontech.com>
+ */
+
+/*\
+ * This test case is to verify unshare(CLONE_NEWNS) also unshares filesystem
+ * information.
+ *
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/sched.h"
+
+#ifdef HAVE_UNSHARE
+
+#define TMP "/tmp"
+
+static void run(void)
+{
+	char *c_cwd;
+	char *p_cwd;
+	size_t size = 1024;
+
+	c_cwd = SAFE_MMAP(NULL, size, PROT_READ | PROT_WRITE,
+			MAP_SHARED | MAP_ANONYMOUS,
+			-1, 0);
+
+	p_cwd = SAFE_MALLOC(size);
+
+	struct tst_clone_args args = {
+		.flags = CLONE_FS,
+		.exit_signal = SIGCHLD,
+	};
+
+	if (!SAFE_CLONE(&args)) {
+
+		TST_EXP_PASS(unshare(CLONE_NEWNS));
+
+		SAFE_CHDIR(TMP);
+		SAFE_GETCWD(c_cwd, size);
+	} else {
+		SAFE_WAIT(NULL);
+
+		SAFE_GETCWD(p_cwd, size);
+
+		tst_res(TDEBUG, "parent cwd: %s", p_cwd);
+		tst_res(TDEBUG, "child cwd: %s", c_cwd);
+
+		//in parent, cwd stays in tst_tmpdir_path than TMP.
+		if (strcmp(p_cwd, c_cwd) == 0)
+			tst_res(TFAIL, "cwd not unshared as expected");
+		else
+			tst_res(TPASS, "cwd unshared");
+	}
+}
+
+static struct tst_test test = {
+	.forks_child = 1,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.test_all = run,
+};
+
+#else
+TST_TEST_TCONF("unshare syscall is undefined.");
+#endif
-- 
2.39.3


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

             reply	other threads:[~2025-04-23  4:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-23  4:46 lufei [this message]
2025-04-23  9:10 ` [LTP] [PATCH] syscalls/unshare: New test: CLONE_NEWNS unshares fs info Cyril Hrubis
2025-04-23 12:05 ` [LTP] [PATCH v2] " lufei
2025-04-25  9:07   ` Cyril Hrubis
2025-04-25  9:33   ` [LTP] [PATCH v3] " lufei
2025-04-25 12:10     ` Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250423044601.9320-1-lufei@uniontech.com \
    --to=lufei@uniontech.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.