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

selftests/bpf: Test struct_ops bpf map auto-attach

Adding selftest to verify that struct_ops maps are auto attached by
bpf skeleton's `*__attach` function.

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20240621180324.238379-1-yatsenko@meta.com

authored by

Mykyta Yatsenko and committed by
Andrii Nakryiko
cd387ce5 2bb138cb

+35
+35
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
··· 185 185 close(fd); 186 186 } 187 187 188 + static void test_dctcp_autoattach_map(void) 189 + { 190 + struct cb_opts cb_opts = { 191 + .cc = "bpf_dctcp", 192 + }; 193 + struct network_helper_opts opts = { 194 + .post_socket_cb = cc_cb, 195 + .cb_opts = &cb_opts, 196 + }; 197 + struct bpf_dctcp *dctcp_skel; 198 + struct bpf_link *link; 199 + 200 + dctcp_skel = bpf_dctcp__open_and_load(); 201 + if (!ASSERT_OK_PTR(dctcp_skel, "bpf_dctcp__open_and_load")) 202 + return; 203 + 204 + bpf_map__set_autoattach(dctcp_skel->maps.dctcp, true); 205 + bpf_map__set_autoattach(dctcp_skel->maps.dctcp_nouse, false); 206 + 207 + if (!ASSERT_OK(bpf_dctcp__attach(dctcp_skel), "bpf_dctcp__attach")) 208 + goto destroy; 209 + 210 + /* struct_ops is auto-attached */ 211 + link = dctcp_skel->links.dctcp; 212 + if (!ASSERT_OK_PTR(link, "link")) 213 + goto destroy; 214 + 215 + do_test(&opts); 216 + 217 + destroy: 218 + bpf_dctcp__destroy(dctcp_skel); 219 + } 220 + 188 221 static char *err_str; 189 222 static bool found; 190 223 ··· 631 598 test_tcp_ca_kfunc(); 632 599 if (test__start_subtest("cc_cubic")) 633 600 test_cc_cubic(); 601 + if (test__start_subtest("dctcp_autoattach_map")) 602 + test_dctcp_autoattach_map(); 634 603 }