Skip to content

Commit

Permalink
[eclipse-iceoryx#490] Test newly exposed configuration options
Browse files Browse the repository at this point in the history
  • Loading branch information
orecham committed Oct 31, 2024
1 parent 1100afd commit 83cfcec
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/publisher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class Publisher {
/// since the [`Subscriber`]s buffer is full.
auto unable_to_deliver_strategy() const -> UnableToDeliverStrategy;

/// Returns the maximum number of elements that can be loaned in a slice.
auto max_slice_len() const -> uint64_t;

/// Copies the input `value` into a [`SampleMut`] and delivers it.
/// On success it returns the number of [`Subscriber`]s that received
/// the data, otherwise a [`PublisherSendError`] describing the failure.
Expand Down Expand Up @@ -141,6 +144,12 @@ inline auto Publisher<S, Payload, UserHeader>::unable_to_deliver_strategy() cons
return iox::into<UnableToDeliverStrategy>(static_cast<int>(iox2_publisher_unable_to_deliver_strategy(&m_handle)));
}


template <ServiceType S, typename Payload, typename UserHeader>
inline auto Publisher<S, Payload, UserHeader>::max_slice_len() const -> uint64_t {
return iox2_publisher_max_slice_len(&m_handle);
}

template <ServiceType S, typename Payload, typename UserHeader>
inline auto Publisher<S, Payload, UserHeader>::id() const -> UniquePublisherId {
iox2_unique_publisher_id_h id_handle = nullptr;
Expand Down
17 changes: 17 additions & 0 deletions iceoryx2-ffi/cxx/tests/src/service_publish_subscribe_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ TYPED_TEST(ServicePublishSubscribeTest, setting_service_properties_works) {
constexpr uint64_t HISTORY_SIZE = 13;
constexpr uint64_t SUBSCRIBER_MAX_BUFFER_SIZE = 14;
constexpr uint64_t SUBSCRIBER_MAX_BORROWED_SAMPLES = 15;
constexpr uint64_t PAYLOAD_ALIGNMENT = 4;

const auto service_name = iox2_testing::generate_service_name();

Expand All @@ -264,6 +265,7 @@ TYPED_TEST(ServicePublishSubscribeTest, setting_service_properties_works) {
.history_size(HISTORY_SIZE)
.subscriber_max_buffer_size(SUBSCRIBER_MAX_BUFFER_SIZE)
.subscriber_max_borrowed_samples(SUBSCRIBER_MAX_BORROWED_SAMPLES)
.payload_alignment(PAYLOAD_ALIGNMENT)
.create()
.expect("");

Expand Down Expand Up @@ -363,6 +365,21 @@ TYPED_TEST(ServicePublishSubscribeTest, publisher_applies_unable_to_deliver_stra
ASSERT_THAT(sut_pub_2.unable_to_deliver_strategy(), Eq(UnableToDeliverStrategy::DiscardSample));
}

TYPED_TEST(ServicePublishSubscribeTest, publisher_applies_max_slice_len) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;
constexpr uint64_t MAX_SLICE_LEN = 256;

const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto service =
node.service_builder(service_name).template publish_subscribe<iox::Slice<uint64_t>>().create().expect("");

auto sut = service.publisher_builder().max_slice_len(MAX_SLICE_LEN).create().expect("");

ASSERT_THAT(sut.max_slice_len(), Eq(MAX_SLICE_LEN));
}

TYPED_TEST(ServicePublishSubscribeTest, send_receive_with_user_header_works) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

Expand Down
13 changes: 13 additions & 0 deletions iceoryx2-ffi/ffi/src/api/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,19 @@ pub unsafe extern "C" fn iox2_publisher_unable_to_deliver_strategy(
}
}

#[no_mangle]
pub unsafe extern "C" fn iox2_publisher_max_slice_len(
publisher_handle: iox2_publisher_h_ref,
) -> c_int {
publisher_handle.assert_non_null();

let publisher = &mut *publisher_handle.as_type();
match publisher.service_type {
iox2_service_type_e::IPC => publisher.value.as_mut().ipc.max_slice_len() as c_int,
iox2_service_type_e::LOCAL => publisher.value.as_mut().local.max_slice_len() as c_int,
}
}

/// Returns the unique port id of the publisher.
///
/// # Arguments
Expand Down
5 changes: 5 additions & 0 deletions iceoryx2/src/port/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,11 @@ impl<Service: service::Service, Payload: Debug + ?Sized, UserHeader: Debug>
self.data_segment.config.unable_to_deliver_strategy
}

/// Returns the maximum slice length configured for this [`Publisher`].
pub fn max_slice_len(&self) -> usize {
self.data_segment.config.max_slice_len
}

fn allocate(&self, layout: Layout) -> Result<ShmPointer, PublisherLoanError> {
let msg = "Unable to allocate Sample with";

Expand Down

0 comments on commit 83cfcec

Please sign in to comment.