Skip to content

Commit

Permalink
selftests/bpf: Test query on empty mprog and pass revision into attach
Browse files Browse the repository at this point in the history
Add a new test case to query on an empty bpf_mprog and pass the revision
directly into expected_revision for attachment to assert that this does
succeed.

  ./test_progs -t tc_opts
  [    1.406778] tsc: Refined TSC clocksource calibration: 3407.990 MHz
  [    1.408863] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x311fcaf6eb0, max_idle_ns: 440795321766 ns
  [    1.412419] clocksource: Switched to clocksource tsc
  [    1.428671] bpf_testmod: loading out-of-tree module taints kernel.
  [    1.430260] bpf_testmod: module verification failed: signature and/or required key missing - tainting kernel
  rockchip-linux#252     tc_opts_after:OK
  rockchip-linux#253     tc_opts_append:OK
  rockchip-linux#254     tc_opts_basic:OK
  rockchip-linux#255     tc_opts_before:OK
  rockchip-linux#256     tc_opts_chain_classic:OK
  rockchip-linux#257     tc_opts_chain_mixed:OK
  rockchip-linux#258     tc_opts_delete_empty:OK
  rockchip-linux#259     tc_opts_demixed:OK
  rockchip-linux#260     tc_opts_detach:OK
  rockchip-linux#261     tc_opts_detach_after:OK
  rockchip-linux#262     tc_opts_detach_before:OK
  rockchip-linux#263     tc_opts_dev_cleanup:OK
  rockchip-linux#264     tc_opts_invalid:OK
  rockchip-linux#265     tc_opts_max:OK
  rockchip-linux#266     tc_opts_mixed:OK
  rockchip-linux#267     tc_opts_prepend:OK
  rockchip-linux#268     tc_opts_query:OK
  rockchip-linux#269     tc_opts_query_attach:OK     <--- (new test)
  rockchip-linux#270     tc_opts_replace:OK
  rockchip-linux#271     tc_opts_revision:OK
  Summary: 20/0 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Daniel Borkmann <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Martin KaFai Lau <[email protected]>
  • Loading branch information
borkmann authored and Martin KaFai Lau committed Oct 7, 2023
1 parent b773682 commit 685446b
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tools/testing/selftests/bpf/prog_tests/tc_opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -2629,3 +2629,62 @@ void serial_test_tc_opts_query(void)
test_tc_opts_query_target(BPF_TCX_INGRESS);
test_tc_opts_query_target(BPF_TCX_EGRESS);
}

static void test_tc_opts_query_attach_target(int target)
{
LIBBPF_OPTS(bpf_prog_attach_opts, opta);
LIBBPF_OPTS(bpf_prog_detach_opts, optd);
LIBBPF_OPTS(bpf_prog_query_opts, optq);
struct test_tc_link *skel;
__u32 prog_ids[2];
__u32 fd1, id1;
int err;

skel = test_tc_link__open_and_load();
if (!ASSERT_OK_PTR(skel, "skel_load"))
goto cleanup;

fd1 = bpf_program__fd(skel->progs.tc1);
id1 = id_from_prog_fd(fd1);

err = bpf_prog_query_opts(loopback, target, &optq);
if (!ASSERT_OK(err, "prog_query"))
goto cleanup;

ASSERT_EQ(optq.count, 0, "count");
ASSERT_EQ(optq.revision, 1, "revision");

LIBBPF_OPTS_RESET(opta,
.expected_revision = optq.revision,
);

err = bpf_prog_attach_opts(fd1, loopback, target, &opta);
if (!ASSERT_EQ(err, 0, "prog_attach"))
goto cleanup;

memset(prog_ids, 0, sizeof(prog_ids));
optq.prog_ids = prog_ids;
optq.count = ARRAY_SIZE(prog_ids);

err = bpf_prog_query_opts(loopback, target, &optq);
if (!ASSERT_OK(err, "prog_query"))
goto cleanup1;

ASSERT_EQ(optq.count, 1, "count");
ASSERT_EQ(optq.revision, 2, "revision");
ASSERT_EQ(optq.prog_ids[0], id1, "prog_ids[0]");
ASSERT_EQ(optq.prog_ids[1], 0, "prog_ids[1]");

cleanup1:
err = bpf_prog_detach_opts(fd1, loopback, target, &optd);
ASSERT_OK(err, "prog_detach");
assert_mprog_count(target, 0);
cleanup:
test_tc_link__destroy(skel);
}

void serial_test_tc_opts_query_attach(void)
{
test_tc_opts_query_attach_target(BPF_TCX_INGRESS);
test_tc_opts_query_attach_target(BPF_TCX_EGRESS);
}

0 comments on commit 685446b

Please sign in to comment.