Add checks to test-loop-handles

This commit is contained in:
Bert Belder 2011-05-09 04:27:42 +02:00
parent 50dbf654b9
commit 517a296c85

View File

@ -107,22 +107,28 @@ static int timeout_cb_called = 0;
static void timeout_cb(oio_req_t *req, int64_t skew, int status) {
int r;
ASSERT(req == &timeout_req);
ASSERT(status == 0);
timeout_cb_called++;
oio_timeout(req, TIMEOUT);
r = oio_timeout(req, TIMEOUT);
ASSERT(r == 0);
}
static void idle_2_cb(oio_handle_t* handle, int status) {
int r;
ASSERT(handle == &idle_2_handle);
ASSERT(status == 0);
idle_2_cb_called++;
oio_close(handle);
r = oio_close(handle);
ASSERT(r == 0);
}
@ -138,6 +144,8 @@ static void idle_2_close_cb(oio_handle_t* handle, int status){
static void idle_1_cb(oio_handle_t* handle, int status) {
int r;
ASSERT(handle != NULL);
ASSERT(status == 0);
@ -145,8 +153,10 @@ static void idle_1_cb(oio_handle_t* handle, int status) {
/* Init idle_2 and make it active */
if (!idle_2_is_active) {
oio_idle_init(&idle_2_handle, idle_2_close_cb, NULL);
oio_idle_start(&idle_2_handle, idle_2_cb);
r = oio_idle_init(&idle_2_handle, idle_2_close_cb, NULL);
ASSERT(r == 0);
r = oio_idle_start(&idle_2_handle, idle_2_cb);
ASSERT(r == 0);
idle_2_is_active = 1;
idle_2_cb_started++;
}
@ -154,7 +164,8 @@ static void idle_1_cb(oio_handle_t* handle, int status) {
idle_1_cb_called++;
if (idle_1_cb_called % 5 == 0) {
oio_idle_stop(handle);
r = oio_idle_stop(handle);
ASSERT(r == 0);
idles_1_active--;
}
}
@ -169,7 +180,7 @@ static void idle_1_close_cb(oio_handle_t* handle, int status){
static void check_cb(oio_handle_t* handle, int status) {
int i;
int i, r;
ASSERT(handle == &check_handle);
ASSERT(status == 0);
@ -180,24 +191,30 @@ static void check_cb(oio_handle_t* handle, int status) {
if (loop_iteration < ITERATIONS) {
/* Make some idle watchers active */
for (i = 0; i < 1 + (loop_iteration % IDLE_COUNT); i++) {
oio_idle_start(&idle_1_handles[i], idle_1_cb);
r = oio_idle_start(&idle_1_handles[i], idle_1_cb);
ASSERT(r == 0);
idles_1_active++;
}
} else {
/* End of the test - close all handles */
oio_close(&prepare_1_handle);
oio_close(&check_handle);
oio_close(&prepare_2_handle);
r = oio_close(&prepare_1_handle);
ASSERT(r == 0);
r = oio_close(&check_handle);
ASSERT(r == 0);
r = oio_close(&prepare_2_handle);
ASSERT(r == 0);
for (i = 0; i < IDLE_COUNT; i++) {
oio_close(&idle_1_handles[i]);
r = oio_close(&idle_1_handles[i]);
ASSERT(r == 0);
}
/* This handle is closed/recreated every time, close it only if it is */
/* active.*/
if (idle_2_is_active) {
oio_close(&idle_2_handle);
r = oio_close(&idle_2_handle);
ASSERT(r == 0);
}
}
@ -214,6 +231,8 @@ static void check_close_cb(oio_handle_t* handle, int status){
static void prepare_2_cb(oio_handle_t* handle, int status) {
int r;
ASSERT(handle == &prepare_2_handle);
ASSERT(status == 0);
@ -226,7 +245,8 @@ static void prepare_2_cb(oio_handle_t* handle, int status) {
/* (loop_iteration % 2 == 0) cannot be true. */
ASSERT(loop_iteration % 2 != 0);
oio_prepare_stop(handle);
r = oio_prepare_stop(handle);
ASSERT(r == 0);
prepare_2_cb_called++;
}
@ -241,6 +261,8 @@ static void prepare_2_close_cb(oio_handle_t* handle, int status){
static void prepare_1_cb(oio_handle_t* handle, int status) {
int r;
ASSERT(handle == &prepare_1_handle);
ASSERT(status == 0);
@ -248,7 +270,8 @@ static void prepare_1_cb(oio_handle_t* handle, int status) {
ASSERT(idle_2_is_active == 0);
if (loop_iteration % 2 == 0) {
oio_prepare_start(&prepare_2_handle, prepare_2_cb);
r = oio_prepare_start(&prepare_2_handle, prepare_2_cb);
ASSERT(r == 0);
}
prepare_1_cb_called++;
@ -275,21 +298,28 @@ static oio_buf alloc_cb(oio_handle_t* handle, size_t size) {
TEST_IMPL(loop_handles) {
int i;
int r;
oio_init(alloc_cb);
oio_prepare_init(&prepare_1_handle, prepare_1_close_cb, NULL);
oio_prepare_start(&prepare_1_handle, prepare_1_cb);
r = oio_prepare_init(&prepare_1_handle, prepare_1_close_cb, NULL);
ASSERT(r == 0);
r = oio_prepare_start(&prepare_1_handle, prepare_1_cb);
ASSERT(r == 0);
oio_check_init(&check_handle, check_close_cb, NULL);
oio_check_start(&check_handle, check_cb);
r = oio_check_init(&check_handle, check_close_cb, NULL);
ASSERT(r == 0);
r = oio_check_start(&check_handle, check_cb);
ASSERT(r == 0);
/* initialize only, prepare_2 is started by prepare_1_cb */
oio_prepare_init(&prepare_2_handle, prepare_2_close_cb, NULL);
r = oio_prepare_init(&prepare_2_handle, prepare_2_close_cb, NULL);
ASSERT(r == 0);
for (i = 0; i < IDLE_COUNT; i++) {
/* initialize only, idle_1 handles are started by check_cb */
oio_idle_init(&idle_1_handles[i], idle_1_close_cb, NULL);
r = oio_idle_init(&idle_1_handles[i], idle_1_close_cb, NULL);
ASSERT(r == 0);
}
/* don't init or start idle_2, both is done by idle_1_cb */
@ -297,10 +327,12 @@ TEST_IMPL(loop_handles) {
/* the timer callback is there to keep the event loop polling */
/* unref it as it is not supposed to keep the loop alive */
oio_req_init(&timeout_req, NULL, timeout_cb);
oio_timeout(&timeout_req, TIMEOUT);
r = oio_timeout(&timeout_req, TIMEOUT);
ASSERT(r == 0);
oio_unref();
oio_run();
r = oio_run();
ASSERT(r == 0);
ASSERT(loop_iteration == ITERATIONS);