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
5 changes: 1 addition & 4 deletions score/mw/com/impl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1322,12 +1322,9 @@ cc_unit_test(
name = "proxy_field_test",
srcs = ["proxy_field_test.cpp"],
deps = [
":error",
":impl",
":runtime_mock",
"//score/mw/com/impl/bindings/mock_binding",
"//score/mw/com/impl/plumbing:proxy_field_binding_factory_mock",
"//score/mw/com/impl/test:binding_factory_resources",
"//score/mw/com/impl/test:proxy_resources",
"//score/mw/com/impl/test:runtime_mock_guard",
],
)
Expand Down
23 changes: 11 additions & 12 deletions score/mw/com/test/common_test_resources/proxy_event_receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,24 @@

#include "score/concurrency/notification.h"
#include "score/mw/com/test/common_test_resources/fail_test.h"
#include "score/mw/com/types.h"

#include <score/stop_token.hpp>

#include <cstdint>
#include <functional>
#include <iostream>
#include <optional>
#include <utility>

namespace score::mw::com::test
{

/// \brief Helper class which registers a receiveHandler on construction and allows waiting for a
/// certain number of samples to be received. It also checks that the received samples are in the expected order.
template <typename ProxyEventType, typename GetNewSamplesCallback>
template <typename ProxyEventType>
class ProxyEventReceiver
{
public:
explicit ProxyEventReceiver(ProxyEventType& proxy_event, GetNewSamplesCallback get_new_samples_callback)
: proxy_event_{proxy_event}, get_new_samples_callback_{std::move(get_new_samples_callback)}
explicit ProxyEventReceiver(ProxyEventType& proxy_event)
: received_sample_notification_{}, proxy_event_{proxy_event}
{
auto receive_handler = [&received_sample_notification = received_sample_notification_]() {
std::cout << "ProxyEventReceiver: Received event notification" << std::endl;
Expand All @@ -56,15 +55,17 @@ class ProxyEventReceiver
///
/// \return true if the expected number of samples was received, false if the wait was interrupted by the
/// stop_token.
template <typename GetNewSamplesCallback>
[[nodiscard]] bool WaitForSamples(const score::cpp::stop_token& stop_token,
const std::size_t num_samples_to_receive)
const std::size_t num_samples_to_receive,
GetNewSamplesCallback&& get_new_samples_callback)
{
std::size_t received_count{0U};
while (!stop_token.stop_requested())
{
auto get_samples_result = proxy_event_.GetNewSamples(
[this](auto sample) {
std::invoke(get_new_samples_callback_, std::move(sample));
[&get_new_samples_callback](auto sample) {
std::invoke(get_new_samples_callback, std::move(sample));
},
num_samples_to_receive);
if (!get_samples_result.has_value())
Expand Down Expand Up @@ -104,10 +105,8 @@ class ProxyEventReceiver
}

private:
score::concurrency::Notification received_sample_notification_{};
std::optional<std::uint32_t> latest_value_{};
score::concurrency::Notification received_sample_notification_;
ProxyEventType& proxy_event_;
GetNewSamplesCallback get_new_samples_callback_;
};

} // namespace score::mw::com::test
Expand Down
81 changes: 56 additions & 25 deletions score/mw/com/test/fields/set_and_notifier/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,10 @@ validate_json_schema_test(
tags = ["lint"],
)

validate_json_schema_test(
name = "validate_initial_only_field_lola_schema",
json = "config/initial_only_field_mw_com_config.json",
schema = "//score/mw/com:config_schema",
tags = ["lint"],
)

cc_library(
name = "field_types",
srcs = [
"initial_only_field.cpp",
"set_and_notifier_enabled_field.cpp",
"test_constants.cpp",
],
hdrs = [
"initial_only_field.h",
"set_and_notifier_enabled_field.h",
"test_constants.h",
],
name = "test_constants",
srcs = ["test_constants.cpp"],
hdrs = ["test_constants.h"],
features = COMPILER_WARNING_FEATURES,
deps = [
"//score/mw/com",
Expand All @@ -54,14 +39,15 @@ cc_library(
hdrs = ["consumer.h"],
features = COMPILER_WARNING_FEATURES,
deps = [
":field_types",
":common_resources",
":test_constants",
"//score/mw/com",
"//score/mw/com/test/common_test_resources:command_line_parser",
"//score/mw/com/test/common_test_resources:fail_test",
"//score/mw/com/test/common_test_resources:process_synchronizer",
"//score/mw/com/test/common_test_resources:proxy_container",
"//score/mw/com/test/common_test_resources:proxy_event_receiver",
"//score/mw/com/test/common_test_resources:proxy_event_state_change_notifier",
"//score/mw/com/test/fields/set_and_notifier/datatypes:field_datatypes",
],
)

Expand All @@ -71,26 +57,28 @@ cc_library(
hdrs = ["provider.h"],
features = COMPILER_WARNING_FEATURES,
deps = [
":field_types",
":common_resources",
":test_constants",
"//score/mw/com",
"//score/mw/com/test/common_test_resources:fail_test",
"//score/mw/com/test/common_test_resources:process_synchronizer",
"//score/mw/com/test/common_test_resources:skeleton_container",
"//score/mw/com/test/fields/set_and_notifier/datatypes:field_datatypes",
],
)

cc_binary(
name = "provider",
srcs = ["main_provider.cpp"],
data = [
"config/initial_only_field_mw_com_config.json",
"config/mw_com_config.json",
],
features = COMPILER_WARNING_FEATURES + [
"aborts_upon_exception",
],
visibility = ["//score/mw/com/test/fields:__pkg__"],
deps = [
":common_resources",
":field_provider",
"//score/mw/com",
"//score/mw/com/test/common_test_resources:command_line_parser",
Expand All @@ -104,27 +92,57 @@ cc_binary(
name = "consumer",
srcs = ["main_consumer.cpp"],
data = [
"config/initial_only_field_mw_com_config.json",
"config/mw_com_config.json",
],
features = COMPILER_WARNING_FEATURES + [
"aborts_upon_exception",
],
visibility = ["//score/mw/com/test/fields:__pkg__"],
deps = [
":common_resources",
":field_consumer",
"//score/mw/com",
"//score/mw/com/test/common_test_resources:stop_token_sig_term_handler",
"@score_baselibs//score/mw/log",
],
)

cc_binary(
name = "consumer_and_provider",
srcs = ["main_consumer_and_provider.cpp"],
data = [
"config/mw_com_config.json",
],
features = COMPILER_WARNING_FEATURES + [
"aborts_upon_exception",
],
visibility = ["//score/mw/com/test/fields:__pkg__"],
deps = [
":common_resources",
":field_consumer",
":field_provider",
"//score/mw/com",
"//score/mw/com/test/common_test_resources:stop_token_sig_term_handler",
"@score_baselibs//score/mw/log",
],
)

cc_library(
name = "common_resources",
srcs = ["common_resources.cpp"],
hdrs = ["common_resources.h"],
features = COMPILER_WARNING_FEATURES,
deps = [
"//score/mw/com/test/common_test_resources:command_line_parser",
"//score/mw/com/test/common_test_resources:fail_test",
],
)

pkg_application(
name = "provider-pkg",
app_name = "MainProviderApp",
bin = [":provider"],
etc = [
"config/initial_only_field_mw_com_config.json",
"config/logging.json",
"config/mw_com_config.json",
],
Expand All @@ -139,7 +157,20 @@ pkg_application(
app_name = "MainConsumerApp",
bin = [":consumer"],
etc = [
"config/initial_only_field_mw_com_config.json",
"config/logging.json",
"config/mw_com_config.json",
],
visibility = [
"//platform/aas/test/mw/com:__pkg__",
"//score/mw/com/test/fields/set_and_notifier:__subpackages__",
],
)

pkg_application(
name = "consumer_and_provider-pkg",
app_name = "MainConsumerAndProviderApp",
bin = [":consumer_and_provider"],
etc = [
"config/logging.json",
"config/mw_com_config.json",
],
Expand Down
70 changes: 70 additions & 0 deletions score/mw/com/test/fields/set_and_notifier/common_resources.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/********************************************************************************
* Copyright (c) 2026 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#include "score/mw/com/test/fields/set_and_notifier/common_resources.h"

#include "score/mw/com/test/common_test_resources/command_line_parser.h"

namespace score::mw::com::test
{
namespace
{

TestMode ParseTestMode(std::string_view mode)
{
if (mode == "notifier")
{
return TestMode::kNotifier;
}
if (mode == "set_and_notifier")
{
return TestMode::kSetAndNotifier;
}
FailTest("Provider: unsupported --mode value: ", mode);

// Unreachable, but required to avoid compiler warning: "error: non-void function
// does not return a value in all control paths [-Werror,-Wreturn-type]"
return TestMode::kNotifier;
}

} // namespace

TestConfig ParseConfig(int argc, const char** argv)
{
constexpr auto kModeArg = "mode";
constexpr auto kServiceInstanceManifestArg = "service-instance-manifest";

const std::vector<std::pair<std::string, std::string>> parameter_description_pairs{
{kModeArg, "Provider mode: notifier or set"},
{kServiceInstanceManifestArg, "Path to the service instance manifest"},
};

const auto args = ParseCommandLineArguments(argc, argv, parameter_description_pairs);

const auto mode_result = GetValueIfProvided<std::string>(args, kModeArg);
if (!mode_result.has_value())
{
FailTest("Provider: missing or invalid --", kModeArg, " argument");
}

const auto mode = ParseTestMode(mode_result.value());

const auto manifest_result = GetValueIfProvided<std::string>(args, kServiceInstanceManifestArg);
if (!manifest_result.has_value())
{
FailTest("Provider: missing or invalid --", kServiceInstanceManifestArg, " argument");
}

return TestConfig{mode, manifest_result.value()};
}

} // namespace score::mw::com::test
43 changes: 43 additions & 0 deletions score/mw/com/test/fields/set_and_notifier/common_resources.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/********************************************************************************
* Copyright (c) 2026 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#ifndef SCORE_MW_COM_TEST_FIELDS_SET_AND_NOTIFIER_COMMON_RESOURCES_H
#define SCORE_MW_COM_TEST_FIELDS_SET_AND_NOTIFIER_COMMON_RESOURCES_H

#include <string>

namespace score::mw::com::test
{

/// \brief Test scenarios supported by this test application.
enum class TestMode
{
kNotifier,
kSetAndNotifier,
};

struct TestConfig
{
TestMode mode;
std::string config_file_path;
};

/// \brief Parses the command line arguments for the test and returns a TestConfig object.
///
/// Terminates if the argument is not provided. We use this function instead of providing argc / argv directly to
/// InitializeRuntime so that we detect if the config file was not provided instead of silently falling back to the
/// default config. It also makes it easier to extend the command line arguments in the future if needed.
TestConfig ParseConfig(int argc, const char** argv);

} // namespace score::mw::com::test

#endif // SCORE_MW_COM_TEST_FIELDS_SET_AND_NOTIFIER_COMMON_RESOURCES_H
Loading
Loading