test: use check() instead of assert()
This is to ensure these checks also run in release builds.
This commit is contained in:
parent
056b2d72c4
commit
6317d82823
@ -1,10 +1,10 @@
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "init.h"
|
||||
#include "test-util.h"
|
||||
#include "util.h"
|
||||
#include "wepoll.h"
|
||||
#include "win.h"
|
||||
@ -22,16 +22,16 @@ static SOCKET create_and_add_socket(HANDLE epfd) {
|
||||
struct epoll_event ev;
|
||||
|
||||
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
assert(sock > 0);
|
||||
check(sock > 0);
|
||||
|
||||
one = 1;
|
||||
r = ioctlsocket(sock, FIONBIO, &one);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
|
||||
ev.events = 0;
|
||||
ev.data.u64 = 42;
|
||||
r = epoll_ctl(epfd, EPOLL_CTL_ADD, sock, &ev);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
|
||||
return sock;
|
||||
}
|
||||
@ -44,10 +44,10 @@ int main(void) {
|
||||
HANDLE epfd;
|
||||
|
||||
r = init();
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
|
||||
epfd = epoll_create1(0);
|
||||
assert(epfd != NULL);
|
||||
check(epfd != NULL);
|
||||
|
||||
for (size_t i = 0; i < NUM_SOCKETS; i++)
|
||||
sockets[i] = create_and_add_socket(epfd);
|
||||
@ -67,13 +67,13 @@ int main(void) {
|
||||
ev_in.data.u64 = 42;
|
||||
|
||||
r = epoll_ctl(epfd, EPOLL_CTL_MOD, sock, &ev_in);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
}
|
||||
|
||||
count = 0;
|
||||
do {
|
||||
r = epoll_wait(epfd, ev_out, array_count(ev_out), count > 0 ? 0 : -1);
|
||||
assert(r >= 0);
|
||||
check(r >= 0);
|
||||
count += r;
|
||||
} while (r > 0);
|
||||
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
#include <assert.h>
|
||||
#include <process.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "init.h"
|
||||
#include "test-util.h"
|
||||
#include "util.h"
|
||||
#include "wepoll.h"
|
||||
#include "win.h"
|
||||
@ -30,17 +30,17 @@ static SOCKET create_socket(unsigned short port) {
|
||||
int r;
|
||||
|
||||
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
assert(sock > 0);
|
||||
check(sock > 0);
|
||||
|
||||
address.sin_family = AF_INET;
|
||||
address.sin_port = htons(port);
|
||||
address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
r = bind(sock, (struct sockaddr*) &address, sizeof address);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
|
||||
one = 1;
|
||||
r = ioctlsocket(sock, FIONBIO, &one);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
|
||||
return sock;
|
||||
}
|
||||
@ -68,7 +68,7 @@ static void send_message(SOCKET sock, unsigned short port) {
|
||||
sizeof address,
|
||||
NULL,
|
||||
NULL);
|
||||
assert(r >= 0);
|
||||
check(r >= 0);
|
||||
}
|
||||
|
||||
static unsigned int __stdcall poll_thread(void* arg) {
|
||||
@ -78,10 +78,10 @@ static unsigned int __stdcall poll_thread(void* arg) {
|
||||
|
||||
memset(&ev_out, 0, sizeof ev_out);
|
||||
r = epoll_wait(context->port, &ev_out, 1, -1);
|
||||
assert(r == 1);
|
||||
check(r == 1);
|
||||
|
||||
assert(ev_out.events == EPOLLIN);
|
||||
assert(ev_out.data.u64 == context->data);
|
||||
check(ev_out.events == EPOLLIN);
|
||||
check(ev_out.data.u64 == context->data);
|
||||
|
||||
printf("Got event (port %p, thread %p)\n", context->port, context->thread);
|
||||
|
||||
@ -96,7 +96,7 @@ int main(void) {
|
||||
|
||||
/* Initialize winsock. */
|
||||
r = WSAStartup(MAKEWORD(2, 2), &wsa_data);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
|
||||
SOCKET send_sock = create_socket(0);
|
||||
SOCKET recv_sock = create_socket(LISTEN_PORT);
|
||||
@ -109,14 +109,14 @@ int main(void) {
|
||||
|
||||
/* Create epoll port. */
|
||||
port = epoll_create1(0);
|
||||
assert(port != INVALID_HANDLE_VALUE);
|
||||
check(port != INVALID_HANDLE_VALUE);
|
||||
ports[i] = port;
|
||||
|
||||
/* Register recv_sock with the epoll port. */
|
||||
ev.events = EPOLLIN;
|
||||
ev.data.u64 = rand();
|
||||
r = epoll_ctl(port, EPOLL_CTL_ADD, recv_sock, &ev);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
|
||||
/* Start THREADS_PER_PORT threads which will all poll the port. */
|
||||
for (size_t j = 0; j < array_count(contexts[i]); j++) {
|
||||
@ -131,7 +131,7 @@ int main(void) {
|
||||
/* Start thread. */
|
||||
thread = (HANDLE) _beginthreadex(
|
||||
NULL, 0, poll_thread, (void*) context, 0, NULL);
|
||||
assert(thread != INVALID_HANDLE_VALUE);
|
||||
check(thread != INVALID_HANDLE_VALUE);
|
||||
context->thread = thread;
|
||||
}
|
||||
}
|
||||
@ -147,7 +147,7 @@ int main(void) {
|
||||
for (size_t j = 0; j < array_count(contexts[i]); j++) {
|
||||
HANDLE thread = contexts[i][j].thread;
|
||||
DWORD wr = WaitForSingleObject(thread, INFINITE);
|
||||
assert(wr == WAIT_OBJECT_0);
|
||||
check(wr == WAIT_OBJECT_0);
|
||||
CloseHandle(thread);
|
||||
}
|
||||
}
|
||||
@ -156,7 +156,7 @@ int main(void) {
|
||||
for (size_t i = 0; i < array_count(ports); i++) {
|
||||
HANDLE port = ports[i];
|
||||
r = epoll_close(port);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "test-util.h"
|
||||
#include "wepoll.h"
|
||||
#include "win.h"
|
||||
|
||||
@ -67,14 +67,14 @@ int main(void) {
|
||||
{
|
||||
/* Create an epoll instance. */
|
||||
epoll_port = epoll_create(1);
|
||||
assert(epoll_port > 0);
|
||||
check(epoll_port > 0);
|
||||
}
|
||||
|
||||
{
|
||||
/* Create a TCP socket pair. */
|
||||
SOCKET socks[2];
|
||||
int r = tcp_socketpair(socks);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
|
||||
send_sock = socks[0];
|
||||
recv_sock = socks[1];
|
||||
@ -83,13 +83,13 @@ int main(void) {
|
||||
{
|
||||
/* Enable non-blocking mode on the receiving end. */
|
||||
int r = sock_set_nonblock(recv_sock, true);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
}
|
||||
|
||||
{
|
||||
/* Send some data in order to trigger an event on the receiving socket. */
|
||||
int r = send(send_sock, HELLO, sizeof HELLO, 0);
|
||||
assert(r == sizeof HELLO);
|
||||
check(r == sizeof HELLO);
|
||||
}
|
||||
|
||||
{
|
||||
@ -101,7 +101,7 @@ int main(void) {
|
||||
ev.data.sock = recv_sock;
|
||||
|
||||
r = epoll_ctl(epoll_port, EPOLL_CTL_ADD, recv_sock, &ev);
|
||||
assert(r >= 0);
|
||||
check(r >= 0);
|
||||
}
|
||||
|
||||
{
|
||||
@ -112,16 +112,16 @@ int main(void) {
|
||||
memset(&ev, 0, sizeof ev);
|
||||
|
||||
r = epoll_wait(epoll_port, &ev, 1, -1);
|
||||
assert(r == 1);
|
||||
assert(ev.events == EPOLLIN);
|
||||
assert(ev.data.sock == recv_sock);
|
||||
check(r == 1);
|
||||
check(ev.events == EPOLLIN);
|
||||
check(ev.data.sock == recv_sock);
|
||||
}
|
||||
|
||||
{
|
||||
/* Read the data from the socket. */
|
||||
char buffer[16];
|
||||
int r = recv(recv_sock, buffer, sizeof buffer, 0);
|
||||
assert(r > 0);
|
||||
check(r > 0);
|
||||
}
|
||||
|
||||
{
|
||||
@ -134,7 +134,7 @@ int main(void) {
|
||||
memset(&ev, 0, sizeof ev);
|
||||
|
||||
r = epoll_wait(epoll_port, &ev, 1, timeout);
|
||||
assert(r == 0); /* Time-out. */
|
||||
check(r == 0); /* Time-out. */
|
||||
}
|
||||
|
||||
{
|
||||
@ -149,9 +149,9 @@ int main(void) {
|
||||
|
||||
r = epoll_ctl(epoll_port, EPOLL_CTL_ADD, recv_sock, &ev);
|
||||
|
||||
assert(r == -1);
|
||||
assert(errno == EEXIST);
|
||||
assert(GetLastError() == ERROR_ALREADY_EXISTS);
|
||||
check(r == -1);
|
||||
check(errno == EEXIST);
|
||||
check(GetLastError() == ERROR_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
{
|
||||
@ -163,20 +163,20 @@ int main(void) {
|
||||
ev.data.sock = recv_sock;
|
||||
|
||||
r = epoll_ctl(epoll_port, EPOLL_CTL_MOD, recv_sock, &ev);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
}
|
||||
|
||||
{
|
||||
/* Send some data, which will never be read by the receiving end, otherwise
|
||||
* Windows won't detect that the connection is closed. */
|
||||
int r = send(send_sock, HELLO, sizeof HELLO, 0);
|
||||
assert(r == sizeof HELLO);
|
||||
check(r == sizeof HELLO);
|
||||
}
|
||||
|
||||
{
|
||||
/* Send FIN packet. */
|
||||
int r = shutdown(send_sock, SD_SEND);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
}
|
||||
|
||||
{
|
||||
@ -187,16 +187,16 @@ int main(void) {
|
||||
memset(&ev, 0, sizeof ev);
|
||||
|
||||
r = epoll_wait(epoll_port, &ev, 1, -1);
|
||||
assert(r == 1);
|
||||
assert(ev.events == EPOLLRDHUP);
|
||||
assert(ev.data.sock == recv_sock);
|
||||
check(r == 1);
|
||||
check(ev.events == EPOLLRDHUP);
|
||||
check(ev.data.sock == recv_sock);
|
||||
}
|
||||
|
||||
{
|
||||
/* Close to receiving socket, so the sending socket should detect a
|
||||
* connection hang-up */
|
||||
int r = closesocket(recv_sock);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
}
|
||||
|
||||
{
|
||||
@ -211,7 +211,7 @@ int main(void) {
|
||||
ev.data.sock = send_sock;
|
||||
|
||||
r = epoll_ctl(epoll_port, EPOLL_CTL_ADD, send_sock, &ev);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
}
|
||||
|
||||
{
|
||||
@ -222,21 +222,21 @@ int main(void) {
|
||||
memset(&ev, 0, sizeof ev);
|
||||
|
||||
r = epoll_wait(epoll_port, &ev, 1, -1);
|
||||
assert(r == 1);
|
||||
assert(ev.events == EPOLLHUP);
|
||||
assert(ev.data.sock == send_sock);
|
||||
check(r == 1);
|
||||
check(ev.events == EPOLLHUP);
|
||||
check(ev.data.sock == send_sock);
|
||||
}
|
||||
|
||||
{
|
||||
/* Close the send socket. */
|
||||
int r = closesocket(send_sock);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
}
|
||||
|
||||
{
|
||||
/* Close the epoll port. */
|
||||
int r = epoll_close(epoll_port);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
#include <assert.h>
|
||||
#include <process.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
@ -6,6 +5,7 @@
|
||||
|
||||
#include "init.h"
|
||||
#include "reflock.h"
|
||||
#include "test-util.h"
|
||||
#include "util.h"
|
||||
#include "win.h"
|
||||
|
||||
@ -53,7 +53,7 @@ static unsigned int __stdcall test_thread(void* arg) {
|
||||
|
||||
ReleaseSRWLockShared(&context->srwlock);
|
||||
|
||||
assert(lock_count > 100); /* Hopefully much more. */
|
||||
check(lock_count > 100); /* Hopefully much more. */
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -76,7 +76,7 @@ static void run_test_iteration(void) {
|
||||
for (size_t i = 0; i < array_count(threads); i++) {
|
||||
HANDLE thread =
|
||||
(HANDLE) _beginthreadex(NULL, 0, test_thread, &context, 0, NULL);
|
||||
assert(thread != INVALID_HANDLE_VALUE);
|
||||
check(thread != INVALID_HANDLE_VALUE);
|
||||
threads[i] = thread;
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ static void run_test_iteration(void) {
|
||||
for (size_t i = 0; i < array_count(threads); i++) {
|
||||
HANDLE thread = threads[i];
|
||||
DWORD wr = WaitForSingleObject(thread, INFINITE);
|
||||
assert(wr == WAIT_OBJECT_0);
|
||||
check(wr == WAIT_OBJECT_0);
|
||||
CloseHandle(thread);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "error.h"
|
||||
#include "test-util.h"
|
||||
#include "wepoll.h"
|
||||
#include "win.h"
|
||||
|
||||
@ -24,43 +24,43 @@ int main(void) {
|
||||
struct epoll_event ev;
|
||||
|
||||
epoll_hnd = epoll_create1(0);
|
||||
assert(epoll_hnd && epoll_hnd != INVALID_HANDLE_VALUE);
|
||||
check(epoll_hnd && epoll_hnd != INVALID_HANDLE_VALUE);
|
||||
|
||||
srv = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
r = ioctlsocket(srv, FIONBIO, &one);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
|
||||
address.sin_family = AF_INET;
|
||||
address.sin_port = htons(LISTEN_PORT);
|
||||
address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
r = bind(srv, (struct sockaddr*) &address, sizeof address);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
|
||||
ev.events = EPOLLIN | EPOLLERR;
|
||||
ev.data.sock = srv;
|
||||
r = epoll_ctl(epoll_hnd, EPOLL_CTL_ADD, srv, &ev);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
|
||||
for (i = 0; i < NUM_PINGERS; i++) {
|
||||
SOCKET sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
|
||||
r = ioctlsocket(sock, FIONBIO, &one);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
|
||||
r = setsockopt(
|
||||
sock, SOL_SOCKET, SO_REUSEADDR, (const char*) &one, sizeof one);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
|
||||
r = connect(sock, (struct sockaddr*) &address, sizeof address);
|
||||
/* Unlike unix, windows sets the error to EWOULDBLOCK when the connection
|
||||
* is being established in the background.
|
||||
*/
|
||||
assert(r == 0 || WSAGetLastError() == WSAEWOULDBLOCK);
|
||||
check(r == 0 || WSAGetLastError() == WSAEWOULDBLOCK);
|
||||
|
||||
ev.events = (uint32_t) EPOLLOUT | EPOLLERR | EPOLLONESHOT;
|
||||
ev.data.sock = sock;
|
||||
r = epoll_ctl(epoll_hnd, EPOLL_CTL_ADD, sock, &ev);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
}
|
||||
|
||||
ticks_start = GetTickCount();
|
||||
@ -86,7 +86,7 @@ int main(void) {
|
||||
}
|
||||
|
||||
count = epoll_wait(epoll_hnd, events, 15, 1000);
|
||||
assert(count >= 0);
|
||||
check(count >= 0);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
int revents = events[i].events;
|
||||
@ -97,11 +97,11 @@ int main(void) {
|
||||
int err_len = sizeof err;
|
||||
|
||||
r = getsockopt(sock, SOL_SOCKET, SO_ERROR, (char*) &err, &err_len);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
fprintf(stderr, "Socket error: %d\n", err);
|
||||
|
||||
r = epoll_ctl(epoll_hnd, EPOLL_CTL_DEL, sock, NULL);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -119,8 +119,8 @@ int main(void) {
|
||||
r = WSARecv(sock, &wsa_buf, 1, &bytes, &flags, NULL, NULL);
|
||||
if (r == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
|
||||
break;
|
||||
assert(r >= 0);
|
||||
assert(bytes == sizeof PING);
|
||||
check(r >= 0);
|
||||
check(bytes == sizeof PING);
|
||||
pings++;
|
||||
}
|
||||
|
||||
@ -135,8 +135,8 @@ int main(void) {
|
||||
wsa_buf.buf = (char*) PING;
|
||||
wsa_buf.len = sizeof PING;
|
||||
r = WSASend(sock, &wsa_buf, 1, &bytes, 0, NULL, NULL);
|
||||
assert(r >= 0);
|
||||
assert(bytes == sizeof PING);
|
||||
check(r >= 0);
|
||||
check(bytes == sizeof PING);
|
||||
|
||||
pings_sent++;
|
||||
|
||||
@ -150,12 +150,12 @@ int main(void) {
|
||||
continue;
|
||||
}
|
||||
|
||||
assert(0);
|
||||
check(0);
|
||||
}
|
||||
}
|
||||
|
||||
r = epoll_close(epoll_hnd);
|
||||
assert(r == 0);
|
||||
check(r == 0);
|
||||
|
||||
closesocket(srv);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user