xref: /minix/minix/tests/common-socket.h (revision 03ac74ed)
1 #define DEBUG 0
2 
3 /* buffer for send/recv */
4 #define BUFSIZE (128)
5 
6 /* macro to display information about a failed test and increment the errct */
7 void test_fail_fl(char *msg, char *file, int line);
8 #define test_fail(msg)	test_fail_fl(msg, __FILE__, __LINE__)
9 
10 #if DEBUG == 1
11 /* macros to display debugging information */
12 void debug_fl(char *msg, char *file, int line);
13 #define debug(msg) debug_fl(msg, __FILE__, __LINE__)
14 #else
15 #define debug(msg)
16 #endif
17 
18 #define SOCKET(sd,domain,type,protocol)					\
19 	do {								\
20 		errno = 0;						\
21 		sd = socket(domain, type, protocol);			\
22 		if (sd == -1) {						\
23 		test_fail("sd = socket(domain, type, protocol) failed");\
24 		}							\
25 	} while (0)
26 
27 #define UNLINK(path)						\
28 	do {							\
29 		int rc;						\
30 		errno = 0;					\
31 		rc = unlink(path);				\
32 		if (rc == -1 && errno != ENOENT) {		\
33 			test_fail("unlink(path) failed");	\
34 		}						\
35 	} while(0)
36 
37 #define SYMLINK(oldpath,newpath)					\
38 	do {								\
39 		int rc;							\
40 		errno = 0;						\
41 		rc = symlink(oldpath,newpath);				\
42 		if (rc == -1) {						\
43 			test_fail("symlink(oldpath,newpath) failed");	\
44 		}							\
45 	} while(0)
46 
47 #define CLOSE(sd)					\
48 	do {						\
49 		int rc;					\
50 		errno = 0;				\
51 		rc = close(sd);				\
52 		if (rc == -1) {				\
53 			test_fail("close(sd) failed");	\
54 		}					\
55 	} while (0)
56 
57 extern int server_ready;
58 void test_xfer_sighdlr(int sig);
59 
60 struct socket_test_info {
61 	const struct sockaddr *clientaddr;
62 	socklen_t clientaddrlen;
63 	const struct sockaddr *clientaddr2;
64 	socklen_t clientaddr2len;
65 	const struct sockaddr *clientaddrsym;
66 	socklen_t clientaddrsymlen;
67 	int domain;
68 	int expected_rcvbuf;
69 	int expected_sndbuf;
70 	const struct sockaddr *serveraddr;
71 	socklen_t serveraddrlen;
72 	const struct sockaddr *serveraddr2;
73 	socklen_t serveraddr2len;
74 	int type;
75 	const int *types;
76 	size_t typecount;
77 
78 	int ignore_accept_delay; /* success from accept after aborted connect */
79 	int ignore_connect_delay; /* nb connect not instant */
80 	int ignore_connect_unaccepted; /* connect succeeds without accept */
81 	int ignore_select_delay; /* select delay reflecting other side nb op */
82 	int ignore_send_waiting; /* can send while waiting for nb recv */
83 	int ignore_write_conn_reset; /* write does not guarantee ECONNRESET */
84 
85 	void (* callback_check_sockaddr)(const struct sockaddr *sockaddr,
86 		socklen_t sockaddrlen, const char *callname, int addridx);
87 	void (* callback_cleanup)(void);
88 	void (* callback_xfer_peercred)(int sd); /* can be NULL */
89 	void (* callback_xfer_prepclient)(void); /* can be NULL */
90 	void (* callback_set_listen_opt)(int sd); /* can be NULL */
91 };
92 
93 void test_abort_client_server(const struct socket_test_info *info,
94 	int abort_type);
95 void test_bind(const struct socket_test_info *info);
96 void test_close(const struct socket_test_info *info);
97 void test_connect_close(const struct socket_test_info *info);
98 void test_connect_nb(const struct socket_test_info *info);
99 void test_dup(const struct socket_test_info *info);
100 void test_dup2(const struct socket_test_info *info);
101 void test_getsockname(const struct socket_test_info *info);
102 void test_intr(const struct socket_test_info *info);
103 void test_listen(const struct socket_test_info *info);
104 void test_listen_close(const struct socket_test_info *info);
105 void test_listen_close_nb(const struct socket_test_info *info);
106 void test_msg_dgram(const struct socket_test_info *info);
107 void test_nonblock(const struct socket_test_info *info);
108 void test_read(const struct socket_test_info *info);
109 void test_shutdown(const struct socket_test_info *info);
110 void test_simple_client_server(const struct socket_test_info *info, int type);
111 void test_sockopts(const struct socket_test_info *info);
112 void test_socket(const struct socket_test_info *info);
113 void test_write(const struct socket_test_info *info);
114 void test_xfer(const struct socket_test_info *info);
115