Skip to content

Commit

Permalink
selftests/bpf: Add timeout_ms for send_recv_data
Browse files Browse the repository at this point in the history
Some self-test cases, such as MPTCP, require longer timeout values than
the default 3 sec. So this patch adds a new parameter "timeout_ms" to
send_recv_data to set different timeout values in ms. Also, a new member
"tout" is added to struct send_recv_arg to pass the timeout value to
send_recv_server() and to settimeo().

Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang committed Jan 16, 2025
1 parent f982dea commit 20128ed
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions tools/testing/selftests/bpf/network_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param)
struct send_recv_arg {
int fd;
uint32_t bytes;
int tout;
int stop;
};

Expand All @@ -640,7 +641,7 @@ static void *send_recv_server(void *arg)
goto done;
}

if (settimeo(fd, 0)) {
if (settimeo(fd, a->tout)) {
err = -errno;
goto done;
}
Expand Down Expand Up @@ -673,12 +674,13 @@ static void *send_recv_server(void *arg)
return NULL;
}

int send_recv_data(int lfd, int fd, uint32_t total_bytes)
int send_recv_data(int lfd, int fd, uint32_t total_bytes, int timeout_ms)
{
ssize_t nr_recv = 0, bytes = 0;
struct send_recv_arg arg = {
.fd = lfd,
.bytes = total_bytes,
.tout = timeout_ms,
.stop = 0,
};
pthread_t srv_thread;
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/bpf/network_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct nstoken;
*/
struct nstoken *open_netns(const char *name);
void close_netns(struct nstoken *token);
int send_recv_data(int lfd, int fd, uint32_t total_bytes);
int send_recv_data(int lfd, int fd, uint32_t total_bytes, int timeout_ms);
int make_netns(const char *name);
int remove_netns(const char *name);

Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void do_test(const struct network_helper_opts *opts)
if (!start_test(NULL, opts, opts, &lfd, &fd))
goto done;

ASSERT_OK(send_recv_data(lfd, fd, total_bytes), "send_recv_data");
ASSERT_OK(send_recv_data(lfd, fd, total_bytes, 0), "send_recv_data");

done:
if (lfd != -1)
Expand Down Expand Up @@ -169,7 +169,7 @@ static void test_dctcp(void)
!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_OK(send_recv_data(lfd, fd, total_bytes, 0), "send_recv_data");
ASSERT_EQ(dctcp_skel->bss->stg_result, expected_stg, "stg_result");

done:
Expand Down

0 comments on commit 20128ed

Please sign in to comment.