| 552 | } |
| 553 | |
| 554 | static bool |
| 555 | test_RamCache(RegressionTest *t, RamCache *cache, const char *name, int64_t cache_size) |
| 556 | { |
| 557 | bool pass = true; |
| 558 | CacheKey key; |
| 559 | StripeSM *stripe = theCache->key_to_stripe(&key, "example.com", sizeof("example.com") - 1); |
| 560 | std::vector<Ptr<IOBufferData>> data; |
| 561 | |
| 562 | cache->init(cache_size, stripe); |
| 563 | |
| 564 | for (int l = 0; l < 10; l++) { |
| 565 | for (int i = 0; i < 200; i++) { |
| 566 | IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_thread()); |
| 567 | CryptoHash hash; |
| 568 | |
| 569 | d->alloc(BUFFER_SIZE_INDEX_16K); |
| 570 | data.push_back(make_ptr(d)); |
| 571 | hash.u64[0] = (static_cast<uint64_t>(i) << 32) + i; |
| 572 | hash.u64[1] = (static_cast<uint64_t>(i) << 32) + i; |
| 573 | cache->put(&hash, data[i].get(), 1 << 15); |
| 574 | // More hits for the first 10. |
| 575 | for (int j = 0; j <= i && j < 10; j++) { |
| 576 | Ptr<IOBufferData> data; |
| 577 | CryptoHash hash; |
| 578 | |
| 579 | hash.u64[0] = (static_cast<uint64_t>(j) << 32) + j; |
| 580 | hash.u64[1] = (static_cast<uint64_t>(j) << 32) + j; |
| 581 | cache->get(&hash, &data); |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | for (int i = 0; i < 10; i++) { |
| 587 | CryptoHash hash; |
| 588 | Ptr<IOBufferData> data; |
| 589 | |
| 590 | hash.u64[0] = (static_cast<uint64_t>(i) << 32) + i; |
| 591 | hash.u64[1] = (static_cast<uint64_t>(i) << 32) + i; |
| 592 | if (!cache->get(&hash, &data)) { |
| 593 | pass = false; |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | int sample_size = cache_size >> 6; |
| 598 | build_zipf(); |
| 599 | ts::Random::seed(13); |
| 600 | int *r = static_cast<int *>(ats_malloc(sample_size * sizeof(int))); |
| 601 | for (int i = 0; i < sample_size; i++) { |
| 602 | r[i] = get_zipf(ts::Random::drandom()); |
| 603 | } |
| 604 | data.clear(); |
| 605 | int misses = 0; |
| 606 | for (int i = 0; i < sample_size; i++) { |
| 607 | CryptoHash hash; |
| 608 | hash.u64[0] = (static_cast<uint64_t>(r[i]) << 32) + r[i]; |
| 609 | hash.u64[1] = (static_cast<uint64_t>(r[i]) << 32) + r[i]; |
| 610 | Ptr<IOBufferData> get_data; |
| 611 | if (!cache->get(&hash, &get_data)) { |
no test coverage detected