On 4/2/24 6:17 AM, Eduard Zingerman wrote:
On Mon, 2024-03-25 at 19:22 -0700, Yonghong Song wrote:
Add a few more tests in sockmap_basic.c and sockmap_listen.c to
test bpf_link based APIs for SK_MSG and SK_SKB programs.
Link attach/detach/update are all tested.
All tests are passed.
Signed-off-by: Yonghong Song <yonghong.song@xxxxxxxxx>
---
Acked-by: Eduard Zingerman <eddyz87@xxxxxxxxx>
As far as I understand patch #1 there are several error conditions
that are not covered by these tests:
- update link using program with wrong expected attach type;
- bpf_program__attach_sockmap() _after_ bpf_prog_attach();
- creation of a second link between same prog and map
(if I understand 'link && link != progs->msg_parser_link' checks in
sock_map_link_lookup() correctly).
Are these important enough to have a dedicated test?
All these are missed. I can add them in the next revision.
[...]
diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
index 63fb2da7930a..b4b38f92b864 100644
--- a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
+++ b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
@@ -131,6 +131,40 @@ static void test_skmsg_helpers(enum bpf_map_type map_type)
test_skmsg_load_helpers__destroy(skel);
}
+static void test_skmsg_helpers_with_link(enum bpf_map_type map_type)
+{
+ struct test_skmsg_load_helpers *skel;
+ struct bpf_link *link, *link2;
+ struct bpf_program *prog;
+ int err, map;
+
+ skel = test_skmsg_load_helpers__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "test_skmsg_load_helpers__open_and_load"))
+ return;
+
+ prog = skel->progs.prog_msg_verdict;
+ map = bpf_map__fd(skel->maps.sock_map);
+
+ link = bpf_program__attach_sockmap(prog, map);
+ if (!ASSERT_OK_PTR(link, "bpf_program__attach_sockmap"))
+ goto out;
+
+ err = bpf_prog_attach(bpf_program__fd(prog), map, BPF_SK_MSG_VERDICT, 0);
+ if (!ASSERT_ERR(err, "bpf_prog_attach"))
+ goto out;
+
+ link2 = bpf_program__attach_sockmap(skel->progs.prog_msg_verdict_clone, map);
+ if (!ASSERT_ERR_PTR(link2, "bpf_program__attach_sockmap"))
+ goto out;
Nit: should bpf_link__detach(link2) be called before 'goto out' ?
Yes, we should do this although it will auto detach when test_progs exists.
+
+ err = bpf_link__update_program(link, skel->progs.prog_msg_verdict_clone);
+ ASSERT_OK(err, "bpf_link__update_program");
+
+out:
+ bpf_link__detach(link);
+ test_skmsg_load_helpers__destroy(skel);
+}
+
static void test_sockmap_update(enum bpf_map_type map_type)
{
int err, prog, src;