parent
d546a3115f
commit
59f1ce0f44
@ -38,7 +38,7 @@ void after_read(oio_req* req, size_t nread) {
|
||||
oio_req_init(&peer->req, &peer->handle, after_write);
|
||||
peer->req.data = peer;
|
||||
if (oio_write(&peer->req, &peer->buf, 1)) {
|
||||
FATAL(oio_write failed)
|
||||
FATAL("oio_write failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -49,7 +49,7 @@ void try_read(peer_t* peer) {
|
||||
oio_req_init(&peer->req, &peer->handle, after_read);
|
||||
peer->req.data = peer;
|
||||
if (oio_read(&peer->req, &peer->buf, 1)) {
|
||||
FATAL(oio_read failed)
|
||||
FATAL("oio_read failed");
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,10 +65,10 @@ void on_accept(oio_handle* server) {
|
||||
peer_t* p = (peer_t*)calloc(sizeof(peer_t), 1);
|
||||
|
||||
int r = oio_tcp_handle_init(&p->handle, on_close, (void*)p);
|
||||
ASSERT(!r)
|
||||
ASSERT(!r);
|
||||
|
||||
if (oio_tcp_handle_accept(server, &p->handle)) {
|
||||
FATAL(oio_tcp_handle_accept failed)
|
||||
FATAL("oio_tcp_handle_accept failed");
|
||||
}
|
||||
|
||||
p->buf.base = (char*)&p->read_buffer;
|
||||
@ -79,7 +79,7 @@ void on_accept(oio_handle* server) {
|
||||
|
||||
void on_server_close(oio_handle* handle, oio_err err) {
|
||||
ASSERT(handle == &server);
|
||||
ASSERT(!err)
|
||||
ASSERT(!err);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -10,8 +10,8 @@ int close_cb_called = 0;
|
||||
|
||||
|
||||
void close_cb(oio_handle *handle, oio_err err) {
|
||||
ASSERT(!err)
|
||||
ASSERT(nested == 0 && "oio_close_cb must be called from a fresh stack")
|
||||
ASSERT(!err);
|
||||
ASSERT(nested == 0 && "oio_close_cb must be called from a fresh stack");
|
||||
close_cb_called++;
|
||||
}
|
||||
|
||||
@ -22,21 +22,21 @@ TEST_IMPL(close_cb_stack) {
|
||||
oio_init();
|
||||
|
||||
if (oio_tcp_handle_init(&handle, &close_cb, NULL)) {
|
||||
FATAL(oio_tcp_handle_init failed)
|
||||
FATAL("oio_tcp_handle_init failed");
|
||||
}
|
||||
|
||||
nested++;
|
||||
|
||||
if (oio_close(&handle)) {
|
||||
FATAL(oio_close failed)
|
||||
FATAL("oio_close failed");
|
||||
}
|
||||
|
||||
nested--;
|
||||
|
||||
oio_run();
|
||||
|
||||
ASSERT(nested == 0)
|
||||
ASSERT(close_cb_called == 1 && "oio_close_cb must be called exactly once")
|
||||
ASSERT(nested == 0);
|
||||
ASSERT(close_cb_called == 1 && "oio_close_cb must be called exactly once");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -2,6 +2,6 @@
|
||||
|
||||
TEST_IMPL(fail_always) {
|
||||
/* This test always fails. It is used to test the test runner. */
|
||||
FATAL("Yes, it always fails")
|
||||
FATAL("Yes, it always fails");
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,8 +29,8 @@ void pinger_try_read(pinger_t* pinger);
|
||||
void pinger_on_close(oio_handle* handle, oio_err err) {
|
||||
pinger_t* pinger = (pinger_t*)handle->data;
|
||||
|
||||
ASSERT(!err)
|
||||
ASSERT(NUM_PINGS == pinger->pongs)
|
||||
ASSERT(!err);
|
||||
ASSERT(NUM_PINGS == pinger->pongs);
|
||||
|
||||
free(pinger);
|
||||
|
||||
@ -50,7 +50,7 @@ static void pinger_write_ping(pinger_t* pinger) {
|
||||
oio_req_init(req, &pinger->handle, pinger_after_write);
|
||||
|
||||
if (oio_write2(req, (char*)&PING)) {
|
||||
FATAL(oio_write2 failed)
|
||||
FATAL("oio_write2 failed");
|
||||
}
|
||||
|
||||
puts("PING");
|
||||
@ -71,7 +71,7 @@ static void pinger_after_read(oio_req* req, size_t nread) {
|
||||
|
||||
/* Now we count the pings */
|
||||
for (i = 0; i < nread; i++) {
|
||||
ASSERT(pinger->buf.base[i] == PING[pinger->state])
|
||||
ASSERT(pinger->buf.base[i] == PING[pinger->state]);
|
||||
pinger->state = (pinger->state + 1) % (sizeof(PING) - 1);
|
||||
if (pinger->state == 0) {
|
||||
printf("PONG %d\n", pinger->pongs);
|
||||
@ -98,7 +98,7 @@ void pinger_try_read(pinger_t* pinger) {
|
||||
void pinger_on_connect(oio_req *req, oio_err err) {
|
||||
pinger_t *pinger = (pinger_t*)req->handle->data;
|
||||
|
||||
ASSERT(!err)
|
||||
ASSERT(!err);
|
||||
|
||||
pinger_try_read(pinger);
|
||||
pinger_write_ping(pinger);
|
||||
@ -119,7 +119,7 @@ void pinger_new() {
|
||||
|
||||
/* Try to connec to the server and do NUM_PINGS ping-pongs. */
|
||||
r = oio_tcp_handle_init(&pinger->handle, pinger_on_close, (void*)pinger);
|
||||
ASSERT(!r)
|
||||
ASSERT(!r);
|
||||
|
||||
/* We are never doing multiple reads/connects at a time anyway. */
|
||||
/* so these handles can be pre-initialized. */
|
||||
@ -127,7 +127,7 @@ void pinger_new() {
|
||||
|
||||
oio_bind(&pinger->handle, (struct sockaddr*)&client_addr);
|
||||
r = oio_connect(&pinger->connect_req, (struct sockaddr*)&server_addr);
|
||||
ASSERT(!r)
|
||||
ASSERT(!r);
|
||||
}
|
||||
|
||||
|
||||
@ -137,7 +137,7 @@ TEST_IMPL(ping_pong) {
|
||||
pinger_new();
|
||||
oio_run();
|
||||
|
||||
ASSERT(completed_pingers == 1)
|
||||
ASSERT(completed_pingers == 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -159,4 +159,5 @@ void process_cleanup(process_info_t *p) {
|
||||
/* Move the console cursor one line up and back to the first column. */
|
||||
int rewind_cursor() {
|
||||
printf("\033[1A\033[80D");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ int run_test(test_entry_t *test) {
|
||||
/* Wait for the main process to terminate. */
|
||||
result = process_wait(main_process, 1, TEST_TIMEOUT);
|
||||
if (result == -1) {
|
||||
FATAL(process_wait failed)
|
||||
FATAL("process_wait failed");
|
||||
} else if (result == -2) {
|
||||
snprintf((char*)&errmsg, sizeof(errmsg), "timeout.");
|
||||
goto finalize;
|
||||
@ -78,7 +78,7 @@ finalize:
|
||||
|
||||
/* Wait until all processes have really terminated. */
|
||||
if (process_wait((process_info_t*)&processes, process_count, -1) < 0)
|
||||
FATAL(process_wait failed)
|
||||
FATAL("process_wait failed");
|
||||
|
||||
/* Show error and output from processes if the test failed. */
|
||||
if (!success) {
|
||||
|
||||
@ -26,7 +26,7 @@ static void exit_timeout_cb(oio_req *req) {
|
||||
|
||||
static void dummy_timeout_cb(oio_req *req) {
|
||||
/* Should never be called */
|
||||
FATAL(dummy_timer_cb should never be called)
|
||||
FATAL("dummy_timer_cb should never be called");
|
||||
}
|
||||
|
||||
|
||||
@ -44,28 +44,31 @@ TEST_IMPL(timeout) {
|
||||
/* Let 10 timers time out in 500 ms total. */
|
||||
for (i = 0; i < 10; i++) {
|
||||
req = (oio_req*)malloc(sizeof(*req));
|
||||
ASSERT(req != NULL)
|
||||
ASSERT(req != NULL);
|
||||
|
||||
oio_req_init(req, NULL, timeout_cb);
|
||||
|
||||
if (oio_timeout(req, i * 50) < 0)
|
||||
FATAL(oio_timeout failed)
|
||||
if (oio_timeout(req, i * 50) < 0) {
|
||||
FATAL("oio_timeout failed");
|
||||
}
|
||||
|
||||
expected++;
|
||||
}
|
||||
|
||||
/* The 11th timer exits the test and runs after 1 s. */
|
||||
oio_req_init(&exit_req, NULL, exit_timeout_cb);
|
||||
if (oio_timeout(&exit_req, 1000) < 0)
|
||||
FATAL(oio_timeout failed)
|
||||
if (oio_timeout(&exit_req, 1000) < 0) {
|
||||
FATAL("oio_timeout failed");
|
||||
}
|
||||
|
||||
/* The 12th timer should never run. */
|
||||
oio_req_init(&dummy_req, NULL, dummy_timeout_cb);
|
||||
if (oio_timeout(&dummy_req, 2000))
|
||||
FATAL(oio_timeout failed)
|
||||
if (oio_timeout(&dummy_req, 2000)) {
|
||||
FATAL("oio_timeout failed");
|
||||
}
|
||||
|
||||
oio_run();
|
||||
|
||||
FATAL(should never get here)
|
||||
FATAL("should never get here");
|
||||
return 2;
|
||||
}
|
||||
|
||||
22
test/test.h
22
test/test.h
@ -19,9 +19,9 @@
|
||||
"Fatal error in %s on line %d: %s\n", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
#msg); \
|
||||
msg); \
|
||||
abort(); \
|
||||
} while (0);
|
||||
} while (0)
|
||||
|
||||
|
||||
/*
|
||||
@ -29,14 +29,16 @@
|
||||
* a release build.
|
||||
*/
|
||||
#define ASSERT(expr) \
|
||||
if (!(expr)) { \
|
||||
fprintf(stderr, \
|
||||
"Assertion failed in %s on line %d: %s\n", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
#expr); \
|
||||
abort(); \
|
||||
}
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
fprintf(stderr, \
|
||||
"Assertion failed in %s on line %d: %s\n", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
#expr); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* Just sugar for wrapping the main() for a test. */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user