On Wed, Oct 9, 2019 at 9:15 PM Alexei Starovoitov <[email protected]> wrote:
>
> Load basic cls_bpf program.
> Load raw_tracepoint program and attach to kfree_skb raw tracepoint.
> Trigger cls_bpf via prog_test_run.
> At the end of test_run kernel will call kfree_skb
> which will trigger trace_kfree_skb tracepoint.
> Which will call our raw_tracepoint program.
> Which will take that skb and will dump it into perf ring buffer.
> Check that user space received correct packet.
>
> Signed-off-by: Alexei Starovoitov <[email protected]>
> Acked-by: Andrii Nakryiko <[email protected]>
> ---
> .../selftests/bpf/prog_tests/kfree_skb.c | 90 +++++++++++++++++++
> tools/testing/selftests/bpf/progs/kfree_skb.c | 74 +++++++++++++++
> 2 files changed, 164 insertions(+)
> create mode 100644 tools/testing/selftests/bpf/prog_tests/kfree_skb.c
> create mode 100644 tools/testing/selftests/bpf/progs/kfree_skb.c
>
[...]
> +
> +void test_kfree_skb(void)
> +{
> + struct bpf_prog_load_attr attr = {
> + .file = "./kfree_skb.o",
> + .log_level = 2,
This is rather verbose and memory-consuming. Do you really want to
leave it at 2?
> + };
> +
> + struct bpf_object *obj, *obj2 = NULL;
> + struct perf_buffer_opts pb_opts = {};
> + struct perf_buffer *pb = NULL;
> + struct bpf_link *link = NULL;
> + struct bpf_map *perf_buf_map;
> + struct bpf_program *prog;
> + __u32 duration, retval;
> + int err, pkt_fd, kfree_skb_fd;
> + bool passed = false;
> +
[...]