test_size_map.cpp 964 B

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