12345678910111213141516171819202122232425262728293031323334353637383940 |
-
- #include "catch.hpp"
- #include "size_map.h"
- #include "shm_manager.h"
- TEST_CASE("SizeMap, CalcAlignment")
- {
- for(size_t i = 0; i < CLASS_MAX_BYTES; ++i)
- {
- auto value = bg::detail::SizeMap::CalcAlignment(i);
- REQUIRE(value > 0);
- REQUIRE(value % 8 == 0);
- REQUIRE(value <= PAGE_BYTES);
- if(i > 0x7F && i < (PAGE_BYTES << 4))
- {
- REQUIRE(PALIGN_DOWN(i, value << 3) == value << 3);
- }
- }
- }
- TEST_CASE("SizeMap, Class Index to Page")
- {
- bg::detail::SizeMap sizemap;
- sizemap.Init();
- for(size_t bytes = 0; bytes < CLASS_MAX_BYTES; ++bytes)
- {
- size_t index = sizemap.GetClassByBytes(bytes);
- REQUIRE(index < CLASS_MAX_COUNT);
- REQUIRE(sizemap.ClassToSize(index) >= bytes);
- REQUIRE(sizemap.ClassToPages(index) * PAGE_BYTES >= bytes);
- REQUIRE(sizemap.ClassToPages(index) * PAGE_BYTES <= CLASS_MAX_BYTES);
- if(index > 1)
- {
- REQUIRE(sizemap.ClassToSize(index - 1) < bytes);
- }
- }
- }
|