tools/testing/vsock/vsock_test.c
Source file repositories/reference/linux-study-clean/tools/testing/vsock/vsock_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/vsock/vsock_test.c- Extension
.c- Size
- 63782 bytes
- Lines
- 2720
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
getopt.hstdio.hstdlib.hstring.herrno.hunistd.hlinux/kernel.hsys/types.hsys/socket.htime.hsys/mman.hpoll.hsignal.hsys/ioctl.hlinux/time64.hpthread.hfcntl.hlinux/sockios.hvsock_test_zerocopy.htimeout.hcontrol.hutil.h
Detected Declarations
function Copyrightfunction test_stream_bind_only_clientfunction test_stream_bind_only_serverfunction test_stream_client_close_clientfunction test_stream_client_close_serverfunction test_stream_server_close_clientfunction test_stream_server_close_serverfunction test_stream_multiconn_clientfunction test_stream_multiconn_serverfunction test_msg_peek_clientfunction test_msg_peek_serverfunction test_stream_msg_peek_clientfunction test_stream_msg_peek_serverfunction test_stream_peek_after_recv_serverfunction test_seqpacket_msg_bounds_clientfunction test_seqpacket_msg_bounds_serverfunction test_seqpacket_msg_trunc_clientfunction test_seqpacket_msg_trunc_serverfunction current_nsecfunction test_seqpacket_timeout_clientfunction test_seqpacket_timeout_serverfunction test_seqpacket_bigmsg_clientfunction test_seqpacket_bigmsg_serverfunction test_seqpacket_invalid_rec_buffer_clientfunction test_seqpacket_invalid_rec_buffer_serverfunction test_stream_poll_rcvlowat_serverfunction test_stream_poll_rcvlowat_clientfunction test_inv_buf_clientfunction test_inv_buf_serverfunction test_stream_inv_buf_clientfunction test_stream_inv_buf_serverfunction test_seqpacket_inv_buf_clientfunction test_seqpacket_inv_buf_serverfunction test_stream_virtio_skb_merge_clientfunction test_stream_virtio_skb_merge_serverfunction test_seqpacket_msg_peek_clientfunction test_seqpacket_msg_peek_serverfunction sigpipefunction test_stream_check_sigpipefunction test_stream_shutwr_clientfunction test_stream_shutwr_serverfunction test_stream_shutrd_clientfunction test_stream_shutrd_serverfunction test_double_bind_connect_serverfunction test_double_bind_connect_clientfunction test_unsent_bytes_serverfunction test_unsent_bytes_clientfunction test_unread_bytes_server
Annotated Snippet
if (fds[i] < 0) {
perror("connect");
exit(EXIT_FAILURE);
}
}
for (i = 0; i < MULTICONN_NFDS; i++) {
if (i % 2)
recv_byte(fds[i], 1, 0);
else
send_byte(fds[i], 1, 0);
}
for (i = 0; i < MULTICONN_NFDS; i++)
close(fds[i]);
}
static void test_stream_multiconn_server(const struct test_opts *opts)
{
int fds[MULTICONN_NFDS];
int i;
for (i = 0; i < MULTICONN_NFDS; i++) {
fds[i] = vsock_stream_accept(VMADDR_CID_ANY, opts->peer_port, NULL);
if (fds[i] < 0) {
perror("accept");
exit(EXIT_FAILURE);
}
}
for (i = 0; i < MULTICONN_NFDS; i++) {
if (i % 2)
send_byte(fds[i], 1, 0);
else
recv_byte(fds[i], 1, 0);
}
for (i = 0; i < MULTICONN_NFDS; i++)
close(fds[i]);
}
#define MSG_PEEK_BUF_LEN 64
static void test_msg_peek_client(const struct test_opts *opts,
bool seqpacket)
{
unsigned char buf[MSG_PEEK_BUF_LEN];
int fd;
int i;
if (seqpacket)
fd = vsock_seqpacket_connect(opts->peer_cid, opts->peer_port);
else
fd = vsock_stream_connect(opts->peer_cid, opts->peer_port);
if (fd < 0) {
perror("connect");
exit(EXIT_FAILURE);
}
for (i = 0; i < sizeof(buf); i++)
buf[i] = rand() & 0xFF;
control_expectln("SRVREADY");
send_buf(fd, buf, sizeof(buf), 0, sizeof(buf));
close(fd);
}
static void test_msg_peek_server(const struct test_opts *opts,
bool seqpacket)
{
unsigned char buf_half[MSG_PEEK_BUF_LEN / 2];
unsigned char buf_normal[MSG_PEEK_BUF_LEN];
unsigned char buf_peek[MSG_PEEK_BUF_LEN];
int fd;
if (seqpacket)
fd = vsock_seqpacket_accept(VMADDR_CID_ANY, opts->peer_port, NULL);
else
fd = vsock_stream_accept(VMADDR_CID_ANY, opts->peer_port, NULL);
if (fd < 0) {
perror("accept");
exit(EXIT_FAILURE);
}
/* Peek from empty socket. */
recv_buf(fd, buf_peek, sizeof(buf_peek), MSG_PEEK | MSG_DONTWAIT,
Annotation
- Immediate include surface: `getopt.h`, `stdio.h`, `stdlib.h`, `string.h`, `errno.h`, `unistd.h`, `linux/kernel.h`, `sys/types.h`.
- Detected declarations: `function Copyright`, `function test_stream_bind_only_client`, `function test_stream_bind_only_server`, `function test_stream_client_close_client`, `function test_stream_client_close_server`, `function test_stream_server_close_client`, `function test_stream_server_close_server`, `function test_stream_multiconn_client`, `function test_stream_multiconn_server`, `function test_msg_peek_client`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.