summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf
diff options
context:
space:
mode:
authorGeliang Tang <tanggeliang@kylinos.cn>2024-05-30 15:41:11 +0800
committerDaniel Borkmann <daniel@iogearbox.net>2024-06-06 23:04:05 +0200
commitcd984b2ed62423eb3daceacb21d651115a612af6 (patch)
treefb8752b38572b05a18f08ea1e4bef42d9b6ea174 /tools/testing/selftests/bpf
parent224eeb5598c30ee835dc9fea4c7ad85a8fb7eda4 (diff)
selftests/bpf: Use start_test in test_dctcp in bpf_tcp_ca
The "if (sk_stg_map)" block in do_test() is only used by test_dctcp(), it makes sense to move it from do_test() into test_dctcp(). Then do_test() can be used by other tests except test_dctcp(). Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/9938916627b9810c877e5c03a621bc0ba5acf5c5.1717054461.git.tanggeliang@kylinos.cn
Diffstat (limited to 'tools/testing/selftests/bpf')
-rw-r--r--tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
index d10217169ff8..1b27d0232cbd 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
@@ -72,21 +72,10 @@ static void do_test(const struct network_helper_opts *opts,
const struct bpf_map *sk_stg_map)
{
int lfd = -1, fd = -1;
- int err;
if (!start_test(NULL, opts, cli_opts, &lfd, &fd))
goto done;
- if (sk_stg_map) {
- int tmp_stg;
-
- err = bpf_map_lookup_elem(bpf_map__fd(sk_stg_map), &fd,
- &tmp_stg);
- if (!ASSERT_ERR(err, "bpf_map_lookup_elem(sk_stg_map)") ||
- !ASSERT_EQ(errno, ENOENT, "bpf_map_lookup_elem(sk_stg_map)"))
- goto done;
- }
-
ASSERT_OK(send_recv_data(lfd, fd, total_bytes), "send_recv_data");
done:
@@ -163,6 +152,7 @@ static void test_dctcp(void)
.post_socket_cb = stg_post_socket_cb,
.cb_opts = &cb_opts,
};
+ int lfd = -1, fd = -1, tmp_stg, err;
struct bpf_dctcp *dctcp_skel;
struct bpf_link *link;
@@ -177,11 +167,24 @@ static void test_dctcp(void)
}
cb_opts.map_fd = bpf_map__fd(dctcp_skel->maps.sk_stg_map);
- do_test(&opts, &cli_opts, dctcp_skel->maps.sk_stg_map);
+ if (!start_test(NULL, &opts, &cli_opts, &lfd, &fd))
+ goto done;
+
+ err = bpf_map_lookup_elem(cb_opts.map_fd, &fd, &tmp_stg);
+ if (!ASSERT_ERR(err, "bpf_map_lookup_elem(sk_stg_map)") ||
+ !ASSERT_EQ(errno, ENOENT, "bpf_map_lookup_elem(sk_stg_map)"))
+ goto done;
+
+ ASSERT_OK(send_recv_data(lfd, fd, total_bytes), "send_recv_data");
ASSERT_EQ(dctcp_skel->bss->stg_result, expected_stg, "stg_result");
+done:
bpf_link__destroy(link);
bpf_dctcp__destroy(dctcp_skel);
+ if (lfd != -1)
+ close(lfd);
+ if (fd != -1)
+ close(fd);
}
static char *err_str;