Skip to contentSkip to conversation

selftests: net: improve error handling in passive TFO test

PATCH Superseded Yohei Kojima 2 participants 7 messages Jan 12 – Jan 13

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover selftests: net: improve error handling in passive TFO test

This series improves error handling in the passive TFO test by (1) fixing a broken behavior when the child processes failed (or timed out), and (2) adding more error handlng code in the test program.

The first patch fixes the behavior that the test didn't report failure even if the server or the client process exited with non-zero status. The second patch adds error handling code in the test program to improve reliability of the test.

This series was split out from the following series to address the feedback from Andrew Lunn:
https://lore.kernel.org/netdev/[email protected]/

Yohei Kojima (2):
selftests: net: fix passive TFO test to fail if child processes failed
selftests: net: improve error handling in passive TFO test

 tools/testing/selftests/net/tfo.c          | 10 +++++++---
 tools/testing/selftests/net/tfo_passive.sh | 13 ++++++++++++-
 2 files changed, 19 insertions(+), 4 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH 1/2 selftests: net: fix passive TFO test to fail if child processes failed

This commit improves the passive TFO test to report failure if the server or the cliend timed out or exited with non-zero status.

Before this commit, TFO test didn't fail even if exit(EXIT_FAILURE) is added to the first line of the run_server() and run_client() functions.

---
 tools/testing/selftests/net/tfo_passive.sh | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
tools/testing/selftests/net/tfo_passive.sh +12 -1
index a4550511830a..f116f888b794 100755
@@ -85,12 +85,15 @@ timeout -k 1s 30s ip netns exec nssv ./tfo        \
 				-s                \
 				-p ${SERVER_PORT} \
 				-o ${out_file}&
+server_pid="$!"
 
 wait_local_port_listen nssv ${SERVER_PORT} tcp
 
 ip netns exec nscl ./tfo -c -h ${SERVER_IP} -p ${SERVER_PORT}
+client_exit_status="$?"
 
-wait
+wait "$server_pid"
+server_exit_status="$?"
 
 res=$(cat $out_file)
 rm $out_file
@@ -101,6 +104,14 @@ if [ "$res" = "0" ]; then
 	exit 1
 fi
 
+if [ "$client_exit_status" -ne 0 ] || [ "$server_exit_status" -ne 0 ]; then
+	# Note: timeout(1) exits with 124 if it timed out
+	echo "client exited with ${client_exit_status}"
+	echo "server exited with ${server_exit_status}"
+	cleanup_ns
+	exit 1
+fi
+
 echo "$NSIM_SV_FD:$NSIM_SV_IFIDX" > $NSIM_DEV_SYS_UNLINK
 
 echo $NSIM_CL_ID > $NSIM_DEV_SYS_DEL
Signature · 1 line
2.52.0
#2 lore raw

PATCH 2/2 selftests: net: improve error handling in passive TFO test

In reply to Yohei Kojima

This commit improves the error handling in passive TFO test to check the return value from sendto(), and to fail if read() failed.

---
 tools/testing/selftests/net/tfo.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
tools/testing/selftests/net/tfo.c +7 -3
index 8d82140f0f76..4572eb9b8968 100644
@@ -82,7 +82,8 @@ static void run_server(void)
 		error(1, errno, "getsockopt(SO_INCOMING_NAPI_ID)");
 
 	if (read(connfd, buf, 64) < 0)
-		perror("read()");
+		error(1, errno, "read()");
+
 	fprintf(outfile, "%d\n", opt);
 
 	fclose(outfile);
@@ -92,14 +93,17 @@ static void run_server(void)
 
 static void run_client(void)
 {
-	int fd;
+	int fd, ret;
 	char *msg = "Hello, world!";
 
 	fd = socket(AF_INET6, SOCK_STREAM, 0);
 	if (fd == -1)
 		error(1, errno, "socket()");
 
-	sendto(fd, msg, strlen(msg), MSG_FASTOPEN, (struct sockaddr *)&cfg_addr, sizeof(cfg_addr));
+	ret = sendto(fd, msg, strlen(msg), MSG_FASTOPEN,
+		     (struct sockaddr *)&cfg_addr, sizeof(cfg_addr));
+	if (ret < 0)
+		error(1, errno, "sendto()");
 
 	close(fd);
 }
Signature · 1 line
2.52.0
#6 lore raw
Quoted 6 lines · Markus Elfring
Quoted 2 lines

This commit improves the error handling in passive TFO test to check the return value from … and to fail if read() failed.

Would any developers and system testers like to care more also for data output failures?
https://elixir.bootlin.com/linux/v6.19-rc4/source/tools/testing/selftests/net/tfo.c#L86-L88
https://cwe.mitre.org/data/definitions/252.html

That's right. Although we can assume that fprintf() usually succeeds, it worth checking its return value as tfo_passive.sh relies on the content of the output.

I posted the v2 series adding fprintf() error handling here:
https://lore.kernel.org/netdev/[email protected]/

Thank you,
Yohei

Quoted 3 lines

Regards,
Markus