Stefan Hajnoczi | df7e0e0 | 2019-12-18 19:07:00 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | #ifndef UTIL_H |
| 3 | #define UTIL_H |
| 4 | |
Stefan Hajnoczi | 9bb8a29 | 2019-12-18 19:07:01 +0100 | [diff] [blame] | 5 | #include <sys/socket.h> |
| 6 | #include <linux/vm_sockets.h> |
| 7 | |
Stefan Hajnoczi | df7e0e0 | 2019-12-18 19:07:00 +0100 | [diff] [blame] | 8 | /* Tests can either run as the client or the server */ |
| 9 | enum test_mode { |
| 10 | TEST_MODE_UNSET, |
| 11 | TEST_MODE_CLIENT, |
| 12 | TEST_MODE_SERVER |
| 13 | }; |
| 14 | |
| 15 | /* Test runner options */ |
| 16 | struct test_opts { |
| 17 | enum test_mode mode; |
| 18 | unsigned int peer_cid; |
| 19 | }; |
| 20 | |
| 21 | /* A test case definition. Test functions must print failures to stderr and |
| 22 | * terminate with exit(EXIT_FAILURE). |
| 23 | */ |
| 24 | struct test_case { |
| 25 | const char *name; /* human-readable name */ |
| 26 | |
| 27 | /* Called when test mode is TEST_MODE_CLIENT */ |
| 28 | void (*run_client)(const struct test_opts *opts); |
| 29 | |
| 30 | /* Called when test mode is TEST_MODE_SERVER */ |
| 31 | void (*run_server)(const struct test_opts *opts); |
Stefano Garzarella | 5a2b242 | 2019-12-18 19:07:06 +0100 | [diff] [blame] | 32 | |
| 33 | bool skip; |
Stefan Hajnoczi | df7e0e0 | 2019-12-18 19:07:00 +0100 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | void init_signals(void); |
| 37 | unsigned int parse_cid(const char *str); |
Stefan Hajnoczi | 9bb8a29 | 2019-12-18 19:07:01 +0100 | [diff] [blame] | 38 | int vsock_stream_connect(unsigned int cid, unsigned int port); |
| 39 | int vsock_stream_accept(unsigned int cid, unsigned int port, |
| 40 | struct sockaddr_vm *clientaddrp); |
Stefano Garzarella | 770ce00 | 2019-12-18 19:07:05 +0100 | [diff] [blame] | 41 | void vsock_wait_remote_close(int fd); |
Stefan Hajnoczi | 092f32a | 2019-12-18 19:07:03 +0100 | [diff] [blame] | 42 | void send_byte(int fd, int expected_ret, int flags); |
| 43 | void recv_byte(int fd, int expected_ret, int flags); |
Stefan Hajnoczi | df7e0e0 | 2019-12-18 19:07:00 +0100 | [diff] [blame] | 44 | void run_tests(const struct test_case *test_cases, |
| 45 | const struct test_opts *opts); |
Stefano Garzarella | 5a2b242 | 2019-12-18 19:07:06 +0100 | [diff] [blame] | 46 | void list_tests(const struct test_case *test_cases); |
| 47 | void skip_test(struct test_case *test_cases, size_t test_cases_len, |
| 48 | const char *test_id_str); |
Stefan Hajnoczi | df7e0e0 | 2019-12-18 19:07:00 +0100 | [diff] [blame] | 49 | #endif /* UTIL_H */ |