From 50d399ef669503ebca4ffe26a4f1ac9b21f9f216 Mon Sep 17 00:00:00 2001 From: Christian Eltzschig Date: Mon, 25 Nov 2024 20:29:13 +0100 Subject: [PATCH] [#525] Finalize tests for zero copy channel with multiple segment ids --- .../src/zero_copy_connection/common.rs | 43 ++-- iceoryx2-cal/src/zero_copy_connection/mod.rs | 2 +- ...py_connection_posix_shared_memory_tests.rs | 2 +- .../tests/zero_copy_connection_trait_tests.rs | 214 ++++++++++++------ .../src/port/details/publisher_connections.rs | 2 +- .../port/details/subscriber_connections.rs | 2 +- 6 files changed, 171 insertions(+), 94 deletions(-) diff --git a/iceoryx2-cal/src/zero_copy_connection/common.rs b/iceoryx2-cal/src/zero_copy_connection/common.rs index 9420fa65c..e32b77388 100644 --- a/iceoryx2-cal/src/zero_copy_connection/common.rs +++ b/iceoryx2-cal/src/zero_copy_connection/common.rs @@ -1,5 +1,3 @@ -// Copyright (c) 2023 Contributors to the Eclipse Foundation -// // See the NOTICE file(s) distributed with this work for additional // information regarding copyright ownership. // @@ -158,7 +156,7 @@ pub mod details { used_chunk_list: RelocatableVec, max_borrowed_samples: usize, sample_size: usize, - number_of_samples: usize, + number_of_samples_per_segment: usize, number_of_segments: u8, state: IoxAtomicU8, init_state: IoxAtomicU64, @@ -172,7 +170,7 @@ pub mod details { enable_safe_overflow: bool, max_borrowed_samples: usize, sample_size: usize, - number_of_samples: usize, + number_of_samples_per_segment: usize, number_of_segments: u8, ) -> Self { Self { @@ -190,7 +188,7 @@ pub mod details { enable_safe_overflow, sample_size, max_borrowed_samples, - number_of_samples, + number_of_samples_per_segment, number_of_segments, } } @@ -219,7 +217,7 @@ pub mod details { enable_safe_overflow: bool, max_borrowed_samples: usize, sample_size: usize, - number_of_samples: usize, + number_of_samples_per_segment: usize, number_of_segments: u8, timeout: Duration, config: Configuration, @@ -238,7 +236,7 @@ pub mod details { let supplementary_size = SharedManagementData::const_memory_size( self.submission_channel_size(), self.completion_channel_size(), - self.number_of_samples, + self.number_of_samples_per_segment, self.number_of_segments, ); @@ -259,7 +257,7 @@ pub mod details { for _ in 0..self.number_of_segments { if !unsafe { - data.used_chunk_list.push(RelocatableUsedChunkList::new_uninit(self.number_of_samples)) + data.used_chunk_list.push(RelocatableUsedChunkList::new_uninit(self.number_of_samples_per_segment)) } { fatal_panic!(from self, "{} since the used chunk list could not be added. - This is an implementation bug!", msg); @@ -281,7 +279,7 @@ pub mod details { self.enable_safe_overflow, self.max_borrowed_samples, self.sample_size, - self.number_of_samples, + self.number_of_samples_per_segment, self.number_of_segments ) ); @@ -341,10 +339,11 @@ pub mod details { msg, self.sample_size, storage.get().sample_size); } - if storage.get().number_of_samples != self.number_of_samples { + if storage.get().number_of_samples_per_segment != self.number_of_samples_per_segment + { fail!(from self, with ZeroCopyCreationError::IncompatibleNumberOfSamples, "{} since the requested number of samples is set to {} but should be set to {}.", - msg, self.number_of_samples, storage.get().number_of_samples); + msg, self.number_of_samples_per_segment, storage.get().number_of_samples_per_segment); } if storage.get().number_of_segments != self.number_of_segments { @@ -400,7 +399,7 @@ pub mod details { enable_safe_overflow: DEFAULT_ENABLE_SAFE_OVERFLOW, max_borrowed_samples: DEFAULT_MAX_BORROWED_SAMPLES, sample_size: 0, - number_of_samples: 0, + number_of_samples_per_segment: 0, number_of_segments: DEFAULT_MAX_SUPPORTED_SHARED_MEMORY_SEGMENTS, config: Configuration::default(), timeout: Duration::ZERO, @@ -436,8 +435,8 @@ pub mod details { self } - fn number_of_samples(mut self, value: usize) -> Self { - self.number_of_samples = value; + fn number_of_samples_per_segment(mut self, value: usize) -> Self { + self.number_of_samples_per_segment = value; self } @@ -543,19 +542,17 @@ pub mod details { debug_assert!(segment_id < storage.number_of_segments as usize); - if !storage.used_chunk_list[segment_id].insert(index) { - fail!(from self, with ZeroCopySendError::UsedChunkListFull, - "{} since the used chunk list is full.", msg); - } + let did_not_send_same_offset_twice = storage.used_chunk_list[segment_id].insert(index); + debug_assert!(did_not_send_same_offset_twice); match unsafe { storage.submission_channel.push(ptr.as_value()) } { Some(v) => { - let pointer_offset = PointerOffset::from_value(v as u64); - if !storage.used_chunk_list[segment_id] + let pointer_offset = PointerOffset::from_value(v); + if !storage.used_chunk_list[pointer_offset.segment_id().value() as usize] .remove(pointer_offset.offset() / sample_size) { fail!(from self, with ZeroCopySendError::ConnectionCorrupted, - "{} since an invalid offset was returned on overflow.", msg); + "{} since the invalid offset {:?} was returned on overflow.", msg, pointer_offset); } Ok(Some(pointer_offset)) @@ -586,7 +583,7 @@ pub mod details { match unsafe { storage.completion_channel.pop() } { None => Ok(None), Some(v) => { - let pointer_offset = PointerOffset::from_value(v as u64); + let pointer_offset = PointerOffset::from_value(v); let segment_id = pointer_offset.segment_id().value() as usize; debug_assert!(segment_id < storage.number_of_segments as usize); @@ -691,7 +688,7 @@ pub mod details { None => Ok(None), Some(v) => { *self.borrow_counter() += 1; - Ok(Some(PointerOffset::from_value(v as u64))) + Ok(Some(PointerOffset::from_value(v))) } } } diff --git a/iceoryx2-cal/src/zero_copy_connection/mod.rs b/iceoryx2-cal/src/zero_copy_connection/mod.rs index 4f4937c7f..d3900b23b 100644 --- a/iceoryx2-cal/src/zero_copy_connection/mod.rs +++ b/iceoryx2-cal/src/zero_copy_connection/mod.rs @@ -112,7 +112,7 @@ pub trait ZeroCopyConnectionBuilder: NamedConceptBuilder< fn enable_safe_overflow(self, value: bool) -> Self; fn receiver_max_borrowed_samples(self, value: usize) -> Self; fn max_supported_shared_memory_segments(self, value: u8) -> Self; - fn number_of_samples(self, value: usize) -> Self; + fn number_of_samples_per_segment(self, value: usize) -> Self; /// The timeout defines how long the [`ZeroCopyConnectionBuilder`] should wait for /// concurrent /// [`ZeroCopyConnectionBuilder::create_sender()`] or diff --git a/iceoryx2-cal/tests/zero_copy_connection_posix_shared_memory_tests.rs b/iceoryx2-cal/tests/zero_copy_connection_posix_shared_memory_tests.rs index d946a20a2..63bdcffda 100644 --- a/iceoryx2-cal/tests/zero_copy_connection_posix_shared_memory_tests.rs +++ b/iceoryx2-cal/tests/zero_copy_connection_posix_shared_memory_tests.rs @@ -49,7 +49,7 @@ mod zero_copy_connection_posix_shared_memory_tests { let start = std::time::SystemTime::now(); let sut = ::Builder::new(&storage_name) .timeout(TIMEOUT) - .number_of_samples(1) + .number_of_samples_per_segment(1) .receiver_max_borrowed_samples(1) .create_sender(1); diff --git a/iceoryx2-cal/tests/zero_copy_connection_trait_tests.rs b/iceoryx2-cal/tests/zero_copy_connection_trait_tests.rs index 5bffb3453..76656be12 100644 --- a/iceoryx2-cal/tests/zero_copy_connection_trait_tests.rs +++ b/iceoryx2-cal/tests/zero_copy_connection_trait_tests.rs @@ -39,14 +39,14 @@ mod zero_copy_connection { assert_that!( Sut::Builder::new(&name) .config(&config) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .create_receiver(SAMPLE_SIZE), is_ok ); assert_that!( Sut::Builder::new(&name) .config(&config) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .create_sender(SAMPLE_SIZE), is_ok ); @@ -58,14 +58,14 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE) .unwrap(); assert_that!(!sut_sender.is_connected(), eq true); let sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_receiver(SAMPLE_SIZE) .unwrap(); @@ -82,7 +82,7 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE) .unwrap(); @@ -97,7 +97,7 @@ mod zero_copy_connection { ); let sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_receiver(SAMPLE_SIZE) .unwrap(); @@ -118,18 +118,18 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let _sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE) .unwrap(); let _sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_receiver(SAMPLE_SIZE) .unwrap(); let sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE); assert_that!(sut_sender, is_err); @@ -139,7 +139,7 @@ mod zero_copy_connection { ); let sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_receiver(SAMPLE_SIZE); assert_that!(sut_receiver, is_err); @@ -155,19 +155,19 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let _sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE) .unwrap(); let _sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_receiver(SAMPLE_SIZE) .unwrap(); drop(_sut_sender); let sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE); assert_that!(sut_sender, is_ok); @@ -179,19 +179,19 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let _sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE) .unwrap(); let _sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_receiver(SAMPLE_SIZE) .unwrap(); drop(_sut_receiver); let sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_receiver(SAMPLE_SIZE); assert_that!(sut_receiver, is_ok); @@ -203,12 +203,12 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE) .unwrap(); let sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_receiver(SAMPLE_SIZE) .unwrap(); @@ -226,14 +226,14 @@ mod zero_copy_connection { let _sut_sender = Sut::Builder::new(&name) .buffer_size(12) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE) .unwrap(); let sut_receiver = Sut::Builder::new(&name) .buffer_size(16) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_receiver(SAMPLE_SIZE); @@ -247,14 +247,14 @@ mod zero_copy_connection { let _sut_sender = Sut::Builder::new(&name) .receiver_max_borrowed_samples(2) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE) .unwrap(); let sut_receiver = Sut::Builder::new(&name) .receiver_max_borrowed_samples(4) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_receiver(SAMPLE_SIZE); @@ -268,13 +268,13 @@ mod zero_copy_connection { let _sut_sender = Sut::Builder::new(&name) .enable_safe_overflow(true) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE) .unwrap(); let sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_receiver(SAMPLE_SIZE); @@ -291,13 +291,13 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let _sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE) .unwrap(); let sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_receiver(2 * SAMPLE_SIZE); @@ -314,13 +314,13 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let _sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE) .unwrap(); let sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES * 2) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES * 2) .config(&config) .create_receiver(SAMPLE_SIZE); @@ -333,12 +333,12 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE) .unwrap(); let sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_receiver(SAMPLE_SIZE) .unwrap(); @@ -367,12 +367,12 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE) .unwrap(); let sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_receiver(SAMPLE_SIZE) .unwrap(); @@ -395,7 +395,7 @@ mod zero_copy_connection { let sut_sender = Sut::Builder::new(&name) .buffer_size(BUFFER_SIZE) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE) .unwrap(); @@ -421,7 +421,7 @@ mod zero_copy_connection { let sut_sender = Sut::Builder::new(&name) .buffer_size(BUFFER_SIZE) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .enable_safe_overflow(true) .config(&config) .create_sender(SAMPLE_SIZE) @@ -453,7 +453,7 @@ mod zero_copy_connection { let sut_sender = Sut::Builder::new(&name) .buffer_size(BUFFER_SIZE) .receiver_max_borrowed_samples(BUFFER_SIZE) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE) .unwrap(); @@ -469,7 +469,7 @@ mod zero_copy_connection { let receiver = Sut::Builder::new(&name) .buffer_size(BUFFER_SIZE) .receiver_max_borrowed_samples(BUFFER_SIZE) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_receiver(SAMPLE_SIZE) .unwrap(); @@ -487,7 +487,7 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_receiver(SAMPLE_SIZE) .unwrap(); @@ -507,7 +507,7 @@ mod zero_copy_connection { .buffer_size(BUFFER_SIZE) .receiver_max_borrowed_samples(MAX_BORROW) .enable_safe_overflow(true) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE) .unwrap(); @@ -515,7 +515,7 @@ mod zero_copy_connection { .buffer_size(BUFFER_SIZE) .receiver_max_borrowed_samples(MAX_BORROW) .enable_safe_overflow(true) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_receiver(SAMPLE_SIZE) .unwrap(); @@ -558,7 +558,7 @@ mod zero_copy_connection { let sut_sender = Sut::Builder::new(&name) .buffer_size(1) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config.lock().unwrap()) .create_sender(SAMPLE_SIZE) .unwrap(); @@ -573,7 +573,7 @@ mod zero_copy_connection { s.spawn(|| { let sut_receiver = Sut::Builder::new(&name) .buffer_size(1) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config.lock().unwrap()) .create_receiver(SAMPLE_SIZE) .unwrap(); @@ -616,13 +616,13 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(BUFFER_SIZE) .config(&config) .create_sender(SAMPLE_SIZE) .unwrap(); let _sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(BUFFER_SIZE) .config(&config) .create_receiver(SAMPLE_SIZE) @@ -655,7 +655,7 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(BUFFER_SIZE) .receiver_max_borrowed_samples(BUFFER_SIZE) .enable_safe_overflow(true) @@ -663,7 +663,7 @@ mod zero_copy_connection { .create_sender(SAMPLE_SIZE) .unwrap(); let _sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(BUFFER_SIZE) .receiver_max_borrowed_samples(BUFFER_SIZE) .enable_safe_overflow(true) @@ -705,7 +705,7 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(BUFFER_SIZE) .receiver_max_borrowed_samples(BUFFER_SIZE) .enable_safe_overflow(true) @@ -713,7 +713,7 @@ mod zero_copy_connection { .create_sender(SAMPLE_SIZE) .unwrap(); let sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(BUFFER_SIZE) .receiver_max_borrowed_samples(BUFFER_SIZE) .enable_safe_overflow(true) @@ -750,7 +750,7 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(BUFFER_SIZE) .receiver_max_borrowed_samples(BUFFER_SIZE) .enable_safe_overflow(true) @@ -758,7 +758,7 @@ mod zero_copy_connection { .create_sender(SAMPLE_SIZE) .unwrap(); let sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(BUFFER_SIZE) .receiver_max_borrowed_samples(BUFFER_SIZE) .enable_safe_overflow(true) @@ -803,7 +803,7 @@ mod zero_copy_connection { assert_that!(::does_exist_cfg(&sut_names[i], &config), eq Ok(false)); std::mem::forget( Sut::Builder::new(&sut_names[i]) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .config(&config) .create_sender(SAMPLE_SIZE) .unwrap(), @@ -853,7 +853,7 @@ mod zero_copy_connection { let sut_1 = Sut::Builder::new(&sut_name) .config(&config_1) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .create_sender(SAMPLE_SIZE) .unwrap(); @@ -864,7 +864,7 @@ mod zero_copy_connection { let sut_2 = Sut::Builder::new(&sut_name) .config(&config_2) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .create_sender(SAMPLE_SIZE) .unwrap(); @@ -904,7 +904,7 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let _sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(BUFFER_SIZE) .max_supported_shared_memory_segments(NUMBER_OF_SEGMENTS) .receiver_max_borrowed_samples(BUFFER_SIZE) @@ -915,7 +915,7 @@ mod zero_copy_connection { let create_receiver = |number_of_segments: u8| { Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(BUFFER_SIZE) .max_supported_shared_memory_segments(number_of_segments) .receiver_max_borrowed_samples(BUFFER_SIZE) @@ -944,7 +944,7 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(BUFFER_SIZE) .max_supported_shared_memory_segments(NUMBER_OF_SEGMENTS) .receiver_max_borrowed_samples(BUFFER_SIZE) @@ -972,7 +972,7 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(BUFFER_SIZE) .max_supported_shared_memory_segments(NUMBER_OF_SEGMENTS) .receiver_max_borrowed_samples(BUFFER_SIZE) @@ -1000,7 +1000,7 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(BUFFER_SIZE) .max_supported_shared_memory_segments(NUMBER_OF_SEGMENTS) .receiver_max_borrowed_samples(BUFFER_SIZE) @@ -1010,7 +1010,7 @@ mod zero_copy_connection { .unwrap(); let sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(BUFFER_SIZE) .max_supported_shared_memory_segments(NUMBER_OF_SEGMENTS) .receiver_max_borrowed_samples(BUFFER_SIZE) @@ -1038,7 +1038,7 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(BUFFER_SIZE) .max_supported_shared_memory_segments(0) .receiver_max_borrowed_samples(BUFFER_SIZE) @@ -1061,7 +1061,7 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(2 * BUFFER_SIZE) .max_supported_shared_memory_segments(NUMBER_OF_SEGMENTS) .receiver_max_borrowed_samples(BUFFER_SIZE) @@ -1071,7 +1071,7 @@ mod zero_copy_connection { .unwrap(); let sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(2 * BUFFER_SIZE) .max_supported_shared_memory_segments(NUMBER_OF_SEGMENTS) .receiver_max_borrowed_samples(BUFFER_SIZE) @@ -1115,7 +1115,7 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(2 * BUFFER_SIZE) .max_supported_shared_memory_segments(NUMBER_OF_SEGMENTS) .receiver_max_borrowed_samples(BUFFER_SIZE) @@ -1125,7 +1125,7 @@ mod zero_copy_connection { .unwrap(); let sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(2 * BUFFER_SIZE) .max_supported_shared_memory_segments(NUMBER_OF_SEGMENTS) .receiver_max_borrowed_samples(BUFFER_SIZE) @@ -1166,7 +1166,7 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(2 * BUFFER_SIZE) .max_supported_shared_memory_segments(NUMBER_OF_SEGMENTS) .receiver_max_borrowed_samples(BUFFER_SIZE) @@ -1176,7 +1176,7 @@ mod zero_copy_connection { .unwrap(); let sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(2 * BUFFER_SIZE) .max_supported_shared_memory_segments(NUMBER_OF_SEGMENTS) .receiver_max_borrowed_samples(BUFFER_SIZE) @@ -1223,7 +1223,7 @@ mod zero_copy_connection { let config = generate_isolated_config::(); let sut_sender = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(2 * BUFFER_SIZE) .max_supported_shared_memory_segments(NUMBER_OF_SEGMENTS) .receiver_max_borrowed_samples(BUFFER_SIZE) @@ -1233,7 +1233,7 @@ mod zero_copy_connection { .unwrap(); let _sut_receiver = Sut::Builder::new(&name) - .number_of_samples(NUMBER_OF_SAMPLES) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) .buffer_size(2 * BUFFER_SIZE) .max_supported_shared_memory_segments(NUMBER_OF_SEGMENTS) .receiver_max_borrowed_samples(BUFFER_SIZE) @@ -1261,6 +1261,86 @@ mod zero_copy_connection { }; } + #[cfg(debug_assertions)] + #[should_panic] + #[test] + fn panic_when_same_offset_is_sent_twice() { + iceoryx2_bb_log::set_log_level(iceoryx2_bb_log::LogLevel::Trace); + const BUFFER_SIZE: usize = 10; + const NUMBER_OF_SEGMENTS: u8 = 10; + let name = generate_name(); + let config = generate_isolated_config::(); + + let sut_sender = Sut::Builder::new(&name) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) + .buffer_size(2 * BUFFER_SIZE) + .max_supported_shared_memory_segments(NUMBER_OF_SEGMENTS) + .receiver_max_borrowed_samples(BUFFER_SIZE) + .enable_safe_overflow(true) + .config(&config) + .create_sender(SAMPLE_SIZE) + .unwrap(); + + let _sut_receiver = Sut::Builder::new(&name) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) + .buffer_size(2 * BUFFER_SIZE) + .max_supported_shared_memory_segments(NUMBER_OF_SEGMENTS) + .receiver_max_borrowed_samples(BUFFER_SIZE) + .enable_safe_overflow(true) + .config(&config) + .create_receiver(SAMPLE_SIZE) + .unwrap(); + + let offset = + PointerOffset::from_offset_and_segment_id(SAMPLE_SIZE, SegmentId::new(1 as u8)); + + assert_that!(sut_sender.try_send(offset), is_ok); + + // panics here + sut_sender.try_send(offset).unwrap(); + } + + #[test] + fn overflow_works_with_multiple_segments() { + iceoryx2_bb_log::set_log_level(iceoryx2_bb_log::LogLevel::Trace); + const NUMBER_OF_SEGMENTS: u8 = 98; + let name = generate_name(); + let config = generate_isolated_config::(); + + let sut_sender = Sut::Builder::new(&name) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) + .buffer_size(1) + .max_supported_shared_memory_segments(NUMBER_OF_SEGMENTS) + .receiver_max_borrowed_samples(1) + .enable_safe_overflow(true) + .config(&config) + .create_sender(SAMPLE_SIZE) + .unwrap(); + + let _sut_receiver = Sut::Builder::new(&name) + .number_of_samples_per_segment(NUMBER_OF_SAMPLES) + .buffer_size(1) + .max_supported_shared_memory_segments(NUMBER_OF_SEGMENTS) + .receiver_max_borrowed_samples(1) + .enable_safe_overflow(true) + .config(&config) + .create_receiver(SAMPLE_SIZE) + .unwrap(); + + let overflow_sample = + PointerOffset::from_offset_and_segment_id(11 * SAMPLE_SIZE, SegmentId::new(73 as u8)); + sut_sender.try_send(overflow_sample).unwrap(); + + let returned_sample = sut_sender + .try_send(PointerOffset::from_offset_and_segment_id( + SAMPLE_SIZE, + SegmentId::new(1 as u8), + )) + .unwrap(); + + assert_that!(returned_sample, eq Some(overflow_sample)); + } + #[instantiate_tests()] mod posix_shared_memory {} diff --git a/iceoryx2/src/port/details/publisher_connections.rs b/iceoryx2/src/port/details/publisher_connections.rs index 081d7a2fd..507aae352 100644 --- a/iceoryx2/src/port/details/publisher_connections.rs +++ b/iceoryx2/src/port/details/publisher_connections.rs @@ -56,7 +56,7 @@ impl Connection { .buffer_size(this.buffer_size) .receiver_max_borrowed_samples(this.static_config.subscriber_max_borrowed_samples) .enable_safe_overflow(this.static_config.enable_safe_overflow) - .number_of_samples(details.number_of_samples) + .number_of_samples_per_segment(details.number_of_samples) .timeout(this.service_state.shared_node.config().global.service.creation_timeout) .create_receiver(this.static_config.message_type_details().sample_layout(details.max_slice_len).size()), "{} since the zero copy connection could not be established.", msg); diff --git a/iceoryx2/src/port/details/subscriber_connections.rs b/iceoryx2/src/port/details/subscriber_connections.rs index 852ea04da..e33815689 100644 --- a/iceoryx2/src/port/details/subscriber_connections.rs +++ b/iceoryx2/src/port/details/subscriber_connections.rs @@ -57,7 +57,7 @@ impl Connection { .buffer_size(subscriber_details.buffer_size) .receiver_max_borrowed_samples(this.static_config.subscriber_max_borrowed_samples) .enable_safe_overflow(this.static_config.enable_safe_overflow) - .number_of_samples(number_of_samples) + .number_of_samples_per_segment(number_of_samples) .timeout(this.shared_node.config().global.service.creation_timeout) .create_sender(this.static_config.message_type_details().sample_layout(max_slice_len).size()), "{}.", msg);