Skip to content

Commit 7fd7ad6

Browse files
Konstantin Shkolnyykuba-moo
Konstantin Shkolnyy
authored andcommitted
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 <[email protected]> Reviewed-by: Stefano Garzarella <[email protected]> Fixes: 18ee44c ("test/vsock: add ioctl unsent bytes test") Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 396786a commit 7fd7ad6

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

tools/testing/vsock/vsock_test.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,21 +1264,25 @@ static void test_unsent_bytes_client(const struct test_opts *opts, int type)
12641264
send_buf(fd, buf, sizeof(buf), 0, sizeof(buf));
12651265
control_expectln("RECEIVED");
12661266

1267-
ret = ioctl(fd, SIOCOUTQ, &sock_bytes_unsent);
1268-
if (ret < 0) {
1269-
if (errno == EOPNOTSUPP) {
1270-
fprintf(stderr, "Test skipped, SIOCOUTQ not supported.\n");
1271-
} else {
1267+
/* SIOCOUTQ isn't guaranteed to instantly track sent data. Even though
1268+
* the "RECEIVED" message means that the other side has received the
1269+
* data, there can be a delay in our kernel before updating the "unsent
1270+
* bytes" counter. Repeat SIOCOUTQ until it returns 0.
1271+
*/
1272+
timeout_begin(TIMEOUT);
1273+
do {
1274+
ret = ioctl(fd, SIOCOUTQ, &sock_bytes_unsent);
1275+
if (ret < 0) {
1276+
if (errno == EOPNOTSUPP) {
1277+
fprintf(stderr, "Test skipped, SIOCOUTQ not supported.\n");
1278+
break;
1279+
}
12721280
perror("ioctl");
12731281
exit(EXIT_FAILURE);
12741282
}
1275-
} else if (ret == 0 && sock_bytes_unsent != 0) {
1276-
fprintf(stderr,
1277-
"Unexpected 'SIOCOUTQ' value, expected 0, got %i\n",
1278-
sock_bytes_unsent);
1279-
exit(EXIT_FAILURE);
1280-
}
1281-
1283+
timeout_check("SIOCOUTQ");
1284+
} while (sock_bytes_unsent != 0);
1285+
timeout_end();
12821286
close(fd);
12831287
}
12841288

0 commit comments

Comments
 (0)