| 199 | } |
| 200 | |
| 201 | int |
| 202 | test() |
| 203 | { |
| 204 | // Initialize IOBufAllocator |
| 205 | Layout::create(); |
| 206 | init_diags("", nullptr); |
| 207 | RecProcessInit(); |
| 208 | ink_event_system_init(EVENT_SYSTEM_MODULE_PUBLIC_VERSION); |
| 209 | |
| 210 | int ret = 0; |
| 211 | |
| 212 | printf("Starting tests\n"); |
| 213 | |
| 214 | printf("Testing refcounts\n"); |
| 215 | ret |= testRefcounting(); |
| 216 | printf("refcount ret %d\n", ret); |
| 217 | |
| 218 | // Initialize our cache |
| 219 | int cachePartitions = 4; |
| 220 | RefCountCache<ExampleStruct> *cache = new RefCountCache<ExampleStruct>(cachePartitions); |
| 221 | printf("Created...\n"); |
| 222 | |
| 223 | LoadRefCountCacheFromPath<ExampleStruct>(*cache, "/tmp/hostdb_cache", ExampleStruct::unmarshall); |
| 224 | printf("Cache started...\n"); |
| 225 | int numTestEntries = 10000; |
| 226 | |
| 227 | // See if anything persisted across the restart |
| 228 | ret |= verifyCache(cache, 0, numTestEntries); |
| 229 | printf("done verifying startup\n"); |
| 230 | |
| 231 | // Clear the cache |
| 232 | cache->clear(); |
| 233 | ret |= cache->count() != 0; |
| 234 | printf("clear %d\n", ret); |
| 235 | |
| 236 | // fill it |
| 237 | printf("filling...\n"); |
| 238 | fillCache(cache, 0, numTestEntries); |
| 239 | printf("filled...\n"); |
| 240 | |
| 241 | // Verify that it has items |
| 242 | printf("verifying...\n"); |
| 243 | ret |= verifyCache(cache, 0, numTestEntries); |
| 244 | printf("verified %d\n", ret); |
| 245 | |
| 246 | // Verify that we can alloc() with no extra space |
| 247 | printf("Alloc item idx 1\n"); |
| 248 | ExampleStruct *tmp = ExampleStruct::alloc(); |
| 249 | cache->put(static_cast<uint64_t>(1), tmp); |
| 250 | tmp->idx = 1; |
| 251 | |
| 252 | Ptr<ExampleStruct> tmpAfter = cache->get(static_cast<uint64_t>(1)); |
| 253 | printf("Item after (ret=%d) %d %d\n", ret, 1, tmpAfter->idx); |
| 254 | // Verify every item in the cache |
| 255 | ret |= verifyCache(cache, 0, numTestEntries); |
| 256 | printf("verified entire cache ret=%d\n", ret); |
| 257 | |
| 258 | // Grab a pointer to item 1 |
no test coverage detected