Skip to content

Commit 2643492

Browse files
Konstantin Shkolnyyjfvogel
authored andcommitted
vsock/test: Fix occasional failure in SIOCOUTQ tests
[ Upstream commit 7fd7ad6f36af36f30a06d165eff3780cb139fa79 ] 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]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 462e2243812e7bdcfa3c23a621aca5d62004d2d7) Signed-off-by: Jack Vogel <[email protected]>
1 parent 12aad64 commit 2643492

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
@@ -1283,21 +1283,25 @@ static void test_unsent_bytes_client(const struct test_opts *opts, int type)
12831283
send_buf(fd, buf, sizeof(buf), 0, sizeof(buf));
12841284
control_expectln("RECEIVED");
12851285

1286-
ret = ioctl(fd, SIOCOUTQ, &sock_bytes_unsent);
1287-
if (ret < 0) {
1288-
if (errno == EOPNOTSUPP) {
1289-
fprintf(stderr, "Test skipped, SIOCOUTQ not supported.\n");
1290-
} else {
1286+
/* SIOCOUTQ isn't guaranteed to instantly track sent data. Even though
1287+
* the "RECEIVED" message means that the other side has received the
1288+
* data, there can be a delay in our kernel before updating the "unsent
1289+
* bytes" counter. Repeat SIOCOUTQ until it returns 0.
1290+
*/
1291+
timeout_begin(TIMEOUT);
1292+
do {
1293+
ret = ioctl(fd, SIOCOUTQ, &sock_bytes_unsent);
1294+
if (ret < 0) {
1295+
if (errno == EOPNOTSUPP) {
1296+
fprintf(stderr, "Test skipped, SIOCOUTQ not supported.\n");
1297+
break;
1298+
}
12911299
perror("ioctl");
12921300
exit(EXIT_FAILURE);
12931301
}
1294-
} else if (ret == 0 && sock_bytes_unsent != 0) {
1295-
fprintf(stderr,
1296-
"Unexpected 'SIOCOUTQ' value, expected 0, got %i\n",
1297-
sock_bytes_unsent);
1298-
exit(EXIT_FAILURE);
1299-
}
1300-
1302+
timeout_check("SIOCOUTQ");
1303+
} while (sock_bytes_unsent != 0);
1304+
timeout_end();
13011305
close(fd);
13021306
}
13031307

0 commit comments

Comments
 (0)