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
15 changes: 15 additions & 0 deletions score/mw/com/test/common_test_resources/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ cc_library(
deps = [
"//score/mw/com",
"//score/mw/com/test/common_test_resources:fail_test",
"//score/mw/com/test/common_test_resources:proxy_event_receiver",
"//score/mw/com/test/common_test_resources:proxy_event_state_change_notifier",
],
)

Expand Down Expand Up @@ -314,6 +316,19 @@ cc_library(
],
)

cc_library(
name = "proxy_event_consumer",
srcs = ["proxy_event_consumer.cpp"],
hdrs = ["proxy_event_consumer.h"],
features = COMPILER_WARNING_FEATURES,
visibility = ["//score/mw/com/test:__subpackages__"],
deps = [
":fail_test",
"//score/mw/com:types",
"@score_baselibs//score/language/futurecpp",
],
)

cc_library(
name = "generic_trace_api_test_resources",
srcs = ["generic_trace_api_test_resources.cpp"],
Expand Down
10 changes: 10 additions & 0 deletions score/mw/com/test/common_test_resources/proxy_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#define SCORE_MW_COM_TEST_METHODS_METHODS_TEST_RESOURCES_PROXY_CONTAINER_H

#include "score/mw/com/test/common_test_resources/fail_test.h"
#include "score/mw/com/test/common_test_resources/proxy_event_receiver.h"
#include "score/mw/com/test/common_test_resources/proxy_event_state_change_notifier.h"
#include "score/mw/com/types.h"

#include <chrono>
Expand All @@ -22,6 +24,7 @@
#include <memory>
#include <mutex>
#include <string>
#include <utility>

namespace score::mw::com::test
{
Expand All @@ -39,6 +42,13 @@ class ProxyContainer
return *proxy_;
}

Proxy&& Extract()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

directory structure:
move_semantics/
....proxy_event/
....skeleton_event/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in the PR - #610

{
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(proxy_ != nullptr,
"Proxy was not successfully created! Cannot extract it!");
return std::move(*proxy_);
}

private:
std::unique_ptr<typename Proxy::HandleType> handle_{nullptr};
std::mutex proxy_creation_mutex_{};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/********************************************************************************
* 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/common_test_resources/proxy_event_consumer.h"
109 changes: 109 additions & 0 deletions score/mw/com/test/common_test_resources/proxy_event_consumer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/********************************************************************************
* 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_COMMON_TEST_RESOURCES_PROXY_EVENT_CONSUMER_H
#define SCORE_MW_COM_TEST_COMMON_TEST_RESOURCES_PROXY_EVENT_CONSUMER_H

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

#include <score/stop_token.hpp>

#include <cstddef>
#include <cstdint>
#include <iostream>
#include <optional>

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

inline auto MakeSampleSequenceCallback(std::optional<std::uint32_t>& latest_value, const char* failure_message_prefix)
{
return [&latest_value, failure_message_prefix](SamplePtr<std::uint32_t> sample) {
if (sample == nullptr)
{
FailTest(failure_message_prefix, " received null sample");
}
// After a reset latest_value is empty, so the next sample is accepted as the new baseline.
const std::uint32_t expected_value = latest_value.has_value() ? latest_value.value() + 1U : *sample;
if (*sample != expected_value)
{
FailTest(
failure_message_prefix, " received value ", *sample, " does not match expected value ", expected_value);
}
latest_value = *sample;
};
}

/// \brief Waits until subscribed, receives the expected number of samples, and notifies the provider once - repeated
/// for the given number of iterations.
template <typename ProxyEventReceiverType, typename ProxyStateChangeNotifierType, typename ProcessSynchronizerType>
void ReceiveAndNotify(ProxyEventReceiverType& proxy_event_receiver,
ProxyStateChangeNotifierType& proxy_state_change_notifier,
ProcessSynchronizerType& process_synchronizer,
const std::size_t num_samples_to_receive,
const std::size_t num_iterations,
const score::cpp::stop_token& stop_token)
{
for (std::size_t iteration = 0U; iteration < num_iterations; ++iteration)
{
std::cout << "\nConsumer: Iteration " << (iteration + 1U) << " of " << num_iterations << std::endl;
const bool subscribed =
proxy_state_change_notifier.WaitForStateChange(stop_token, SubscriptionState::kSubscribed);
if (!subscribed)
{
FailTest("proxy_event_move_semantics consumer failed: WaitForStateChange was interrupted by stop_token");
}

const bool received = proxy_event_receiver.WaitForSamples(stop_token, num_samples_to_receive);
if (!received)
{
FailTest("proxy_event_move_semantics consumer failed: WaitForSamples was interrupted by stop_token");
}
process_synchronizer.Notify();
}
}

/// \brief Coordinates a proxy re-subscription across a provider re-offer. Waits until the provider has withdrawn its
/// offer (kSubscriptionPending), unsubscribes and subscribes again while the service is withdrawn, then notifies the
/// provider so that it re-offers. This ordering guarantees that the samples received afterwards come from the fresh
/// offer instead of being stale buffered samples from the previous offer.
template <typename ProxyEventType, typename ProxyStateChangeNotifierType, typename ProcessSynchronizerType>
void ResubscribeAcrossReoffer(ProxyEventType& proxy_event,
ProxyStateChangeNotifierType& proxy_state_change_notifier,
ProcessSynchronizerType& process_synchronizer,
const std::size_t num_samples_to_receive,
const score::cpp::stop_token& stop_token)
{
std::cout << "\nConsumer: Waiting for provider to withdraw its offer" << std::endl;
const bool withdrawn =
proxy_state_change_notifier.WaitForStateChange(stop_token, SubscriptionState::kSubscriptionPending);
if (!withdrawn)
{
FailTest("proxy_event_move_semantics consumer failed: WaitForStateChange was interrupted by stop_token");
}

std::cout << "Consumer: Unsubscribe and subscribe again" << std::endl;
proxy_event.Unsubscribe();
const auto subscribe_result = proxy_event.Subscribe(num_samples_to_receive);
if (!subscribe_result.has_value())
{
FailTest("proxy_event_move_semantics consumer failed: Re-subscribe failed: ", subscribe_result.error());
}

// Tell the provider we have re-subscribed so that it can re-offer the service.
process_synchronizer.Notify();
}

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

#endif // SCORE_MW_COM_TEST_COMMON_TEST_RESOURCES_PROXY_EVENT_CONSUMER_H
168 changes: 168 additions & 0 deletions score/mw/com/test/move_semantics/proxy_event/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# *******************************************************************************
# 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
# *******************************************************************************

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("@score_baselibs//score/language/safecpp:toolchain_features.bzl", "COMPILER_WARNING_FEATURES")
load("//bazel/tools:json_schema_validator.bzl", "validate_json_schema_test")
load("//score/mw/com/test:pkg_application.bzl", "pkg_application")

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

cc_library(
name = "test_event_datatype",
srcs = ["test_event_datatype.cpp"],
hdrs = ["test_event_datatype.h"],
features = COMPILER_WARNING_FEATURES,
deps = [
"//score/mw/com",
],
)

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

cc_library(
name = "provider",
srcs = ["provider.cpp"],
hdrs = ["provider.h"],
features = COMPILER_WARNING_FEATURES,
deps = [
":test_event_datatype",
":test_parameters",
"//score/mw/com",
"//score/mw/com/test/common_test_resources:fail_test",
"//score/mw/com/test/common_test_resources:skeleton_container",
"//score/mw/com/test/methods/methods_test_resources:process_synchronizer",
],
)

cc_library(
name = "consumer",
srcs = ["consumer.cpp"],
hdrs = ["consumer.h"],
features = COMPILER_WARNING_FEATURES,
deps = [
":test_event_datatype",
":test_parameters",
"//score/mw/com",
"//score/mw/com/test/common_test_resources:fail_test",
"//score/mw/com/test/common_test_resources:proxy_container",
"//score/mw/com/test/common_test_resources:proxy_event_consumer",
"//score/mw/com/test/methods/methods_test_resources:process_synchronizer",
],
)

cc_binary(
name = "main_provider",
srcs = ["main_provider.cpp"],
data = ["config/mw_com_config.json"],
features = COMPILER_WARNING_FEATURES + [
"aborts_upon_exception",
],
deps = [
":provider",
":test_parameters",
"//score/mw/com",
"//score/mw/com/test/common_test_resources:assert_handler",
"//score/mw/com/test/common_test_resources:fail_test",
"//score/mw/com/test/common_test_resources:stop_token_sig_term_handler",
],
)

cc_binary(
name = "main_consumer",
srcs = ["main_consumer.cpp"],
data = ["config/mw_com_config.json"],
features = COMPILER_WARNING_FEATURES + [
"aborts_upon_exception",
],
deps = [
":consumer",
":test_parameters",
"//score/mw/com",
"//score/mw/com/test/common_test_resources:assert_handler",
"//score/mw/com/test/common_test_resources:fail_test",
"//score/mw/com/test/common_test_resources:stop_token_sig_term_handler",
],
)

cc_binary(
name = "main_consumer_and_provider",
srcs = ["main_consumer_and_provider.cpp"],
data = ["config/mw_com_config.json"],
features = COMPILER_WARNING_FEATURES + [
"aborts_upon_exception",
],
deps = [
":consumer",
":provider",
":test_parameters",
"//score/mw/com",
"//score/mw/com/test/common_test_resources:assert_handler",
"//score/mw/com/test/common_test_resources:fail_test",
"//score/mw/com/test/common_test_resources:stop_token_sig_term_handler",
],
)

pkg_application(
name = "main_provider-pkg",
app_name = "MainProviderApp",
bin = [":main_provider"],
etc = [
"config/mw_com_config.json",
"config/logging.json",
],
visibility = [
"//score/mw/com/test/move_semantics/proxy_event:__subpackages__",
],
)

pkg_application(
name = "main_consumer-pkg",
app_name = "MainConsumerApp",
bin = [":main_consumer"],
etc = [
"config/mw_com_config.json",
"config/logging.json",
],
visibility = [
"//score/mw/com/test/move_semantics/proxy_event:__subpackages__",
],
)

pkg_application(
name = "main_consumer_and_provider-pkg",
app_name = "MainConsumerAndProviderApp",
bin = [":main_consumer_and_provider"],
etc = [
"config/mw_com_config.json",
"config/logging.json",
],
visibility = [
"//score/mw/com/test/move_semantics/proxy_event:__subpackages__",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"appId": "PRMS",
"appDesc": "proxy_event_move_semantics",
"logLevel": "kDebug",
"logLevelThresholdConsole": "kDebug",
"logMode": "kRemote|kConsole"
}
Loading
Loading