Skip to content

Commit

Permalink
[eclipse-iceoryx#195] Add aligned slice test
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Apr 25, 2024
1 parent 6e2c04a commit cec647f
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions iceoryx2/tests/service_publish_subscribe_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,48 @@ mod service_publish_subscribe {
}
}

#[test]
fn sliced_aligned_service_works<Sut: Service>() {
const MAX_ELEMENTS: usize = 91;
const ALIGNMENT: usize = 64;
let service_name = generate_name();
let service_pub = Sut::new(&service_name)
.publish_subscribe::<[u64]>()
.subscriber_max_buffer_size(MAX_ELEMENTS)
.subscriber_max_borrowed_samples(MAX_ELEMENTS)
.payload_alignment(Alignment::new(ALIGNMENT).unwrap())
.create()
.unwrap();

let service_sub = Sut::new(&service_name)
.publish_subscribe::<[u64]>()
.open()
.unwrap();

let publisher = service_pub
.publisher()
.max_slice_len(MAX_ELEMENTS)
.create()
.unwrap();
let subscriber = service_sub.subscriber().create().unwrap();

let mut samples = vec![];
for n in 0..MAX_ELEMENTS {
let sample = publisher.loan_slice_uninit(n).unwrap();
assert_that!((sample.payload().as_ptr() as usize) % ALIGNMENT, eq 0);
sample.write_from_fn(|i| i as u64 * 25).send().unwrap();

let recv_sample = subscriber.receive().unwrap().unwrap();

assert_that!((recv_sample.payload().as_ptr() as usize) % ALIGNMENT, eq 0);
assert_that!(recv_sample.payload(), len n);
for (i, element) in recv_sample.payload().iter().enumerate() {
assert_that!(*element, eq i as u64 * 25);
}
samples.push(recv_sample);
}
}

#[instantiate_tests(<iceoryx2::service::zero_copy::Service>)]
mod zero_copy {}

Expand Down

0 comments on commit cec647f

Please sign in to comment.