test_size_map.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 
  2. #include "catch.hpp"
  3. #include "size_map.h"
  4. #include "shm_manager.h"
  5. TEST_CASE("SizeMap, CalcAlignment")
  6. {
  7. for(size_t i = 0; i < CLASS_MAX_BYTES; ++i)
  8. {
  9. auto value = bg::detail::SizeMap::CalcAlignment(i);
  10. REQUIRE(value > 0);
  11. REQUIRE(value % 8 == 0);
  12. REQUIRE(value <= PAGE_BYTES);
  13. if(i > 0x7F && i < (PAGE_BYTES << 4))
  14. {
  15. REQUIRE(PALIGN_DOWN(i, value << 3) == value << 3);
  16. }
  17. }
  18. }
  19. TEST_CASE("SizeMap, Class Index to Page")
  20. {
  21. bg::detail::SizeMap sizemap;
  22. sizemap.Init();
  23. for(size_t bytes = 0; bytes < CLASS_MAX_BYTES; ++bytes)
  24. {
  25. size_t index = sizemap.GetClassByBytes(bytes);
  26. REQUIRE(index < CLASS_MAX_COUNT);
  27. REQUIRE(sizemap.ClassToSize(index) >= bytes);
  28. REQUIRE(sizemap.ClassToPages(index) * PAGE_BYTES >= bytes);
  29. REQUIRE(sizemap.ClassToPages(index) * PAGE_BYTES <= CLASS_MAX_BYTES);
  30. if(index > 1)
  31. {
  32. REQUIRE(sizemap.ClassToSize(index - 1) < bytes);
  33. }
  34. }
  35. }