test_page_heap.cpp 967 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "catch.hpp"
  2. #include "page_heap.h"
  3. #include "shm.h"
  4. TEST_CASE("RadixTree, Allocate Span")
  5. {
  6. bg::ShmOptions opts(false, "Test", nullptr);
  7. opts.fix_vptr_on_init = false;
  8. REQUIRE(bg::ShmInit(opts) == true);
  9. bg::detail::MetadataAllocator<bg::detail::Span> span_allocator;
  10. std::vector<bg::detail::Span*> vec;
  11. vec.reserve(2340);
  12. for(int i = 0; i < 2340; ++i)
  13. {
  14. bg::detail::Span* span = span_allocator.Allocate();
  15. REQUIRE(span);
  16. span->SetUsedCount(i);
  17. vec.push_back(span);
  18. }
  19. for(int i = 2340 - 1; i >= 0; --i)
  20. {
  21. span_allocator.Destroy(vec[i]);
  22. }
  23. for(int i = 0; i < 2340; ++i)
  24. {
  25. bg::detail::Span* span = span_allocator.Allocate();
  26. REQUIRE(span);
  27. REQUIRE(span->GetUsedCount() == i);
  28. }
  29. for(int i = 2340 - 1; i >= 0; --i)
  30. {
  31. span_allocator.Destroy(vec[i]);
  32. }
  33. bg::ShmFini();
  34. }