util.h 1.5 KB

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