Commit b7736826 authored by Daniel Borkmann's avatar Daniel Borkmann Committed by Martin KaFai Lau

selftests/bpf: Adapt assert_mprog_count to always expect 0 count

Simplify __assert_mprog_count() to remove the -ENOENT corner case as the
bpf_prog_query() now returns 0 when no bpf_mprog is attached. This also
allows to convert a few test cases from using raw __assert_mprog_count()
over to plain assert_mprog_count() helper.
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/r/20231006220655.1653-5-daniel@iogearbox.netSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
parent f9b08790
...@@ -45,7 +45,7 @@ static inline __u32 ifindex_from_link_fd(int fd) ...@@ -45,7 +45,7 @@ static inline __u32 ifindex_from_link_fd(int fd)
return link_info.tcx.ifindex; return link_info.tcx.ifindex;
} }
static inline void __assert_mprog_count(int target, int expected, bool miniq, int ifindex) static inline void __assert_mprog_count(int target, int expected, int ifindex)
{ {
__u32 count = 0, attach_flags = 0; __u32 count = 0, attach_flags = 0;
int err; int err;
...@@ -53,20 +53,17 @@ static inline void __assert_mprog_count(int target, int expected, bool miniq, in ...@@ -53,20 +53,17 @@ static inline void __assert_mprog_count(int target, int expected, bool miniq, in
err = bpf_prog_query(ifindex, target, 0, &attach_flags, err = bpf_prog_query(ifindex, target, 0, &attach_flags,
NULL, &count); NULL, &count);
ASSERT_EQ(count, expected, "count"); ASSERT_EQ(count, expected, "count");
if (!expected && !miniq) ASSERT_EQ(err, 0, "prog_query");
ASSERT_EQ(err, -ENOENT, "prog_query");
else
ASSERT_EQ(err, 0, "prog_query");
} }
static inline void assert_mprog_count(int target, int expected) static inline void assert_mprog_count(int target, int expected)
{ {
__assert_mprog_count(target, expected, false, loopback); __assert_mprog_count(target, expected, loopback);
} }
static inline void assert_mprog_count_ifindex(int ifindex, int target, int expected) static inline void assert_mprog_count_ifindex(int ifindex, int target, int expected)
{ {
__assert_mprog_count(target, expected, false, ifindex); __assert_mprog_count(target, expected, ifindex);
} }
#endif /* TC_HELPERS */ #endif /* TC_HELPERS */
...@@ -1667,7 +1667,7 @@ static void test_tc_chain_mixed(int target) ...@@ -1667,7 +1667,7 @@ static void test_tc_chain_mixed(int target)
if (!ASSERT_OK(err, "prog_detach")) if (!ASSERT_OK(err, "prog_detach"))
goto cleanup; goto cleanup;
__assert_mprog_count(target, 0, true, loopback); assert_mprog_count(target, 0);
ASSERT_OK(system(ping_cmd), ping_cmd); ASSERT_OK(system(ping_cmd), ping_cmd);
......
...@@ -635,7 +635,7 @@ static void test_tc_chain_classic(int target, bool chain_tc_old) ...@@ -635,7 +635,7 @@ static void test_tc_chain_classic(int target, bool chain_tc_old)
if (!ASSERT_OK(err, "prog_detach")) if (!ASSERT_OK(err, "prog_detach"))
goto cleanup; goto cleanup;
__assert_mprog_count(target, 0, chain_tc_old, loopback); assert_mprog_count(target, 0);
cleanup: cleanup:
if (tc_attached) { if (tc_attached) {
tc_opts.flags = tc_opts.prog_fd = tc_opts.prog_id = 0; tc_opts.flags = tc_opts.prog_fd = tc_opts.prog_id = 0;
...@@ -2250,7 +2250,7 @@ static void test_tc_opts_delete_empty(int target, bool chain_tc_old) ...@@ -2250,7 +2250,7 @@ static void test_tc_opts_delete_empty(int target, bool chain_tc_old)
BPF_TC_INGRESS : BPF_TC_EGRESS; BPF_TC_INGRESS : BPF_TC_EGRESS;
err = bpf_tc_hook_create(&tc_hook); err = bpf_tc_hook_create(&tc_hook);
ASSERT_OK(err, "bpf_tc_hook_create"); ASSERT_OK(err, "bpf_tc_hook_create");
__assert_mprog_count(target, 0, true, loopback); assert_mprog_count(target, 0);
} }
err = bpf_prog_detach_opts(0, loopback, target, &optd); err = bpf_prog_detach_opts(0, loopback, target, &optd);
ASSERT_EQ(err, -ENOENT, "prog_detach"); ASSERT_EQ(err, -ENOENT, "prog_detach");
...@@ -2352,7 +2352,7 @@ static void test_tc_chain_mixed(int target) ...@@ -2352,7 +2352,7 @@ static void test_tc_chain_mixed(int target)
cleanup_opts: cleanup_opts:
err = bpf_prog_detach_opts(detach_fd, loopback, target, &optd); err = bpf_prog_detach_opts(detach_fd, loopback, target, &optd);
ASSERT_OK(err, "prog_detach"); ASSERT_OK(err, "prog_detach");
__assert_mprog_count(target, 0, true, loopback); assert_mprog_count(target, 0);
ASSERT_OK(system(ping_cmd), ping_cmd); ASSERT_OK(system(ping_cmd), ping_cmd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment