Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Geliang Tang <geliang@kernel.org>
Cc: Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Mykola Lysenko <mykolal@fb.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
	Geliang Tang <tanggeliang@kylinos.cn>,
	bpf@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf-next v5 6/7] selftests/bpf: Use connect_to_fd_opts in do_test in bpf_tcp_ca
Date: Tue, 28 May 2024 22:21:24 -0700	[thread overview]
Message-ID: <7e9c544a-fd2a-4c19-b06b-d72b5e7fc543@linux.dev> (raw)
In-Reply-To: <bd55a421ab8e8b8bce4658840bc028d9aa6965c5.1716638248.git.tanggeliang@kylinos.cn>

On 5/25/24 5:08 AM, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> This patch uses connect_to_fd_opts() instead of using connect_fd_to_fd()
> and settcpca() in do_test() in prog_tests/bpf_tcp_ca.c to accept a struct
> network_helper_opts argument.
> 
> Then define a dctcp dedicated post_socket_cb callback stg_post_socket_cb(),
> invoking both cc_cb() and bpf_map_update_elem() in it, and set it in
> test_dctcp(). For passing map_fd into stg_post_socket_cb() callback, a new
> member map_fd is added in struct cb_opts.
> 
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>   .../selftests/bpf/prog_tests/bpf_tcp_ca.c     | 42 ++++++++++---------
>   1 file changed, 22 insertions(+), 20 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
> index ebc7d4616880..9a7c3dc39008 100644
> --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
> +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
> @@ -25,6 +25,7 @@ static int expected_stg = 0xeB9F;
>   
>   struct cb_opts {
>   	const char *cc;
> +	int map_fd;
>   };
>   
>   static int settcpca(int fd, const char *tcp_ca)
> @@ -41,7 +42,6 @@ static int settcpca(int fd, const char *tcp_ca)
>   static void do_test(const struct network_helper_opts *opts,
>   		    const struct bpf_map *sk_stg_map)
>   {
> -	struct cb_opts *cb_opts = (struct cb_opts *)opts->cb_opts;
>   	int lfd = -1, fd = -1;
>   	int err;
>   
> @@ -49,25 +49,9 @@ static void do_test(const struct network_helper_opts *opts,
>   	if (!ASSERT_NEQ(lfd, -1, "socket"))
>   		return;
>   
> -	fd = socket(AF_INET6, SOCK_STREAM, 0);
> -	if (!ASSERT_NEQ(fd, -1, "socket")) {
> -		close(lfd);
> -		return;
> -	}
> -
> -	if (settcpca(fd, cb_opts->cc))
> -		goto done;
> -
> -	if (sk_stg_map) {
> -		err = bpf_map_update_elem(bpf_map__fd(sk_stg_map), &fd,
> -					  &expected_stg, BPF_NOEXIST);
> -		if (!ASSERT_OK(err, "bpf_map_update_elem(sk_stg_map)"))
> -			goto done;
> -	}
> -
>   	/* connect to server */
> -	err = connect_fd_to_fd(fd, lfd, 0);
> -	if (!ASSERT_NEQ(err, -1, "connect"))
> +	fd = connect_to_fd_opts(lfd, opts);
> +	if (!ASSERT_NEQ(fd, -1, "connect_to_fd_opts"))
>   		goto done;
>   
>   	if (sk_stg_map) {
> @@ -124,13 +108,30 @@ static void test_cubic(void)
>   	bpf_cubic__destroy(cubic_skel);
>   }
>   
> +static int stg_post_socket_cb(int fd, void *opts)
> +{
> +	struct cb_opts *cb_opts = (struct cb_opts *)opts;
> +	int err;
> +
> +	err = settcpca(fd, cb_opts->cc);
> +	if (err)
> +		return err;
> +
> +	err = bpf_map_update_elem(cb_opts->map_fd, &fd,
> +				  &expected_stg, BPF_NOEXIST);

Looking at it again, it is not very correct. At least this map update is 
unnecessary for the start_server_str() in do_test(). do_test() uses the same 
opts for start_server_str() and connect_to_fd_opts().

Also, the post_connect_cb in patch 8 is unnecessary for network_helpers.c. The 
connect_to_fd_opts helper is going to return the fd anyway. It is unnecessary to 
have the helper to do the post_connect_cb(fd). The caller (do_test here) can 
directly do that instead. Lets not add unnecessary post_connect_cb to the 
network_helpers.c now until there is a clear case that the caller cannot do it.

I would just add another "const struct network_helper_opts *cli_opts" to the
do_test() to do what patch 7 and patch 8 need to do. Separate it from the server 
"opts".

Patach 1 to 5 is applied. Thanks.


> +	if (!ASSERT_OK(err, "bpf_map_update_elem(sk_stg_map)"))
> +		return err;
> +
> +	return 0;
> +}
> +
>   static void test_dctcp(void)
>   {
>   	struct cb_opts cb_opts = {
>   		.cc = "bpf_dctcp",
>   	};
>   	struct network_helper_opts opts = {
> -		.post_socket_cb	= cc_cb,
> +		.post_socket_cb	= stg_post_socket_cb,
>   		.cb_opts	= &cb_opts,
>   	};
>   	struct bpf_dctcp *dctcp_skel;
> @@ -146,6 +147,7 @@ static void test_dctcp(void)
>   		return;
>   	}
>   
> +	cb_opts.map_fd = bpf_map__fd(dctcp_skel->maps.sk_stg_map);
>   	do_test(&opts, dctcp_skel->maps.sk_stg_map);
>   	ASSERT_EQ(dctcp_skel->bss->stg_result, expected_stg, "stg_result");
>   


  reply	other threads:[~2024-05-29  5:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-25 12:08 [PATCH bpf-next v5 0/7] use network helpers, part 5 Geliang Tang
2024-05-25 12:08 ` [PATCH bpf-next v5 1/7] selftests/bpf: Drop struct post_socket_opts Geliang Tang
2024-05-25 12:08 ` [PATCH bpf-next v5 2/7] selftests/bpf: Add start_server_str helper Geliang Tang
2024-05-25 12:08 ` [PATCH bpf-next v5 3/7] selftests/bpf: Use post_socket_cb in connect_to_fd_opts Geliang Tang
2024-05-25 12:08 ` [PATCH bpf-next v5 4/7] selftests/bpf: Use post_socket_cb in start_server_str Geliang Tang
2024-05-25 12:08 ` [PATCH bpf-next v5 5/7] selftests/bpf: Use start_server_str in do_test in bpf_tcp_ca Geliang Tang
2024-05-25 12:08 ` [PATCH bpf-next v5 6/7] selftests/bpf: Use connect_to_fd_opts " Geliang Tang
2024-05-29  5:21   ` Martin KaFai Lau [this message]
2024-05-25 12:08 ` [PATCH bpf-next v5 7/7] selftests/bpf: Add post_connect_cb callback Geliang Tang
2024-05-29  5:20 ` [PATCH bpf-next v5 0/7] use network helpers, part 5 patchwork-bot+netdevbpf

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=7e9c544a-fd2a-4c19-b06b-d72b5e7fc543@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=geliang@kernel.org \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mykolal@fb.com \
    --cc=sdf@google.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=tanggeliang@kylinos.cn \
    --cc=yonghong.song@linux.dev \
    /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