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 buf_accept_intr; /* accept can return success when interrupted */ 79 int bug_bind_in_use; /* bind does not return EADDRINUSE */ 80 int bug_bind_null; /* bind segfaults with NULL pointer */ 81 int bug_connect_after_close; /* connect succeeds after server closed */ 82 int bug_select_nonblock; /* select unexpected results for nb sockets */ 83 int bug_shutdown; /* shutdown not supported */ 84 int bug_shutdown_not_conn; /* shutdown does not return ENOTCONN */ 85 int bug_shutdown_read; /* shutdown does not support SHUT_RD */ 86 int bug_sockopt_rcvbuf; /* get/setsockopt does not support SO_RCVBUF */ 87 int bug_sockopt_sndbuf; /* get/setsockopt does not support SO_SNDBUF */ 88 int ignore_accept_delay; /* success from accept after aborted connect */ 89 int ignore_connect_delay; /* nb connect not instant */ 90 int ignore_connect_unaccepted; /* connect succeeds without accept */ 91 int ignore_read_conn_reset; /* read does not guarantee ECONNRESET */ 92 int ignore_select_delay; /* select delay reflecting other side nb op */ 93 int ignore_send_waiting; /* can send while waiting for nb recv */ 94 int ignore_write_conn_reset; /* write does not guarantee ECONNRESET */ 95 96 void (* callback_check_sockaddr)(const struct sockaddr *sockaddr, 97 socklen_t sockaddrlen, const char *callname, int addridx); 98 void (* callback_cleanup)(void); 99 void (* callback_xfer_peercred)(int sd); /* can be NULL */ 100 void (* callback_xfer_prepclient)(void); /* can be NULL */ 101 }; 102 103 void test_abort_client_server(const struct socket_test_info *info, 104 int abort_type); 105 void test_bind(const struct socket_test_info *info); 106 void test_close(const struct socket_test_info *info); 107 void test_connect_close(const struct socket_test_info *info); 108 void test_connect_nb(const struct socket_test_info *info); 109 void test_dup(const struct socket_test_info *info); 110 void test_dup2(const struct socket_test_info *info); 111 void test_getsockname(const struct socket_test_info *info); 112 void test_intr(const struct socket_test_info *info); 113 void test_listen(const struct socket_test_info *info); 114 void test_listen_close(const struct socket_test_info *info); 115 void test_listen_close_nb(const struct socket_test_info *info); 116 void test_msg_dgram(const struct socket_test_info *info); 117 void test_nonblock(const struct socket_test_info *info); 118 void test_read(const struct socket_test_info *info); 119 void test_shutdown(const struct socket_test_info *info); 120 void test_simple_client_server(const struct socket_test_info *info, int type); 121 void test_sockopts(const struct socket_test_info *info); 122 void test_socket(const struct socket_test_info *info); 123 void test_write(const struct socket_test_info *info); 124 void test_xfer(const struct socket_test_info *info); 125