Skip to content

Commit 4695f64

Browse files
mmhalkuba-moo
authored andcommitted
vsock/test: Add test for connect() retries
Deliberately fail a connect() attempt; expect error. Then verify that subsequent attempt (using the same socket) can still succeed, rather than fail outright. Reviewed-by: Stefano Garzarella <[email protected]> Reviewed-by: Luigi Leonardi <[email protected]> Signed-off-by: Michal Luczaj <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 301a62d commit 4695f64

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tools/testing/vsock/vsock_test.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,48 @@ static void test_stream_transport_uaf_server(const struct test_opts *opts)
17461746
control_expectln("DONE");
17471747
}
17481748

1749+
static void test_stream_connect_retry_client(const struct test_opts *opts)
1750+
{
1751+
int fd;
1752+
1753+
fd = socket(AF_VSOCK, SOCK_STREAM, 0);
1754+
if (fd < 0) {
1755+
perror("socket");
1756+
exit(EXIT_FAILURE);
1757+
}
1758+
1759+
if (!vsock_connect_fd(fd, opts->peer_cid, opts->peer_port)) {
1760+
fprintf(stderr, "Unexpected connect() #1 success\n");
1761+
exit(EXIT_FAILURE);
1762+
}
1763+
1764+
control_writeln("LISTEN");
1765+
control_expectln("LISTENING");
1766+
1767+
if (vsock_connect_fd(fd, opts->peer_cid, opts->peer_port)) {
1768+
perror("connect() #2");
1769+
exit(EXIT_FAILURE);
1770+
}
1771+
1772+
close(fd);
1773+
}
1774+
1775+
static void test_stream_connect_retry_server(const struct test_opts *opts)
1776+
{
1777+
int fd;
1778+
1779+
control_expectln("LISTEN");
1780+
1781+
fd = vsock_stream_accept(VMADDR_CID_ANY, opts->peer_port, NULL);
1782+
if (fd < 0) {
1783+
perror("accept");
1784+
exit(EXIT_FAILURE);
1785+
}
1786+
1787+
vsock_wait_remote_close(fd);
1788+
close(fd);
1789+
}
1790+
17491791
static struct test_case test_cases[] = {
17501792
{
17511793
.name = "SOCK_STREAM connection reset",
@@ -1896,6 +1938,11 @@ static struct test_case test_cases[] = {
18961938
.run_client = test_stream_transport_uaf_client,
18971939
.run_server = test_stream_transport_uaf_server,
18981940
},
1941+
{
1942+
.name = "SOCK_STREAM retry failed connect()",
1943+
.run_client = test_stream_connect_retry_client,
1944+
.run_server = test_stream_connect_retry_server,
1945+
},
18991946
{},
19001947
};
19011948

0 commit comments

Comments
 (0)