linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests/filesystems/binderfs: Skip tests if user namespaces are unavailable
@ 2025-08-07 13:45 Wake Liu
  2025-08-07 19:24 ` Shuah Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Wake Liu @ 2025-08-07 13:45 UTC (permalink / raw)
  To: shuah; +Cc: linux-kselftest, linux-kernel, wakel

The binderfs selftests, specifically `binderfs_stress` and
`binderfs_test_unprivileged`, depend on user namespaces to run.

On kernels built without user namespace support (CONFIG_USER_NS=n),
these tests will fail.

To prevent these failures, add a check for the availability of user
namespaces by testing for the existence of "/proc/self/ns/user". If
the check fails, skip the tests and print an informative message.

Signed-off-by: Wake Liu <wakel@google.com>
---
 .../selftests/filesystems/binderfs/binderfs_test.c     | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
index 81db85a5cc16..e77ed34ebd06 100644
--- a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
+++ b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
@@ -291,6 +291,11 @@ static int write_id_mapping(enum idmap_type type, pid_t pid, const char *buf,
 	return 0;
 }
 
+static bool has_userns(void)
+{
+	return (access("/proc/self/ns/user", F_OK) == 0);
+}
+
 static void change_userns(struct __test_metadata *_metadata, int syncfds[2])
 {
 	int ret;
@@ -378,6 +383,9 @@ static void *binder_version_thread(void *data)
  */
 TEST(binderfs_stress)
 {
+	if (!has_userns())
+		SKIP(return, "%s: user namespace not supported\n", __func__);
+
 	int fds[1000];
 	int syncfds[2];
 	pid_t pid;
@@ -502,6 +510,8 @@ TEST(binderfs_test_privileged)
 
 TEST(binderfs_test_unprivileged)
 {
+	if (!has_userns())
+		SKIP(return, "%s: user namespace not supported\n", __func__);
 	int ret;
 	int syncfds[2];
 	pid_t pid;
-- 
2.50.1.703.g449372360f-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests/filesystems/binderfs: Skip tests if user namespaces are unavailable
  2025-08-07 13:45 [PATCH] selftests/filesystems/binderfs: Skip tests if user namespaces are unavailable Wake Liu
@ 2025-08-07 19:24 ` Shuah Khan
  2025-08-09  9:26   ` [PATCH v2] selftests/binderfs: Add CONFIG_USER_NS dependency Wake Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Shuah Khan @ 2025-08-07 19:24 UTC (permalink / raw)
  To: Wake Liu, shuah; +Cc: linux-kselftest, linux-kernel, Shuah Khan

On 8/7/25 07:45, Wake Liu wrote:
> The binderfs selftests, specifically `binderfs_stress` and
> `binderfs_test_unprivileged`, depend on user namespaces to run.
> 
> On kernels built without user namespace support (CONFIG_USER_NS=n),
> these tests will fail.

Why not add CONFIG_USER_NS to config file instead to indicate the
dependency.

tools/testing/selftests/filesystems/binderfs/config which has these
as dependencies at the moment.

CONFIG_ANDROID_BINDERFS=y
CONFIG_ANDROID_BINDER_IPC=y
> 
> To prevent these failures, add a check for the availability of user
> namespaces by testing for the existence of "/proc/self/ns/user". If
> the check fails, skip the tests and print an informative message.]

Can you try adding the dependency first?

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2] selftests/binderfs: Add CONFIG_USER_NS dependency
  2025-08-07 19:24 ` Shuah Khan
@ 2025-08-09  9:26   ` Wake Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Wake Liu @ 2025-08-09  9:26 UTC (permalink / raw)
  To: shuah; +Cc: Wake Liu, linux-kselftest, linux-kernel, Shuah Khan

The binderfs selftests, specifically binderfs_stress and
binderfs_test_unprivileged, depend on user namespaces to run.

On kernels built without user namespace support (CONFIG_USER_NS=n),
these tests will fail.

Instead of adding a runtime check, indicate the dependency on
CONFIG_USER_NS in the selftest config file. This allows the
test runner to skip the tests if the required config is not enabled.

Signed-off-by: Wake Liu <wakel@google.com>
---
V1 -> V2: Use selftest config to declare dependency instead of a runtime check.
---
 tools/testing/selftests/filesystems/binderfs/config | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/filesystems/binderfs/config b/tools/testing/selftests/filesystems/binderfs/config
index 7b4fc6ee6205..7d5f941d03a8 100644
--- a/tools/testing/selftests/filesystems/binderfs/config
+++ b/tools/testing/selftests/filesystems/binderfs/config
@@ -1,2 +1,3 @@
 CONFIG_ANDROID_BINDERFS=y
 CONFIG_ANDROID_BINDER_IPC=y
+CONFIG_USER_NS=y
\ No newline at end of file
-- 
2.50.1.703.g449372360f-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-09  9:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-07 13:45 [PATCH] selftests/filesystems/binderfs: Skip tests if user namespaces are unavailable Wake Liu
2025-08-07 19:24 ` Shuah Khan
2025-08-09  9:26   ` [PATCH v2] selftests/binderfs: Add CONFIG_USER_NS dependency Wake Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).