From 7b65616df306037fecc19a6cd7ccf9828ffbba1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadiusz=20J=C4=99drzejewski?= Date: Mon, 26 Jan 2026 12:54:13 +0000 Subject: [PATCH] log: add Rust log init for C++ tests Add logging init as an env in GTest. --- MODULE.bazel | 2 +- MODULE.bazel.lock | 4 +- src/health_monitoring_lib/BUILD | 2 + .../cpp/tests/log_init.cpp | 44 +++++++++++++++++++ 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 src/health_monitoring_lib/cpp/tests/log_init.cpp diff --git a/MODULE.bazel b/MODULE.bazel index 5b50b795..f44180e8 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -103,7 +103,7 @@ use_repo(toolchains_qnx, "toolchains_qnx_sdp") use_repo(toolchains_qnx, "toolchains_qnx_qcc") use_repo(toolchains_qnx, "toolchains_qnx_ifs") -bazel_dep(name = "score_baselibs_rust", version = "0.0.3") +bazel_dep(name = "score_baselibs_rust", version = "0.0.4") bazel_dep(name = "score_baselibs", version = "0.2.2") # Hedron's Compile Commands Extractor for Bazel diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 6babb4e0..eab36cce 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -729,8 +729,8 @@ "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/rules_swift/2.1.1/MODULE.bazel": "not found", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/score_baselibs/0.2.2/MODULE.bazel": "3888c6eda7a326395813d049609e1fccb83e2ca09f945372b705d35e3524971f", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/score_baselibs/0.2.2/source.json": "c2eb71e930456d2f8e5b051455a2afa72110e100ac7eed06dd21920a3500d22c", - "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/score_baselibs_rust/0.0.3/MODULE.bazel": "5fc61f1f82b5223f61cdd58105d420c12d254ee4370f878539f94704a15c1e97", - "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/score_baselibs_rust/0.0.3/source.json": "3be439e9b23651511e835ec89edbb7d18b5d476ade913b24537111f1bf993cc7", + "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/score_baselibs_rust/0.0.4/MODULE.bazel": "c2a24d3b16bb294cc06b5829ad01d61ad06393f5155447e3ff8b8589a3871db4", + "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/score_baselibs_rust/0.0.4/source.json": "261211b66de824e5b202b971e5b60c380ac4b3c502c13f16dad43e1645c2c64a", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/score_bazel_platforms/0.0.3/MODULE.bazel": "14c96e378c08705a46abe0799d6236fe3095c342c34f83f8d1b3f6046ce00651", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/score_bazel_platforms/0.0.3/source.json": "1a853ab23455388d550a9aecf3d8b53ec73de50e7fe2914d9269a3c698bf3624", "https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/modules/score_cr_checker/0.2.2/MODULE.bazel": "dc36d9c35543db918c3fb5b93a8e684431f56c7c784cf2a1b90f35802a373c98", diff --git a/src/health_monitoring_lib/BUILD b/src/health_monitoring_lib/BUILD index c61c5134..b509acc5 100644 --- a/src/health_monitoring_lib/BUILD +++ b/src/health_monitoring_lib/BUILD @@ -74,6 +74,7 @@ cc_gtest_unit_test( name = "cpp_tests", srcs = [ "cpp/tests/health_monitor_test.cpp", + "cpp/tests/log_init.cpp", ], linkopts = select({ "@platforms//os:qnx": ["-lsocket"], @@ -81,5 +82,6 @@ cc_gtest_unit_test( }), deps = [ ":health_monitoring_lib_cc", + "@score_baselibs_rust//src/log/stdout_logger_cpp_init", ], ) diff --git a/src/health_monitoring_lib/cpp/tests/log_init.cpp b/src/health_monitoring_lib/cpp/tests/log_init.cpp new file mode 100644 index 00000000..cdcd4d8b --- /dev/null +++ b/src/health_monitoring_lib/cpp/tests/log_init.cpp @@ -0,0 +1,44 @@ +/******************************************************************************** + * 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/log/rust/stdout_logger_init.h" +#include + +/// Initializer for `StdoutLogger`. +/// This enables logging for Rust libraries. +class LogEnvironment final : public ::testing::Environment +{ + protected: + void SetUp() override + { + using namespace score::mw::log::rust; + + StdoutLoggerBuilder builder; + builder.Context("TEST") + .LogLevel(LogLevel::Verbose) + .ShowModule(false) + .ShowFile(true) + .ShowLine(true) + .SetAsDefaultLogger(); + } +}; + +struct RegisterLogEnvironment +{ + RegisterLogEnvironment() + { + ::testing::AddGlobalTestEnvironment(new LogEnvironment()); + } +}; + +static RegisterLogEnvironment register_log_environment;