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

selftests/bpf: ns_current_pid_tgid: Use test_progs's ns_ feature

Two subtests use the test_in_netns() function to run the test in a
dedicated network namespace. This can now be done directly through the
test_progs framework with a test name starting with 'ns_'.

Replace the use of test_in_netns() by test_ns_* calls.

Signed-off-by: Bastien Curutchet (eBPF Foundation) <bastien.curutchet@bootlin.com>
Link: https://lore.kernel.org/r/20250219-b4-tc_links-v2-4-14504db136b7@bootlin.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

+17 -30
+17 -30
tools/testing/selftests/bpf/prog_tests/ns_current_pid_tgid.c
··· 200 200 return; 201 201 } 202 202 203 - static void test_in_netns(int (*fn)(void *), void *arg) 204 - { 205 - struct nstoken *nstoken = NULL; 206 - 207 - SYS(cleanup, "ip netns add ns_current_pid_tgid"); 208 - SYS(cleanup, "ip -net ns_current_pid_tgid link set dev lo up"); 209 - 210 - nstoken = open_netns("ns_current_pid_tgid"); 211 - if (!ASSERT_OK_PTR(nstoken, "open_netns")) 212 - goto cleanup; 213 - 214 - test_ns_current_pid_tgid_new_ns(fn, arg); 215 - 216 - cleanup: 217 - if (nstoken) 218 - close_netns(nstoken); 219 - SYS_NOFAIL("ip netns del ns_current_pid_tgid"); 220 - } 221 - 222 203 /* TODO: use a different tracepoint */ 223 204 void serial_test_current_pid_tgid(void) 224 205 { ··· 207 226 test_current_pid_tgid_tp(NULL); 208 227 if (test__start_subtest("new_ns_tp")) 209 228 test_ns_current_pid_tgid_new_ns(test_current_pid_tgid_tp, NULL); 210 - if (test__start_subtest("new_ns_cgrp")) { 211 - int cgroup_fd = -1; 212 - 213 - cgroup_fd = test__join_cgroup("/sock_addr"); 214 - if (ASSERT_GE(cgroup_fd, 0, "join_cgroup")) { 215 - test_in_netns(test_current_pid_tgid_cgrp, &cgroup_fd); 216 - close(cgroup_fd); 217 - } 218 - } 219 - if (test__start_subtest("new_ns_sk_msg")) 220 - test_in_netns(test_current_pid_tgid_sk_msg, NULL); 221 229 } 230 + 231 + void test_ns_current_pid_tgid_cgrp(void) 232 + { 233 + int cgroup_fd = test__join_cgroup("/sock_addr"); 234 + 235 + if (ASSERT_OK_FD(cgroup_fd, "join_cgroup")) { 236 + test_ns_current_pid_tgid_new_ns(test_current_pid_tgid_cgrp, &cgroup_fd); 237 + close(cgroup_fd); 238 + } 239 + } 240 + 241 + void test_ns_current_pid_tgid_sk_msg(void) 242 + { 243 + test_ns_current_pid_tgid_new_ns(test_current_pid_tgid_sk_msg, NULL); 244 + } 245 + 246 +