This commit is contained in:
@ -21,45 +21,30 @@ using namespace IACore;
|
||||
|
||||
IAT_BEGIN_BLOCK(Core, IPC)
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 1. Layout Constraints
|
||||
// -------------------------------------------------------------------------
|
||||
auto test_layout_constraints() -> bool {
|
||||
// Verify alignment
|
||||
|
||||
IAT_CHECK_EQ(alignof(IpcSharedMemoryLayout), static_cast<usize>(64));
|
||||
|
||||
// Verify offsets to ensure cache-line isolation
|
||||
// Header is at 0
|
||||
IAT_CHECK_EQ(offsetof(IpcSharedMemoryLayout, meta), static_cast<usize>(0));
|
||||
|
||||
// moni_control should be at 64 (cache line 1)
|
||||
IAT_CHECK_EQ(offsetof(IpcSharedMemoryLayout, moni_control),
|
||||
static_cast<usize>(64));
|
||||
|
||||
// ControlBlock is 128 bytes (64 for producer, 64 for consumer)
|
||||
// So mino_control should be at 64 + 128 = 192
|
||||
IAT_CHECK_EQ(offsetof(IpcSharedMemoryLayout, mino_control),
|
||||
static_cast<usize>(192));
|
||||
|
||||
// Data offsets should follow mino_control (192 + 128 = 320)
|
||||
IAT_CHECK_EQ(offsetof(IpcSharedMemoryLayout, moni_data_offset),
|
||||
static_cast<usize>(320));
|
||||
|
||||
// Ensure the whole struct is a multiple of 64
|
||||
IAT_CHECK_EQ(sizeof(IpcSharedMemoryLayout) % 64, static_cast<usize>(0));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 2. Manual Shared Memory & RingBuffer Setup
|
||||
// -------------------------------------------------------------------------
|
||||
auto test_manual_shm_ringbuffer() -> bool {
|
||||
const String shm_name = "IA_TEST_IPC_LAYOUT_CHECK";
|
||||
const usize shm_size = 16 * 1024; // 16KB
|
||||
const usize shm_size = 16 * 1024;
|
||||
|
||||
// 1. Create Shared Memory
|
||||
// Ensure it doesn't exist first
|
||||
FileOps::unlink_shared_memory(shm_name);
|
||||
|
||||
auto map_res = FileOps::map_shared_memory(shm_name, shm_size, true);
|
||||
@ -68,14 +53,10 @@ auto test_manual_shm_ringbuffer() -> bool {
|
||||
u8 *base_ptr = *map_res;
|
||||
auto *layout = reinterpret_cast<IpcSharedMemoryLayout *>(base_ptr);
|
||||
|
||||
// 2. Initialize Layout
|
||||
// We simulate what IpcManager would do
|
||||
layout->meta.magic = 0xDEADBEEF; // Dummy
|
||||
layout->meta.magic = 0xDEADBEEF;
|
||||
layout->meta.version = 1;
|
||||
layout->meta.total_size = shm_size;
|
||||
|
||||
// Define data regions
|
||||
// Data starts after the layout struct
|
||||
const usize header_size = IpcSharedMemoryLayout::get_header_size();
|
||||
const usize data_available = shm_size - header_size;
|
||||
const usize half_data = data_available / 2;
|
||||
@ -86,9 +67,6 @@ auto test_manual_shm_ringbuffer() -> bool {
|
||||
layout->mino_data_offset = header_size + half_data;
|
||||
layout->mino_data_size = half_data;
|
||||
|
||||
// 3. Initialize RingBuffers
|
||||
// MONI (Manager Out, Node In)
|
||||
// Manager is Owner of MONI
|
||||
Span<u8> moni_data_span(base_ptr + layout->moni_data_offset,
|
||||
static_cast<usize>(layout->moni_data_size));
|
||||
auto moni_res =
|
||||
@ -96,9 +74,6 @@ auto test_manual_shm_ringbuffer() -> bool {
|
||||
IAT_CHECK(moni_res.has_value());
|
||||
auto moni = std::move(*moni_res);
|
||||
|
||||
// MINO (Manager In, Node Out)
|
||||
// Manager is NOT Owner of MINO (Node writes to it)
|
||||
// But for this test, let's pretend we are the Node for MINO to test writing
|
||||
Span<u8> mino_data_span(base_ptr + layout->mino_data_offset,
|
||||
static_cast<usize>(layout->mino_data_size));
|
||||
auto mino_res =
|
||||
@ -106,16 +81,12 @@ auto test_manual_shm_ringbuffer() -> bool {
|
||||
IAT_CHECK(mino_res.has_value());
|
||||
auto _ = std::move(*mino_res);
|
||||
|
||||
// 4. Test Data Flow
|
||||
// Write to MONI
|
||||
String msg = "IPC_TEST_MESSAGE";
|
||||
IAT_CHECK(
|
||||
moni.push(100, Span<const u8>(reinterpret_cast<const u8 *>(msg.data()),
|
||||
msg.size()))
|
||||
.has_value());
|
||||
|
||||
// Read from MONI (Simulate Node reading)
|
||||
// Create a reader view
|
||||
auto moni_reader_res =
|
||||
RingBufferView::create(&layout->moni_control, moni_data_span, false);
|
||||
IAT_CHECK(moni_reader_res.has_value());
|
||||
@ -125,22 +96,18 @@ auto test_manual_shm_ringbuffer() -> bool {
|
||||
u8 buffer[128];
|
||||
auto pop_res = moni_reader.pop(header, Span<u8>(buffer, 128));
|
||||
IAT_CHECK(pop_res.has_value());
|
||||
IAT_CHECK(pop_res->has_value()); // Should have data
|
||||
IAT_CHECK(pop_res->has_value());
|
||||
IAT_CHECK_EQ(header.id, static_cast<u16>(100));
|
||||
|
||||
String received((char *)buffer, *pop_res.value());
|
||||
IAT_CHECK_EQ(received, msg);
|
||||
|
||||
// Cleanup
|
||||
FileOps::unmap_file(base_ptr);
|
||||
FileOps::unlink_shared_memory(shm_name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 3. Manager Instantiation
|
||||
// -------------------------------------------------------------------------
|
||||
class TestManager : public IpcManager {
|
||||
public:
|
||||
void on_signal(NativeProcessID, u8) override {}
|
||||
|
||||
Reference in New Issue
Block a user