Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-only */
2#ifndef UTIL_H
3#define UTIL_H
4
5#include <sys/socket.h>
6#include <linux/vm_sockets.h>
7
8/* Tests can either run as the client or the server */
9enum test_mode {
10 TEST_MODE_UNSET,
11 TEST_MODE_CLIENT,
12 TEST_MODE_SERVER
13};
14
15#define DEFAULT_PEER_PORT 1234
16
17/* Test runner options */
18struct test_opts {
19 enum test_mode mode;
20 unsigned int peer_cid;
21 unsigned int peer_port;
22};
23
24/* A test case definition. Test functions must print failures to stderr and
25 * terminate with exit(EXIT_FAILURE).
26 */
27struct test_case {
28 const char *name; /* human-readable name */
29
30 /* Called when test mode is TEST_MODE_CLIENT */
31 void (*run_client)(const struct test_opts *opts);
32
33 /* Called when test mode is TEST_MODE_SERVER */
34 void (*run_server)(const struct test_opts *opts);
35
36 bool skip;
37};
38
39void init_signals(void);
40unsigned int parse_cid(const char *str);
41unsigned int parse_port(const char *str);
42int vsock_connect_fd(int fd, unsigned int cid, unsigned int port);
43int vsock_connect(unsigned int cid, unsigned int port, int type);
44int vsock_accept(unsigned int cid, unsigned int port,
45 struct sockaddr_vm *clientaddrp, int type);
46int vsock_stream_connect(unsigned int cid, unsigned int port);
47int vsock_bind(unsigned int cid, unsigned int port, int type);
48int vsock_bind_connect(unsigned int cid, unsigned int port,
49 unsigned int bind_port, int type);
50int vsock_seqpacket_connect(unsigned int cid, unsigned int port);
51int vsock_stream_accept(unsigned int cid, unsigned int port,
52 struct sockaddr_vm *clientaddrp);
53int vsock_stream_listen(unsigned int cid, unsigned int port);
54int vsock_seqpacket_accept(unsigned int cid, unsigned int port,
55 struct sockaddr_vm *clientaddrp);
56void vsock_wait_remote_close(int fd);
57bool vsock_wait_sent(int fd);
58void send_buf(int fd, const void *buf, size_t len, int flags,
59 ssize_t expected_ret);
60void recv_buf(int fd, void *buf, size_t len, int flags, ssize_t expected_ret);
61void send_byte(int fd, int expected_ret, int flags);
62void recv_byte(int fd, int expected_ret, int flags);
63void run_tests(const struct test_case *test_cases,
64 const struct test_opts *opts);
65void list_tests(const struct test_case *test_cases);
66void skip_test(struct test_case *test_cases, size_t test_cases_len,
67 const char *test_id_str);
68void pick_test(struct test_case *test_cases, size_t test_cases_len,
69 const char *test_id_str);
70unsigned long hash_djb2(const void *data, size_t len);
71size_t iovec_bytes(const struct iovec *iov, size_t iovnum);
72unsigned long iovec_hash_djb2(const struct iovec *iov, size_t iovnum);
73struct iovec *alloc_test_iovec(const struct iovec *test_iovec, int iovnum);
74void free_test_iovec(const struct iovec *test_iovec,
75 struct iovec *iovec, int iovnum);
76void setsockopt_ull_check(int fd, int level, int optname,
77 unsigned long long val, char const *errmsg);
78void setsockopt_int_check(int fd, int level, int optname, int val,
79 char const *errmsg);
80void setsockopt_timeval_check(int fd, int level, int optname,
81 struct timeval val, char const *errmsg);
82void enable_so_zerocopy_check(int fd);
83void enable_so_linger(int fd, int timeout);
84#endif /* UTIL_H */