Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/namespaces: seventh listns() test

Test listns() with multiple namespace types filter.

Link: https://patch.msgid.link/20251029-work-namespace-nstree-listns-v4-45-2e6f823ebdc0@kernel.org
Tested-by: syzbot@syzkaller.appspotmail.com
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>

+31
+31
tools/testing/selftests/namespaces/listns_test.c
··· 446 446 waitpid(pid, &status, 0); 447 447 } 448 448 449 + /* 450 + * Test listns() with multiple namespace types filter. 451 + */ 452 + TEST(listns_multiple_types) 453 + { 454 + struct ns_id_req req = { 455 + .size = sizeof(req), 456 + .spare = 0, 457 + .ns_id = 0, 458 + .ns_type = CLONE_NEWNET | CLONE_NEWUTS, /* Network and UTS */ 459 + .spare2 = 0, 460 + .user_ns_id = 0, 461 + }; 462 + __u64 ns_ids[100]; 463 + ssize_t ret; 464 + 465 + ret = sys_listns(&req, ns_ids, ARRAY_SIZE(ns_ids), 0); 466 + if (ret < 0) { 467 + if (errno == ENOSYS) 468 + SKIP(return, "listns() not supported"); 469 + TH_LOG("listns failed: %s (errno=%d)", strerror(errno), errno); 470 + ASSERT_TRUE(false); 471 + } 472 + ASSERT_GE(ret, 0); 473 + 474 + TH_LOG("Found %zd active network/UTS namespaces", ret); 475 + 476 + for (ssize_t i = 0; i < ret; i++) 477 + TH_LOG(" [%zd] ns_id: %llu", i, (unsigned long long)ns_ids[i]); 478 + } 479 + 449 480 TEST_HARNESS_MAIN