Skip to contentSkip to conversation

selftests: bpf: test BPF_PROG_QUERY for progs attached to sockmap

PATCH zhudi (E) 1 participant 1 message Jan 21, 2022 BPF

lore
Share & tools
lore

zhudi (E)

author
#0 lore raw
Quoted 54 lines
Quoted 11 lines

Add test for querying progs attached to sockmap. we use an existing libbpf query interface to query prog cnt before and after progs attaching to sockmap and check whether the queried prog id is right.

---
 .../selftests/bpf/prog_tests/sockmap_basic.c  | 66 +++++++++++++++++++
 .../bpf/progs/test_sockmap_progs_query.c      | 24 +++++++
 2 files changed, 90 insertions(+)
 create mode 100644

tools/testing/selftests/bpf/progs/test_sockmap_progs_query.c

Review

Quoted 2 lines
(quoted diff) +0 -0

b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c

tools/testing/selftests/bpf/prog_tests/sockmap_basic.c line 14

Quoted 11 lines

index 85db0f4cdd95..1ab57cdc4ae4 100644

tools/testing/selftests/bpf/prog_tests/sockmap_basic.c +1 -0
@@ -8,6 +8,7 @@
 #include "test_sockmap_update.skel.h"
 #include "test_sockmap_invalid_update.skel.h"
 #include "test_sockmap_skb_verdict_attach.skel.h"
+#include "test_sockmap_progs_query.skel.h"
 #include "bpf_iter_sockmap.skel.h"
 
 #define TCP_REPAIR             19      /* TCP sock is under repair

right now */

tools/testing/selftests/bpf/prog_tests/sockmap_basic.c static void test_sockmap_skb_verdict_attach(enum

Quoted 1 line
tools/testing/selftests/bpf/prog_tests/sockmap_basic.c +0 -0
@@ -315,6 +316,63 @@ static void test_sockmap_skb_verdict_attach(enum

bpf_attach_type first,

Quoted 11 lines
tools/testing/selftests/bpf/prog_tests/sockmap_basic.c +8 -0
        test_sockmap_skb_verdict_attach__destroy(skel);
 }
 
+static __u32 query_prog_id(int prog_fd)
+{
+       struct bpf_prog_info info = {};
+       __u32 info_len = sizeof(info);
+       int err;
+
+       err = bpf_obj_get_info_by_fd(prog_fd, &info, &info_len);
+       if (!ASSERT_OK(err, "bpf_obj_get_info_by_fd") ||

tools/testing/selftests/bpf/prog_tests/sockmap_basic.c static void test_sockmap_skb_verdict_attach(enum · line 336

Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/sockmap_basic.c +10 -0
+           !ASSERT_EQ(info_len, sizeof(info), "bpf_obj_get_info_by_fd"))
+               return 0;
+
+       return info.id;
+}
+
+static void test_sockmap_progs_query(enum bpf_attach_type attach_type)
+{
+       struct test_sockmap_progs_query *skel;
+       int err, map_fd, verdict_fd, duration = 0;

The 'duration' is unused.
You should have seen a warning while compiling the selftests?

Quoted 1 line

Anyway. I've fixed it while applying.

Thank you. I'll be more careful next time.