Skip to content

Commit

Permalink
[eclipse-iceoryx#525] Finalize tests for zero copy channel with multi…
Browse files Browse the repository at this point in the history
…ple segment ids
  • Loading branch information
elfenpiff committed Nov 25, 2024
1 parent 5f51073 commit 5dfcfae
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 92 deletions.
41 changes: 20 additions & 21 deletions iceoryx2-cal/src/zero_copy_connection/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub mod details {
used_chunk_list: RelocatableVec<RelocatableUsedChunkList>,
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,
Expand All @@ -172,7 +172,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 {
Expand All @@ -190,7 +190,7 @@ pub mod details {
enable_safe_overflow,
sample_size,
max_borrowed_samples,
number_of_samples,
number_of_samples_per_segment,
number_of_segments,
}
}
Expand Down Expand Up @@ -219,7 +219,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<Storage>,
Expand All @@ -238,7 +238,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,
);

Expand All @@ -259,7 +259,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);
Expand All @@ -281,7 +281,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
)
);
Expand Down Expand Up @@ -341,10 +341,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 {
Expand Down Expand Up @@ -400,7 +401,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,
Expand Down Expand Up @@ -436,8 +437,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
}

Expand Down Expand Up @@ -543,19 +544,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))
Expand Down Expand Up @@ -586,7 +585,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);
Expand Down Expand Up @@ -691,7 +690,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)))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-cal/src/zero_copy_connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub trait ZeroCopyConnectionBuilder<C: ZeroCopyConnection>: 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mod zero_copy_connection_posix_shared_memory_tests {
let start = std::time::SystemTime::now();
let sut = <Sut as ZeroCopyConnection>::Builder::new(&storage_name)
.timeout(TIMEOUT)
.number_of_samples(1)
.number_of_samples_per_segment(1)
.receiver_max_borrowed_samples(1)
.create_sender(1);

Expand Down
Loading

0 comments on commit 5dfcfae

Please sign in to comment.