On 4/1/24 11:38 PM, Geliang Tang wrote:
From: Geliang Tang <tanggeliang@xxxxxxxxxx>
The helper send_byte is defined in mptcp.c, sk_lookup.c and tcp_rtt.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@xxxxxxxxxx>
---
tools/testing/selftests/bpf/network_helpers.c | 9 +++++++++
tools/testing/selftests/bpf/network_helpers.h | 1 +
tools/testing/selftests/bpf/prog_tests/mptcp.c | 7 -------
tools/testing/selftests/bpf/prog_tests/sk_lookup.c | 13 -------------
tools/testing/selftests/bpf/prog_tests/tcp_rtt.c | 7 -------
5 files changed, 10 insertions(+), 27 deletions(-)
diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index 6db27a9088e9..f2f8f7388d7c 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -497,3 +497,12 @@ int get_socket_local_port(int sock_fd)
return -1;
}
+
+int send_byte(int fd)
+{
+ char b = 0x55;
+
+ if (!ASSERT_EQ(write(fd, &b, sizeof(b)), 1, "send single byte"))
+ return -1;
+ return 0;
+}
I think it is overkill to have a dedicated helper that only does the error
checking on the single syscall send/write. I would drop this patch and directly
use the syscall send/write instead.