Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 #ifndef UTIL_H
0003 #define UTIL_H
0004 
0005 #include <sys/socket.h>
0006 #include <linux/vm_sockets.h>
0007 
0008 /* Tests can either run as the client or the server */
0009 enum test_mode {
0010     TEST_MODE_UNSET,
0011     TEST_MODE_CLIENT,
0012     TEST_MODE_SERVER
0013 };
0014 
0015 /* Test runner options */
0016 struct test_opts {
0017     enum test_mode mode;
0018     unsigned int peer_cid;
0019 };
0020 
0021 /* A test case definition.  Test functions must print failures to stderr and
0022  * terminate with exit(EXIT_FAILURE).
0023  */
0024 struct test_case {
0025     const char *name; /* human-readable name */
0026 
0027     /* Called when test mode is TEST_MODE_CLIENT */
0028     void (*run_client)(const struct test_opts *opts);
0029 
0030     /* Called when test mode is TEST_MODE_SERVER */
0031     void (*run_server)(const struct test_opts *opts);
0032 
0033     bool skip;
0034 };
0035 
0036 void init_signals(void);
0037 unsigned int parse_cid(const char *str);
0038 int vsock_stream_connect(unsigned int cid, unsigned int port);
0039 int vsock_seqpacket_connect(unsigned int cid, unsigned int port);
0040 int vsock_stream_accept(unsigned int cid, unsigned int port,
0041             struct sockaddr_vm *clientaddrp);
0042 int vsock_seqpacket_accept(unsigned int cid, unsigned int port,
0043                struct sockaddr_vm *clientaddrp);
0044 void vsock_wait_remote_close(int fd);
0045 void send_byte(int fd, int expected_ret, int flags);
0046 void recv_byte(int fd, int expected_ret, int flags);
0047 void run_tests(const struct test_case *test_cases,
0048            const struct test_opts *opts);
0049 void list_tests(const struct test_case *test_cases);
0050 void skip_test(struct test_case *test_cases, size_t test_cases_len,
0051            const char *test_id_str);
0052 #endif /* UTIL_H */