From: Geliang Tang <tanggeliang@kylinos.cn>
The helper send_byte is defined in both tcp_rtt.c and mptcp.c. It makes
sense to export it into network_helpers.h to let it can be used for all
BPF selftests.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
tools/testing/selftests/bpf/network_helpers.c | 7 +++++++
tools/testing/selftests/bpf/network_helpers.h | 1 +
tools/testing/selftests/bpf/prog_tests/mptcp.c | 9 +--------
tools/testing/selftests/bpf/prog_tests/tcp_rtt.c | 9 +--------
4 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index 6db27a9088e9..8dea4160bfee 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -497,3 +497,10 @@ int get_socket_local_port(int sock_fd)
return -1;
}
+
+void send_single_byte(int fd)
+{
+ char b = 0x55;
+
+ ASSERT_EQ(write(fd, &b, sizeof(b)), 1, "send single byte");
+}
diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h
index 94b9be24e39b..b3c2238772c8 100644
--- a/tools/testing/selftests/bpf/network_helpers.h
+++ b/tools/testing/selftests/bpf/network_helpers.h
@@ -71,6 +71,7 @@ struct nstoken;
*/
struct nstoken *open_netns(const char *name);
void close_netns(struct nstoken *token);
+void send_single_byte(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 7fec91ab19cf..42edf9f80d68 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -231,13 +231,6 @@ static void test_base(void)
close(cgroup_fd);
}
-static void send_byte(int fd)
-{
- char b = 0x55;
-
- ASSERT_EQ(write(fd, &b, sizeof(b)), 1, "send single byte");
-}
-
static int verify_mptcpify(int server_fd, int client_fd)
{
struct __mptcp_info info;
@@ -296,7 +289,7 @@ static int run_mptcpify(int cgroup_fd)
goto close_server;
}
- send_byte(client_fd);
+ send_single_byte(client_fd);
err = verify_mptcpify(server_fd, client_fd);
diff --git a/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c b/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c
index 8fe84da1b9b4..5e23cf1e951c 100644
--- a/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c
+++ b/tools/testing/selftests/bpf/prog_tests/tcp_rtt.c
@@ -12,13 +12,6 @@ struct tcp_rtt_storage {
__u32 icsk_retransmits;
};
-static void send_byte(int fd)
-{
- char b = 0x55;
-
- ASSERT_EQ(write(fd, &b, sizeof(b)), 1, "send single byte");
-}
-
static int wait_for_ack(int fd, int retries)
{
struct tcp_info info;
@@ -121,7 +114,7 @@ static int run_test(int cgroup_fd, int server_fd)
/*delivered_ce=*/0,
/*icsk_retransmits=*/0);
- send_byte(client_fd);
+ send_single_byte(client_fd);
if (wait_for_ack(client_fd, 100) < 0) {
err = -1;
goto close_client_fd;
--
2.40.1