Skip to content

Commit

Permalink
selftests/bpf: Add test for detachment on empty mprog entry
Browse files Browse the repository at this point in the history
Add a detachment test case with miniq present to assert that with and
without the miniq we get the same error.

  # ./test_progs -t tc_opts
  torvalds#244     tc_opts_after:OK
  torvalds#245     tc_opts_append:OK
  torvalds#246     tc_opts_basic:OK
  torvalds#247     tc_opts_before:OK
  torvalds#248     tc_opts_chain_classic:OK
  torvalds#249     tc_opts_delete_empty:OK
  torvalds#250     tc_opts_demixed:OK
  torvalds#251     tc_opts_detach:OK
  torvalds#252     tc_opts_detach_after:OK
  torvalds#253     tc_opts_detach_before:OK
  torvalds#254     tc_opts_dev_cleanup:OK
  torvalds#255     tc_opts_invalid:OK
  torvalds#256     tc_opts_mixed:OK
  torvalds#257     tc_opts_prepend:OK
  torvalds#258     tc_opts_replace:OK
  torvalds#259     tc_opts_revision:OK
  Summary: 16/0 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/r/20230804131112.11012-2-daniel@iogearbox.net
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
  • Loading branch information
borkmann authored and Martin KaFai Lau committed Aug 4, 2023
1 parent d210f97 commit 21ce6ab
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tools/testing/selftests/bpf/prog_tests/tc_opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -2237,3 +2237,34 @@ void serial_test_tc_opts_detach_after(void)
test_tc_opts_detach_after_target(BPF_TCX_INGRESS);
test_tc_opts_detach_after_target(BPF_TCX_EGRESS);
}

static void test_tc_opts_delete_empty(int target, bool chain_tc_old)
{
LIBBPF_OPTS(bpf_tc_hook, tc_hook, .ifindex = loopback);
LIBBPF_OPTS(bpf_prog_detach_opts, optd);
int err;

assert_mprog_count(target, 0);
if (chain_tc_old) {
tc_hook.attach_point = target == BPF_TCX_INGRESS ?
BPF_TC_INGRESS : BPF_TC_EGRESS;
err = bpf_tc_hook_create(&tc_hook);
ASSERT_OK(err, "bpf_tc_hook_create");
__assert_mprog_count(target, 0, true, loopback);
}
err = bpf_prog_detach_opts(0, loopback, target, &optd);
ASSERT_EQ(err, -ENOENT, "prog_detach");
if (chain_tc_old) {
tc_hook.attach_point = BPF_TC_INGRESS | BPF_TC_EGRESS;
bpf_tc_hook_destroy(&tc_hook);
}
assert_mprog_count(target, 0);
}

void serial_test_tc_opts_delete_empty(void)
{
test_tc_opts_delete_empty(BPF_TCX_INGRESS, false);
test_tc_opts_delete_empty(BPF_TCX_EGRESS, false);
test_tc_opts_delete_empty(BPF_TCX_INGRESS, true);
test_tc_opts_delete_empty(BPF_TCX_EGRESS, true);
}

0 comments on commit 21ce6ab

Please sign in to comment.