1 /* SPDX-License-Identifier: GPL-2.0-only */
5 #include <sys/socket.h>
6 #include <linux/vm_sockets.h>
8 /* Tests can either run as the client or the server */
15 #define DEFAULT_PEER_PORT 1234
17 /* Test runner options */
20 unsigned int peer_cid
;
21 unsigned int peer_port
;
24 /* A test case definition. Test functions must print failures to stderr and
25 * terminate with exit(EXIT_FAILURE).
28 const char *name
; /* human-readable name */
30 /* Called when test mode is TEST_MODE_CLIENT */
31 void (*run_client
)(const struct test_opts
*opts
);
33 /* Called when test mode is TEST_MODE_SERVER */
34 void (*run_server
)(const struct test_opts
*opts
);
39 void init_signals(void);
40 unsigned int parse_cid(const char *str
);
41 unsigned int parse_port(const char *str
);
42 int vsock_connect(unsigned int cid
, unsigned int port
, int type
);
43 int vsock_accept(unsigned int cid
, unsigned int port
,
44 struct sockaddr_vm
*clientaddrp
, int type
);
45 int vsock_stream_connect(unsigned int cid
, unsigned int port
);
46 int vsock_bind_connect(unsigned int cid
, unsigned int port
,
47 unsigned int bind_port
, int type
);
48 int vsock_seqpacket_connect(unsigned int cid
, unsigned int port
);
49 int vsock_stream_accept(unsigned int cid
, unsigned int port
,
50 struct sockaddr_vm
*clientaddrp
);
51 int vsock_stream_listen(unsigned int cid
, unsigned int port
);
52 int vsock_seqpacket_accept(unsigned int cid
, unsigned int port
,
53 struct sockaddr_vm
*clientaddrp
);
54 void vsock_wait_remote_close(int fd
);
55 void send_buf(int fd
, const void *buf
, size_t len
, int flags
,
56 ssize_t expected_ret
);
57 void recv_buf(int fd
, void *buf
, size_t len
, int flags
, ssize_t expected_ret
);
58 void send_byte(int fd
, int expected_ret
, int flags
);
59 void recv_byte(int fd
, int expected_ret
, int flags
);
60 void run_tests(const struct test_case
*test_cases
,
61 const struct test_opts
*opts
);
62 void list_tests(const struct test_case
*test_cases
);
63 void skip_test(struct test_case
*test_cases
, size_t test_cases_len
,
64 const char *test_id_str
);
65 unsigned long hash_djb2(const void *data
, size_t len
);
66 size_t iovec_bytes(const struct iovec
*iov
, size_t iovnum
);
67 unsigned long iovec_hash_djb2(const struct iovec
*iov
, size_t iovnum
);
68 struct iovec
*alloc_test_iovec(const struct iovec
*test_iovec
, int iovnum
);
69 void free_test_iovec(const struct iovec
*test_iovec
,
70 struct iovec
*iovec
, int iovnum
);