Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
fix

Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang committed May 29, 2024
1 parent 075e84f commit d6d9caf
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,32 +111,24 @@ static int stg_post_socket_cb(int fd, void *opts)
return 0;
}

static int stg_post_connect_cb(int fd, void *opts)
{
struct cb_opts *cb_opts = (struct cb_opts *)opts;
int tmp_stg;
int err;

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)"))
return err;

return 0;
}

static void test_dctcp(void)
{
struct cb_opts cb_opts = {
.cc = "bpf_dctcp",
};
struct network_helper_opts opts = {
.post_socket_cb = cc_cb,
.cb_opts = &cb_opts,
};
struct network_helper_opts cli_opts = {
.post_socket_cb = stg_post_socket_cb,
.post_connect_cb = stg_post_connect_cb,
.cb_opts = &cb_opts,
};
struct bpf_dctcp *dctcp_skel;
struct bpf_link *link;
int lfd = -1, fd = -1;
int tmp_stg;
int err;

dctcp_skel = bpf_dctcp__open_and_load();
if (!ASSERT_OK_PTR(dctcp_skel, "bpf_dctcp__open_and_load"))
Expand All @@ -149,11 +141,31 @@ static void test_dctcp(void)
}

cb_opts.map_fd = bpf_map__fd(dctcp_skel->maps.sk_stg_map);
do_test(&opts);

lfd = start_server_str(AF_INET6, SOCK_STREAM, NULL, 0, &opts);
if (!ASSERT_NEQ(lfd, -1, "socket"))
goto done;

/* connect to server */
fd = connect_to_fd_opts(lfd, &cli_opts);
if (!ASSERT_NEQ(fd, -1, "connect_to_fd_opts"))
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, NULL), "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;
Expand Down

0 comments on commit d6d9caf

Please sign in to comment.