Optimize bpf selftest to increase CI success rate
Subsystems (5)
cover Optimize bpf selftest to increase CI success rate
1. Optimized some static bound port selftests to avoid port occupation when running test_progs -j.
2. Optimized the retry logic for test_maps.
Some Failed CI:
https://github.com/kernel-patches/bpf/actions/runs/13275542359/job/37064974076
https://github.com/kernel-patches/bpf/actions/runs/13549227497/job/37868926343
https://github.com/kernel-patches/bpf/actions/runs/13548089029/job/37865812030
https://github.com/kernel-patches/bpf/actions/runs/13553536268/job/37883329296
(Perhaps it's due to the large number of pull requests requiring CI runs?)
Jiayuan Chen (3):
selftests/bpf: Allow auto port binding for cgroup connect selftests/bpf: Allow auto port binding for bpf nf selftests/bpf: Fixes for test_maps test
tools/testing/selftests/bpf/prog_tests/bpf_nf.c | 9 ++++++--- .../testing/selftests/bpf/prog_tests/cgroup_v1v2.c | 13 +++++++++---- .../testing/selftests/bpf/progs/connect4_dropper.c | 4 +++- tools/testing/selftests/bpf/test_maps.c | 9 +++++---- 4 files changed, 23 insertions(+), 12 deletions(-)
Signature · 1 line
2.47.1
PATCH 1/3 selftests/bpf: Allow auto port binding for cgroup connect
Allow auto port binding for cgroup connect test to avoid binding conflict.
Result:
./test_progs -a cgroup_v1v2
59 cgroup_v1v2:OK
Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
--- .../testing/selftests/bpf/prog_tests/cgroup_v1v2.c | 13 +++++++++---- .../testing/selftests/bpf/progs/connect4_dropper.c | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-)
tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c +9 -4
@@ -10,12 +10,18 @@static int run_test (int cgroup_fd,int server_fd,bool classid) {struct connect4_dropper *skel; -int fd, err =0 ; +int fd, err =0 , port; skel =connect4_dropper__open_and_load ();if (!ASSERT_OK_PTR (skel,"skel_open" ))return -1 ; + port =get_socket_local_port (server_fd); +if (!ASSERT_GE (port,0 ,"get_socket_local_port" )) +return -1 ; + + skel->bss->port =ntohs (port); + skel->links.connect_v4_dropper =bpf_program__attach_cgroup (skel->progs.connect_v4_dropper, cgroup_fd);
@@ -48,10 +54,9 @@ void test_cgroup_v1v2(void) {struct network_helper_opts opts = {};int server_fd, client_fd, cgroup_fd; -static const int port =60120 ;/* Step 1: Check base connectivity works without any BPF. */ - server_fd =start_server (AF_INET ,SOCK_STREAM ,NULL , port,0 ); + server_fd =start_server (AF_INET ,SOCK_STREAM ,NULL ,0 ,0 );if (!ASSERT_GE (server_fd,0 ,"server_fd" ))return ; client_fd =connect_to_fd_opts (server_fd, &opts);
@@ -66,7 +71,7 @@ void test_cgroup_v1v2(void) cgroup_fd =test__join_cgroup ("/connect_dropper" );if (!ASSERT_GE (cgroup_fd,0 ,"cgroup_fd" ))return ; - server_fd =start_server (AF_INET ,SOCK_STREAM ,NULL , port,0 ); + server_fd =start_server (AF_INET ,SOCK_STREAM ,NULL ,0 ,0 );if (!ASSERT_GE (server_fd,0 ,"server_fd" )) {close (cgroup_fd);return ;
tools/testing/selftests/bpf/progs/connect4_dropper.c +3 -1
@@ -13,12 +13,14 @@#define VERDICT_REJECT 0#define VERDICT_PROCEED 1 +int port; + SEC("cgroup/connect4")int connect_v4_dropper (struct bpf_sock_addr *ctx) {if (ctx->type !=SOCK_STREAM )return VERDICT_PROCEED ; -if (ctx->user_port ==bpf_htons (60120 )) +if (ctx->user_port ==bpf_htons (port))return VERDICT_REJECT ;return VERDICT_PROCEED ; }
Signature · 1 line
2.47.1
PATCH 2/3 selftests/bpf: Allow auto port binding for bpf nf
In reply to Jiayuan ChenAllow auto port binding for bpf nf test to avoid binding conflict.
./test_progs -a bpf_nf
24/1 bpf_nf/xdp-ct:OK 24/2 bpf_nf/tc-bpf-ct:OK 24/3 bpf_nf/alloc_release:OK 24/4 bpf_nf/insert_insert:OK 24/5 bpf_nf/lookup_insert:OK 24/6 bpf_nf/set_timeout_after_insert:OK 24/7 bpf_nf/set_status_after_insert:OK 24/8 bpf_nf/change_timeout_after_alloc:OK 24/9 bpf_nf/change_status_after_alloc:OK 24/10 bpf_nf/write_not_allowlisted_field:OK 24 bpf_nf:OK
Summary: 1/10 PASSED, 0 SKIPPED, 0 FAILED
--- tools/testing/selftests/bpf/prog_tests/bpf_nf.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/prog_tests/bpf_nf.c +6 -3
@@ -72,11 +72,14 @@ static void test_bpf_nf_ct(int mode)if (!ASSERT_OK (system (cmd), cmd)) goto end; - srv_port = (mode ==TEST_XDP ) ?5005 :5006 ; - srv_fd =start_server (AF_INET ,SOCK_STREAM ,"127.0.0.1" , srv_port,TIMEOUT_MS ); + srv_fd =start_server (AF_INET ,SOCK_STREAM ,"127.0.0.1" ,0 ,TIMEOUT_MS );if (!ASSERT_GE (srv_fd,0 ,"start_server" )) goto end; + srv_port =get_socket_local_port (srv_fd); +if (!ASSERT_GE (srv_port,0 ,"get_sock_local_port" )) + goto end; + client_fd =connect_to_server (srv_fd);if (!ASSERT_GE (client_fd,0 ,"connect_to_server" )) goto end;
@@ -91,7 +94,7 @@ static void test_bpf_nf_ct(int mode) skel->bss->saddr = peer_addr.sin_addr.s_addr; skel->bss->sport = peer_addr.sin_port; skel->bss->daddr = peer_addr.sin_addr.s_addr; - skel->bss->dport =htons (srv_port); + skel->bss->dport = srv_port;if (mode ==TEST_XDP ) prog_fd =bpf_program__fd (skel->progs.nf_xdp_ct_test);
Signature · 1 line
2.47.1
PATCH 3/3 selftests/bpf: Fixes for test_maps test
In reply to Jiayuan ChenBPF CI has failed 3 times in the last 24 hours. Add retry for ENOMEM.
It's similar to the optimization plan:
commit 2f553b032cad ("selftsets/bpf: Retry map update for non-preallocated per-cpu map")
Failed CI:
https://github.com/kernel-patches/bpf/actions/runs/13549227497/job/37868926343
https://github.com/kernel-patches/bpf/actions/runs/13548089029/job/37865812030
https://github.com/kernel-patches/bpf/actions/runs/13553536268/job/37883329296
selftests/bpf: Fixes for test_maps test Fork 100 tasks to 'test_update_delete' Fork 100 tasks to 'test_update_delete' Fork 100 tasks to 'test_update_delete' Fork 100 tasks to 'test_update_delete'
......
test_task_storage_map_stress_lookup:PASStest_maps: OK, 0 SKIPPED
--- tools/testing/selftests/bpf/test_maps.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/test_maps.c +5 -4
@@ -1396,9 +1396,10 @@ static void test_map_stress(void)#define MAX_DELAY_US 50000#define MIN_DELAY_RANGE_US 5000 -static bool retry_for_again_or_busy (int err) +static bool can_retry (int err) { -return (err ==EAGAIN || err ==EBUSY ); +return (err ==EAGAIN || err ==EBUSY || + (err ==ENOMEM && map_opts.map_flags ==BPF_F_NO_PREALLOC )); } int map_update_retriable(int map_fd, const void *key, const void *value, int flags, int attempts,
@@ -1451,12 +1452,12 @@ static void test_update_delete(unsigned int fn, void *data)if (do_update) { err =map_update_retriable (fd, &key, &value,BPF_NOEXIST ,MAP_RETRIES , - retry_for_again_or_busy); + can_retry);if (err)printf ("error %d %d\n" , err, errno);assert (err ==0 ); err =map_update_retriable (fd, &key, &value,BPF_EXIST ,MAP_RETRIES , - retry_for_again_or_busy); + can_retry);if (err)printf ("error %d %d\n" , err, errno);assert (err ==0 );
Signature · 1 line
2.47.1
Quoted 4 lines · Jiayuan Chen
1. Optimized some static bound port selftests to avoid port occupation when running
test_progs-j.
2. Optimized the retry logic fortest_maps.
Looks great. Applied.
Thank you for fixing them.
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 4 lines · On Thu, 27 Feb 2025 22:26:43 +0800 you wrote:
1. Optimized some static bound port selftests to avoid port occupation when running
test_progs-j.
2. Optimized the retry logic fortest_maps.
Quoted 8 lines
Some Failed CI:
https://github.com/kernel-patches/bpf/actions/runs/13275542359/job/37064974076
https://github.com/kernel-patches/bpf/actions/runs/13549227497/job/37868926343
https://github.com/kernel-patches/bpf/actions/runs/13548089029/job/37865812030
https://github.com/kernel-patches/bpf/actions/runs/13553536268/job/37883329296
(Perhaps it's due to the large number of pull requests requiring CI runs?)[...]
Here is the summary with links:
- [bpf-next,v1,1/3] selftests/bpf: Allow auto port binding for cgroup connect
https://git.kernel.org/bpf/bpf-next/c/27e3162a0364 - [bpf-next,v1,2/3] selftests/bpf: Allow auto port binding for bpf nf https://git.kernel.org/bpf/bpf-next/c/dbe7d46ed109 - [bpf-next,v1,3/3] selftests/bpf: Fixes for test_maps test https://git.kernel.org/bpf/bpf-next/c/09de329523c8
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Re: [PATCH bpf-next v1 3/3] selftests/bpf: Fixes for test_maps test
In reply to Jiayuan ChenHi,
Quoted 8 lines · Jiayuan Chen
BPF CI has failed 3 times in the last 24 hours. Add retry for ENOMEM.
It's similar to the optimization plan:
commit2f553b032cad("selftsets/bpf: Retry map update for non-preallocated per-cpu map")Failed CI:
https://github.com/kernel-patches/bpf/actions/runs/13549227497/job/37868926343
https://github.com/kernel-patches/bpf/actions/runs/13548089029/job/37865812030
https://github.com/kernel-patches/bpf/actions/runs/13553536268/job/37883329296
Er, it is suspicious that the allocation of htab_elem failed, because the size of key and value is small in these cases. It usually means that there is something wrong with bpf mem allocator or the slub, therefore, I think it is a bad idea to retry for ENOMEM in this case. Will try to reproduce the problem first when get some time.
Quoted 47 lines
selftests/bpf: Fixes for
test_mapstest Fork 100 tasks to 'test_update_delete' Fork 100 tasks to 'test_update_delete' Fork 100 tasks to 'test_update_delete' Fork 100 tasks to 'test_update_delete'
......
test_task_storage_map_stress_lookup:PASStest_maps: OK, 0 SKIPPEDSigned-off-by Jiayuan Chen <[email protected]>--- tools/testing/selftests/bpf/test_maps.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)tools/testing/selftests/bpf/test_maps.c +5
-4@@ -1396,9 +1396,10 @@ static void test_map_stress(void)#define MAX_DELAY_US 50000#define MIN_DELAY_RANGE_US 5000 -static bool retry_for_again_or_busy (int err) +static bool can_retry (int err) { -return (err ==EAGAIN || err ==EBUSY ); +return (err ==EAGAIN || err ==EBUSY || + (err ==ENOMEM && map_opts.map_flags ==BPF_F_NO_PREALLOC )); } int map_update_retriable(int map_fd, const void *key, const void *value, int flags, int attempts,@@ -1451,12 +1452,12 @@ static void test_update_delete(unsigned int fn, void *data)if (do_update) { err =map_update_retriable (fd, &key, &value,BPF_NOEXIST ,MAP_RETRIES , - retry_for_again_or_busy); + can_retry);if (err)printf ("error %d %d\n" , err, errno);assert (err ==0 ); err =map_update_retriable (fd, &key, &value,BPF_EXIST ,MAP_RETRIES , - retry_for_again_or_busy); + can_retry);if (err)printf ("error %d %d\n" , err, errno);assert (err ==0 );