123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #include "catch.hpp"
- #include "page_heap.h"
- #include "shm.h"
- #include "size_map.h"
- TEST_CASE("RadixTree, Allocate Span")
- {
- bg::ShmOptions opts(false, "Test", nullptr);
- opts.fix_vptr_on_init = false;
- REQUIRE(bg::ShmInit(opts) == true);
- bg::detail::MetadataAllocator<bg::detail::Span> span_allocator;
- std::vector<bg::detail::Span*> vec;
- vec.reserve(2340);
- for(int i = 0; i < 2340; ++i)
- {
- bg::detail::Span* span = span_allocator.Allocate();
- REQUIRE(span);
- span->SetUsedCount(i);
- vec.push_back(span);
- }
- for(int i = 2340 - 1; i >= 0; --i)
- {
- span_allocator.Destroy(vec[i]);
- }
- for(size_t i = 0; i < 2340; ++i)
- {
- bg::detail::Span* span = span_allocator.Allocate();
- REQUIRE(span);
- REQUIRE(span->GetUsedCount() == i);
- }
- for(int i = 2340 - 1; i >= 0; --i)
- {
- span_allocator.Destroy(vec[i]);
- }
- bg::ShmFini();
- }
- TEST_CASE("RadixTree, 1- CLASS_MAX_BYTES ")
- {
- bg::ShmOptions opts(false, "Test", nullptr);
- opts.fix_vptr_on_init = false;
- REQUIRE(bg::ShmInit(opts) == true);
- bg::detail::SizeMap sizemap;
- sizemap.Init();
- bg::detail::PageHeap page_heap;
- for(size_t i = 1; i < CLASS_MAX_BYTES; i = i << 2)
- {
- size_t index = sizemap.GetClassByBytes(i);
- REQUIRE(index);
- REQUIRE(sizemap.ClassToSize(index) >= i);
- REQUIRE(PAGES_TO_BYTES(sizemap.ClassToPages(index)) >= i);
- auto span = page_heap.AllocateSpan(sizemap.ClassToPages(index));
- REQUIRE(span);
- void* memory = (void*)PAGES_TO_BYTES(span->GetStartPage());
- REQUIRE(memory);
- memset(memory, 0, PAGES_TO_BYTES(span->GetPageCount()));
- REQUIRE(page_heap.GetSpanMap(span->GetStartPage()) == span);
- REQUIRE(page_heap.GetSpanMap(span->GetLastPage()) == span);
- page_heap.RegisterSpan(span);
- for(size_t j = 1; i < span->GetPageCount(); ++j)
- {
- REQUIRE(page_heap.GetSpanMap(span->GetStartPage() + i) == span);
- }
- page_heap.DeallocateSpan(span);
- }
- bg::ShmFini();
- }
- TEST_CASE("RadixTree, 0x1000000LL - CLASS_MAX_BYTES ")
- {
- bg::ShmOptions opts(false, "Test", nullptr);
- opts.fix_vptr_on_init = false;
- REQUIRE(bg::ShmInit(opts) == true);
- bg::detail::PageHeap page_heap;
- for(size_t i = 0x1000000LL; i >= CLASS_MAX_BYTES; i = i >> 10)
- {
- auto span = page_heap.AllocateSpan(BYTES_TO_PAGES(i));
- REQUIRE(span);
- void* memory = (void*)PAGES_TO_BYTES(span->GetStartPage());
- REQUIRE(memory);
- memset(memory, 0, PAGES_TO_BYTES(span->GetPageCount()));
- REQUIRE(page_heap.GetSpanMap(span->GetStartPage()) == span);
- REQUIRE(page_heap.GetSpanMap(span->GetLastPage()) == span);
- page_heap.DeallocateSpan(span);
- }
- bg::ShmFini();
- }
|