Skip to content
Merged
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
6 changes: 1 addition & 5 deletions score/mw/com/impl/bindings/lola/proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,7 @@ void AppendEnabledMethodIdsAndQueueSizesImpl(
const LolaMethodInstanceDeployment& lola_method_instance_deployment,
LolaServiceElementId method_id)
{
// At this point the enabled_ field must be set by the config parser.
SCORE_LANGUAGE_FUTURECPP_PRECONDITION_PRD_MESSAGE(lola_method_instance_deployment.enabled_.has_value(),
"Method instance deployment must contain enabled on proxy side!");

if (lola_method_instance_deployment.enabled_.value())
if (lola_method_instance_deployment.enabled_)
{
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(
lola_method_instance_deployment.queue_size_.has_value(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ const LolaServiceInstanceDeployment kLolaServiceInstanceDeploymentWithMethods{
LolaServiceInstanceId{kLolaInstanceId},
{},
{},
{{kDummyMethodName0, LolaMethodInstanceDeployment{kDummyQueueSize0}},
{kDummyMethodName1, LolaMethodInstanceDeployment{kDummyQueueSize1}},
{kDummyMethodName2, LolaMethodInstanceDeployment{kDummyQueueSize2}}}};
{{kDummyMethodName0, LolaMethodInstanceDeployment{kDummyQueueSize0, true}},
{kDummyMethodName1, LolaMethodInstanceDeployment{kDummyQueueSize1, true}},
{kDummyMethodName2, LolaMethodInstanceDeployment{kDummyQueueSize2, true}}}};
const LolaServiceTypeDeployment kLolaServiceTypeDeploymentWithMethods{
kLolaServiceId,
{},
Expand Down
42 changes: 22 additions & 20 deletions score/mw/com/impl/bindings/lola/test/skeleton_test_resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,17 @@ static const ServiceInstanceDeployment kValidInstanceDeploymentWithField{

static const ServiceInstanceDeployment kValidInstanceDeploymentWithMethods{
kFooService,
CreateLolaServiceInstanceDeployment(kDefaultLolaInstanceId,
{},
{},
{{test::kFooMethodName, LolaMethodInstanceDeployment{kFooMethodQueueSize}},
{test::kDumbMethodName, LolaMethodInstanceDeployment{kDumbMethodQueueSize}}},
{kAllowedQmMethodConsumer},
{},
kConfiguredDeploymentShmSize,
kConfiguredDeploymentControlAsilBShmSize,
kConfiguredDeploymentControlQmShmSize),
CreateLolaServiceInstanceDeployment(
kDefaultLolaInstanceId,
{},
{},
{{test::kFooMethodName, LolaMethodInstanceDeployment{kFooMethodQueueSize, true}},
{test::kDumbMethodName, LolaMethodInstanceDeployment{kDumbMethodQueueSize, true}}},
{kAllowedQmMethodConsumer},
{},
kConfiguredDeploymentShmSize,
kConfiguredDeploymentControlAsilBShmSize,
kConfiguredDeploymentControlQmShmSize),
QualityType::kASIL_QM,
kFooInstanceSpecifier};

Expand Down Expand Up @@ -301,16 +302,17 @@ static const ServiceInstanceDeployment kValidAsilInstanceDeploymentWithField{

static const ServiceInstanceDeployment kValidAsilInstanceDeploymentWithMethods{
kFooService,
CreateLolaServiceInstanceDeployment(kDefaultLolaInstanceId,
{},
{},
{{test::kFooMethodName, LolaMethodInstanceDeployment{kFooMethodQueueSize}},
{test::kDumbMethodName, LolaMethodInstanceDeployment{kDumbMethodQueueSize}}},
{},
{kAllowedAsilBMethodConsumer},
kConfiguredDeploymentShmSize,
kConfiguredDeploymentControlAsilBShmSize,
kConfiguredDeploymentControlQmShmSize),
CreateLolaServiceInstanceDeployment(
kDefaultLolaInstanceId,
{},
{},
{{test::kFooMethodName, LolaMethodInstanceDeployment{kFooMethodQueueSize, true}},
{test::kDumbMethodName, LolaMethodInstanceDeployment{kDumbMethodQueueSize, true}}},
{},
{kAllowedAsilBMethodConsumer},
kConfiguredDeploymentShmSize,
kConfiguredDeploymentControlAsilBShmSize,
kConfiguredDeploymentControlQmShmSize),
QualityType::kASIL_B,
kFooInstanceSpecifier};

Expand Down
7 changes: 6 additions & 1 deletion score/mw/com/impl/configuration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ cc_library(
srcs = ["lola_method_instance_deployment.cpp"],
hdrs = ["lola_method_instance_deployment.h"],
features = COMPILER_WARNING_FEATURES,
implementation_deps = [":configuration_common_resources"],
tags = ["FFI"],
deps = ["@score_baselibs//score/json"],
)
Expand Down Expand Up @@ -501,9 +502,13 @@ cc_unit_test(
cc_unit_test(
name = "lola_method_instance_deployment_test",
srcs = ["lola_method_instance_deployment_test.cpp"],
features = COMPILER_WARNING_FEATURES,
features = COMPILER_WARNING_FEATURES + [
# These tests catch exceptions instead of using gtest EXPECT_DEATH so we disable aborts_upon_exception.
"-aborts_upon_exception",
],
deps = [
":lola_method_instance_deployment",
"@score_baselibs//score/language/futurecpp:futurecpp_test_support",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,7 @@ TEST_F(ConfigParserFixture, MethodCanBeExplicitlyDisabled)
const auto deployments =
config.GetServiceInstances().at(InstanceSpecifier::Create(std::string{"abc/abc/TirePressurePort"}).value());
const auto& lola_deployment = std::get<LolaServiceInstanceDeployment>(deployments.bindingInfo_);
ASSERT_TRUE(lola_deployment.methods_.at("SetPressure").enabled_.has_value());
EXPECT_FALSE(lola_deployment.methods_.at("SetPressure").enabled_.value());
EXPECT_FALSE(lola_deployment.methods_.at("SetPressure").enabled_);
}

TEST_F(ConfigParserFixture, MethodCanBeExplicitlyEnabled)
Expand Down Expand Up @@ -761,8 +760,7 @@ TEST_F(ConfigParserFixture, MethodCanBeExplicitlyEnabled)
const auto deployments =
config.GetServiceInstances().at(InstanceSpecifier::Create(std::string{"abc/abc/TirePressurePort"}).value());
const auto& lola_deployment = std::get<LolaServiceInstanceDeployment>(deployments.bindingInfo_);
ASSERT_TRUE(lola_deployment.methods_.at("SetPressure").enabled_.has_value());
EXPECT_TRUE(lola_deployment.methods_.at("SetPressure").enabled_.value());
EXPECT_TRUE(lola_deployment.methods_.at("SetPressure").enabled_);
}

} // namespace
Expand Down
3 changes: 1 addition & 2 deletions score/mw/com/impl/configuration/config_parser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ TEST_F(ConfigParserFixture, ParseExampleJson)
1);
EXPECT_EQ(secondDeploymentInfo.fields_.at("CurrentTemperatureFrontLeft").use_get_if_available_, true);
EXPECT_EQ(secondDeploymentInfo.fields_.at("CurrentTemperatureFrontLeft").use_set_if_available_, true);
ASSERT_TRUE(secondDeploymentInfo.methods_.at("SetPressure").enabled_.has_value());
EXPECT_TRUE(secondDeploymentInfo.methods_.at("SetPressure").enabled_.value());
EXPECT_TRUE(secondDeploymentInfo.methods_.at("SetPressure").enabled_);

const auto service_deployment = config.GetServiceTypes().at(deployments.service_);
const auto* const lola_service_type_deployment =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
********************************************************************************/
#include "score/mw/com/impl/configuration/lola_method_instance_deployment.h"

#include "score/mw/com/impl/configuration/configuration_common_resources.h"

#include <limits>
#include <string_view>

Expand All @@ -26,25 +28,17 @@ constexpr auto kMethodEnabledKey = "use"sv;
} // namespace

LolaMethodInstanceDeployment::LolaMethodInstanceDeployment(std::optional<QueueSize> queue_size,
std::optional<bool> enabled)
MethodEnabledType enabled)
: queue_size_{queue_size}, enabled_{enabled}
{
}

LolaMethodInstanceDeployment::LolaMethodInstanceDeployment(
const score::json::Object& serialized_lola_method_instance_deployment)
: queue_size_{std::nullopt}, enabled_{std::nullopt}
: queue_size_{std::nullopt}, enabled_{}
{
const auto queue_size_iter = serialized_lola_method_instance_deployment.find(kQueueSizeKey.data());
if (queue_size_iter != serialized_lola_method_instance_deployment.cend())
{
queue_size_ = queue_size_iter->second.As<QueueSize>().value();
}
const auto enabled_iter = serialized_lola_method_instance_deployment.find(kMethodEnabledKey.data());
if (enabled_iter != serialized_lola_method_instance_deployment.cend())
{
enabled_ = enabled_iter->second.As<bool>().value();
}
queue_size_ = GetOptionalValueFromJson<QueueSize>(serialized_lola_method_instance_deployment, kQueueSizeKey);
enabled_ = GetValueFromJson<MethodEnabledType>(serialized_lola_method_instance_deployment, kMethodEnabledKey);
}

LolaMethodInstanceDeployment LolaMethodInstanceDeployment::CreateFromJson(
Expand All @@ -55,16 +49,14 @@ LolaMethodInstanceDeployment LolaMethodInstanceDeployment::CreateFromJson(

score::json::Object LolaMethodInstanceDeployment::Serialize() const
{
score::json::Object result;
score::json::Object json_object;
if (queue_size_.has_value())
{
result[kQueueSizeKey.data()] = score::json::Any{queue_size_.value()};
}
if (enabled_.has_value())
{
result[kMethodEnabledKey.data()] = score::json::Any{enabled_.value()};
json_object[kQueueSizeKey] = score::json::Any{queue_size_.value()};
}
return result;
json_object[kMethodEnabledKey] = score::json::Any{enabled_};

return json_object;
}

} // namespace score::mw::com::impl
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ class LolaMethodInstanceDeployment
{
public:
using QueueSize = std::uint8_t;
using MethodEnabledType = bool;

/**
* @brief Construct LolaMethodInstanceDeployment with optional queue size, because LolaMethodInstanceDeployment for
* a consumer will have a value while one for a provider will not.
* @param queue_size The maximum number of pending method requests that can be queued.
* @param enabled Optional flag to disable/enable the method. It is always filled on proxy side and always empty
* on skeleton side.
* @param enabled Flag to disable/enable the method. It is always filled on proxy side and it is unused on skeleton
* side.
*/
explicit LolaMethodInstanceDeployment(std::optional<QueueSize> queue_size,
std::optional<bool> enabled = std::nullopt);
explicit LolaMethodInstanceDeployment(std::optional<QueueSize> queue_size, MethodEnabledType enabled);

explicit LolaMethodInstanceDeployment(const score::json::Object& serialized_lola_method_instance_deployment);

Expand Down Expand Up @@ -73,7 +73,7 @@ class LolaMethodInstanceDeployment
* @brief The maximum number of method requests that can be queued on the server side.
*/
std::optional<QueueSize> queue_size_;
std::optional<bool> enabled_;
MethodEnabledType enabled_;
};

inline bool operator==(const LolaMethodInstanceDeployment& lhs, const LolaMethodInstanceDeployment& rhs) noexcept
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

#include <gtest/gtest.h>

#include <score/assert_support.hpp>
#include <score/utility.hpp>

#include <cstdint>
#include <limits>

Expand All @@ -25,8 +28,8 @@ namespace
TEST(LolaMethodInstanceDeploymentTest, EqualityOperatorWithSameQueueSize)
{
// Given two LolaMethodInstanceDeployments with the same queue size
LolaMethodInstanceDeployment unit1{50U};
LolaMethodInstanceDeployment unit2{50U};
LolaMethodInstanceDeployment unit1{50U, true};
LolaMethodInstanceDeployment unit2{50U, true};

// When comparing them
// Then they should be equal
Expand All @@ -36,8 +39,8 @@ TEST(LolaMethodInstanceDeploymentTest, EqualityOperatorWithSameQueueSize)
TEST(LolaMethodInstanceDeploymentTest, EqualityOperatorWithDifferentQueueSize)
{
// Given two LolaMethodInstanceDeployments with different queue sizes
LolaMethodInstanceDeployment unit1{10U};
LolaMethodInstanceDeployment unit2{20U};
LolaMethodInstanceDeployment unit1{10U, true};
LolaMethodInstanceDeployment unit2{20U, true};

// When comparing them
// Then they should not be equal
Expand All @@ -47,8 +50,8 @@ TEST(LolaMethodInstanceDeploymentTest, EqualityOperatorWithDifferentQueueSize)
TEST(LolaMethodInstanceDeploymentTest, DefaultInstancesAreEqual)
{
// Given two LolaMethodInstanceDeployments constructed with std::nullopt
LolaMethodInstanceDeployment unit1{std::nullopt};
LolaMethodInstanceDeployment unit2{std::nullopt};
LolaMethodInstanceDeployment unit1{std::nullopt, true};
LolaMethodInstanceDeployment unit2{std::nullopt, true};

// When comparing them
// Then they should be equal
Expand All @@ -58,30 +61,33 @@ TEST(LolaMethodInstanceDeploymentTest, DefaultInstancesAreEqual)
TEST(LolaMethodInstanceDeploymentTest, MaxQueueSize)
{
// Given a LolaMethodInstanceDeployment with maximum queue size
LolaMethodInstanceDeployment unit{std::numeric_limits<LolaMethodInstanceDeployment::QueueSize>::max()};
LolaMethodInstanceDeployment unit{std::numeric_limits<LolaMethodInstanceDeployment::QueueSize>::max(), true};

// Then the queue size should match
EXPECT_EQ(unit.queue_size_, std::numeric_limits<LolaMethodInstanceDeployment::QueueSize>::max());
}

TEST(LolaMethodInstanceDeploymentSerializationTest, CreateFromJsonWithQueueSize)
TEST(LolaMethodInstanceDeploymentSerializationTest, CreateFromJsonWithQueueSizeAndEnabledFlag)
{
// Given a JSON object with queueSize
const LolaMethodInstanceDeployment::QueueSize queue_size{20U};
score::json::Object json_object{};
json_object["queueSize"] = score::json::Any{queue_size};
json_object["use"] = score::json::Any{true};

// When creating from JSON
auto unit = LolaMethodInstanceDeployment::CreateFromJson(json_object);

// Then the queue size should match the value from JSON
EXPECT_EQ(unit.queue_size_, queue_size);
EXPECT_TRUE(unit.enabled_);
}

TEST(LolaMethodInstanceDeploymentSerializationTest, CreateFromJsonWithoutQueueSizeResultsInNullopt)
{
// Given an empty JSON object
score::json::Object json_object{};
json_object["use"] = score::json::Any{true};

// When creating from JSON
auto unit = LolaMethodInstanceDeployment::CreateFromJson(json_object);
Expand All @@ -91,19 +97,16 @@ TEST(LolaMethodInstanceDeploymentSerializationTest, CreateFromJsonWithoutQueueSi
EXPECT_EQ(unit.queue_size_, std::nullopt);
}

TEST(LolaMethodInstanceDeploymentSerializationTest, CreateFromJsonWithoutEnabledLeavesEnabledUnset)
TEST(LolaMethodInstanceDeploymentSerializationTest, CreateFromJsonWithoutEnabledFlagTerminates)
{
// Given a JSON object without enabled
const LolaMethodInstanceDeployment::QueueSize queue_size{20U};
score::json::Object json_object{};
json_object["queueSize"] = score::json::Any{queue_size};

// When creating from JSON
auto unit = LolaMethodInstanceDeployment::CreateFromJson(json_object);

// Then the method instance should keep enabled unset
EXPECT_FALSE(unit.enabled_.has_value());
EXPECT_EQ(unit.enabled_, std::nullopt);
// Then we terminate because the enabled flag is required.
SCORE_LANGUAGE_FUTURECPP_EXPECT_CONTRACT_VIOLATED(LolaMethodInstanceDeployment::CreateFromJson(json_object));
}

TEST(LolaMethodInstanceDeploymentSerializationTest, CreateFromJsonWithEnabledFalseDisablesMethod)
Expand All @@ -116,8 +119,7 @@ TEST(LolaMethodInstanceDeploymentSerializationTest, CreateFromJsonWithEnabledFal
auto unit = LolaMethodInstanceDeployment::CreateFromJson(json_object);

// Then the method instance should be disabled
ASSERT_TRUE(unit.enabled_.has_value());
EXPECT_FALSE(unit.enabled_.value());
EXPECT_FALSE(unit.enabled_);
}

TEST(LolaMethodInstanceDeploymentSerializationTest, CreateFromJsonWithEnabledTrueEnablesMethod)
Expand All @@ -130,8 +132,7 @@ TEST(LolaMethodInstanceDeploymentSerializationTest, CreateFromJsonWithEnabledTru
auto unit = LolaMethodInstanceDeployment::CreateFromJson(json_object);

// Then the method instance should be enabled
ASSERT_TRUE(unit.enabled_.has_value());
EXPECT_TRUE(unit.enabled_.value());
EXPECT_TRUE(unit.enabled_);
}

TEST(LolaMethodInstanceDeploymentSerializationTest, SerializeAndDeserializePreservesQueueSize)
Expand All @@ -140,6 +141,8 @@ TEST(LolaMethodInstanceDeploymentSerializationTest, SerializeAndDeserializePrese
const LolaMethodInstanceDeployment::QueueSize queue_size{100U};
score::json::Object json_object{};
json_object["queueSize"] = score::json::Any{queue_size};
json_object["use"] = score::json::Any{true};

auto original_unit = LolaMethodInstanceDeployment::CreateFromJson(json_object);

// When serializing and deserializing
Expand All @@ -157,6 +160,8 @@ TEST(LolaMethodInstanceDeploymentSerializationTest, SerializeIncludesQueueSize)
const LolaMethodInstanceDeployment::QueueSize queue_size{42U};
score::json::Object json_object{};
json_object["queueSize"] = score::json::Any{queue_size};
json_object["use"] = score::json::Any{true};

auto unit = LolaMethodInstanceDeployment::CreateFromJson(json_object);

// When serializing
Expand All @@ -180,8 +185,7 @@ TEST(LolaMethodInstanceDeploymentSerializationTest, SerializeAndDeserializePrese
auto reconstructed_unit = LolaMethodInstanceDeployment::CreateFromJson(serialized);

// Then the use state should be preserved
ASSERT_TRUE(reconstructed_unit.enabled_.has_value());
EXPECT_FALSE(reconstructed_unit.enabled_.value());
EXPECT_FALSE(reconstructed_unit.enabled_);
EXPECT_EQ(reconstructed_unit, original_unit);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ LolaFieldInstanceDeployment MakeLolaFieldInstanceDeployment(

LolaMethodInstanceDeployment MakeDefaultLolaMethodInstanceDeployment() noexcept
{
return LolaMethodInstanceDeployment{std::nullopt};
return LolaMethodInstanceDeployment{std::nullopt, true};
}

LolaMethodInstanceDeployment MakeLolaMethodInstanceDeployment(
const std::optional<LolaMethodInstanceDeployment::QueueSize> queue_size) noexcept
{
const LolaMethodInstanceDeployment unit{queue_size};
const LolaMethodInstanceDeployment unit{queue_size, true};
return unit;
}

Expand Down
Loading
Loading