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 v2 2/4] selftests/bpf: Use start_server_addr in bpf_tcp_ca
Date: Tue, 21 May 2024 10:02:14 -0700	[thread overview]
Message-ID: <b4a654a3-6078-4aca-98f5-f98bc319240d@linux.dev> (raw)
In-Reply-To: <bc13f05ea454890af39ebefb7231b66b545f0486.1715745588.git.tanggeliang@kylinos.cn>

On 5/14/24 9:20 PM, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> This patch uses start_server_addr() in do_test() in prog_tests/bpf_tcp_ca.c
> to accept a struct network_helper_opts argument instead of using
> start_server() and settcpca(). Then change the type of the first paramenter
> of do_test() into a struct network_helper_opts one.
> 
> Define its own opts for each test, set its own cc name into cb_opts.cc, and
> cc_cb() into post_socket_cb callback, then pass it to do_test().
> 
> opts->cb_opts needs to be passed to post_socket_cb() in __start_server().
> 
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>   tools/testing/selftests/bpf/network_helpers.c |  2 +-
>   .../selftests/bpf/prog_tests/bpf_tcp_ca.c     | 52 +++++++++++++++----
>   2 files changed, 42 insertions(+), 12 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
> index d97f8a669b38..6864af665508 100644
> --- a/tools/testing/selftests/bpf/network_helpers.c
> +++ b/tools/testing/selftests/bpf/network_helpers.c
> @@ -94,7 +94,7 @@ static int __start_server(int type, const struct sockaddr *addr, socklen_t addrl
>   	if (settimeo(fd, opts->timeout_ms))
>   		goto error_close;
>   
> -	if (opts->post_socket_cb && opts->post_socket_cb(fd, NULL)) {
> +	if (opts->post_socket_cb && opts->post_socket_cb(fd, &opts->cb_opts)) {
>   		log_err("Failed to call post_socket_cb");
>   		goto error_close;
>   	}
> 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 9bc909fa0833..25961ce850cb 100644
> --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
> +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
> @@ -34,12 +34,18 @@ static int settcpca(int fd, const char *tcp_ca)
>   	return 0;
>   }
>   
> -static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
> +static void do_test(const struct network_helper_opts *opts,
> +		    const struct bpf_map *sk_stg_map)
>   {
> +	struct sockaddr_storage addr;
>   	int lfd = -1, fd = -1;
> +	socklen_t addrlen;
>   	int err;
>   
> -	lfd = start_server(AF_INET6, SOCK_STREAM, NULL, 0, 0);
> +	if (make_sockaddr(AF_INET6, NULL, 0, &addr, &addrlen))
> +		return;
> +
> +	lfd = start_server_addr(SOCK_STREAM, &addr, addrlen, opts);

It is a tech debt that start_server does not take the "opts" argument.
It is pretty handy to have start_server as a helper that takes string address.

How about create a start_server_str() and start using it in this set. The other 
existing start_server() usages can be retired later.

int start_server_str(int family, int type, const char *addr, __u16 port,
		     const struct network_helper_opts *opts);


  reply	other threads:[~2024-05-21 17:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-15  4:20 [PATCH bpf-next v2 0/4] use network helpers, part 5 Geliang Tang
2024-05-15  4:20 ` [PATCH bpf-next v2 1/4] selftests/bpf: Use post_socket_cb in connect_to_fd_opts Geliang Tang
2024-05-21 16:56   ` Martin KaFai Lau
2024-05-15  4:20 ` [PATCH bpf-next v2 2/4] selftests/bpf: Use start_server_addr in bpf_tcp_ca Geliang Tang
2024-05-21 17:02   ` Martin KaFai Lau [this message]
2024-05-15  4:20 ` [PATCH bpf-next v2 3/4] selftests/bpf: Use connect_to_fd_opts in do_test " Geliang Tang
2024-05-15  4:20 ` [PATCH bpf-next v2 4/4] selftests/bpf: Add post_connect_cb callback Geliang Tang

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=b4a654a3-6078-4aca-98f5-f98bc319240d@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