Skip to content

Commit fb2eb33

Browse files
borkmannhonjow
authored andcommitted
selftests/bpf: Test query on empty mprog and pass revision into attach
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 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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin KaFai Lau <[email protected]>
1 parent 6cbba87 commit fb2eb33

File tree

1 file changed

+59
-0
lines changed
  • tools/testing/selftests/bpf/prog_tests

1 file changed

+59
-0
lines changed

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

+59
Original file line numberDiff line numberDiff line change
@@ -2629,3 +2629,62 @@ void serial_test_tc_opts_query(void)
26292629
test_tc_opts_query_target(BPF_TCX_INGRESS);
26302630
test_tc_opts_query_target(BPF_TCX_EGRESS);
26312631
}
2632+
2633+
static void test_tc_opts_query_attach_target(int target)
2634+
{
2635+
LIBBPF_OPTS(bpf_prog_attach_opts, opta);
2636+
LIBBPF_OPTS(bpf_prog_detach_opts, optd);
2637+
LIBBPF_OPTS(bpf_prog_query_opts, optq);
2638+
struct test_tc_link *skel;
2639+
__u32 prog_ids[2];
2640+
__u32 fd1, id1;
2641+
int err;
2642+
2643+
skel = test_tc_link__open_and_load();
2644+
if (!ASSERT_OK_PTR(skel, "skel_load"))
2645+
goto cleanup;
2646+
2647+
fd1 = bpf_program__fd(skel->progs.tc1);
2648+
id1 = id_from_prog_fd(fd1);
2649+
2650+
err = bpf_prog_query_opts(loopback, target, &optq);
2651+
if (!ASSERT_OK(err, "prog_query"))
2652+
goto cleanup;
2653+
2654+
ASSERT_EQ(optq.count, 0, "count");
2655+
ASSERT_EQ(optq.revision, 1, "revision");
2656+
2657+
LIBBPF_OPTS_RESET(opta,
2658+
.expected_revision = optq.revision,
2659+
);
2660+
2661+
err = bpf_prog_attach_opts(fd1, loopback, target, &opta);
2662+
if (!ASSERT_EQ(err, 0, "prog_attach"))
2663+
goto cleanup;
2664+
2665+
memset(prog_ids, 0, sizeof(prog_ids));
2666+
optq.prog_ids = prog_ids;
2667+
optq.count = ARRAY_SIZE(prog_ids);
2668+
2669+
err = bpf_prog_query_opts(loopback, target, &optq);
2670+
if (!ASSERT_OK(err, "prog_query"))
2671+
goto cleanup1;
2672+
2673+
ASSERT_EQ(optq.count, 1, "count");
2674+
ASSERT_EQ(optq.revision, 2, "revision");
2675+
ASSERT_EQ(optq.prog_ids[0], id1, "prog_ids[0]");
2676+
ASSERT_EQ(optq.prog_ids[1], 0, "prog_ids[1]");
2677+
2678+
cleanup1:
2679+
err = bpf_prog_detach_opts(fd1, loopback, target, &optd);
2680+
ASSERT_OK(err, "prog_detach");
2681+
assert_mprog_count(target, 0);
2682+
cleanup:
2683+
test_tc_link__destroy(skel);
2684+
}
2685+
2686+
void serial_test_tc_opts_query_attach(void)
2687+
{
2688+
test_tc_opts_query_attach_target(BPF_TCX_INGRESS);
2689+
test_tc_opts_query_attach_target(BPF_TCX_EGRESS);
2690+
}

0 commit comments

Comments
 (0)