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
168 changes: 168 additions & 0 deletions score/mw/com/test/move_semantics/skeleton_method/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_method_datatype",
srcs = ["test_method_datatype.cpp"],
hdrs = ["test_method_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_method_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_baselibs//score/concurrency:notification",
"@score_baselibs//score/language/futurecpp",
],
)

cc_library(
name = "consumer",
srcs = ["consumer.cpp"],
hdrs = ["consumer.h"],
features = COMPILER_WARNING_FEATURES,
deps = [
":test_method_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_baselibs//score/language/futurecpp",
],
)

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/skeleton_method:__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/skeleton_method:__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/skeleton_method:__subpackages__",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"appId": "SMMS",
"appDesc": "skeleton_method_move_semantics",
"logLevel": "kDebug",
"logLevelThresholdConsole": "kDebug",
"logMode": "kRemote|kConsole"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"serviceTypes": [
{
"serviceTypeName": "/test/move_semantics/skeleton_method/SkeletonMethodMoveInterface",
"version": {
"major": 1,
"minor": 0
},
"bindings": [
{
"binding": "SHM",
"serviceId": 2200,
"methods": [
{
"methodName": "moved_method",
"methodId": 1
}
]
}
]
}
],
"serviceInstances": [
{
"instanceSpecifier": "test/move_semantics/skeleton_method/SkeletonMethodMoveInterfaceMovedTo",
"serviceTypeName": "/test/move_semantics/skeleton_method/SkeletonMethodMoveInterface",
"version": {
"major": 1,
"minor": 0
},
"instances": [
{
"instanceId": 1,
"asil-level": "B",
"binding": "SHM",
"methods": [
{
"methodName": "moved_method",
"queueSize": 1
}
],
"allowedConsumer": {
"QM": [
0
],
"B": [
0
]
},
"allowedProvider": {
"QM": [
0
],
"B": [
0
]
}
}
]
},
{
"instanceSpecifier": "test/move_semantics/skeleton_method/SkeletonMethodMoveInterfaceMovedFrom",
"serviceTypeName": "/test/move_semantics/skeleton_method/SkeletonMethodMoveInterface",
"version": {
"major": 1,
"minor": 0
},
"instances": [
{
"instanceId": 2,
"asil-level": "B",
"binding": "SHM",
"methods": [
{
"methodName": "moved_method",
"queueSize": 1
}
],
"allowedConsumer": {
"QM": [
0
],
"B": [
0
]
},
"allowedProvider": {
"QM": [
0
],
"B": [
0
]
}
}
]
}
],
"global": {
"asil-level": "B"
}
}
92 changes: 92 additions & 0 deletions score/mw/com/test/move_semantics/skeleton_method/consumer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/********************************************************************************
* 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/move_semantics/skeleton_method/consumer.h"

#include "score/mw/com/test/common_test_resources/fail_test.h"
#include "score/mw/com/test/common_test_resources/proxy_container.h"
#include "score/mw/com/test/move_semantics/skeleton_method/test_method_datatype.h"
#include "score/mw/com/test/move_semantics/skeleton_method/test_parameters.h"

#include <chrono>
#include <iostream>
#include <optional>
#include <thread>

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

constexpr auto kMethodCallInterval = std::chrono::milliseconds{2};

std::int32_t CallMethodOrFail(SkeletonMethodMoveProxy& proxy)
{
auto result = proxy.moved_method_(kTestArgA, kTestArgB);
if (!result.has_value())
{
FailTest("Consumer: moved_method_ call failed: ", result.error());
}
return *(result.value());
}

} // namespace

void RunConsumer()
{
// Step 1. Create proxy for kInstanceSpecifierMovedTo.
std::cout << "\nConsumer: Step 1 - Create proxy (kMovedTo)" << std::endl;
ProxyContainer<SkeletonMethodMoveProxy> proxy_moved_to_container{};
proxy_moved_to_container.CreateProxy(kInstanceSpecifierMovedTo, "skeleton_method_move_semantics");
auto& proxy_moved_to = proxy_moved_to_container.GetProxy();

// Step 2. Keep calling the method until the return value identifies the second handler. For
// "before offered" scenarios the first call is always Handler A. For "after offered"
// (fuzzy) scenarios the move may already have happened, so any call may return either
// handler's result — each call is just checked against the two known-valid results.
std::cout << "\nConsumer: Step 2 - Loop calling until second handler is detected" << std::endl;
std::size_t call_count = 0U;
std::optional<std::int32_t> actual_method_return_value{};
while (!actual_method_return_value.has_value() ||
actual_method_return_value.value() != kSecondHandlerExpectedResult)
{
actual_method_return_value = CallMethodOrFail(proxy_moved_to);
++call_count;

// If the first handler is still registered, then we continue calling the method.
if (actual_method_return_value == kFirstHandlerExpectedResult)
{
std::this_thread::sleep_for(kMethodCallInterval);
continue;
}

// If the second handler has been registered, then we can finish.
if (actual_method_return_value == kSecondHandlerExpectedResult)
{
break;
}

FailTest("Consumer: call ",
call_count,
" expected ",
kFirstHandlerExpectedResult,
" or ",
kSecondHandlerExpectedResult,
" but got ",
actual_method_return_value.value());
}

std::cout << "\nConsumer: Step 2 done (" << call_count
<< " calls, second handler result=" << actual_method_return_value.value() << ")" << std::endl;
}

} // namespace score::mw::com::test
25 changes: 25 additions & 0 deletions score/mw/com/test/move_semantics/skeleton_method/consumer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/********************************************************************************
* 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_MOVE_SEMANTICS_SKELETON_METHOD_CONSUMER_H
#define SCORE_MW_COM_TEST_MOVE_SEMANTICS_SKELETON_METHOD_CONSUMER_H

#include "score/mw/com/test/move_semantics/skeleton_method/test_parameters.h"

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

void RunConsumer();

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

#endif // SCORE_MW_COM_TEST_MOVE_SEMANTICS_SKELETON_METHOD_CONSUMER_H
Loading
Loading