From: Martin KaFai Lau <martin.lau@linux.dev>
To: Amery Hung <ameryhung@gmail.com>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
daniel@iogearbox.net, andrii@kernel.org,
alexei.starovoitov@gmail.com, martin.lau@kernel.org,
sinquersw@gmail.com, toke@redhat.com, jhs@mojatatu.com,
jiri@resnulli.us, stfomichev@gmail.com,
ekarani.silvestre@ccc.ufcg.edu.br, yangpeihao@sjtu.edu.cn,
xiyou.wangcong@gmail.com, yepeilin.cs@gmail.com
Subject: Re: [PATCH bpf-next v2 13/14] selftests: Add a basic fifo qdisc test
Date: Thu, 9 Jan 2025 16:05:20 -0800 [thread overview]
Message-ID: <88e9291e-cd67-4fa2-8a91-d475e29ab832@linux.dev> (raw)
In-Reply-To: <20241220195619.2022866-14-amery.hung@gmail.com>
On 12/20/24 11:55 AM, Amery Hung wrote:
> +static void do_test(char *qdisc)
> +{
> + DECLARE_LIBBPF_OPTS(bpf_tc_hook, hook, .ifindex = LO_IFINDEX,
> + .attach_point = BPF_TC_QDISC,
> + .parent = TC_H_ROOT,
> + .handle = 0x8000000,
> + .qdisc = qdisc);
> + struct sockaddr_in6 sa6 = {};
> + ssize_t nr_recv = 0, bytes = 0;
> + int lfd = -1, fd = -1;
> + pthread_t srv_thread;
> + socklen_t addrlen = sizeof(sa6);
> + void *thread_ret;
> + char batch[1500];
> + int err;
> +
> + WRITE_ONCE(stop, 0);
> +
> + err = bpf_tc_hook_create(&hook);
> + if (!ASSERT_OK(err, "attach qdisc"))
> + return;
> +
> + lfd = start_server(AF_INET6, SOCK_STREAM, NULL, 0, 0);
> + if (!ASSERT_NEQ(lfd, -1, "socket")) {
nit. ASSERT_OK_FD.
> + bpf_tc_hook_destroy(&hook);
> + return;
> + }
> +
> + fd = socket(AF_INET6, SOCK_STREAM, 0);
> + if (!ASSERT_NEQ(fd, -1, "socket")) {
> + bpf_tc_hook_destroy(&hook);
> + close(lfd);
> + return;
> + }
> +
> + if (settimeo(lfd, 0) || settimeo(fd, 0))
> + goto done;
> +
> + err = getsockname(lfd, (struct sockaddr *)&sa6, &addrlen);
> + if (!ASSERT_NEQ(err, -1, "getsockname"))
> + goto done;
> +
> + /* connect to server */
> + err = connect(fd, (struct sockaddr *)&sa6, addrlen);
Instead of socket/getsockname/connect, "fd = connect_to_fd(lfd);" from the
network_helpers.c should do.
The above settimeo({lfd,fd}) is not needed also. The helpers from
network_helpers.c should have already set the default timeout.
> + if (!ASSERT_NEQ(err, -1, "connect"))
> + goto done;
> +
> + err = pthread_create(&srv_thread, NULL, server, (void *)(long)lfd);
> + if (!ASSERT_OK(err, "pthread_create"))
> + goto done;
> +
> + /* recv total_bytes */
> + while (bytes < total_bytes && !READ_ONCE(stop)) {
> + nr_recv = recv(fd, &batch,
> + MIN(total_bytes - bytes, sizeof(batch)), 0);
> + if (nr_recv == -1 && errno == EINTR)
> + continue;
> + if (nr_recv == -1)
> + break;
> + bytes += nr_recv;
> + }
> +
> + ASSERT_EQ(bytes, total_bytes, "recv");
> +
> + WRITE_ONCE(stop, 1);
> + pthread_join(srv_thread, &thread_ret);
> + ASSERT_OK(IS_ERR(thread_ret), "thread_ret");
> +
> +done:
> + close(lfd);
> + close(fd);
> +
> + bpf_tc_hook_destroy(&hook);
> + return;
> +}
> +
> +static void test_fifo(void)
> +{
> + struct bpf_qdisc_fifo *fifo_skel;
> + struct bpf_link *link;
> +
> + fifo_skel = bpf_qdisc_fifo__open_and_load();
> + if (!ASSERT_OK_PTR(fifo_skel, "bpf_qdisc_fifo__open_and_load"))
> + return;
> +
> + link = bpf_map__attach_struct_ops(fifo_skel->maps.fifo);
> + if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops")) {
> + bpf_qdisc_fifo__destroy(fifo_skel);
> + return;
> + }
> +
> + do_test("bpf_fifo");
> +
> + bpf_link__destroy(link);
> + bpf_qdisc_fifo__destroy(fifo_skel);
> +}
> +
> +void test_bpf_qdisc(void)
> +{
Run the whole test under its own netns. Use netns_new("bpf_qdisc_ns", true) from
the test_progs.c should do.
> + if (test__start_subtest("fifo"))
> + test_fifo();
> +}
next prev parent reply other threads:[~2025-01-10 0:05 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-20 19:55 [PATCH bpf-next v2 00/14] bpf qdisc Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 01/14] bpf: Support getting referenced kptr from struct_ops argument Amery Hung
2025-01-23 9:57 ` Eduard Zingerman
2025-01-23 19:41 ` Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 02/14] selftests/bpf: Test referenced kptr arguments of struct_ops programs Amery Hung
2025-01-23 9:57 ` Eduard Zingerman
2025-01-24 0:04 ` Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 03/14] bpf: Allow struct_ops prog to return referenced kptr Amery Hung
2025-01-15 15:25 ` Ming Lei
2025-01-23 9:57 ` Eduard Zingerman
2025-01-23 18:19 ` Eduard Zingerman
2024-12-20 19:55 ` [PATCH bpf-next v2 04/14] selftests/bpf: Test returning referenced kptr from struct_ops programs Amery Hung
2025-01-23 9:58 ` Eduard Zingerman
2024-12-20 19:55 ` [PATCH bpf-next v2 05/14] bpf: net_sched: Support implementation of Qdisc_ops in bpf Amery Hung
2025-01-09 15:00 ` Amery Hung
2025-01-10 0:28 ` Martin KaFai Lau
2025-01-10 1:20 ` Jakub Kicinski
2024-12-20 19:55 ` [PATCH bpf-next v2 06/14] bpf: net_sched: Add basic bpf qdisc kfuncs Amery Hung
2025-01-10 0:24 ` Martin KaFai Lau
2025-01-10 18:00 ` Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 07/14] bpf: Search and add kfuncs in struct_ops prologue and epilogue Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 08/14] bpf: net_sched: Add a qdisc watchdog timer Amery Hung
2025-01-09 0:20 ` Martin KaFai Lau
2025-01-09 15:00 ` Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 09/14] bpf: net_sched: Support updating bstats Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 10/14] bpf: net_sched: Support updating qstats Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 11/14] bpf: net_sched: Allow writing to more Qdisc members Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 12/14] libbpf: Support creating and destroying qdisc Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 13/14] selftests: Add a basic fifo qdisc test Amery Hung
2025-01-10 0:05 ` Martin KaFai Lau [this message]
2024-12-20 19:55 ` [PATCH bpf-next v2 14/14] selftests: Add a bpf fq qdisc to selftest Amery Hung
2025-01-09 23:36 ` Martin KaFai Lau
2025-01-02 17:29 ` [PATCH bpf-next v2 00/14] bpf qdisc Toke Høiland-Jørgensen
2025-01-10 1:43 ` Martin KaFai Lau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=88e9291e-cd67-4fa2-8a91-d475e29ab832@linux.dev \
--to=martin.lau@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=ekarani.silvestre@ccc.ufcg.edu.br \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=martin.lau@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sinquersw@gmail.com \
--cc=stfomichev@gmail.com \
--cc=toke@redhat.com \
--cc=xiyou.wangcong@gmail.com \
--cc=yangpeihao@sjtu.edu.cn \
--cc=yepeilin.cs@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).