Skip to content

Commit 0ed4b33

Browse files
committed
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: Daniel Borkmann <[email protected]>
1 parent 4434e18 commit 0ed4b33

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

tools/testing/selftests/bpf/prog_tests/tc_helpers.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,25 @@ static inline __u32 ifindex_from_link_fd(int fd)
4545
return link_info.tcx.ifindex;
4646
}
4747

48-
static inline void __assert_mprog_count(int target, int expected, bool miniq, int ifindex)
48+
static inline void __assert_mprog_count(int target, int expected, int ifindex)
4949
{
5050
__u32 count = 0, attach_flags = 0;
5151
int err;
5252

5353
err = bpf_prog_query(ifindex, target, 0, &attach_flags,
5454
NULL, &count);
5555
ASSERT_EQ(count, expected, "count");
56-
if (!expected && !miniq)
57-
ASSERT_EQ(err, -ENOENT, "prog_query");
58-
else
59-
ASSERT_EQ(err, 0, "prog_query");
56+
ASSERT_EQ(err, 0, "prog_query");
6057
}
6158

6259
static inline void assert_mprog_count(int target, int expected)
6360
{
64-
__assert_mprog_count(target, expected, false, loopback);
61+
__assert_mprog_count(target, expected, loopback);
6562
}
6663

6764
static inline void assert_mprog_count_ifindex(int ifindex, int target, int expected)
6865
{
69-
__assert_mprog_count(target, expected, false, ifindex);
66+
__assert_mprog_count(target, expected, ifindex);
7067
}
7168

7269
#endif /* TC_HELPERS */

tools/testing/selftests/bpf/prog_tests/tc_links.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ static void test_tc_chain_mixed(int target)
16671667
if (!ASSERT_OK(err, "prog_detach"))
16681668
goto cleanup;
16691669

1670-
__assert_mprog_count(target, 0, true, loopback);
1670+
assert_mprog_count(target, 0);
16711671

16721672
ASSERT_OK(system(ping_cmd), ping_cmd);
16731673

tools/testing/selftests/bpf/prog_tests/tc_opts.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ static void test_tc_chain_classic(int target, bool chain_tc_old)
635635
if (!ASSERT_OK(err, "prog_detach"))
636636
goto cleanup;
637637

638-
__assert_mprog_count(target, 0, chain_tc_old, loopback);
638+
assert_mprog_count(target, 0);
639639
cleanup:
640640
if (tc_attached) {
641641
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)
22502250
BPF_TC_INGRESS : BPF_TC_EGRESS;
22512251
err = bpf_tc_hook_create(&tc_hook);
22522252
ASSERT_OK(err, "bpf_tc_hook_create");
2253-
__assert_mprog_count(target, 0, true, loopback);
2253+
assert_mprog_count(target, 0);
22542254
}
22552255
err = bpf_prog_detach_opts(0, loopback, target, &optd);
22562256
ASSERT_EQ(err, -ENOENT, "prog_detach");
@@ -2352,7 +2352,7 @@ static void test_tc_chain_mixed(int target)
23522352
cleanup_opts:
23532353
err = bpf_prog_detach_opts(detach_fd, loopback, target, &optd);
23542354
ASSERT_OK(err, "prog_detach");
2355-
__assert_mprog_count(target, 0, true, loopback);
2355+
assert_mprog_count(target, 0);
23562356

23572357
ASSERT_OK(system(ping_cmd), ping_cmd);
23582358

0 commit comments

Comments
 (0)