diff --git a/score/launch_manager/BUILD b/score/launch_manager/BUILD index d6eda34ae..405337a89 100644 --- a/score/launch_manager/BUILD +++ b/score/launch_manager/BUILD @@ -11,6 +11,7 @@ # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* load("@rules_cc//cc:defs.bzl", "cc_library") +load("//tests/utils/bazel:unit_test.bzl", "lm_cc_test") package(default_visibility = ["//visibility:public"]) @@ -70,7 +71,7 @@ cc_library( ], ) -cc_test( +lm_cc_test( name = "exec_error_domain_UT", srcs = ["src/exec_error_domain_UT.cpp"], visibility = ["//visibility:private"], diff --git a/score/launch_manager/src/alive/src/details/BUILD b/score/launch_manager/src/alive/src/details/BUILD index d0f15b16d..a5bb24a9e 100644 --- a/score/launch_manager/src/alive/src/details/BUILD +++ b/score/launch_manager/src/alive/src/details/BUILD @@ -11,8 +11,9 @@ # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* load("@rules_cc//cc:defs.bzl", "cc_library") +load("//tests/utils/bazel:unit_test.bzl", "lm_cc_test") -cc_test( +lm_cc_test( name = "AliveImpl_UT", srcs = ["AliveImpl_UT.cpp"], deps = [ diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/ifappl/BUILD b/score/launch_manager/src/daemon/src/alive_monitor/details/ifappl/BUILD index 1728f5a8c..485c65ce0 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/ifappl/BUILD +++ b/score/launch_manager/src/daemon/src/alive_monitor/details/ifappl/BUILD @@ -11,6 +11,7 @@ # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* load("@rules_cc//cc:defs.bzl", "cc_library") +load("//tests/utils/bazel:unit_test.bzl", "lm_cc_test") cc_library( name = "data_structures", @@ -56,7 +57,7 @@ cc_library( ], ) -cc_test( +lm_cc_test( name = "MonitorIfDaemon_UT", srcs = [ "MonitorIfDaemon_UT.cpp", diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/supervision/BUILD b/score/launch_manager/src/daemon/src/alive_monitor/details/supervision/BUILD index d1419f637..d28ff611d 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/supervision/BUILD +++ b/score/launch_manager/src/daemon/src/alive_monitor/details/supervision/BUILD @@ -11,6 +11,7 @@ # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* load("@rules_cc//cc:defs.bzl", "cc_library") +load("//tests/utils/bazel:unit_test.bzl", "lm_cc_test") cc_library( name = "supervision_cfg", @@ -57,7 +58,7 @@ cc_library( ], ) -cc_test( +lm_cc_test( name = "Alive_UT", srcs = ["Alive_UT.cpp"], deps = [ diff --git a/score/launch_manager/src/daemon/src/common/BUILD b/score/launch_manager/src/daemon/src/common/BUILD index 2aac5cfa1..f261c65d6 100644 --- a/score/launch_manager/src/daemon/src/common/BUILD +++ b/score/launch_manager/src/daemon/src/common/BUILD @@ -10,7 +10,7 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_cc//cc:defs.bzl", "cc_test") +load("//tests/utils/bazel:unit_test.bzl", "lm_cc_test") cc_library( name = "identifier_hash", @@ -25,7 +25,7 @@ cc_library( visibility = ["//score:__subpackages__"], ) -cc_test( +lm_cc_test( name = "identifier_hash_UT", srcs = ["identifier_hash_UT.cpp"], deps = [ diff --git a/score/launch_manager/src/daemon/src/common/concurrency/BUILD b/score/launch_manager/src/daemon/src/common/concurrency/BUILD index efecb3822..434901d4f 100644 --- a/score/launch_manager/src/daemon/src/common/concurrency/BUILD +++ b/score/launch_manager/src/daemon/src/common/concurrency/BUILD @@ -10,7 +10,8 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") +load("//tests/utils/bazel:unit_test.bzl", "lm_cc_test") cc_library( name = "workerthread", @@ -38,7 +39,7 @@ cc_library( ], ) -cc_test( +lm_cc_test( name = "fixed_size_queue_test", srcs = ["fixed_size_queue_test.cpp"], visibility = ["//tests:__subpackages__"], @@ -96,7 +97,7 @@ cc_library( ], ) -cc_test( +lm_cc_test( name = "mpsc_bounded_queue_test", srcs = ["mpsc_bounded_queue_test.cpp"], visibility = ["//tests:__subpackages__"], @@ -106,7 +107,7 @@ cc_test( ], ) -cc_test( +lm_cc_test( name = "mpsc_bounded_queue_tsan_test", srcs = ["mpsc_bounded_queue_test.cpp"], copts = [ @@ -127,7 +128,7 @@ cc_test( ], ) -cc_test( +lm_cc_test( name = "mpmc_concurrent_queue_test", srcs = ["mpmc_concurrent_queue_test.cpp"], visibility = ["//tests:__subpackages__"], @@ -137,7 +138,7 @@ cc_test( ], ) -cc_test( +lm_cc_test( name = "mpmc_concurrent_queue_helgrind_test", srcs = ["mpmc_concurrent_queue_test.cpp"], data = ["mpmc_concurrent_queue_test_helgrind.supp"], @@ -151,7 +152,7 @@ cc_test( ], ) -cc_test( +lm_cc_test( name = "mpmc_concurrent_queue_tsan_test", srcs = ["mpmc_concurrent_queue_test.cpp"], copts = [ diff --git a/score/launch_manager/src/daemon/src/configuration/BUILD b/score/launch_manager/src/daemon/src/configuration/BUILD index 8d6fe7eb3..9116bdbb7 100644 --- a/score/launch_manager/src/daemon/src/configuration/BUILD +++ b/score/launch_manager/src/daemon/src/configuration/BUILD @@ -12,6 +12,7 @@ # ******************************************************************************* load("@rules_cc//cc:defs.bzl", "cc_library") load("@score_baselibs//score/flatbuffers/bazel:codegen.bzl", "generate_cpp") +load("//tests/utils/bazel:unit_test.bzl", "lm_cc_test") filegroup( name = "new_lm_flatcfg_fbs", @@ -35,7 +36,7 @@ cc_library( deps = ["@score_baselibs//score/language/futurecpp"], ) -cc_test( +lm_cc_test( name = "config_UT", srcs = ["details/config_UT.cpp"], visibility = ["//score:__subpackages__"], @@ -94,7 +95,7 @@ cc_library( ], ) -cc_test( +lm_cc_test( name = "flatbuffer_type_converters_UT", srcs = ["details/flatbuffer_type_converters_UT.cpp"], visibility = ["//tests:__subpackages__"], @@ -105,7 +106,7 @@ cc_test( ], ) -cc_test( +lm_cc_test( name = "flatbuffer_config_loader_UT", srcs = ["details/flatbuffer_config_loader_UT.cpp"], visibility = ["//tests:__subpackages__"], @@ -159,7 +160,7 @@ cc_library( ], ) -cc_test( +lm_cc_test( name = "configuration_adapter_UT", srcs = ["configuration_adapter_UT.cpp"], visibility = ["//tests:__subpackages__"], diff --git a/score/launch_manager/src/daemon/src/process_group_manager/details/BUILD b/score/launch_manager/src/daemon/src/process_group_manager/details/BUILD index 2bc35491f..62c60af95 100644 --- a/score/launch_manager/src/daemon/src/process_group_manager/details/BUILD +++ b/score/launch_manager/src/daemon/src/process_group_manager/details/BUILD @@ -11,6 +11,7 @@ # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* load("@rules_cc//cc:defs.bzl", "cc_library") +load("//tests/utils/bazel:unit_test.bzl", "lm_cc_test") cc_library( name = "process_info_node", @@ -67,7 +68,7 @@ cc_library( ], ) -cc_test( +lm_cc_test( name = "safeprocessmap_UT", timeout = "long", srcs = ["safeprocessmap_UT.cpp"], @@ -92,7 +93,7 @@ cc_library( ], ) -cc_test( +lm_cc_test( name = "oshandler_UT", srcs = ["oshandler_UT.cpp"], deps = [ diff --git a/score/launch_manager/src/daemon/src/process_state_client/BUILD b/score/launch_manager/src/daemon/src/process_state_client/BUILD index 223b38670..25838e161 100644 --- a/score/launch_manager/src/daemon/src/process_state_client/BUILD +++ b/score/launch_manager/src/daemon/src/process_state_client/BUILD @@ -10,7 +10,8 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") +load("@rules_cc//cc:defs.bzl", "cc_library") +load("//tests/utils/bazel:unit_test.bzl", "lm_cc_test") cc_library( name = "posix_process", @@ -72,7 +73,7 @@ cc_library( ], ) -cc_test( +lm_cc_test( name = "process_state_client_ut", srcs = ["process_state_client_ut.cpp"], tags = ["no-tsan"], diff --git a/score/launch_manager/src/daemon/src/recovery_client/BUILD b/score/launch_manager/src/daemon/src/recovery_client/BUILD index 0944da271..bea6bd7b7 100644 --- a/score/launch_manager/src/daemon/src/recovery_client/BUILD +++ b/score/launch_manager/src/daemon/src/recovery_client/BUILD @@ -10,7 +10,8 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") +load("@rules_cc//cc:defs.bzl", "cc_library") +load("//tests/utils/bazel:unit_test.bzl", "lm_cc_test") cc_library( name = "recovery_client", @@ -32,7 +33,7 @@ cc_library( ], ) -cc_test( +lm_cc_test( name = "recovery_client_UT", srcs = ["recovery_client_UT.cpp"], deps = [ diff --git a/score/launch_manager/src/lifecycle_client/BUILD b/score/launch_manager/src/lifecycle_client/BUILD index 72a9c9cc7..7dc47b33a 100644 --- a/score/launch_manager/src/lifecycle_client/BUILD +++ b/score/launch_manager/src/lifecycle_client/BUILD @@ -12,6 +12,7 @@ # ******************************************************************************* load("@rules_cc//cc:defs.bzl", "cc_library") load("@score_baselibs//score/language/safecpp:toolchain_features.bzl", "COMPILER_WARNING_FEATURES") +load("//tests/utils/bazel:unit_test.bzl", "lm_cc_test") cc_library( name = "lifecycle_client", @@ -209,7 +210,7 @@ cc_library( ], ) -cc_test( +lm_cc_test( name = "runapplication_UT", srcs = ["src/runapplication_UT.cpp"], deps = [ diff --git a/score/launch_manager/src/testing/BUILD b/score/launch_manager/src/testing/BUILD new file mode 100644 index 000000000..23a30a96b --- /dev/null +++ b/score/launch_manager/src/testing/BUILD @@ -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 +# ******************************************************************************* +load("@rules_cc//cc:defs.bzl", "cc_library") + +cc_library( + name = "testing_assertion_handler", + testonly = True, + srcs = ["assertion_handler.cpp"], + hdrs = ["assertion_handler.hpp"], + include_prefix = "score/mw/launch_manager/testing", + strip_include_prefix = "/score/launch_manager/src/testing", + visibility = ["//score/launch_manager:__subpackages__"], + deps = ["@score_baselibs//score/language/futurecpp"], + alwayslink = True, +) diff --git a/score/launch_manager/src/testing/assertion_handler.cpp b/score/launch_manager/src/testing/assertion_handler.cpp new file mode 100644 index 000000000..541c7ba73 --- /dev/null +++ b/score/launch_manager/src/testing/assertion_handler.cpp @@ -0,0 +1,27 @@ +/******************************************************************************** + * 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/launch_manager/testing/assertion_handler.hpp" + +namespace +{ + +// Registers the assertion handler at static-initialization time so every unit +// test binary that links this library gets diagnostic output on assertion failure +// without any explicit setup call. +const bool kAssertionHandlerRegistered = []() noexcept { + score::lcm::testing::registerAssertionHandler(); + return true; +}(); + +} // namespace diff --git a/score/launch_manager/src/testing/assertion_handler.hpp b/score/launch_manager/src/testing/assertion_handler.hpp new file mode 100644 index 000000000..f65429837 --- /dev/null +++ b/score/launch_manager/src/testing/assertion_handler.hpp @@ -0,0 +1,40 @@ +/******************************************************************************** + * 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 + ********************************************************************************/ + +#pragma once + +#include + +#include +#include + +namespace score::lcm::testing +{ + +inline void registerAssertionHandler() noexcept +{ + score::cpp::set_assertion_handler([](const score::cpp::handler_parameters& params) { + std::ostringstream msg; + msg << "Assertion failed: " << (params.condition != nullptr ? params.condition : "") + << "\n Location: " << (params.file != nullptr ? params.file : "?") << ":" << params.line + << " (" << (params.function != nullptr ? params.function : "?") << ")"; + if (params.message != nullptr) + { + msg << "\n Message: " << params.message; + } + msg << "\n"; + std::cerr << msg.str(); + }); +} + +} // namespace score::lcm::testing diff --git a/tests/utils/bazel/unit_test.bzl b/tests/utils/bazel/unit_test.bzl new file mode 100644 index 000000000..3d4990523 --- /dev/null +++ b/tests/utils/bazel/unit_test.bzl @@ -0,0 +1,34 @@ +# ******************************************************************************* +# 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 +# ******************************************************************************* +"""Bazel macros for LCM unit tests.""" + +load("@rules_cc//cc:defs.bzl", "cc_test") + +def lm_cc_test(name, deps = [], **kwargs): + """Wrapper around cc_test that auto-registers the LCM assertion handler. + + All arguments are forwarded to cc_test unchanged. The assertion handler + library is injected so that assertion failures in any unit test binary + print a diagnostic message before aborting, without requiring any + explicit setup call in test code. + + Args: + name: Test target name. + deps: Additional dependencies (assertion handler is appended automatically). + **kwargs: Forwarded verbatim to cc_test. + """ + cc_test( + name = name, + deps = deps + ["//score/launch_manager/src/testing:testing_assertion_handler"], + **kwargs + )