00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include <atf-c.h>
00024
00025 #include <unistd.h>
00026
00027 #include <isc/mem.h>
00028 #include <isc/pool.h>
00029
00030 #include "isctest.h"
00031
00032 static isc_result_t
00033 poolinit(void **target, void *arg) {
00034 isc_result_t result;
00035
00036 isc_taskmgr_t *mgr = (isc_taskmgr_t *) arg;
00037 isc_task_t *task = NULL;
00038 result = isc_task_create(mgr, 0, &task);
00039 if (result != ISC_R_SUCCESS)
00040 return (result);
00041
00042 *target = (void *) task;
00043 return (ISC_R_SUCCESS);
00044 }
00045
00046 static void
00047 poolfree(void **target) {
00048 isc_task_t *task = *(isc_task_t **) target;
00049 isc_task_destroy(&task);
00050 *target = NULL;
00051 }
00052
00053
00054
00055
00056
00057
00058 ATF_TC(create_pool);
00059 ATF_TC_HEAD(create_pool, tc) {
00060 atf_tc_set_md_var(tc, "descr", "create a pool");
00061 }
00062 ATF_TC_BODY(create_pool, tc) {
00063 isc_result_t result;
00064 isc_pool_t *pool = NULL;
00065
00066 UNUSED(tc);
00067
00068 result = isc_test_begin(NULL, ISC_TRUE);
00069 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00070
00071 result = isc_pool_create(mctx, 8, poolfree, poolinit, taskmgr, &pool);
00072 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00073 ATF_REQUIRE_EQ(isc_pool_count(pool), 8);
00074
00075 isc_pool_destroy(&pool);
00076 ATF_REQUIRE_EQ(pool, NULL);
00077
00078 isc_test_end();
00079 }
00080
00081
00082 ATF_TC(expand_pool);
00083 ATF_TC_HEAD(expand_pool, tc) {
00084 atf_tc_set_md_var(tc, "descr", "expand a pool");
00085 }
00086 ATF_TC_BODY(expand_pool, tc) {
00087 isc_result_t result;
00088 isc_pool_t *pool1 = NULL, *pool2 = NULL, *hold = NULL;
00089
00090 UNUSED(tc);
00091
00092 result = isc_test_begin(NULL, ISC_TRUE);
00093 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00094
00095 result = isc_pool_create(mctx, 10, poolfree, poolinit, taskmgr, &pool1);
00096 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00097 ATF_REQUIRE_EQ(isc_pool_count(pool1), 10);
00098
00099
00100 hold = pool1;
00101 result = isc_pool_expand(&pool1, 5, &pool2);
00102 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00103 ATF_REQUIRE_EQ(isc_pool_count(pool2), 10);
00104 ATF_REQUIRE_EQ(pool2, hold);
00105 ATF_REQUIRE_EQ(pool1, NULL);
00106 pool1 = pool2;
00107 pool2 = NULL;
00108
00109
00110 hold = pool1;
00111 result = isc_pool_expand(&pool1, 10, &pool2);
00112 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00113 ATF_REQUIRE_EQ(isc_pool_count(pool2), 10);
00114 ATF_REQUIRE_EQ(pool2, hold);
00115 ATF_REQUIRE_EQ(pool1, NULL);
00116 pool1 = pool2;
00117 pool2 = NULL;
00118
00119
00120 hold = pool1;
00121 result = isc_pool_expand(&pool1, 20, &pool2);
00122 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00123 ATF_REQUIRE_EQ(isc_pool_count(pool2), 20);
00124 ATF_REQUIRE(pool2 != hold);
00125 ATF_REQUIRE_EQ(pool1, NULL);
00126
00127 isc_pool_destroy(&pool2);
00128 ATF_REQUIRE_EQ(pool2, NULL);
00129
00130 isc_test_end();
00131 }
00132
00133
00134 ATF_TC(get_objects);
00135 ATF_TC_HEAD(get_objects, tc) {
00136 atf_tc_set_md_var(tc, "descr", "get objects");
00137 }
00138 ATF_TC_BODY(get_objects, tc) {
00139 isc_result_t result;
00140 isc_pool_t *pool = NULL;
00141 void *item;
00142 isc_task_t *task1 = NULL, *task2 = NULL, *task3 = NULL;
00143
00144 UNUSED(tc);
00145
00146 result = isc_test_begin(NULL, ISC_TRUE);
00147 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00148
00149 result = isc_pool_create(mctx, 2, poolfree, poolinit, taskmgr, &pool);
00150 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00151 ATF_REQUIRE_EQ(isc_pool_count(pool), 2);
00152
00153 item = isc_pool_get(pool);
00154 ATF_REQUIRE(item != NULL);
00155 isc_task_attach((isc_task_t *) item, &task1);
00156
00157 item = isc_pool_get(pool);
00158 ATF_REQUIRE(item != NULL);
00159 isc_task_attach((isc_task_t *) item, &task2);
00160
00161 item = isc_pool_get(pool);
00162 ATF_REQUIRE(item != NULL);
00163 isc_task_attach((isc_task_t *) item, &task3);
00164
00165 isc_task_detach(&task1);
00166 isc_task_detach(&task2);
00167 isc_task_detach(&task3);
00168
00169 isc_pool_destroy(&pool);
00170 ATF_REQUIRE_EQ(pool, NULL);
00171
00172 isc_test_end();
00173 }
00174
00175
00176
00177
00178
00179 ATF_TP_ADD_TCS(tp) {
00180 ATF_TP_ADD_TC(tp, create_pool);
00181 ATF_TP_ADD_TC(tp, expand_pool);
00182 ATF_TP_ADD_TC(tp, get_objects);
00183
00184 return (atf_no_error());
00185 }
00186