Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Geliang Tang <geliang@kernel.org>
To: 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>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	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>
Cc: bpf@vger.kernel.org, mptcp@lists.linux.dev,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf-next 06/14] selftests/bpf: Use log_err in network_helpers
Date: Wed, 10 Apr 2024 16:14:29 +0800	[thread overview]
Message-ID: <ff6874d5bd8dc5c89fcd913c3f1ba1820fe7ae4f.camel@kernel.org> (raw)
In-Reply-To: <77e0288d4757b2fcc2c491a2ed535ef223268071.1712733999.git.tanggeliang@kylinos.cn>

On Wed, 2024-04-10 at 15:29 +0800, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> The helpers ASSERT_OK/GE/OK_PTR should avoid using in public
> functions.
> This patch uses log_err() to replace them in network_helpers.c.
> 
> And drop '#include "test_progs.h"' in it, include <pthread.h> and
> <sys/param.h> instead.

Sorry, CI complains about this:

  network_helpers.c: In function ‘open_netns’:
  network_helpers.c:466:25: error: implicit declaration of function
‘open’; did you mean ‘popen’? [-Werror=implicit-function-declaration]
    466 |  token->orig_netns_fd = open("/proc/self/ns/net", O_RDONLY);
        |                         ^~~~
        |                         popen

"test_progs.h" is still needed. I'll update this in v2.

Changes Requested.

-Geliang

> 
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>  tools/testing/selftests/bpf/network_helpers.c | 22 ++++++++++++++---
> --
>  1 file changed, 16 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/network_helpers.c
> b/tools/testing/selftests/bpf/network_helpers.c
> index 7ddeb6698ec7..9fd271d5d571 100644
> --- a/tools/testing/selftests/bpf/network_helpers.c
> +++ b/tools/testing/selftests/bpf/network_helpers.c
> @@ -7,11 +7,13 @@
>  #include <string.h>
>  #include <unistd.h>
>  #include <sched.h>
> +#include <pthread.h>
>  
>  #include <arpa/inet.h>
>  #include <sys/mount.h>
>  #include <sys/stat.h>
>  #include <sys/un.h>
> +#include <sys/param.h>
>  
>  #include <linux/err.h>
>  #include <linux/in.h>
> @@ -20,7 +22,6 @@
>  
>  #include "bpf_util.h"
>  #include "network_helpers.h"
> -#include "test_progs.h"
>  
>  #ifndef IPPROTO_MPTCP
>  #define IPPROTO_MPTCP 262
> @@ -447,22 +448,30 @@ struct nstoken *open_netns(const char *name)
>  	struct nstoken *token;
>  
>  	token = calloc(1, sizeof(struct nstoken));
> -	if (!ASSERT_OK_PTR(token, "malloc token"))
> +	if (!token) {
> +		log_err("malloc token");
>  		return NULL;
> +	}
>  
>  	token->orig_netns_fd = open("/proc/self/ns/net", O_RDONLY);
> -	if (!ASSERT_GE(token->orig_netns_fd, 0, "open
> /proc/self/ns/net"))
> +	if (token->orig_netns_fd <= 0) {
> +		log_err("open /proc/self/ns/net");
>  		goto fail;
> +	}
>  
>  	snprintf(nspath, sizeof(nspath), "%s/%s", "/var/run/netns",
> name);
>  	nsfd = open(nspath, O_RDONLY | O_CLOEXEC);
> -	if (!ASSERT_GE(nsfd, 0, "open netns fd"))
> +	if (nsfd <= 0) {
> +		log_err("open netns fd");
>  		goto fail;
> +	}
>  
>  	err = setns(nsfd, CLONE_NEWNET);
>  	close(nsfd);
> -	if (!ASSERT_OK(err, "setns"))
> +	if (err) {
> +		log_err("setns");
>  		goto fail;
> +	}
>  
>  	return token;
>  fail:
> @@ -475,7 +484,8 @@ void close_netns(struct nstoken *token)
>  	if (!token)
>  		return;
>  
> -	ASSERT_OK(setns(token->orig_netns_fd, CLONE_NEWNET),
> "setns");
> +	if (setns(token->orig_netns_fd, CLONE_NEWNET))
> +		log_err("setns");
>  	close(token->orig_netns_fd);
>  	free(token);
>  }


  reply	other threads:[~2024-04-10  8:14 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-10  7:29 [PATCH bpf-next 00/14] use start_server and connect_to helpers Geliang Tang
2024-04-10  7:29 ` [PATCH bpf-next 01/14] selftests/bpf: Add start_server_addr helper Geliang Tang
2024-04-10  7:29 ` [PATCH bpf-next 02/14] selftests/bpf: Use start_server_addr in cls_redirect Geliang Tang
2024-04-10  7:29 ` [PATCH bpf-next 03/14] selftests/bpf: Use connect_to_addr " Geliang Tang
2024-04-10  7:29 ` [PATCH bpf-next 04/14] selftests/bpf: Use start_server_addr in sk_assign Geliang Tang
2024-04-10  7:29 ` [PATCH bpf-next 05/14] selftests/bpf: Use connect_to_addr " Geliang Tang
2024-04-10  7:29 ` [PATCH bpf-next 06/14] selftests/bpf: Use log_err in network_helpers Geliang Tang
2024-04-10  8:14   ` Geliang Tang [this message]
2024-04-10  7:29 ` [PATCH bpf-next 07/14] selftests/bpf: Use start_server_addr in test_sock_addr Geliang Tang
2024-04-10  7:29 ` [PATCH bpf-next 08/14] selftests/bpf: Use connect_to_addr " Geliang Tang
2024-04-10  7:29 ` [PATCH bpf-next 09/14] selftests/bpf: Add function pointer for __start_server Geliang Tang
2024-04-10  7:29 ` [PATCH bpf-next 10/14] selftests/bpf: Add start_server_setsockopt helper Geliang Tang
2024-04-10  7:29 ` [PATCH bpf-next 11/14] selftests/bpf: Use start_server_setsockopt in sockopt_inherit Geliang Tang
2024-04-10  7:29 ` [PATCH bpf-next 12/14] selftests/bpf: Use connect_to_fd " Geliang Tang
2024-04-10  7:29 ` [PATCH bpf-next 13/14] selftests/bpf: Use start_server_* in test_tcp_check_syncookie Geliang Tang
2024-04-10  7:29 ` [PATCH bpf-next 14/14] selftests/bpf: Use connect_to_addr " 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=ff6874d5bd8dc5c89fcd913c3f1ba1820fe7ae4f.camel@kernel.org \
    --to=geliang@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mptcp@lists.linux.dev \
    --cc=mykolal@fb.com \
    --cc=sdf@google.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --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