1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #include "catch.hpp"
- #include "shm_object.h"
- #include "shm.h"
- #include "shm_manager.h"
- #if defined(__GNUC__)
- #include <sys/mman.h>
- #endif
- TEST_CASE("ShmObjectCreate, creat/delete")
- {
- bg::ShmOptions opts(false, "Test", nullptr);
- char path[256];
- bg::detail::ShmManager::ShmBlock m_blocks[17]{};
- size_t count = opts.fixed_address_count;
- for(size_t i = 0; i < count; ++i)
- {
- size_t real_size = opts.shm_block_mmap_size / 0x10000;
- size_t mmap_size = opts.shm_block_mmap_size / 0x10000;
- snprintf(path, 0x100uLL, "%s-%03zu.mmap", opts.identifier, i);
- uintptr_t fixed_addr = 0ll;
- REQUIRE(opts.PopFixedAddress(&fixed_addr));
- void* memory = bg::detail::ShmObjectCreate(path, fixed_addr, &real_size, &mmap_size);
- REQUIRE(memory);
- memset(memory, 0, real_size);
- m_blocks[i].addr = memory;
- m_blocks[i].mmap_size = real_size;
- m_blocks[i].mmap_size = mmap_size;
- }
- for(size_t i = 0; i < count; ++i)
- {
- #if defined(__GNUC__)
-
- size_t real_size = opts.shm_block_mmap_size / 0x10000;
- size_t mmap_size = opts.shm_block_mmap_size / 0x10000;
- munmap(m_blocks[i].addr, m_blocks[i].real_size);
- snprintf(path, 0x100uLL, "%s-%03zu.mmap", opts.identifier, i);
- void* memory = bg::detail::ShmObjectAttach(path, (uintptr_t)m_blocks[i].addr, &real_size, &mmap_size);
- REQUIRE(memory);
- memset(memory, 0, real_size);
- #else
- size_t real_size = opts.shm_block_mmap_size / 0x10000;
- size_t mmap_size = opts.shm_block_mmap_size / 0x10000;
- snprintf(path, 0x100uLL, "%s-%03zu.mmap", opts.identifier, i);
- void* memory = bg::detail::ShmObjectAttach(path, 0, &real_size, &mmap_size);
- REQUIRE(memory);
- memset(memory, 0, real_size);
- bg::detail::ShmObjectDelete(memory, mmap_size, path);
- #endif
- }
-
-
- for(size_t i = 0; i < count; ++i)
- {
- snprintf(path, 0x100uLL, "%s-%03zu.mmap", opts.identifier, i);
- bg::detail::ShmObjectDelete(m_blocks[i].addr, m_blocks[i].mmap_size, path);
- }
- }
|