Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions score/mw/com/impl/bindings/lola/skeleton_event_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,5 +445,62 @@ TEST_F(SkeletonEventTimestampFixture, SendUpdatesTimestampInControlData)
<< "The second timestamp should be exactly one greater than the first.";
}

TEST_F(SkeletonEventTimestampFixture, PrepareOfferInitializesCurrentTimestampFromReopenedControlData)
Comment thread
rudresh-systream marked this conversation as resolved.
{
RecordProperty("Description",
"Checks that a SkeletonEvent which reopens existing shared memory continues the timestamp sequence "
"from the latest timestamp already present in the event control data.");
RecordProperty("TestType", "Unit Test");

// Given existing shared-memory control/data objects for an event
constexpr bool enforce_max_samples{true};
constexpr SlotIndexType existing_slot_index{0U};
constexpr EventSlotStatus::EventTimeStamp existing_latest_timestamp{42U};

auto existing_service_data_control_qm =
CreateServiceDataControlWithEvent(fake_element_fq_id_, QualityType::kASIL_QM);
auto existing_service_data_control_asil_b =
CreateServiceDataControlWithEvent(fake_element_fq_id_, QualityType::kASIL_B);
auto existing_service_data_storage = CreateServiceDataStorageWithEvent<test::TestSampleType>(fake_element_fq_id_);

// and the existing event control data already contains a ready slot with a timestamp
auto& existing_event_control_qm =
GetEventControlFromServiceDataControl(fake_element_fq_id_, *existing_service_data_control_qm);
auto& existing_event_control_asil_b =
GetEventControlFromServiceDataControl(fake_element_fq_id_, *existing_service_data_control_asil_b);
ProviderEventDataControlLocalView<> existing_provider_control_qm{existing_event_control_qm.data_control};
ProviderEventDataControlLocalView<> existing_provider_control_asil_b{existing_event_control_asil_b.data_control};
existing_provider_control_qm.EventReady(existing_slot_index, existing_latest_timestamp);
existing_provider_control_asil_b.EventReady(existing_slot_index, existing_latest_timestamp);

// Expect, that the skeleton event opens the existing control and data segments
ExpectControlSegmentOpened(*existing_service_data_control_qm, existing_service_data_control_asil_b.get());
ExpectDataSegmentOpened(existing_service_data_storage);
WithAlreadyConnectedProxy();

// When initializing a skeleton event and preparing the offer with the reopened control data
InitialiseSkeletonEvent(fake_element_fq_id_, fake_event_name_, max_samples_, max_subscribers_, enforce_max_samples);

std::ignore = skeleton_event_->PrepareOffer();

// and allocating and sending a new sample
auto allocated_slot_result = skeleton_event_->Allocate();
ASSERT_TRUE(allocated_slot_result.has_value());
auto allocated_slot = std::move(allocated_slot_result).value();

const impl::SampleAllocateePtrView<test::TestSampleType> allocated_slot_view{allocated_slot};
const auto* const lola_allocated_slot =
allocated_slot_view.template As<lola::SampleAllocateePtr<test::TestSampleType>>();
ASSERT_NE(lola_allocated_slot, nullptr);
const auto allocated_slot_index = lola_allocated_slot->GetReferencedSlot();

const auto send_result = skeleton_event_->Send(std::move(allocated_slot), std::nullopt);
ASSERT_TRUE(send_result.has_value());

// Then the new sample timestamp continues from the latest timestamp in the reopened control data
const EventSlotStatus final_slot_status{existing_provider_control_qm[allocated_slot_index]};
EXPECT_EQ(final_slot_status.GetTimeStamp(), existing_latest_timestamp + 1U);
}

} // namespace
} // namespace score::mw::com::impl::lola
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,32 @@ void SkeletonMockedMemoryFixture::ExpectServiceUsageMarkerFileCreatedOrOpenedAnd
EXPECT_CALL(*unistd_mock_, unlink(StrEq(test::kServiceInstanceUsageFilePath))).Times(0);
}

void SkeletonMockedMemoryFixture::ExpectControlSegmentOpened(ServiceDataControl& service_data_control_qm,
ServiceDataControl* const service_data_control_asil_b)
noexcept
{
ON_CALL(*control_qm_shared_memory_resource_mock_, getUsableBaseAddress())
.WillByDefault(Return(static_cast<void*>(&service_data_control_qm)));
ON_CALL(shared_memory_factory_mock_, Open(test::kControlChannelPathQm, true, _))
.WillByDefault(Return(control_qm_shared_memory_resource_mock_));

if (service_data_control_asil_b != nullptr)
{
ON_CALL(*control_asil_b_shared_memory_resource_mock_, getUsableBaseAddress())
.WillByDefault(Return(static_cast<void*>(service_data_control_asil_b)));
ON_CALL(shared_memory_factory_mock_, Open(test::kControlChannelPathAsilB, true, _))
.WillByDefault(Return(control_asil_b_shared_memory_resource_mock_));
}
}

void SkeletonMockedMemoryFixture::ExpectDataSegmentOpened(ServiceDataStorage& service_data_storage) noexcept
{
ON_CALL(*data_shared_memory_resource_mock_, getUsableBaseAddress())
.WillByDefault(Return(static_cast<void*>(&service_data_storage)));
ON_CALL(shared_memory_factory_mock_, Open(test::kDataChannelPath, true, _))
.WillByDefault(Return(data_shared_memory_resource_mock_));
}

std::unique_ptr<ServiceDataControl> SkeletonMockedMemoryFixture::CreateServiceDataControlWithEvent(
ElementFqId element_fq_id,
QualityType quality_type) noexcept
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,11 @@ class SkeletonMockedMemoryFixture : public ::testing::Test

void ExpectServiceUsageMarkerFileCreatedOrOpenedAndClosed() noexcept;

void ExpectControlSegmentOpened(ServiceDataControl& service_data_control_qm,
ServiceDataControl* service_data_control_asil_b = nullptr) noexcept;

void ExpectDataSegmentOpened(ServiceDataStorage& service_data_storage) noexcept;

std::unique_ptr<ServiceDataControl> CreateServiceDataControlWithEvent(ElementFqId element_fq_id,
QualityType quality_type) noexcept;
static EventControl& GetEventControlFromServiceDataControl(ElementFqId element_fq_id,
Expand Down
Loading