From: Mark Michelson Date: Mon, 12 Nov 2012 00:36:16 +0000 (+0000) Subject: Refine the taskprocessor listener test a bit more. X-Git-Tag: 13.0.0-beta1~2194^2~173 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=426e8d145437b44e5e8ba0adbde19eae94d906e1;p=thirdparty%2Fasterisk.git Refine the taskprocessor listener test a bit more. This makes it easier to follow and tests more thoroughly. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@376140 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/tests/test_taskprocessor.c b/tests/test_taskprocessor.c index d33b45b7ae..eebf3d0b32 100644 --- a/tests/test_taskprocessor.c +++ b/tests/test_taskprocessor.c @@ -102,6 +102,7 @@ test_end: struct test_listener_pvt { int num_pushed; int num_emptied; + int num_was_empty; }; static void *test_alloc(struct ast_taskprocessor_listener *listener) @@ -116,6 +117,9 @@ static void test_task_pushed(struct ast_taskprocessor_listener *listener, int wa { struct test_listener_pvt *pvt = listener->private_data; ++pvt->num_pushed; + if (was_empty) { + ++pvt->num_was_empty; + } } static void test_emptied(struct ast_taskprocessor_listener *listener) @@ -142,6 +146,29 @@ static int listener_test_task(void *ignore) return 0; } +static int check_stats(struct ast_test *test, const struct test_listener_pvt *pvt, int num_pushed, int num_emptied, int num_was_empty) +{ + if (pvt->num_pushed != num_pushed) { + ast_test_status_update(test, "Unexpected number of tasks pushed. Expected %d but got %d\n", + num_pushed, pvt->num_pushed); + return -1; + } + + if (pvt->num_emptied != num_emptied) { + ast_test_status_update(test, "Unexpected number of empties. Expected %d but got %d\n", + num_emptied, pvt->num_emptied); + return -1; + } + + if (pvt->num_was_empty != num_was_empty) { + ast_test_status_update(test, "Unexpected number of empties. Expected %d but got %d\n", + num_was_empty, pvt->num_emptied); + return -1; + } + + return 0; +} + AST_TEST_DEFINE(taskprocessor_listener) { struct ast_taskprocessor *tps; @@ -174,23 +201,32 @@ AST_TEST_DEFINE(taskprocessor_listener) goto test_exit; } + pvt = listener->private_data; + ast_taskprocessor_push(tps, listener_test_task, NULL); + + if (check_stats(test, pvt, 1, 0, 1) < 0) { + res = AST_TEST_FAIL; + goto test_exit; + } + ast_taskprocessor_push(tps, listener_test_task, NULL); - ast_taskprocessor_execute(tps); + if (check_stats(test, pvt, 2, 0, 1) < 0) { + res = AST_TEST_FAIL; + goto test_exit; + } + ast_taskprocessor_execute(tps); - pvt = listener->private_data; - if (pvt->num_pushed != 2) { - ast_test_status_update(test, "Unexpected number of tasks pushed. Expected %d but got %d\n", - 2, pvt->num_pushed); + if (check_stats(test, pvt, 2, 0, 1) < 0) { res = AST_TEST_FAIL; goto test_exit; } - if (pvt->num_emptied != 1) { - ast_test_status_update(test, "Unexpected number of empties. Expected %d but got %d\n", - 1, pvt->num_emptied); + ast_taskprocessor_execute(tps); + + if (check_stats(test, pvt, 2, 1, 1) < 0) { res = AST_TEST_FAIL; goto test_exit; }