[PATCH mptcp-next v4 2/2] selftests: mptcp: connect: trigger splice_eof

Geliang Tang posted 2 patches 2 months, 1 week ago
[PATCH mptcp-next v4 2/2] selftests: mptcp: connect: trigger splice_eof
Posted by Geliang Tang 2 months, 1 week ago
From: Geliang Tang <tanggeliang@kylinos.cn>

Increase the sendfile count by one to ensure the transmission size
exceeds the actual data length. This triggers the splice_eof path
in the kernel, allowing the newly implemented MPTCP splice_eof
interface to be exercised during testing.

The change from 'count' to 'count + 1' forces the sendfile operation
to attempt sending one more byte than available, which activates the
end-of-file handling in the splicing logic and ensures coverage of
the related MPTCP code paths.

Additionally, handle cases where sendfile returns 0 (no more data)
or a value larger than the remaining count (e.g., due to concurrent
file growth). In such cases, break out of the loop to prevent
unsigned integer underflow and potential infinite loop.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/net/mptcp/mptcp_connect.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c
index cbe573c4ab3a..f6a4dd5597df 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
@@ -870,12 +870,15 @@ static int do_sendfile(int infd, int outfd, unsigned int count,
 	while (count > 0) {
 		ssize_t r;
 
-		r = sendfile(outfd, infd, NULL, count);
+		r = sendfile(outfd, infd, NULL, count + 1);
 		if (r < 0) {
 			perror("sendfile");
 			return 3;
 		}
 
+		if (r == 0 || r > count)
+			break;
+
 		count -= r;
 	}
 
-- 
2.43.0