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
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ test --cxxopt=-Wno-deprecated-declarations
coverage --features=coverage
coverage --combined_report=lcov
coverage --cache_test_results=no
coverage --test_tag_filters=-no-coverage

# Common Lifecycle Toolchain flags for build (do not use it in case of system toolchains!)
build:toolchain_common --incompatible_strict_action_env
Expand Down
2 changes: 2 additions & 0 deletions src/launch_manager_daemon/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ cc_binary_with_common_opts(
"//src/launch_manager_daemon/common:identifier_hash",
"//src/launch_manager_daemon/common:lifecycle_error",
"//src/launch_manager_daemon/common:log",
"//src/launch_manager_daemon/common/concurrency:mpmc_concurrent_queue",
"//src/launch_manager_daemon/health_monitor_lib:health_monitor",
"//src/launch_manager_daemon/process_state_client_lib:process_state_client",
"@flatbuffers",
Expand Down Expand Up @@ -83,6 +84,7 @@ cc_library(
"//src/launch_manager_daemon/common:lifecycle_error",
"//src/launch_manager_daemon/common:log",
"//src/launch_manager_daemon/health_monitor_lib:health_monitor",
"//src/launch_manager_daemon/common/concurrency:mpmc_concurrent_queue",
"@flatbuffers",
"@score_baselibs//score/mw/log",
"@score_baselibs//score/result",
Expand Down
12 changes: 3 additions & 9 deletions src/launch_manager_daemon/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,15 @@ cc_library(

cc_library(
name = "osal",
srcs = select({
srcs = glob(["src/internal/osal/posix/*.cpp"]) + select({
"@platforms//os:qnx": glob(
[
"src/internal/osal/**/*.cpp",
],
exclude = [
"src/internal/osal/linux/**",
"src/internal/osal/qnx/*.cpp",
],
),
"@platforms//os:linux": glob(
[
"src/internal/osal/**/*.cpp",
],
exclude = [
"src/internal/osal/qnx/**",
"src/internal/osal/linux/*.cpp",
],
),
}),
Expand Down
89 changes: 89 additions & 0 deletions src/launch_manager_daemon/common/concurrency/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# *******************************************************************************
Comment thread
MaciejKaszynski marked this conversation as resolved.
# Copyright (c) 2025 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_test")
load("//config:common_cc.bzl", "cc_library_with_common_opts")

cc_library(
name = "helgrind_annotations",
hdrs = ["helgrind_annotations.hpp"],
strip_include_prefix = "//src/launch_manager_daemon/common",
visibility = ["//src:__subpackages__"],
)

cc_library(
name = "mpmc_concurrent_queue",
hdrs = [
"concurrency_error_domain.hpp",
"mpmc_concurrent_queue.hpp",
],
linkopts = [
"-l:libatomic.a",
Comment thread
MaciejKaszynski marked this conversation as resolved.
],
strip_include_prefix = "//src/launch_manager_daemon/common",
visibility = ["//src:__subpackages__"],
deps = [
":helgrind_annotations",
"//src/launch_manager_daemon/common:osal",
"@score_baselibs//score/language/futurecpp",
],
)

cc_test(
name = "mpmc_concurrent_queue_test",
srcs = ["mpmc_concurrent_queue_test.cpp"],
visibility = ["//tests:__subpackages__"],
deps = [
":mpmc_concurrent_queue",
"@googletest//:gtest_main",
],
)

# Run with:
# bazel test --run_under="valgrind --tool=helgrind --suppressions=src/launch_manager_daemon/common/concurrency/helgrind.supp --error-exitcode=1" //src/launch_manager_daemon/common/concurrency:mpmc_concurrent_queue_helgrind_test --config=host --test_output=all
# Note: This is using your host packages so you need to install valgrind.
# Two tests intentionally exercise semaphore failure paths (EINTR / EAGAIN).
# Those expected PthAPIerror reports are silenced via helgrind.supp.
cc_test(
name = "mpmc_concurrent_queue_helgrind_test",
srcs = ["mpmc_concurrent_queue_test.cpp"],
data = ["helgrind.supp"],
tags = [
"helgrind",
"manual",
],
visibility = ["//tests:__subpackages__"],
deps = [
":mpmc_concurrent_queue",
"@googletest//:gtest_main",
],
)

cc_test(
name = "mpmc_concurrent_queue_tsan_test",
srcs = ["mpmc_concurrent_queue_test.cpp"],
copts = [
"-fsanitize=thread",
"-O0",
"-g",
],
linkopts = ["-fsanitize=thread"],
tags = [
"no-coverage", # coverage + tsan might cause problems
"tsan",
],
visibility = ["//tests:__subpackages__"],
deps = [
":mpmc_concurrent_queue",
"@googletest//:gtest_main",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/********************************************************************************
* 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 CONCURRENCY_ERROR_DOMAIN_HPP_INCLUDED
#define CONCURRENCY_ERROR_DOMAIN_HPP_INCLUDED

#include <cstdint>
#include <ostream>

namespace score::lcm::internal
{

enum class ConcurrencyErrc : std::uint8_t
{
/// @brief An OS call returned an error.
kOsError = 1,

// @brief The container has overflowed.
kOverflow = 2,

// @brief The container has stopped.
kStopped = 3,

// @brief A timeout was triggered.
kTimeout = 4,
};

inline std::ostream& operator<<(std::ostream& os, ConcurrencyErrc errc) noexcept
{
switch (errc)
{
case ConcurrencyErrc::kOsError: return os << "kOsError";
case ConcurrencyErrc::kOverflow: return os << "kOverflow";
case ConcurrencyErrc::kStopped: return os << "kStopped";
case ConcurrencyErrc::kTimeout: return os << "kTimeout";
default: return os << static_cast<std::uint8_t>(errc);
}
}

} // namespace score::lcm::internal

#endif // CONCURRENCY_ERROR_DOMAIN_HPP_INCLUDED
42 changes: 42 additions & 0 deletions src/launch_manager_daemon/common/concurrency/helgrind.supp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# *******************************************************************************
# Copyright (c) 2025 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
# *******************************************************************************

# Helgrind suppression file


# --- mpmc_concurrent_queue_helgrind_test ----

# tests intentionally exercise semaphore failure paths and therefore
# trigger Helgrind's PthAPIerror reports
#
# * MPMCConcurrentQueueTest_Basic.PopReturnsNulloptOnSemaphoreWaitFailure
# Sends SIGUSR1 to the consumer so sem_wait() returns -1 / EINTR and
# the kFail path in Semaphore::wait() is taken.
{
mpmc_queue_sem_wait_eintr_intentional
Helgrind:PthAPIerror
obj:*/vgpreload_helgrind-*.so
fun:_ZN5score3lcm8internal4osal9Semaphore4waitEv
...
}

# * MPMCConcurrentQueueTest_Timeout.PushWithTimeoutReturnsFalseWhenFull
# Fills the queue so sem_trywait() inside Semaphore::timedWait()
# returns -1 / EAGAIN until the timeout expires.
{
mpmc_queue_sem_trywait_eagain_intentional
Helgrind:PthAPIerror
obj:*/vgpreload_helgrind-*.so
fun:_ZN5score3lcm8internal4osal9Semaphore9timedWaitENSt6chrono8durationIlSt5ratioILl1ELl1000EEEE
...
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/********************************************************************************
* Copyright (c) 2025 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 HELGRIND_ANNOTATIONS_HPP_INCLUDED
#define HELGRIND_ANNOTATIONS_HPP_INCLUDED

// When built with --config=host the system compiler finds valgrind/helgrind.h
// in its default include paths and the real annotations are active. Under any
// other config the header is absent and the macros expand to no-ops.
#if __has_include(<valgrind/helgrind.h>)
#include <valgrind/helgrind.h>
#else
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define ANNOTATE_HAPPENS_BEFORE(obj) do {} while (false)
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define ANNOTATE_HAPPENS_AFTER(obj) do {} while (false)
#endif

#endif // HELGRIND_ANNOTATIONS_HPP_INCLUDED
Loading
Loading