From 08c7ace7dd56696895347e21384a9b3064720e97 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Fri, 29 Mar 2024 21:25:05 +0800 Subject: [PATCH] send_byte Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 6 ++++-- tools/testing/selftests/bpf/network_helpers.h | 2 +- tools/testing/selftests/bpf/prog_tests/mptcp.c | 4 ++-- tools/testing/selftests/bpf/prog_tests/sk_lookup.c | 13 ------------- tools/testing/selftests/bpf/prog_tests/tcp_rtt.c | 2 +- 5 files changed, 8 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 9e8e2d34f76f0..9491946ce4939 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -498,11 +498,13 @@ int get_socket_local_port(int sock_fd) return -1; } -void send_single_byte(int fd) +int send_byte(int fd) { char b = 0x55; - ASSERT_EQ(write(fd, &b, sizeof(b)), 1, "send single byte"); + if (!ASSERT_EQ(write(fd, &b, sizeof(b)), 1, "send single byte")) + return -1; + return 0; } static const unsigned int total_bytes = 10 * 1024 * 1024; diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index ad8dfca5296f7..a0f094047666d 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -71,7 +71,7 @@ struct nstoken; */ struct nstoken *open_netns(const char *name); void close_netns(struct nstoken *token); -void send_single_byte(int fd); +int send_byte(int fd); void send_recv_data(int lfd, int fd); static __u16 csum_fold(__u32 csum) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 7a20fbff8e9ab..9918d354d508d 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -289,7 +289,7 @@ static void run_mptcpify(int cgroup_fd, struct mptcpify *skel) if (!ASSERT_GE(client_fd, 0, "connect to fd")) goto close_server; - send_single_byte(client_fd); + send_byte(client_fd); err = verify_mptcpify(server_fd, client_fd); ASSERT_OK(err, "verify_mptcpify"); @@ -358,7 +358,7 @@ static void run_mptcp_subflow(int cgroup_fd, struct mptcp_subflow *skel) if (!ASSERT_GE(client_fd, 0, "connect to fd")) goto close_server; - send_single_byte(client_fd); + send_byte(client_fd); ASSERT_OK(ss_search(ADDR1, "fwmark:0x1"), "ss_search fwmark:0x1"); ASSERT_OK(ss_search(ADDR2, "fwmark:0x2"), "ss_search fwmark:0x2"); diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c index 597d0467a9267..b4310a5ec1a46 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c @@ -282,19 +282,6 @@ static int fill_sk_lookup_ctx(struct bpf_sk_lookup *ctx, const char *local_ip, _ return 0; } -static int send_byte(int fd) -{ - ssize_t n; - - errno = 0; - n = send(fd, "a", 1, 0); - if (CHECK(n <= 0, "send_byte", "send")) { - log_err("failed/partial send"); - return -1; - } - return 0; -} - static int recv_byte(int fd) { char buf[1]; diff --git a/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c b/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c index 5e23cf1e951c1..dcb2d5e9c8db5 100644 --- a/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c +++ b/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c @@ -114,7 +114,7 @@ static int run_test(int cgroup_fd, int server_fd) /*delivered_ce=*/0, /*icsk_retransmits=*/0); - send_single_byte(client_fd); + send_byte(client_fd); if (wait_for_ack(client_fd, 100) < 0) { err = -1; goto close_client_fd;