test_object.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "catch.hpp"
  2. #include "shm_object.h"
  3. #include "shm.h"
  4. #include "shm_manager.h"
  5. TEST_CASE("ShmObjectCreate, creat/delete")
  6. {
  7. bg::ShmOptions opts(false, "Test", nullptr);
  8. char path[256];
  9. bg::detail::ShmManager::ShmBlock m_blocks[17]{};
  10. size_t count = opts.fixed_address_count;
  11. for(size_t i = 0; i < count; ++i)
  12. {
  13. size_t real_size = opts.shm_block_mmap_size / 8;
  14. size_t mmap_size = opts.shm_block_mmap_size / 8;
  15. snprintf(path, 0x100uLL, "%s-%03zu.mmap", opts.identifier, i);
  16. uintptr_t fixed_addr = 0ll;
  17. REQUIRE(opts.PopFixedAddress(&fixed_addr));
  18. void* memory = bg::detail::ShmObjectCreate(path, fixed_addr, &real_size, &mmap_size);
  19. REQUIRE(memory);
  20. memset(memory, 0, real_size);
  21. m_blocks[i].addr = memory;
  22. m_blocks[i].mmap_size = real_size;
  23. m_blocks[i].mmap_size = mmap_size;
  24. }
  25. for(size_t i = 0; i < count; ++i)
  26. {
  27. size_t real_size = opts.shm_block_mmap_size / 8;
  28. size_t mmap_size = opts.shm_block_mmap_size / 8;
  29. snprintf(path, 0x100uLL, "%s-%03zu.mmap", opts.identifier, i);
  30. void* memory = bg::detail::ShmObjectAttach(path, 0, &real_size, &mmap_size);
  31. REQUIRE(memory);
  32. memset(memory, 0, real_size);
  33. bg::detail::ShmObjectDelete(memory, mmap_size, path);
  34. }
  35. for(size_t i = 0; i < count; ++i)
  36. {
  37. size_t real_size = opts.shm_block_mmap_size / 8;
  38. size_t mmap_size = opts.shm_block_mmap_size / 8;
  39. snprintf(path, 0x100uLL, "%s-%03zu.mmap", opts.identifier, i);
  40. bg::detail::ShmObjectDelete(m_blocks[i].addr, m_blocks[i].mmap_size, path);
  41. }
  42. }