mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 10:00:17 +00:00
vsock/test: Fix occasional failure in SIOCOUTQ tests
These tests:
"SOCK_STREAM ioctl(SIOCOUTQ) 0 unsent bytes"
"SOCK_SEQPACKET ioctl(SIOCOUTQ) 0 unsent bytes"
output: "Unexpected 'SIOCOUTQ' value, expected 0, got 64 (CLIENT)".
They test that the SIOCOUTQ ioctl reports 0 unsent bytes after the data
have been received by the other side. However, sometimes there is a delay
in updating this "unsent bytes" counter, and the test fails even though
the counter properly goes to 0 several milliseconds later.
The delay occurs in the kernel because the used buffer notification
callback virtio_vsock_tx_done(), called upon receipt of the data by the
other side, doesn't update the counter itself. It delegates that to
a kernel thread (via vsock->tx_work). Sometimes that thread is delayed
more than the test expects.
Change the test to poll SIOCOUTQ until it returns 0 or a timeout occurs.
Signed-off-by: Konstantin Shkolnyy <kshk@linux.ibm.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Fixes: 18ee44ce97 ("test/vsock: add ioctl unsent bytes test")
Link: https://patch.msgid.link/20250507151456.2577061-1-kshk@linux.ibm.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
committed by
Jakub Kicinski
parent
396786af1c
commit
7fd7ad6f36
@@ -1264,21 +1264,25 @@ static void test_unsent_bytes_client(const struct test_opts *opts, int type)
|
|||||||
send_buf(fd, buf, sizeof(buf), 0, sizeof(buf));
|
send_buf(fd, buf, sizeof(buf), 0, sizeof(buf));
|
||||||
control_expectln("RECEIVED");
|
control_expectln("RECEIVED");
|
||||||
|
|
||||||
ret = ioctl(fd, SIOCOUTQ, &sock_bytes_unsent);
|
/* SIOCOUTQ isn't guaranteed to instantly track sent data. Even though
|
||||||
if (ret < 0) {
|
* the "RECEIVED" message means that the other side has received the
|
||||||
if (errno == EOPNOTSUPP) {
|
* data, there can be a delay in our kernel before updating the "unsent
|
||||||
fprintf(stderr, "Test skipped, SIOCOUTQ not supported.\n");
|
* bytes" counter. Repeat SIOCOUTQ until it returns 0.
|
||||||
} else {
|
*/
|
||||||
|
timeout_begin(TIMEOUT);
|
||||||
|
do {
|
||||||
|
ret = ioctl(fd, SIOCOUTQ, &sock_bytes_unsent);
|
||||||
|
if (ret < 0) {
|
||||||
|
if (errno == EOPNOTSUPP) {
|
||||||
|
fprintf(stderr, "Test skipped, SIOCOUTQ not supported.\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
perror("ioctl");
|
perror("ioctl");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
} else if (ret == 0 && sock_bytes_unsent != 0) {
|
timeout_check("SIOCOUTQ");
|
||||||
fprintf(stderr,
|
} while (sock_bytes_unsent != 0);
|
||||||
"Unexpected 'SIOCOUTQ' value, expected 0, got %i\n",
|
timeout_end();
|
||||||
sock_bytes_unsent);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user