[PATCH net-next 2/2] vsock/test: check also expected errno on sigpipe test

Stefano Garzarella posted 2 patches 7 months, 1 week ago
There is a newer version of this series
[PATCH net-next 2/2] vsock/test: check also expected errno on sigpipe test
Posted by Stefano Garzarella 7 months, 1 week ago
From: Stefano Garzarella <sgarzare@redhat.com>

In the sigpipe test, we expect send() to fail, but we do not check if
send() fails with the errno we expect (EPIPE).

Add this check and repeat the send() in case of EINTR as we do in other
tests.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
 tools/testing/vsock/vsock_test.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c
index 7de870dee1cf..533d9463a297 100644
--- a/tools/testing/vsock/vsock_test.c
+++ b/tools/testing/vsock/vsock_test.c
@@ -1074,9 +1074,13 @@ static void test_stream_check_sigpipe(int fd)
 	do {
 		res = send(fd, "A", 1, 0);
 		timeout_check("send");
-	} while (res != -1);
+	} while (res != -1 && errno == EINTR);
 	timeout_end();
 
+	if (errno != EPIPE) {
+		fprintf(stderr, "unexpected send(2) errno %d\n", errno);
+		exit(EXIT_FAILURE);
+	}
 	if (!have_sigpipe) {
 		fprintf(stderr, "SIGPIPE expected\n");
 		exit(EXIT_FAILURE);
@@ -1088,9 +1092,13 @@ static void test_stream_check_sigpipe(int fd)
 	do {
 		res = send(fd, "A", 1, MSG_NOSIGNAL);
 		timeout_check("send");
-	} while (res != -1);
+	} while (res != -1 && errno == EINTR);
 	timeout_end();
 
+	if (errno != EPIPE) {
+		fprintf(stderr, "unexpected send(2) errno %d\n", errno);
+		exit(EXIT_FAILURE);
+	}
 	if (have_sigpipe) {
 		fprintf(stderr, "SIGPIPE not expected\n");
 		exit(EXIT_FAILURE);
-- 
2.49.0
Re: [PATCH net-next 2/2] vsock/test: check also expected errno on sigpipe test
Posted by Paolo Abeni 7 months ago
On 5/8/25 4:20 PM, Stefano Garzarella wrote:
> diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c
> index 7de870dee1cf..533d9463a297 100644
> --- a/tools/testing/vsock/vsock_test.c
> +++ b/tools/testing/vsock/vsock_test.c
> @@ -1074,9 +1074,13 @@ static void test_stream_check_sigpipe(int fd)
>  	do {
>  		res = send(fd, "A", 1, 0);
>  		timeout_check("send");
> -	} while (res != -1);
> +	} while (res != -1 && errno == EINTR);

I'm low on coffee, but should the above condition be:

		res != -1 || errno == EINTR

instead?

Same thing below.

/P
Re: [PATCH net-next 2/2] vsock/test: check also expected errno on sigpipe test
Posted by Stefano Garzarella 7 months ago
On Tue, May 13, 2025 at 12:41:17PM +0200, Paolo Abeni wrote:
>On 5/8/25 4:20 PM, Stefano Garzarella wrote:
>> diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c
>> index 7de870dee1cf..533d9463a297 100644
>> --- a/tools/testing/vsock/vsock_test.c
>> +++ b/tools/testing/vsock/vsock_test.c
>> @@ -1074,9 +1074,13 @@ static void test_stream_check_sigpipe(int fd)
>>  	do {
>>  		res = send(fd, "A", 1, 0);
>>  		timeout_check("send");
>> -	} while (res != -1);
>> +	} while (res != -1 && errno == EINTR);
>
>I'm low on coffee, but should the above condition be:
>
>		res != -1 || errno == EINTR
>
>instead?

Ooops, copy & paste where we waited successful send().

>
>Same thing below.

I'll fix both!

Thanks,
Stefano