misc fixes for sockopt selftests
Subsystems (3)
Geliang Tang
reviewercover misc fixes for sockopt selftests
From: Geliang Tang <[email protected]>
This patch series addresses several resource management issues in the MPTCP sockopt selftests:
Patch 1 fixes a resource leak by ensuring the server's listening socket is properly closed after processing clients, rather than leaving it open.
Patch 2 eliminates double-closing of pipe descriptors by removing redundant close operations in functions where these descriptors are already managed by the main function.
Patch 3 corrects an error reporting issue where the wrong variable was being checked in debug output, ensuring accurate debugging information when assertions fail.
These changes improve the robustness and correctness of the MPTCP selftests by ensuring proper resource cleanup and accurate error reporting.
Geliang Tang (3):
selftests: mptcp: close server file descriptor
selftests: mptcp: avoid double closing pipe descriptor
selftests: mptcp: sockopt: fix variable check in error reporting
tools/testing/selftests/net/mptcp/mptcp_inq.c | 3 +-- tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-)
Signature · 1 line
2.48.1
Geliang Tang
reviewerPATCH 1/3 selftests: mptcp: close server file descriptor
From: Geliang Tang <[email protected]>
The server file descriptor ('fd') is opened in server() but never closed. While accepted connections are properly closed in process_one_client(), the main listening socket remains open, causing a resource leak.
This patch ensures the server fd is properly closed after processing clients, bringing the sockopt and inq test cases in line with proper resource cleanup practices.
--- tools/testing/selftests/net/mptcp/mptcp_inq.c | 1 + tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 1 + 2 files changed, 2 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_inq.c +1 -0
@@ -502,6 +502,7 @@ static int server(int unixfd)process_one_client (r, unixfd); +close (fd);return 0 ; }
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +1 -0
@@ -722,6 +722,7 @@ static int server(int pipefd)process_one_client (r, pipefd); +close (fd);return 0 ; }
Signature · 1 line
2.48.1
Geliang Tang
reviewerPATCH 2/3 selftests: mptcp: avoid double closing pipe descriptor
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
The pipe descriptor (pipefds[0]) is already closed in main() after the client() function completes, making the explicit close in connect_one_server() redundant and potentially harmful.
This patch removes the unnecessary close operations in both the sockopt and inq test cases to prevent double-closing of file descriptors, which could lead to undefined behavior if the descriptor is reused.
--- tools/testing/selftests/net/mptcp/mptcp_inq.c | 2 -- tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 1 - 2 files changed, 3 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_inq.c +0 -2
@@ -314,8 +314,6 @@ static void connect_one_server(int fd, int unixfd)close (fd); ret =write (unixfd,"closed" ,6 );assert (ret ==6 ); - -close (unixfd); }static void get_tcp_inq (struct msghdr *msgh,unsigned int *inqv)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +0 -1
@@ -593,7 +593,6 @@ static void connect_one_server(int fd, int pipefd)/* un-block server */ ret =read (pipefd, buf2,4 );assert (ret ==4 ); -close (pipefd);assert (strncmp (buf2,"xmit" ,4 ) ==0 );
Signature · 1 line
2.48.1
Geliang Tang
reviewerPATCH 3/3 selftests: mptcp: sockopt: fix variable check in error reporting
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
The error message for mptcpi_bytes_acked comparison incorrectly references 'ret2' instead of 'ret'. Since the comparison is between mptcpi_bytes_acked and 'ret', the error output should consistently use 'ret' for both the expected value and difference calculation.
This patch corrects the variable usage in the error output to ensure accurate debugging information when the assertion fails.
--- tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +2 -2
@@ -680,8 +680,8 @@ static void process_one_client(int fd, int pipefd) s.last_sample.mptcpi_bytes_received - ret);if (s.last_sample.mptcpi_bytes_acked != ret)xerror ("mptcpi_bytes_acked %" PRIu64", expect %" PRIu64, - s.last_sample.mptcpi_bytes_acked, ret2, - s.last_sample.mptcpi_bytes_acked - ret2); + s.last_sample.mptcpi_bytes_acked, ret, + s.last_sample.mptcpi_bytes_acked - ret); }close (fd);
Signature · 1 line
2.48.1
Hi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Unstable: 5 failed test(s): packetdrill_mp_join packetdrill_sockopts packetdrill_syscalls selftest_mptcp_connect_checksum selftest_mptcp_join 🔴
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/17391054770
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/05f2aeac85bd
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=997777
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normalFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Re: [PATCH mptcp-net 1/3] selftests: mptcp: close server file descriptor
In reply to Geliang TangHi Geliang,
Quoted 9 lines · Geliang Tang
From: Geliang Tang <[email protected]>
The server file descriptor ('fd') is opened in
server()but never closed. While accepted connections are properly closed inprocess_one_client(), the main listening socket remains open, causing a resource leak.This patch ensures the server fd is properly closed after processing clients, bringing the sockopt and inq test cases in line with proper resource cleanup practices.
Thanks!
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts
maintainerRe: [PATCH mptcp-net 2/3] selftests: mptcp: avoid double closing pipe descriptor
In reply to Geliang TangHi Geliang,
Thank you for the fixes.
Quoted 5 lines · Geliang Tang
From: Geliang Tang <[email protected]>
The pipe descriptor (pipefds[0]) is already closed in
main()after theclient()function completes, making the explicit close inconnect_one_server()redundant and potentially harmful.
Mmh, the close() are done from different processes, after fork(), no?
If yes, each process should close the fd, and what was done was correct. Or did I miss something?
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts
maintainerRe: [PATCH mptcp-net 3/3] selftests: mptcp: sockopt: fix variable check in error reporting
In reply to Geliang TangHi Geliang,
Quoted 21 lines · Geliang Tang
From: Geliang Tang <[email protected]>
The error message for
mptcpi_bytes_ackedcomparison incorrectly references 'ret2' instead of 'ret'. Since the comparison is betweenmptcpi_bytes_ackedand 'ret', the error output should consistently use 'ret' for both the expected value and difference calculation.This patch corrects the variable usage in the error output to ensure accurate debugging information when the assertion fails.
Fixes 5dcff89e1455 ("selftests: mptcp: explicitly tests aggregate counters")Signed-off-by Geliang Tang <[email protected]>--- tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/testing/selftests/net/mptcp/mptcp_sockopt.c +0
-0
tools/testing/selftests/net/mptcp/mptcp_sockopt.c static void process_one_client(int fd, int pipefd) · line 684
Quoted 7 lines
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +2
-2@@ -680,8 +680,8 @@ static void process_one_client(int fd, int pipefd) s.last_sample.mptcpi_bytes_received - ret);if (s.last_sample.mptcpi_bytes_acked != ret)xerror ("mptcpi_bytes_acked %" PRIu64", expect %" PRIu64, - s.last_sample.mptcpi_bytes_acked, ret2, - s.last_sample.mptcpi_bytes_acked - ret2); + s.last_sample.mptcpi_bytes_acked, ret, + s.last_sample.mptcpi_bytes_acked - ret);
Good catch! But I also just noticed there is one extra argument: you have 2 "%", but 3 arguments after the string.
I guess the error should be:
"mptcpi_bytes_acked %" PRIu64 ", expect %" PRIu64 ", diff %" PRIu64, (...)
(Same for the others above.) If yes, can you add this as part of the same commit?
selftests: mptcp: sockopt: fix error messages
(with a note about the fact the wrong variable was used)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c static void process_one_client(int fd, int pipefd) · line 687
Quoted 3 lines
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +0
-0}close (fd);
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.