mission_arena_test.cpp 1.3 KB

12345678910111213141516171819202122232425262728
  1. // Run against the production allocator with Release optimization enabled.
  2. #include <cstdio>
  3. #include <cstring>
  4. #include "server/activity/mission/mission_script_vm_internal.h"
  5. int main() {
  6. using namespace sunrise::server::activity::mission::lua_vm;
  7. detail::Arena arena{};
  8. for (int cycle = 0; cycle < 3; ++cycle) {
  9. if (!detail::arena_initialize(arena) || arena.capacity != kArenaByteCapacity) return 1;
  10. void* small = detail::arena_allocate(&arena, nullptr, 0, 1024);
  11. if (!small) return 2;
  12. std::memset(small, 0x5A, 1024);
  13. void* grown = detail::arena_allocate(&arena, small, 1024, 8192);
  14. if (!grown) return 3;
  15. for (int i = 0; i < 1024; ++i) {
  16. if (static_cast<unsigned char*>(grown)[i] != 0x5A) return 4;
  17. }
  18. if (detail::arena_allocate(&arena, nullptr, 0, kArenaByteCapacity) != nullptr) return 5;
  19. detail::arena_allocate(&arena, grown, 8192, 0);
  20. if (arena.used != 0) return 6;
  21. void* large = detail::arena_allocate(&arena, nullptr, 0, kArenaByteCapacity / 2);
  22. if (!large) return 7;
  23. detail::arena_release(arena);
  24. if (arena.bytes || arena.capacity || arena.used || arena.initialized) return 8;
  25. }
  26. std::puts("production arena allocation, growth, bounds, coalescing and reopen passed");
  27. }