Skip to contentSkip to conversation

BPF selftests misc fixes

PATCH Superseded Geliang Tang 2 participants 8 messages Jul 9, 2024 – Jul 10, 2024

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover BPF selftests misc fixes

From: Geliang Tang <[email protected]>

Resend patch 1 out of "skip ENOTSUPP BPF selftests" set as Eduard suggested. Together with two other cleanups.

Geliang Tang (3):
selftests/bpf: Null checks for links in bpf_tcp_ca selftests/bpf: Check ASSERT_OK(err) in dummy_st_ops selftests/bpf: Close obj in error paths in xdp_adjust_tail

 .../selftests/bpf/prog_tests/bpf_tcp_ca.c     | 21 +++++++++++++------
 .../selftests/bpf/prog_tests/dummy_st_ops.c   |  8 +++++--
 .../bpf/prog_tests/xdp_adjust_tail.c          |  2 +-
 3 files changed, 22 insertions(+), 9 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/3 selftests/bpf: Null checks for links in bpf_tcp_ca

From: Geliang Tang <[email protected]>

Run bpf_tcp_ca selftests (./test_progs -t bpf_tcp_ca) on a Loongarch platform, some "Segmentation fault" errors occur:

'''
test_dctcp:PASS:bpf_dctcp__open_and_load 0 nsec test_dctcp:FAIL:bpf_map__attach_struct_ops unexpected error: -524
#29/1 bpf_tcp_ca/dctcp:FAIL
test_cubic:PASS:bpf_cubic__open_and_load 0 nsec test_cubic:FAIL:bpf_map__attach_struct_ops unexpected error: -524
#29/2 bpf_tcp_ca/cubic:FAIL
test_dctcp_fallback:PASS:dctcp_skel 0 nsec test_dctcp_fallback:PASS:bpf_dctcp__load 0 nsec test_dctcp_fallback:FAIL:dctcp link unexpected error: -524
#29/4 bpf_tcp_ca/dctcp_fallback:FAIL
test_write_sk_pacing:PASS:open_and_load 0 nsec test_write_sk_pacing:FAIL:attach_struct_ops unexpected error: -524
#29/6 bpf_tcp_ca/write_sk_pacing:FAIL
test_update_ca:PASS:open 0 nsec test_update_ca:FAIL:attach_struct_ops unexpected error: -524

 settcpca:FAIL:setsockopt unexpected setsockopt: \
					actual -1 == expected -1
 (network_helpers.c:99: errno: No such file or directory) \
					Failed to call post_socket_cb
 start_test:FAIL:start_server_str unexpected start_server_str: \
					actual -1 == expected -1

test_update_ca:FAIL:ca1_ca1_cnt unexpected ca1_ca1_cnt: \
actual 0 <= expected 0
#29/9 bpf_tcp_ca/update_ca:FAIL
#29 bpf_tcp_ca:FAIL
Caught signal #11!
Stack trace:
./test_progs(crash_handler+0x28)[0x5555567ed91c] linux-vdso.so.1(__vdso_rt_sigreturn+0x0)[0x7ffffee408b0] ./test_progs(bpf_link__update_map+0x80)[0x555556824a78] ./test_progs(+0x94d68)[0x5555564c4d68] ./test_progs(test_bpf_tcp_ca+0xe8)[0x5555564c6a88] ./test_progs(+0x3bde54)[0x5555567ede54] ./test_progs(main+0x61c)[0x5555567efd54] /usr/lib64/libc.so.6(+0x22208)[0x7ffff2aaa208] /usr/lib64/libc.so.6(__libc_start_main+0xac)[0x7ffff2aaa30c] ./test_progs(_start+0x48)[0x55555646bca8] Segmentation fault
'''

This is because BPF trampoline is not implemented on Loongarch yet, "link" returned by bpf_map__attach_struct_ops() is NULL. test_progs crashs when this NULL link passes to bpf_link__update_map(). This patch adds NULL checks for all links in bpf_tcp_ca to fix these errors. If "link" is NULL, goto the newly added label "out" to destroy the skel.

v2:
- use "goto out" instead of "return" as Eduard suggested.

---
 .../selftests/bpf/prog_tests/bpf_tcp_ca.c     | 21 +++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +15 -6
index d842ff64bc2a..efc1bf2ff7de 100644
@@ -411,7 +411,8 @@ static void test_update_ca(void)
 		return;
 
 	link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
-	ASSERT_OK_PTR(link, "attach_struct_ops");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
+		goto out;
 
 	do_test(&opts);
 	saved_ca1_cnt = skel->bss->ca1_cnt;
@@ -425,6 +426,7 @@ static void test_update_ca(void)
 	ASSERT_GT(skel->bss->ca2_cnt, 0, "ca2_ca2_cnt");
 
 	bpf_link__destroy(link);
+out:
 	tcp_ca_update__destroy(skel);
 }
 
@@ -447,7 +449,8 @@ static void test_update_wrong(void)
 		return;
 
 	link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
-	ASSERT_OK_PTR(link, "attach_struct_ops");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
+		goto out;
 
 	do_test(&opts);
 	saved_ca1_cnt = skel->bss->ca1_cnt;
@@ -460,11 +463,13 @@ static void test_update_wrong(void)
 	ASSERT_GT(skel->bss->ca1_cnt, saved_ca1_cnt, "ca2_ca1_cnt");
 
 	bpf_link__destroy(link);
+out:
 	tcp_ca_update__destroy(skel);
 }
 
 static void test_mixed_links(void)
 {
+	struct bpf_link *link = NULL, *link_nl = NULL;
 	struct cb_opts cb_opts = {
 		.cc = "tcp_ca_update",
 	};
@@ -473,7 +478,6 @@ static void test_mixed_links(void)
 		.cb_opts	= &cb_opts,
 	};
 	struct tcp_ca_update *skel;
-	struct bpf_link *link, *link_nl;
 	int err;
 
 	skel = tcp_ca_update__open_and_load();
@@ -481,10 +485,12 @@ static void test_mixed_links(void)
 		return;
 
 	link_nl = bpf_map__attach_struct_ops(skel->maps.ca_no_link);
-	ASSERT_OK_PTR(link_nl, "attach_struct_ops_nl");
+	if (!ASSERT_OK_PTR(link_nl, "attach_struct_ops_nl"))
+		goto out;
 
 	link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
-	ASSERT_OK_PTR(link, "attach_struct_ops");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
+		goto out;
 
 	do_test(&opts);
 	ASSERT_GT(skel->bss->ca1_cnt, 0, "ca1_ca1_cnt");
@@ -492,6 +498,7 @@ static void test_mixed_links(void)
 	err = bpf_link__update_map(link, skel->maps.ca_no_link);
 	ASSERT_ERR(err, "update_map");
 
+out:
 	bpf_link__destroy(link);
 	bpf_link__destroy(link_nl);
 	tcp_ca_update__destroy(skel);
@@ -536,7 +543,8 @@ static void test_link_replace(void)
 	bpf_link__destroy(link);
 
 	link = bpf_map__attach_struct_ops(skel->maps.ca_update_2);
-	ASSERT_OK_PTR(link, "attach_struct_ops_2nd");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops_2nd"))
+		goto out;
 
 	/* BPF_F_REPLACE with a wrong old map Fd. It should fail!
 	 *
@@ -559,6 +567,7 @@ static void test_link_replace(void)
 
 	bpf_link__destroy(link);
 
+out:
 	tcp_ca_update__destroy(skel);
 }
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH bpf-next 1/3] selftests/bpf: Null checks for links in bpf_tcp_ca

Quoted 52 lines · Geliang Tang

From: Geliang Tang <[email protected]>

Run bpf_tcp_ca selftests (./test_progs -t bpf_tcp_ca) on a Loongarch platform, some "Segmentation fault" errors occur:

'''
test_dctcp:PASS:bpf_dctcp__open_and_load 0 nsec test_dctcp:FAIL:bpf_map__attach_struct_ops unexpected error: -524
#29/1 bpf_tcp_ca/dctcp:FAIL
test_cubic:PASS:bpf_cubic__open_and_load 0 nsec test_cubic:FAIL:bpf_map__attach_struct_ops unexpected error: -524
#29/2 bpf_tcp_ca/cubic:FAIL
test_dctcp_fallback:PASS:dctcp_skel 0 nsec test_dctcp_fallback:PASS:bpf_dctcp__load 0 nsec test_dctcp_fallback:FAIL:dctcp link unexpected error: -524
#29/4 bpf_tcp_ca/dctcp_fallback:FAIL
test_write_sk_pacing:PASS:open_and_load 0 nsec test_write_sk_pacing:FAIL:attach_struct_ops unexpected error: -524
#29/6 bpf_tcp_ca/write_sk_pacing:FAIL
test_update_ca:PASS:open 0 nsec test_update_ca:FAIL:attach_struct_ops unexpected error: -524

 settcpca:FAIL:setsockopt unexpected setsockopt: \
					actual -1 == expected -1
 (network_helpers.c:99: errno: No such file or directory) \
					Failed to call post_socket_cb
 start_test:FAIL:start_server_str unexpected start_server_str: \
					actual -1 == expected -1

test_update_ca:FAIL:ca1_ca1_cnt unexpected ca1_ca1_cnt: \
actual 0 <= expected 0
#29/9 bpf_tcp_ca/update_ca:FAIL
#29 bpf_tcp_ca:FAIL
Caught signal #11!
Stack trace:
./test_progs(crash_handler+0x28)[0x5555567ed91c] linux-vdso.so.1(__vdso_rt_sigreturn+0x0)[0x7ffffee408b0] ./test_progs(bpf_link__update_map+0x80)[0x555556824a78] ./test_progs(+0x94d68)[0x5555564c4d68] ./test_progs(test_bpf_tcp_ca+0xe8)[0x5555564c6a88] ./test_progs(+0x3bde54)[0x5555567ede54] ./test_progs(main+0x61c)[0x5555567efd54] /usr/lib64/libc.so.6(+0x22208)[0x7ffff2aaa208] /usr/lib64/libc.so.6(__libc_start_main+0xac)[0x7ffff2aaa30c] ./test_progs(_start+0x48)[0x55555646bca8] Segmentation fault
'''

This is because BPF trampoline is not implemented on Loongarch yet, "link" returned by bpf_map__attach_struct_ops() is NULL. test_progs crashs when this NULL link passes to bpf_link__update_map(). This patch adds NULL checks for all links in bpf_tcp_ca to fix these errors. If "link" is NULL, goto the newly added label "out" to destroy the skel.

Quoted 4 lines

v2:
- use "goto out" instead of "return" as Eduard suggested.

Maybe I'm missing it, but I'm not seeing this series on patchwork.kernel.org/project/netdevbpf, so we don't have an associated CI run (the series is in the kselftest patchwork however). Is there some patchwork bot magic that will do this?

Quoted 99 lines
---
 .../selftests/bpf/prog_tests/bpf_tcp_ca.c     | 21 +++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +15 -6
index d842ff64bc2a..efc1bf2ff7de 100644
@@ -411,7 +411,8 @@ static void test_update_ca(void)
 		return;
 
 	link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
-	ASSERT_OK_PTR(link, "attach_struct_ops");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
+		goto out;
 
 	do_test(&opts);
 	saved_ca1_cnt = skel->bss->ca1_cnt;
@@ -425,6 +426,7 @@ static void test_update_ca(void)
 	ASSERT_GT(skel->bss->ca2_cnt, 0, "ca2_ca2_cnt");
 
 	bpf_link__destroy(link);
+out:
 	tcp_ca_update__destroy(skel);
 }
 
@@ -447,7 +449,8 @@ static void test_update_wrong(void)
 		return;
 
 	link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
-	ASSERT_OK_PTR(link, "attach_struct_ops");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
+		goto out;
 
 	do_test(&opts);
 	saved_ca1_cnt = skel->bss->ca1_cnt;
@@ -460,11 +463,13 @@ static void test_update_wrong(void)
 	ASSERT_GT(skel->bss->ca1_cnt, saved_ca1_cnt, "ca2_ca1_cnt");
 
 	bpf_link__destroy(link);
+out:
 	tcp_ca_update__destroy(skel);
 }
 
 static void test_mixed_links(void)
 {
+	struct bpf_link *link = NULL, *link_nl = NULL;
 	struct cb_opts cb_opts = {
 		.cc = "tcp_ca_update",
 	};
@@ -473,7 +478,6 @@ static void test_mixed_links(void)
 		.cb_opts	= &cb_opts,
 	};
 	struct tcp_ca_update *skel;
-	struct bpf_link *link, *link_nl;
 	int err;
 
 	skel = tcp_ca_update__open_and_load();
@@ -481,10 +485,12 @@ static void test_mixed_links(void)
 		return;
 
 	link_nl = bpf_map__attach_struct_ops(skel->maps.ca_no_link);
-	ASSERT_OK_PTR(link_nl, "attach_struct_ops_nl");
+	if (!ASSERT_OK_PTR(link_nl, "attach_struct_ops_nl"))
+		goto out;
 
 	link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
-	ASSERT_OK_PTR(link, "attach_struct_ops");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
+		goto out;
 
 	do_test(&opts);
 	ASSERT_GT(skel->bss->ca1_cnt, 0, "ca1_ca1_cnt");
@@ -492,6 +498,7 @@ static void test_mixed_links(void)
 	err = bpf_link__update_map(link, skel->maps.ca_no_link);
 	ASSERT_ERR(err, "update_map");
 
+out:
 	bpf_link__destroy(link);
 	bpf_link__destroy(link_nl);
 	tcp_ca_update__destroy(skel);
@@ -536,7 +543,8 @@ static void test_link_replace(void)
 	bpf_link__destroy(link);
 
 	link = bpf_map__attach_struct_ops(skel->maps.ca_update_2);
-	ASSERT_OK_PTR(link, "attach_struct_ops_2nd");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops_2nd"))
+		goto out;
 
 	/* BPF_F_REPLACE with a wrong old map Fd. It should fail!
 	 *
@@ -559,6 +567,7 @@ static void test_link_replace(void)
 
 	bpf_link__destroy(link);
 
+out:
 	tcp_ca_update__destroy(skel);
 }
 
#3 lore raw

Re: [PATCH bpf-next 1/3] selftests/bpf: Null checks for links in bpf_tcp_ca

Quoted 62 lines · Alan Maguire
Quoted 56 lines · Geliang Tang

From: Geliang Tang <[email protected]>

Run bpf_tcp_ca selftests (./test_progs -t bpf_tcp_ca) on a Loongarch
platform, some "Segmentation fault" errors occur:

'''
 test_dctcp:PASS:bpf_dctcp__open_and_load 0 nsec test_dctcp:FAIL:bpf_map__attach_struct_ops unexpected error: -524 #29/1    bpf_tcp_ca/dctcp:FAIL test_cubic:PASS:bpf_cubic__open_and_load 0 nsec test_cubic:FAIL:bpf_map__attach_struct_ops unexpected error: -524 #29/2    bpf_tcp_ca/cubic:FAIL test_dctcp_fallback:PASS:dctcp_skel 0 nsec test_dctcp_fallback:PASS:bpf_dctcp__load 0 nsec test_dctcp_fallback:FAIL:dctcp link unexpected error: -524 #29/4    bpf_tcp_ca/dctcp_fallback:FAIL test_write_sk_pacing:PASS:open_and_load 0 nsec test_write_sk_pacing:FAIL:attach_struct_ops unexpected error: -524 #29/6    bpf_tcp_ca/write_sk_pacing:FAIL test_update_ca:PASS:open 0 nsec test_update_ca:FAIL:attach_struct_ops unexpected error: -524

 settcpca:FAIL:setsockopt unexpected setsockopt: \
					actual -1 == expected -1
 (network_helpers.c:99: errno: No such file or directory) \
					Failed to call
post_socket_cb
 start_test:FAIL:start_server_str unexpected start_server_str: \
					actual -1 == expected -1

 test_update_ca:FAIL:ca1_ca1_cnt unexpected ca1_ca1_cnt: \
actual 0 <= expected 0
 #29/9    bpf_tcp_ca/update_ca:FAIL
 #29      bpf_tcp_ca:FAIL
 Caught signal #11!
 Stack trace:
 ./test_progs(crash_handler+0x28)[0x5555567ed91c] linux-vdso.so.1(__vdso_rt_sigreturn+0x0)[0x7ffffee408b0] ./test_progs(bpf_link__update_map+0x80)[0x555556824a78] ./test_progs(+0x94d68)[0x5555564c4d68] ./test_progs(test_bpf_tcp_ca+0xe8)[0x5555564c6a88] ./test_progs(+0x3bde54)[0x5555567ede54] ./test_progs(main+0x61c)[0x5555567efd54] /usr/lib64/libc.so.6(+0x22208)[0x7ffff2aaa208] /usr/lib64/libc.so.6(__libc_start_main+0xac)[0x7ffff2aaa30c] ./test_progs(_start+0x48)[0x55555646bca8] Segmentation fault
'''

This is because BPF trampoline is not implemented on Loongarch yet, "link" returned by bpf_map__attach_struct_ops() is NULL. test_progs crashs when this NULL link passes to bpf_link__update_map(). This patch adds NULL checks for all links in bpf_tcp_ca to fix these errors.
If "link" is NULL, goto the newly added label "out" to destroy the skel.

Quoted 4 lines

v2:
 - use "goto out" instead of "return" as Eduard suggested.

Quoted 8 lines

Maybe I'm missing it, but I'm not seeing this series on patchwork.kernel.org/project/netdevbpf, so we don't have an associated
CI run (the series is in the kselftest patchwork however). Is there some
patchwork bot magic that will do this?

Thanks for your review. I want to do a small update for this patch, so I changed this set as "Changes Requested". So they are not showed in patchwork. v2 will be sent soon. I will add your "reviewed-by" tag in it.

Thanks,
-Geliang

Quoted 104 lines
Quoted 104 lines

---
 .../selftests/bpf/prog_tests/bpf_tcp_ca.c     | 21 +++++++++++++--
----

 1 file changed, 15 insertions(+), 6 deletions(-)
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +0 -0
index d842ff64bc2a..efc1bf2ff7de 100644
@@ -411,7 +411,8 @@ static void test_update_ca(void)
  		return;


  link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);

tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +2 -1
-	ASSERT_OK_PTR(link, "attach_struct_ops");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
+		goto out;

  do_test(&opts);
  saved_ca1_cnt = skel->bss->ca1_cnt;

tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +0 -0
@@ -425,6 +426,7 @@ static void test_update_ca(void)
  	ASSERT_GT(skel->bss->ca2_cnt, 0, "ca2_ca2_cnt");


  bpf_link__destroy(link);
+out:
  tcp_ca_update__destroy(skel);
 }

tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +0 -0
@@ -447,7 +449,8 @@ static void test_update_wrong(void)
  		return;


  link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);

tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +2 -1
-	ASSERT_OK_PTR(link, "attach_struct_ops");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
+		goto out;


  do_test(&opts);
  saved_ca1_cnt = skel->bss->ca1_cnt;

tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +0 -0
@@ -460,11 +463,13 @@ static void test_update_wrong(void)
  	ASSERT_GT(skel->bss->ca1_cnt, saved_ca1_cnt,
 "ca2_ca1_cnt");


  bpf_link__destroy(link);
+out:
  tcp_ca_update__destroy(skel);
 }

 static void test_mixed_links(void)
 {

tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +1 -0
+	struct bpf_link *link = NULL, *link_nl = NULL;

  struct cb_opts cb_opts = {
  .cc = "tcp_ca_update",
  };

tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +0 -1
@@ -473,7 +478,6 @@ static void test_mixed_links(void)
  		.cb_opts	= &cb_opts,
  	};
  	struct tcp_ca_update *skel;
-	struct bpf_link *link, *link_nl;
  	int err;


  skel = tcp_ca_update__open_and_load();

tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +0 -0
@@ -481,10 +485,12 @@ static void test_mixed_links(void)
  		return;


  link_nl = bpf_map__attach_struct_ops(skel-

Quoted 1 line

maps.ca_no_link);

tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +2 -1
-	ASSERT_OK_PTR(link_nl, "attach_struct_ops_nl");
+	if (!ASSERT_OK_PTR(link_nl, "attach_struct_ops_nl"))
+		goto out;


  link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);

tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +2 -1
-	ASSERT_OK_PTR(link, "attach_struct_ops");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
+		goto out;


  do_test(&opts); ASSERT_GT(skel->bss->ca1_cnt, 0, "ca1_ca1_cnt");

tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +0 -0
@@ -492,6 +498,7 @@ static void test_mixed_links(void)
  	err = bpf_link__update_map(link, skel->maps.ca_no_link);
  	ASSERT_ERR(err, "update_map");


+out:
  bpf_link__destroy(link);
  bpf_link__destroy(link_nl);
  tcp_ca_update__destroy(skel);

tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +0 -0
@@ -536,7 +543,8 @@ static void test_link_replace(void)
  	bpf_link__destroy(link);


  link = bpf_map__attach_struct_ops(skel->maps.ca_update_2);

tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +2 -1
-	ASSERT_OK_PTR(link, "attach_struct_ops_2nd");
+	if (!ASSERT_OK_PTR(link, "attach_struct_ops_2nd"))
+		goto out;


  /* BPF_F_REPLACE with a wrong old map Fd. It should fail! *

tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +0 -0
@@ -559,6 +567,7 @@ static void test_link_replace(void)


  bpf_link__destroy(link);

+out:
  tcp_ca_update__destroy(skel);
 }

#4 lore raw

PATCH 2/3 selftests/bpf: Check ASSERT_OK(err) in dummy_st_ops

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Run dummy_st_ops selftests (./test_progs -t dummy_st_ops) on a Loongarch platform, some "unexpected arg" errors occur:

'''
#78/1 dummy_st_ops/dummy_st_ops_attach:OK

 test_dummy_init_ret_value:FAIL:test_ret unexpected test_ret: \
				actual 0 != expected 4076074229
 #78/2    dummy_st_ops/dummy_init_ret_value:FAIL
 #78/3    dummy_st_ops/dummy_init_ptr_arg:SKIP
 test_dummy_multiple_args:FAIL:arg 0 unexpected arg 0: \
				actual 0 != expected 7
 test_dummy_multiple_args:FAIL:arg 1 unexpected arg 1: \
				actual 0 != expected -100
 test_dummy_multiple_args:FAIL:arg 2 unexpected arg 2: \
				actual 0 != expected 35423
 test_dummy_multiple_args:FAIL:arg 3 unexpected arg 3: \
				actual 0 != expected 99
 test_dummy_multiple_args:FAIL:arg 4 unexpected arg 4: \
				actual 0 != expected 1311768467139281697
 #78/4    dummy_st_ops/dummy_multiple_args:FAIL
 #78/5    dummy_st_ops/dummy_sleepable:SKIP
 #78/6    dummy_st_ops/dummy_sleepable_reject_null:OK
 #78/7    dummy_st_ops/test_unsupported_field_sleepable:OK
 #78      dummy_st_ops:FAIL

'''

This is because BPF trampoline is not implemented on Loongarch yet, bpf_prog_test_run_opts() returns ENOTSUPP.

This patch checks the return values of bpf_prog_test_run_opts() in dummy_st_ops to fix these errors. If error returned, goto the newly added label "out" to destroy the skel.

---
 tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c +6 -2
index d3d94596ab79..a208801f524f 100644
@@ -41,9 +41,11 @@ static void test_dummy_init_ret_value(void)
 
 	fd = bpf_program__fd(skel->progs.test_1);
 	err = bpf_prog_test_run_opts(fd, &attr);
-	ASSERT_OK(err, "test_run");
+	if (!ASSERT_OK(err, "test_run"))
+		goto out;
 	ASSERT_EQ(attr.retval, 0xf2f3f4f5, "test_ret");
 
+out:
 	dummy_st_ops_success__destroy(skel);
 }
 
@@ -115,13 +117,15 @@ static void test_dummy_multiple_args(void)
 
 	fd = bpf_program__fd(skel->progs.test_2);
 	err = bpf_prog_test_run_opts(fd, &attr);
-	ASSERT_OK(err, "test_run");
+	if (!ASSERT_OK(err, "test_run"))
+		goto out;
 	args[0] = 7;
 	for (i = 0; i < ARRAY_SIZE(args); i++) {
 		snprintf(name, sizeof(name), "arg %zu", i);
 		ASSERT_EQ(skel->bss->test_2_args[i], args[i], name);
 	}
 
+out:
 	dummy_st_ops_success__destroy(skel);
 }
 
Signature · 1 line
2.43.0
Reviewed-by Tested-by on v1 2/3
#5 lore raw

Re: [PATCH bpf-next 2/3] selftests/bpf: Check ASSERT_OK(err) in dummy_st_ops

Quoted 28 lines · Geliang Tang

From: Geliang Tang <[email protected]>

Run dummy_st_ops selftests (./test_progs -t dummy_st_ops) on a Loongarch platform, some "unexpected arg" errors occur:

'''
#78/1 dummy_st_ops/dummy_st_ops_attach:OK

 test_dummy_init_ret_value:FAIL:test_ret unexpected test_ret: \
				actual 0 != expected 4076074229
 #78/2    dummy_st_ops/dummy_init_ret_value:FAIL
 #78/3    dummy_st_ops/dummy_init_ptr_arg:SKIP
 test_dummy_multiple_args:FAIL:arg 0 unexpected arg 0: \
				actual 0 != expected 7
 test_dummy_multiple_args:FAIL:arg 1 unexpected arg 1: \
				actual 0 != expected -100
 test_dummy_multiple_args:FAIL:arg 2 unexpected arg 2: \
				actual 0 != expected 35423
 test_dummy_multiple_args:FAIL:arg 3 unexpected arg 3: \
				actual 0 != expected 99
 test_dummy_multiple_args:FAIL:arg 4 unexpected arg 4: \
				actual 0 != expected 1311768467139281697
 #78/4    dummy_st_ops/dummy_multiple_args:FAIL
 #78/5    dummy_st_ops/dummy_sleepable:SKIP
 #78/6    dummy_st_ops/dummy_sleepable_reject_null:OK
 #78/7    dummy_st_ops/test_unsupported_field_sleepable:OK
 #78      dummy_st_ops:FAIL

'''

Quoted 8 lines

This is because BPF trampoline is not implemented on Loongarch yet, bpf_prog_test_run_opts() returns ENOTSUPP.

This patch checks the return values of bpf_prog_test_run_opts() in dummy_st_ops to fix these errors. If error returned, goto the newly added label "out" to destroy the skel.

Verified the test still passes on x86_64 too, so feel free to add

Quoted 38 lines
---
 tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c +6 -2
index d3d94596ab79..a208801f524f 100644
@@ -41,9 +41,11 @@ static void test_dummy_init_ret_value(void)
 
 	fd = bpf_program__fd(skel->progs.test_1);
 	err = bpf_prog_test_run_opts(fd, &attr);
-	ASSERT_OK(err, "test_run");
+	if (!ASSERT_OK(err, "test_run"))
+		goto out;
 	ASSERT_EQ(attr.retval, 0xf2f3f4f5, "test_ret");
 
+out:
 	dummy_st_ops_success__destroy(skel);
 }
 
@@ -115,13 +117,15 @@ static void test_dummy_multiple_args(void)
 
 	fd = bpf_program__fd(skel->progs.test_2);
 	err = bpf_prog_test_run_opts(fd, &attr);
-	ASSERT_OK(err, "test_run");
+	if (!ASSERT_OK(err, "test_run"))
+		goto out;
 	args[0] = 7;
 	for (i = 0; i < ARRAY_SIZE(args); i++) {
 		snprintf(name, sizeof(name), "arg %zu", i);
 		ASSERT_EQ(skel->bss->test_2_args[i], args[i], name);
 	}
 
+out:
 	dummy_st_ops_success__destroy(skel);
 }
 
#6 lore raw

PATCH 3/3 selftests/bpf: Close obj in error paths in xdp_adjust_tail

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

If bpf_object__load() fails in test_xdp_adjust_frags_tail_grow(), "obj" opened before this should be closed. So use "goto out" to close it instead of using "return" here.

---
 tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c +1 -1
index f09505f8b038..53d6ad8c2257 100644
@@ -222,7 +222,7 @@ static void test_xdp_adjust_frags_tail_grow(void)
 
 	prog = bpf_object__next_program(obj, NULL);
 	if (bpf_object__load(obj))
-		return;
+		goto out;
 
 	prog_fd = bpf_program__fd(prog);
 
Signature · 1 line
2.43.0
Reviewed-by on v1 3/3
#7 lore raw

Re: [PATCH bpf-next 3/3] selftests/bpf: Close obj in error paths in xdp_adjust_tail

Quoted 7 lines · Geliang Tang

From: Geliang Tang <[email protected]>

If bpf_object__load() fails in test_xdp_adjust_frags_tail_grow(), "obj" opened before this should be closed. So use "goto out" to close it instead of using "return" here.

...with one suggestion below...

Quoted 9 lines
---
 tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c +0 -0
index f09505f8b038..53d6ad8c2257 100644

tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c static void test_xdp_adjust_frags_tail_grow(void) · line 226

Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c +1 -1
@@ -222,7 +222,7 @@ static void test_xdp_adjust_frags_tail_grow(void)
 
 	prog = bpf_object__next_program(obj, NULL);
 	if (bpf_object__load(obj))
-		return;
+		goto out;
 

Nit: perhaps we should change this to

	if (!ASSERT_OK(bpf_object__load(obj), "obj_load"))
		goto out;

?