selftests/bpf: Use ASSERT_EQ instead ASSERT_OK for testing memcmp result
Subsystems (3)
Martin KaFai Lau
reviewerPATCH 1/2 selftests/bpf: Use ASSERT_EQ instead ASSERT_OK for testing memcmp result
From: Martin KaFai Lau <[email protected]>
In tcp_hdr_options test, it ensures the received tcp hdr option and the sk local storage have the expected values. It uses memcmp to check that. Testing the memcmp result with ASSERT_OK is confusing because ASSERT_OK will print out the errno which is not set. This patch uses ASSERT_EQ to check for 0 instead.
--- tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c +2 -2
@@ -151,7 +151,7 @@ static int check_hdr_opt(const struct bpf_test_option *exp,const struct bpf_test_option *act, const char *hdr_desc) { - if (!ASSERT_OK(memcmp(exp, act, sizeof(*exp)), hdr_desc)) { + if (!ASSERT_EQ(memcmp(exp, act, sizeof(*exp)), 0, hdr_desc)) { print_option(exp, "expected: ");print_option (act," actual: " );return -1 ;
@@ -169,7 +169,7 @@ static int check_hdr_stg(const struct hdr_stg *exp, int fd, "map_lookup(hdr_stg_map_fd)"))return -1 ; -if (!ASSERT_OK (memcmp (exp, &act,sizeof (*exp)), stg_desc)) { +if (!ASSERT_EQ (memcmp (exp, &act,sizeof (*exp)),0 , stg_desc)) {print_hdr_stg (exp,"expected: " );print_hdr_stg (&act," actual: " );return -1 ;
Signature · 1 line
2.34.1
Martin KaFai Lau
reviewerPATCH 2/2 selftests/bpf: Fix a fd leak in an error path in network_helpers.c
From: Martin KaFai Lau <[email protected]>
In __start_server, it leaks a fd when setsockopt(SO_REUSEPORT) fails. This patch fixes it.
--- tools/testing/selftests/bpf/network_helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/network_helpers.c +1 -1
@@ -95,7 +95,7 @@ static int __start_server(int type, int protocol, const struct sockaddr *addr,if (reuseport &&setsockopt (fd,SOL_SOCKET ,SO_REUSEPORT , &on,sizeof (on))) {log_err ("Failed to set SO_REUSEPORT" ); -return -1 ; + goto error_close; }if (bind (fd, addr, addrlen) <0 ) {
Signature · 1 line
2.34.1
Re: [PATCH bpf-next 2/2] selftests/bpf: Fix a fd leak in an error path in network_helpers.c
Quoted 8 lines · Martin KaFai Lau
From: Martin KaFai Lau <[email protected]>
In
__start_server, it leaks a fd whensetsockopt(SO_REUSEPORT)fails. This patch fixes it.Fixes eed92afdd14c ("bpf: selftest: Test batching and bpf_(get|set)sockopt in bpf tcp iter")Reported-by Andrii Nakryiko <[email protected]>Signed-off-by Martin KaFai Lau <[email protected]>
John Fastabend
Acked-byRe: [PATCH bpf-next 2/2] selftests/bpf: Fix a fd leak in an error path in network_helpers.c
Quoted 5 lines · Yonghong Song
Quoted 2 lines · Martin KaFai Lau
From: Martin KaFai Lau <[email protected]>
Quoted 8 lines
Quoted 6 lines
In
__start_server, it leaks a fd whensetsockopt(SO_REUSEPORT)fails. This patch fixes it.Fixes eed92afdd14c ("bpf: selftest: Test batching and bpf_(get|set)sockopt in bpf tcp iter")Reported-by Andrii Nakryiko <[email protected]>Signed-off-by Martin KaFai Lau <[email protected]>Acked-by Yonghong Song <[email protected]>
Quoted 9 lines · Martin KaFai Lau
From: Martin KaFai Lau <[email protected]>
In
tcp_hdr_optionstest, it ensures the received tcp hdr option and the sk local storage have the expected values. It uses memcmp to check that. Testing the memcmp result withASSERT_OKis confusing becauseASSERT_OKwill print out the errno which is not set. This patch usesASSERT_EQto check for 0 instead.Signed-off-by Martin KaFai Lau <[email protected]>
John Fastabend
Acked-byQuoted 11 lines · Yonghong Song
Quoted 8 lines · Martin KaFai Lau
From: Martin KaFai Lau <[email protected]>
In
tcp_hdr_optionstest, it ensures the received tcp hdr option and the sk local storage have the expected values. It uses memcmp to check that. Testing the memcmp result withASSERT_OKis confusing becauseASSERT_OKwill print out the errno which is not set. This patch usesASSERT_EQto check for 0 instead.
Quoted 3 lines
Quoted 1 line
Signed-off-by Martin KaFai Lau <[email protected]>Acked-by Yonghong Song <[email protected]>
This series was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Quoted 9 lines · On Wed, 15 Mar 2023 17:07:25 -0700 you wrote:
From: Martin KaFai Lau <[email protected]>
In
tcp_hdr_optionstest, it ensures the received tcp hdr option and the sk local storage have the expected values. It uses memcmp to check that. Testing the memcmp result withASSERT_OKis confusing becauseASSERT_OKwill print out the errno which is not set. This patch usesASSERT_EQto check for 0 instead.[...]
Here is the summary with links:
- [bpf-next,1/2] selftests/bpf: Use ASSERT_EQ instead ASSERT_OK for testing memcmp result
https://git.kernel.org/bpf/bpf-next/c/ed01385c0d78 - [bpf-next,2/2] selftests/bpf: Fix a fd leak in an error path in network_helpers.c https://git.kernel.org/bpf/bpf-next/c/226efec2b0ef
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html