[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2656c9ec-3d33-4646-8653-5b8069ec38bb@fb.com>
Date: Wed, 21 Apr 2021 00:01:39 -0700
From: Yonghong Song <yhs@...com>
To: Kumar Kartikeya Dwivedi <memxor@...il.com>, <bpf@...r.kernel.org>
CC: Toke Høiland-Jørgensen <toke@...hat.com>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Jesper Dangaard Brouer <brouer@...hat.com>,
<netdev@...r.kernel.org>
Subject: Re: [PATCH bpf-next v3 3/3] libbpf: add selftests for TC-BPF API
On 4/20/21 12:37 PM, Kumar Kartikeya Dwivedi wrote:
> This adds some basic tests for the low level bpf_tc_* API.
>
> Reviewed-by: Toke Høiland-Jørgensen <toke@...hat.com>
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@...il.com>
> ---
> .../selftests/bpf/prog_tests/test_tc_bpf.c | 169 ++++++++++++++++++
> .../selftests/bpf/progs/test_tc_bpf_kern.c | 12 ++
> 2 files changed, 181 insertions(+)
> create mode 100644 tools/testing/selftests/bpf/prog_tests/test_tc_bpf.c
> create mode 100644 tools/testing/selftests/bpf/progs/test_tc_bpf_kern.c
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/test_tc_bpf.c b/tools/testing/selftests/bpf/prog_tests/test_tc_bpf.c
> new file mode 100644
> index 000000000000..563a3944553c
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/test_tc_bpf.c
> @@ -0,0 +1,169 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <linux/bpf.h>
> +#include <linux/err.h>
> +#include <linux/limits.h>
> +#include <bpf/libbpf.h>
> +#include <errno.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <test_progs.h>
> +#include <linux/if_ether.h>
> +
> +#define LO_IFINDEX 1
> +
[...]
> +
> +void test_test_tc_bpf(void)
> +{
> + const char *file = "./test_tc_bpf_kern.o";
> + struct bpf_program *clsp;
> + struct bpf_object *obj;
> + int cls_fd, ret;
> +
> + obj = bpf_object__open(file);
> + if (!ASSERT_OK_PTR(obj, "bpf_object__open"))
> + return;
> +
> + clsp = bpf_object__find_program_by_title(obj, "classifier");
> + if (!ASSERT_OK_PTR(clsp, "bpf_object__find_program_by_title"))
> + goto end;
Please use bpf_object__find_program_by_name() API.
> +
> + ret = bpf_object__load(obj);
> + if (!ASSERT_EQ(ret, 0, "bpf_object__load"))
> + goto end;
> +
> + cls_fd = bpf_program__fd(clsp);
> +
> + system("tc qdisc del dev lo clsact");
> +
> + ret = test_tc_internal(cls_fd, BPF_TC_CLSACT_INGRESS);
> + if (!ASSERT_EQ(ret, 0, "test_tc_internal INGRESS"))
> + goto end;
> +
> + if (!ASSERT_EQ(system("tc qdisc del dev lo clsact"), 0,
> + "clsact qdisc delete failed"))
> + goto end;
> +
> + ret = test_tc_info(cls_fd);
> + if (!ASSERT_EQ(ret, 0, "test_tc_info"))
> + goto end;
> +
> + if (!ASSERT_EQ(system("tc qdisc del dev lo clsact"), 0,
> + "clsact qdisc delete failed"))
> + goto end;
> +
> + ret = test_tc_internal(cls_fd, BPF_TC_CLSACT_EGRESS);
> + if (!ASSERT_EQ(ret, 0, "test_tc_internal EGRESS"))
> + goto end;
> +
> + ASSERT_EQ(system("tc qdisc del dev lo clsact"), 0,
> + "clsact qdisc delete failed");
> +
> +end:
> + bpf_object__close(obj);
> +}
> diff --git a/tools/testing/selftests/bpf/progs/test_tc_bpf_kern.c b/tools/testing/selftests/bpf/progs/test_tc_bpf_kern.c
> new file mode 100644
> index 000000000000..18a3a7ed924a
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/test_tc_bpf_kern.c
> @@ -0,0 +1,12 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <linux/bpf.h>
> +#include <bpf/bpf_helpers.h>
> +
> +/* Dummy prog to test TC-BPF API */
> +
> +SEC("classifier")
> +int cls(struct __sk_buff *skb)
> +{
> + return 0;
> +}
>
Powered by blists - more mailing lists