Skip to content

Commit

Permalink
selftest/bpf: Test query on empty mprog and pass revision into attach
Browse files Browse the repository at this point in the history
  ./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
  torvalds#252     tc_opts_after:OK
  torvalds#253     tc_opts_append:OK
  torvalds#254     tc_opts_basic:OK
  torvalds#255     tc_opts_before:OK
  torvalds#256     tc_opts_chain_classic:OK
  torvalds#257     tc_opts_chain_mixed:OK
  torvalds#258     tc_opts_delete_empty:OK
  torvalds#259     tc_opts_demixed:OK
  torvalds#260     tc_opts_detach:OK
  torvalds#261     tc_opts_detach_after:OK
  torvalds#262     tc_opts_detach_before:OK
  torvalds#263     tc_opts_dev_cleanup:OK
  torvalds#264     tc_opts_invalid:OK
  torvalds#265     tc_opts_max:OK
  torvalds#266     tc_opts_mixed:OK
  torvalds#267     tc_opts_prepend:OK
  torvalds#268     tc_opts_query:OK
  torvalds#269     tc_opts_query_attach:OK     <--- (new test)
  torvalds#270     tc_opts_replace:OK
  torvalds#271     tc_opts_revision:OK
  Summary: 20/0 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
  • Loading branch information
borkmann committed Oct 5, 2023
1 parent 07673c4 commit d2f12b2
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 d2f12b2

Please sign in to comment.