Skip to content

Commit

Permalink
[#532] Add resizable shared memory tests for segment leak fix
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Dec 3, 2024
1 parent cfd8dc6 commit ba28fa3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
1 change: 0 additions & 1 deletion iceoryx2-cal/src/resizable_shared_memory/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,6 @@ where
match state.shared_memory_map.get(segment_id) {
Some(entry) => {
deallocation_call(entry);
//entry.shm.deallocate_bucket(offset);
if entry.unregister_offset() == ShmEntryState::Empty
&& segment_id != state.current_idx
{
Expand Down
38 changes: 38 additions & 0 deletions iceoryx2-cal/tests/resizable_shared_memory_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,44 @@ mod resizable_shared_memory {
assert_that!(sut_viewer.number_of_active_segments(), eq 1);
}

#[test]
fn register_segment_that_was_resized_on_the_first_allocation_leads_to_a_unmap_of_the_old_segment_on_viewer_side<
Shm: SharedMemory<DefaultAllocator>,
Sut: ResizableSharedMemory<DefaultAllocator, Shm>,
>() {
let config = generate_isolated_config::<Sut>();
let storage_name = generate_name();

let sut = Sut::MemoryBuilder::new(&storage_name)
.config(&config)
.max_chunk_layout_hint(Layout::new::<u8>())
.max_number_of_chunks_hint(1)
.allocation_strategy(AllocationStrategy::BestFit)
.create()
.unwrap();

let sut_viewer = Sut::ViewBuilder::new(&storage_name)
.config(&config)
.open()
.unwrap();

let chunk_small = sut.allocate(Layout::new::<u8>()).unwrap().offset;
unsafe {
sut_viewer
.register_and_translate_offset(chunk_small)
.unwrap()
};
unsafe { sut_viewer.unregister_offset(chunk_small) };

let chunk = sut.allocate(Layout::new::<u64>()).unwrap().offset;

// this shall release the old `u8` segment and map the new `u64` segment, therefore
// leading to 1 active segment
unsafe { sut_viewer.register_and_translate_offset(chunk).unwrap() };

assert_that!(sut_viewer.number_of_active_segments(), eq 1);
}

#[instantiate_tests(<iceoryx2_cal::shared_memory::posix::Memory<DefaultAllocator>, resizable_shared_memory::dynamic::DynamicMemory<DefaultAllocator, iceoryx2_cal::shared_memory::posix::Memory<DefaultAllocator>>>)]
mod posix {}

Expand Down

0 comments on commit ba28fa3

Please sign in to comment.