Skip to contentSkip to conversation

selftests/bpf: Use ASSERT_EQ instead ASSERT_OK for testing memcmp result

PATCH Applied Martin KaFai Lau 4 participants 7 messages Mar 16, 2023

Subsystems (3)
lore
Share & tools
lore

Martin KaFai Lau

author reviewer
#0 lore raw

PATCH 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
index 5cf85d0f9827..13bcaeb028b8 100644
@@ -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
author reviewer
#1 lore raw

PATCH 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.

Fixes eed92afdd14c ("bpf: selftest: Test batching and bpf_(get|set)sockopt in bpf tcp iter")
---
 tools/testing/selftests/bpf/network_helpers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/network_helpers.c +1 -1
index 01de33191226..596caa176582 100644
@@ -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
Acked-by on v1 2/2
#2 lore raw

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 when setsockopt(SO_REUSEPORT) fails. This patch fixes it.

Fixes eed92afdd14c ("bpf: selftest: Test batching and bpf_(get|set)sockopt in bpf tcp iter")
#3 lore raw

Re: [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 when setsockopt(SO_REUSEPORT) fails. This patch fixes it.

Fixes eed92afdd14c ("bpf: selftest: Test batching and bpf_(get|set)sockopt in bpf tcp iter")
Acked-by on v1 1/2
#4 lore raw
In reply to Martin KaFai Lau
Quoted 9 lines · Martin KaFai Lau

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.

#5 lore raw
Quoted 11 lines · Yonghong Song
Quoted 8 lines · Martin KaFai Lau

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.

Quoted 3 lines
Quoted 1 line
#6 lore raw
In reply to Martin KaFai Lau
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_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.

[...]

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