taskpool_test.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011, 2012  Internet Systems Consortium, Inc. ("ISC")
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00009  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00010  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00011  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00012  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00013  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00014  * PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 /* $Id$ */
00018 
00019 /*! \file */
00020 
00021 #include <config.h>
00022 
00023 #include <atf-c.h>
00024 
00025 #include <unistd.h>
00026 
00027 #include <isc/task.h>
00028 #include <isc/taskpool.h>
00029 
00030 #include "isctest.h"
00031 
00032 /*
00033  * Individual unit tests
00034  */
00035 
00036 /* Create a taskpool */
00037 ATF_TC(create_pool);
00038 ATF_TC_HEAD(create_pool, tc) {
00039         atf_tc_set_md_var(tc, "descr", "create a taskpool");
00040 }
00041 ATF_TC_BODY(create_pool, tc) {
00042         isc_result_t result;
00043         isc_taskpool_t *pool = NULL;
00044 
00045         UNUSED(tc);
00046 
00047         result = isc_test_begin(NULL, ISC_TRUE);
00048         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00049 
00050         result = isc_taskpool_create(taskmgr, mctx, 8, 2, &pool);
00051         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00052         ATF_REQUIRE_EQ(isc_taskpool_size(pool), 8);
00053 
00054         isc_taskpool_destroy(&pool);
00055         ATF_REQUIRE_EQ(pool, NULL);
00056 
00057         isc_test_end();
00058 }
00059 
00060 /* Resize a taskpool */
00061 ATF_TC(expand_pool);
00062 ATF_TC_HEAD(expand_pool, tc) {
00063         atf_tc_set_md_var(tc, "descr", "expand a taskpool");
00064 }
00065 ATF_TC_BODY(expand_pool, tc) {
00066         isc_result_t result;
00067         isc_taskpool_t *pool1 = NULL, *pool2 = NULL, *hold = NULL;
00068 
00069         UNUSED(tc);
00070 
00071         result = isc_test_begin(NULL, ISC_TRUE);
00072         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00073 
00074         result = isc_taskpool_create(taskmgr, mctx, 10, 2, &pool1);
00075         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00076         ATF_REQUIRE_EQ(isc_taskpool_size(pool1), 10);
00077 
00078         /* resizing to a smaller size should have no effect */
00079         hold = pool1;
00080         result = isc_taskpool_expand(&pool1, 5, &pool2);
00081         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00082         ATF_REQUIRE_EQ(isc_taskpool_size(pool2), 10);
00083         ATF_REQUIRE_EQ(pool2, hold);
00084         ATF_REQUIRE_EQ(pool1, NULL);
00085         pool1 = pool2;
00086         pool2 = NULL;
00087 
00088         /* resizing to the same size should have no effect */
00089         hold = pool1;
00090         result = isc_taskpool_expand(&pool1, 10, &pool2);
00091         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00092         ATF_REQUIRE_EQ(isc_taskpool_size(pool2), 10);
00093         ATF_REQUIRE_EQ(pool2, hold);
00094         ATF_REQUIRE_EQ(pool1, NULL);
00095         pool1 = pool2;
00096         pool2 = NULL;
00097 
00098         /* resizing to larger size should make a new pool */
00099         hold = pool1;
00100         result = isc_taskpool_expand(&pool1, 20, &pool2);
00101         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00102         ATF_REQUIRE_EQ(isc_taskpool_size(pool2), 20);
00103         ATF_REQUIRE(pool2 != hold);
00104         ATF_REQUIRE_EQ(pool1, NULL);
00105 
00106         isc_taskpool_destroy(&pool2);
00107         ATF_REQUIRE_EQ(pool2, NULL);
00108 
00109         isc_test_end();
00110 }
00111 
00112 /* Get tasks */
00113 ATF_TC(get_tasks);
00114 ATF_TC_HEAD(get_tasks, tc) {
00115         atf_tc_set_md_var(tc, "descr", "create a taskpool");
00116 }
00117 ATF_TC_BODY(get_tasks, tc) {
00118         isc_result_t result;
00119         isc_taskpool_t *pool = NULL;
00120         isc_task_t *task1 = NULL, *task2 = NULL, *task3 = NULL;
00121 
00122         UNUSED(tc);
00123 
00124         result = isc_test_begin(NULL, ISC_TRUE);
00125         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00126 
00127         result = isc_taskpool_create(taskmgr, mctx, 2, 2, &pool);
00128         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00129         ATF_REQUIRE_EQ(isc_taskpool_size(pool), 2);
00130 
00131         /* two tasks in pool; make sure we can access them more than twice */
00132         isc_taskpool_gettask(pool, &task1);
00133         ATF_REQUIRE(ISCAPI_TASK_VALID(task1));
00134 
00135         isc_taskpool_gettask(pool, &task2);
00136         ATF_REQUIRE(ISCAPI_TASK_VALID(task2));
00137 
00138         isc_taskpool_gettask(pool, &task3);
00139         ATF_REQUIRE(ISCAPI_TASK_VALID(task3));
00140 
00141         isc_task_destroy(&task1);
00142         isc_task_destroy(&task2);
00143         isc_task_destroy(&task3);
00144 
00145         isc_taskpool_destroy(&pool);
00146         ATF_REQUIRE_EQ(pool, NULL);
00147 
00148         isc_test_end();
00149 }
00150 
00151 /* Get tasks */
00152 ATF_TC(set_privilege);
00153 ATF_TC_HEAD(set_privilege, tc) {
00154         atf_tc_set_md_var(tc, "descr", "create a taskpool");
00155 }
00156 ATF_TC_BODY(set_privilege, tc) {
00157         isc_result_t result;
00158         isc_taskpool_t *pool = NULL;
00159         isc_task_t *task1 = NULL, *task2 = NULL, *task3 = NULL;
00160 
00161         UNUSED(tc);
00162 
00163         result = isc_test_begin(NULL, ISC_TRUE);
00164         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00165 
00166         result = isc_taskpool_create(taskmgr, mctx, 2, 2, &pool);
00167         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00168         ATF_REQUIRE_EQ(isc_taskpool_size(pool), 2);
00169 
00170         isc_taskpool_setprivilege(pool, ISC_TRUE);
00171 
00172         isc_taskpool_gettask(pool, &task1);
00173         isc_taskpool_gettask(pool, &task2);
00174         isc_taskpool_gettask(pool, &task3);
00175 
00176         ATF_CHECK(ISCAPI_TASK_VALID(task1));
00177         ATF_CHECK(ISCAPI_TASK_VALID(task2));
00178         ATF_CHECK(ISCAPI_TASK_VALID(task3));
00179 
00180         ATF_CHECK(isc_task_privilege(task1));
00181         ATF_CHECK(isc_task_privilege(task2));
00182         ATF_CHECK(isc_task_privilege(task3));
00183 
00184         isc_taskpool_setprivilege(pool, ISC_FALSE);
00185 
00186         ATF_CHECK(!isc_task_privilege(task1));
00187         ATF_CHECK(!isc_task_privilege(task2));
00188         ATF_CHECK(!isc_task_privilege(task3));
00189 
00190         isc_task_destroy(&task1);
00191         isc_task_destroy(&task2);
00192         isc_task_destroy(&task3);
00193 
00194         isc_taskpool_destroy(&pool);
00195         ATF_REQUIRE_EQ(pool, NULL);
00196 
00197         isc_test_end();
00198 }
00199 
00200 /*
00201  * Main
00202  */
00203 ATF_TP_ADD_TCS(tp) {
00204         ATF_TP_ADD_TC(tp, create_pool);
00205         ATF_TP_ADD_TC(tp, expand_pool);
00206         ATF_TP_ADD_TC(tp, get_tasks);
00207         ATF_TP_ADD_TC(tp, set_privilege);
00208 
00209         return (atf_no_error());
00210 }
00211 

Generated on Tue Apr 28 17:41:05 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha