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
This commit is contained in:
parent
224eeb5598
commit
cd984b2ed6
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user