Changeset 3081 for pjproject/trunk/pjlib/src/pjlib-test/pool.c
- Timestamp:
- Jan 29, 2010 10:10:49 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pjlib-test/pool.c
r2394 r3081 77 77 78 78 pj_pool_release(pool); 79 return 0; 80 } 81 82 /* Test that the alignment works. */ 83 static int pool_alignment_test(void) 84 { 85 pj_pool_t *pool; 86 void *ptr; 87 88 PJ_LOG(3,("test", "...alignment test")); 89 90 pool = pj_pool_create(mem, NULL, PJ_POOL_SIZE+64, 64, NULL); 91 if (!pool) 92 return -300; 93 94 #define IS_ALIGNED(p) ((((unsigned long)p) & (PJ_POOL_ALIGNMENT-1)) == 0) 95 96 /* Test first allocation */ 97 ptr = pj_pool_alloc(pool, 1); 98 if (!IS_ALIGNED(ptr)) { 99 pj_pool_release(pool); 100 return -310; 101 } 102 103 /* Test subsequent allocation */ 104 ptr = pj_pool_alloc(pool, 1); 105 if (!IS_ALIGNED(ptr)) { 106 pj_pool_release(pool); 107 return -320; 108 } 109 110 /* Test allocation after new block is created */ 111 ptr = pj_pool_alloc(pool, 127); 112 if (!IS_ALIGNED(ptr)) { 113 pj_pool_release(pool); 114 return -330; 115 } 116 117 /* Reset the pool */ 118 pj_pool_reset(pool); 119 120 /* Retest first allocation */ 121 ptr = pj_pool_alloc(pool, 1); 122 if (!IS_ALIGNED(ptr)) { 123 pj_pool_release(pool); 124 return -340; 125 } 126 127 /* Retest subsequent allocation */ 128 ptr = pj_pool_alloc(pool, 1); 129 if (!IS_ALIGNED(ptr)) { 130 pj_pool_release(pool); 131 return -350; 132 } 133 134 /* Done */ 135 pj_pool_release(pool); 136 137 return 0; 138 } 139 140 /* Test that the alignment works for pool on buf. */ 141 static int pool_buf_alignment_test(void) 142 { 143 pj_pool_t *pool; 144 char buf[256]; 145 void *ptr; 146 147 PJ_LOG(3,("test", "...pool_buf alignment test")); 148 149 pool = pj_pool_create_on_buf(NULL, buf, sizeof(buf)); 150 if (!pool) 151 return -400; 152 153 /* Test first allocation */ 154 ptr = pj_pool_alloc(pool, 1); 155 if (!IS_ALIGNED(ptr)) { 156 pj_pool_release(pool); 157 return -410; 158 } 159 160 /* Test subsequent allocation */ 161 ptr = pj_pool_alloc(pool, 1); 162 if (!IS_ALIGNED(ptr)) { 163 pj_pool_release(pool); 164 return -420; 165 } 166 167 /* Reset the pool */ 168 pj_pool_reset(pool); 169 170 /* Retest first allocation */ 171 ptr = pj_pool_alloc(pool, 1); 172 if (!IS_ALIGNED(ptr)) { 173 pj_pool_release(pool); 174 return -430; 175 } 176 177 /* Retest subsequent allocation */ 178 ptr = pj_pool_alloc(pool, 1); 179 if (!IS_ALIGNED(ptr)) { 180 pj_pool_release(pool); 181 return -440; 182 } 183 184 /* Done */ 79 185 return 0; 80 186 } … … 150 256 /* 16 is the internal struct in pool_buf */ 151 257 static char buf[ STATIC_BUF_SIZE + sizeof(pj_pool_t) + 152 sizeof(pj_pool_block) + 16];258 sizeof(pj_pool_block) + 2 * PJ_POOL_ALIGNMENT]; 153 259 pj_pool_t *pool; 154 260 void *p; … … 201 307 if (rc) return rc; 202 308 309 rc = pool_alignment_test(); 310 if (rc) return rc; 311 312 rc = pool_buf_alignment_test(); 313 if (rc) return rc; 314 203 315 for (loop=0; loop<LOOP; ++loop) { 204 316 /* Test that the pool should grow automaticly. */
Note: See TracChangeset
for help on using the changeset viewer.