Add new tests 80 (TCP) and 81 (UDP)

These new tests are largely based on the code from test 56 (UDS). Common code
is moved into a separate file common-socket.c. In some instances the tests
are too strict for TCP/UDP sockets, which may not always react instantly to
whatever happens on the other side (even locally). For these cases, the
ignore_* fields in struct socket_test_info indicate that there needs to be
an exception. There are also tests where it seems the functionality of inet
is either incorrect or incomplete with regard to the POSIX standard. In these
cases, the bug_* fields are used to document the issues while avoiding
failure of the test.

Change-Id: Ia860deb4559d42608790451936b1aade866faebc
This commit is contained in:
Erik van der Kouwe 2015-07-08 09:46:56 +02:00
parent 3e8d796eaa
commit 294d159017
8 changed files with 2632 additions and 2180 deletions

View file

@ -6329,6 +6329,8 @@
./usr/tests/minix-posix/test78 minix-sys
./usr/tests/minix-posix/test79 minix-sys
./usr/tests/minix-posix/test8 minix-sys
./usr/tests/minix-posix/test80 minix-sys
./usr/tests/minix-posix/test81 minix-sys
./usr/tests/minix-posix/test9 minix-sys
./usr/tests/minix-posix/testinterp minix-sys
./usr/tests/minix-posix/testisofs minix-sys

View file

@ -36,6 +36,9 @@ LDADD.test77= -lutil
# Some have an extra file
OBJS.test57= test57loop.o
OBJS.test56+= common-socket.o
OBJS.test80+= common-socket.o
OBJS.test81+= common-socket.o
# Cache testing programs
OBJS.test71+= testcache.o
@ -55,7 +58,8 @@ MINIX_TESTS= \
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \
41 42 43 44 45 46 48 49 50 52 53 54 55 56 58 59 60 \
61 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
61 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 \
81
.if ${MACHINE_ARCH} == "i386"
MINIX_TESTS+= \

2121
minix/tests/common-socket.c Normal file

File diff suppressed because it is too large Load diff

124
minix/tests/common-socket.h Normal file
View file

@ -0,0 +1,124 @@
#define DEBUG 0
/* buffer for send/recv */
#define BUFSIZE (128)
/* macro to display information about a failed test and increment the errct */
void test_fail_fl(char *msg, char *file, int line);
#define test_fail(msg) test_fail_fl(msg, __FILE__, __LINE__)
#if DEBUG == 1
/* macros to display debugging information */
void debug_fl(char *msg, char *file, int line);
#define debug(msg) debug_fl(msg, __FILE__, __LINE__)
#else
#define debug(msg)
#endif
#define SOCKET(sd,domain,type,protocol) \
do { \
errno = 0; \
sd = socket(domain, type, protocol); \
if (sd == -1) { \
test_fail("sd = socket(domain, type, protocol) failed");\
} \
} while (0)
#define UNLINK(path) \
do { \
int rc; \
errno = 0; \
rc = unlink(path); \
if (rc == -1 && errno != ENOENT) { \
test_fail("unlink(path) failed"); \
} \
} while(0)
#define SYMLINK(oldpath,newpath) \
do { \
int rc; \
errno = 0; \
rc = symlink(oldpath,newpath); \
if (rc == -1) { \
test_fail("symlink(oldpath,newpath) failed"); \
} \
} while(0)
#define CLOSE(sd) \
do { \
int rc; \
errno = 0; \
rc = close(sd); \
if (rc == -1) { \
test_fail("close(sd) failed"); \
} \
} while (0)
extern int server_ready;
void test_xfer_sighdlr(int sig);
struct socket_test_info {
const struct sockaddr *clientaddr;
socklen_t clientaddrlen;
const struct sockaddr *clientaddr2;
socklen_t clientaddr2len;
const struct sockaddr *clientaddrsym;
socklen_t clientaddrsymlen;
int domain;
int expected_rcvbuf;
int expected_sndbuf;
const struct sockaddr *serveraddr;
socklen_t serveraddrlen;
const struct sockaddr *serveraddr2;
socklen_t serveraddr2len;
int type;
const int *types;
size_t typecount;
int buf_accept_intr; /* accept can return success when interrupted */
int bug_bind_in_use; /* bind does not return EADDRINUSE */
int bug_bind_null; /* bind segfaults with NULL pointer */
int bug_connect_after_close; /* connect succeeds after server closed */
int bug_select_nonblock; /* select unexpected results for nb sockets */
int bug_shutdown; /* shutdown not supported */
int bug_shutdown_not_conn; /* shutdown does not return ENOTCONN */
int bug_shutdown_read; /* shutdown does not support SHUT_RD */
int bug_sockopt_rcvbuf; /* get/setsockopt does not support SO_RCVBUF */
int bug_sockopt_sndbuf; /* get/setsockopt does not support SO_SNDBUF */
int ignore_accept_delay; /* success from accept after aborted connect */
int ignore_connect_delay; /* nb connect not instant */
int ignore_connect_unaccepted; /* connect succeeds without accept */
int ignore_read_conn_reset; /* read does not guarantee ECONNRESET */
int ignore_select_delay; /* select delay reflecting other side nb op */
int ignore_send_waiting; /* can send while waiting for nb recv */
int ignore_write_conn_reset; /* write does not guarantee ECONNRESET */
void (* callback_check_sockaddr)(const struct sockaddr *sockaddr,
socklen_t sockaddrlen, const char *callname, int addridx);
void (* callback_cleanup)(void);
void (* callback_xfer_peercred)(int sd); /* can be NULL */
void (* callback_xfer_prepclient)(void); /* can be NULL */
};
void test_abort_client_server(const struct socket_test_info *info,
int abort_type);
void test_bind(const struct socket_test_info *info);
void test_close(const struct socket_test_info *info);
void test_connect_close(const struct socket_test_info *info);
void test_connect_nb(const struct socket_test_info *info);
void test_dup(const struct socket_test_info *info);
void test_dup2(const struct socket_test_info *info);
void test_getsockname(const struct socket_test_info *info);
void test_intr(const struct socket_test_info *info);
void test_listen(const struct socket_test_info *info);
void test_listen_close(const struct socket_test_info *info);
void test_listen_close_nb(const struct socket_test_info *info);
void test_msg_dgram(const struct socket_test_info *info);
void test_nonblock(const struct socket_test_info *info);
void test_read(const struct socket_test_info *info);
void test_shutdown(const struct socket_test_info *info);
void test_simple_client_server(const struct socket_test_info *info, int type);
void test_sockopts(const struct socket_test_info *info);
void test_socket(const struct socket_test_info *info);
void test_write(const struct socket_test_info *info);
void test_xfer(const struct socket_test_info *info);

View file

@ -29,8 +29,8 @@ rootscripts="testisofs testvnd testrelpol"
alltests="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 \
sh1 sh2 interp mfs isofs vnd"
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 \
81 sh1 sh2 interp mfs isofs vnd"
tests_no=`expr 0`
# If root, make sure the setuid tests have the correct permissions

File diff suppressed because it is too large Load diff

141
minix/tests/test80.c Normal file
View file

@ -0,0 +1,141 @@
/*
* test80: use the functions originally written for test56 to test TCP
*/
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include "common.h"
#include "common-socket.h"
#define PORT1 4321
#define PORT2 4322
static void callback_check_sockaddr(const struct sockaddr *sockaddr,
socklen_t sockaddrlen, const char *callname, int addridx) {
char buf[256];
int port;
const struct sockaddr_in *sockaddr_in =
(const struct sockaddr_in *) sockaddr;
switch (addridx) {
case 1: port = PORT1; break;
case 2: port = PORT2; break;
default:
fprintf(stderr, "error: invalid addridx %d in "
"callback_check_sockaddr\n", addridx);
abort();
}
if (sockaddr_in->sin_family != AF_INET ||
sockaddr_in->sin_port != htons(port)) {
snprintf(buf, sizeof(buf), "%s() didn't return the right addr",
callname);
test_fail(buf);
memset(buf, 0, sizeof(buf));
inet_ntop(sockaddr_in->sin_family, &sockaddr_in->sin_addr,
buf, sizeof(buf));
fprintf(stderr, "exp: localhost:%d | got: %s:%d\n", port, buf,
ntohs(sockaddr_in->sin_port));
}
}
static void callback_cleanup(void) {
/* nothing to do */
}
int main(int argc, char *argv[])
{
int i;
struct sockaddr_in clientaddr = {
.sin_family = AF_INET,
.sin_port = htons(PORT1),
.sin_addr = { .s_addr = htonl(INADDR_LOOPBACK) },
};
struct sockaddr_in clientaddr2 = {
.sin_family = AF_INET,
.sin_port = htons(PORT2),
.sin_addr = { .s_addr = htonl(INADDR_LOOPBACK) },
};
struct sockaddr_in serveraddr = {
.sin_family = AF_INET,
.sin_port = htons(PORT1),
.sin_addr = { .s_addr = htonl(INADDR_ANY) },
};
struct sockaddr_in serveraddr2 = {
.sin_family = AF_INET,
.sin_port = htons(PORT2),
.sin_addr = { .s_addr = htonl(INADDR_ANY) },
};
const struct socket_test_info info = {
.clientaddr = (struct sockaddr *) &clientaddr,
.clientaddrlen = sizeof(clientaddr),
.clientaddr2 = (struct sockaddr *) &clientaddr2,
.clientaddr2len = sizeof(clientaddr2),
.clientaddrsym = (struct sockaddr *) &clientaddr,
.clientaddrsymlen = sizeof(clientaddr),
.domain = PF_INET,
.expected_rcvbuf = -1,
.expected_sndbuf = -1,
.serveraddr = (struct sockaddr *) &serveraddr,
.serveraddrlen = sizeof(serveraddr),
.serveraddr2 = (struct sockaddr *) &serveraddr2,
.serveraddr2len = sizeof(serveraddr2),
.type = SOCK_STREAM,
.types = &info.type,
.typecount = 1,
.bug_bind_in_use = 1,
.bug_bind_null = 1,
.bug_connect_after_close = 1,
.bug_shutdown_not_conn = 1,
.bug_shutdown_read = 1,
.ignore_accept_delay = 1,
.ignore_connect_unaccepted = 1,
.ignore_connect_delay = 1,
.ignore_read_conn_reset = 1,
.ignore_select_delay = 1,
.ignore_send_waiting = 1,
.ignore_write_conn_reset = 1,
.callback_check_sockaddr = callback_check_sockaddr,
.callback_cleanup = callback_cleanup,
.callback_xfer_prepclient = NULL,
.callback_xfer_peercred = NULL,
};
debug("entering main()");
start(80);
test_socket(&info);
test_bind(&info);
test_listen(&info);
test_getsockname(&info);
test_shutdown(&info);
test_close(&info);
test_dup(&info);
test_dup2(&info);
test_shutdown(&info);
test_read(&info);
test_write(&info);
test_sockopts(&info);
test_xfer(&info);
test_simple_client_server(&info, info.type);
test_abort_client_server(&info, 1);
test_abort_client_server(&info, 2);
test_nonblock(&info);
test_connect_nb(&info);
test_intr(&info);
test_connect_close(&info);
test_listen_close(&info);
test_listen_close_nb(&info);
quit();
return -1; /* we should never get here */
}

134
minix/tests/test81.c Normal file
View file

@ -0,0 +1,134 @@
/*
* test81: use the functions originally written for test56 to test UDP
*/
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include "common.h"
#include "common-socket.h"
#define PORT1 4321
#define PORT2 4322
static void callback_check_sockaddr(const struct sockaddr *sockaddr,
socklen_t sockaddrlen, const char *callname, int addridx) {
char buf[256];
int port;
const struct sockaddr_in *sockaddr_in =
(const struct sockaddr_in *) sockaddr;
switch (addridx) {
case 1: port = PORT1; break;
case 2: port = PORT2; break;
default:
fprintf(stderr, "error: invalid addridx %d in "
"callback_check_sockaddr\n", addridx);
abort();
}
if (sockaddr_in->sin_family != AF_INET ||
sockaddr_in->sin_port != htons(port)) {
snprintf(buf, sizeof(buf), "%s() didn't return the right addr",
callname);
test_fail(buf);
memset(buf, 0, sizeof(buf));
inet_ntop(sockaddr_in->sin_family, &sockaddr_in->sin_addr,
buf, sizeof(buf));
fprintf(stderr, "exp: localhost:%d | got: %s:%d\n", port, buf,
ntohs(sockaddr_in->sin_port));
}
}
static void callback_cleanup(void) {
/* nothing to do */
}
int main(int argc, char *argv[])
{
int i;
struct sockaddr_in clientaddr = {
.sin_family = AF_INET,
.sin_port = htons(PORT1),
.sin_addr = { .s_addr = htonl(INADDR_LOOPBACK) },
};
struct sockaddr_in clientaddr2 = {
.sin_family = AF_INET,
.sin_port = htons(PORT2),
.sin_addr = { .s_addr = htonl(INADDR_LOOPBACK) },
};
struct sockaddr_in serveraddr = {
.sin_family = AF_INET,
.sin_port = htons(PORT1),
.sin_addr = { .s_addr = htonl(INADDR_ANY) },
};
struct sockaddr_in serveraddr2 = {
.sin_family = AF_INET,
.sin_port = htons(PORT2),
.sin_addr = { .s_addr = htonl(INADDR_ANY) },
};
const struct socket_test_info info = {
.clientaddr = (struct sockaddr *) &clientaddr,
.clientaddrlen = sizeof(clientaddr),
.clientaddr2 = (struct sockaddr *) &clientaddr2,
.clientaddr2len = sizeof(clientaddr2),
.clientaddrsym = (struct sockaddr *) &clientaddr,
.clientaddrsymlen = sizeof(clientaddr),
.domain = PF_INET,
.expected_rcvbuf = -1,
.expected_sndbuf = -1,
.serveraddr = (struct sockaddr *) &serveraddr,
.serveraddrlen = sizeof(serveraddr),
.serveraddr2 = (struct sockaddr *) &serveraddr2,
.serveraddr2len = sizeof(serveraddr2),
.type = SOCK_DGRAM,
.types = &info.type,
.typecount = 1,
.bug_bind_in_use = 1,
.bug_bind_null = 1,
.bug_connect_after_close = 1,
.bug_shutdown = 1, /* UDP only problem */
.bug_shutdown_not_conn = 1,
.bug_shutdown_read = 1,
.bug_sockopt_rcvbuf = 1, /* UDP only problem */
.bug_sockopt_sndbuf = 1, /* UDP only problem */
.ignore_accept_delay = 1,
.ignore_connect_unaccepted = 1,
.ignore_connect_delay = 1,
.ignore_read_conn_reset = 1,
.ignore_select_delay = 1,
.ignore_send_waiting = 1,
.ignore_write_conn_reset = 1,
.callback_check_sockaddr = callback_check_sockaddr,
.callback_cleanup = callback_cleanup,
.callback_xfer_prepclient = NULL,
.callback_xfer_peercred = NULL,
};
debug("entering main()");
start(81);
test_socket(&info);
test_bind(&info);
test_getsockname(&info);
test_shutdown(&info);
test_close(&info);
test_dup(&info);
test_dup2(&info);
test_shutdown(&info);
test_read(&info);
test_write(&info);
test_sockopts(&info);
test_simple_client_server(&info, info.type);
quit();
return -1; /* we should never get here */
}