diff --git a/.bazelrc b/.bazelrc index 782efb3d..e147c16d 100644 --- a/.bazelrc +++ b/.bazelrc @@ -96,7 +96,13 @@ build:asan_ubsan_lsan --config=with_debug_symbols build:asan_ubsan_lsan --copt=-fsanitize=undefined,address,leak build:asan_ubsan_lsan --linkopt=-fsanitize=undefined,address,leak build:asan_ubsan_lsan --platform_suffix=asan_ubsan_lsan -build:asan_ubsan_lsan --@score_cpp_policies//sanitizers/flags:sanitizer=asan_ubsan_lsan +# score_cpp_policies removed the combined string flag ":sanitizer" in favor of +# per-sanitizer bool flags; the //sanitizers:wrapper run_under target (and its +# constraints/features) only activate when these are set, otherwise every test +# using it is marked incompatible and silently skipped. +build:asan_ubsan_lsan --@score_cpp_policies//sanitizers/flags:asan=True +build:asan_ubsan_lsan --@score_cpp_policies//sanitizers/flags:ubsan=True +build:asan_ubsan_lsan --@score_cpp_policies//sanitizers/flags:lsan=True test:asan_ubsan_lsan --run_under=@score_cpp_policies//sanitizers:wrapper test:asan_ubsan_lsan --test_tag_filters=-no-asan,-no-lsan,-no-ubsan test:asan_ubsan_lsan --build_tests_only diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..a531ea6c --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,33 @@ +# ******************************************************************************* +# 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 +# ******************************************************************************* + +# Default clang-tidy configuration for S-CORE C++ modules. +# NOTE: the set of enabled checks is yet subject to be tailored per module. +Checks: "-*,clang-analyzer-*,cert-*,cppcoreguidelines-*,bugprone-*,misc-*,performance-*,readability-*,modernize-*,-modernize-use-trailing-return-type" + +# NOTE: WarningsAsErrors is yet subject to be expanded per module as compliance increases. +WarningsAsErrors: "clang-analyzer-*" + +# HeaderFilterRegex is intentionally absent from the central baseline. +# Each consuming module must set this in their local .clang-tidy to match +# their own source tree (e.g., HeaderFilterRegex: 'score/mw/'). +# Setting it here would either suppress all header analysis (empty string) +# or generate noise from external dependency headers (broad regex). +# LLVM's regex engine does not reliably support POSIX lookaheads, so +# negative-lookahead patterns like (?!.*/external/) must not be used here. + +FormatStyle: none + +# NOTE: CheckOptions are yet subject to be provided for each enabled check per module. +#CheckOptions: +# none yet diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index a5d1ac90..650e980d 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -58,15 +58,25 @@ jobs: | xargs cat 2>/dev/null > clang_tidy_findings.txt || true - name: Check violation baseline - # Baseline recorded on 2026-07-03. Decrease when violations are fixed. # Remove this step once https://github.com/eclipse-score/time/issues/111 is resolved. if: always() run: | - BASELINE=85 - COUNT=$(wc -l < clang_tidy_findings.txt 2>/dev/null || echo 0) - echo "Clang-tidy violations: $COUNT (baseline: $BASELINE)" - if [ "$COUNT" -gt "$BASELINE" ]; then - echo "::error::Clang-tidy violations grew: $COUNT > baseline $BASELINE. Fix new violations before merging." + TIME_DAEMON_BASELINE=0 + TIME_DAEMON_COUNT=$(grep -cE "score/time_daemon/[^:]*:[0-9]+:[0-9]+: (warning|error):" clang_tidy_findings.txt 2>/dev/null || true) + TIME_DAEMON_COUNT=${TIME_DAEMON_COUNT:-0} + echo "Clang-tidy violations in score/time_daemon/: $TIME_DAEMON_COUNT (baseline: $TIME_DAEMON_BASELINE)" + + OTHER_BASELINE=1050 + OTHER_COUNT=$(grep -E ":[0-9]+:[0-9]+: (warning|error):" clang_tidy_findings.txt 2>/dev/null | grep -vcE "score/time_daemon/" || true) + OTHER_COUNT=${OTHER_COUNT:-0} + echo "Clang-tidy violations outside score/time_daemon/: $OTHER_COUNT (baseline: $OTHER_BASELINE)" + + if [ "$TIME_DAEMON_COUNT" -gt "$TIME_DAEMON_BASELINE" ]; then + echo "::error::Clang-tidy violations in score/time_daemon/ grew: $TIME_DAEMON_COUNT > baseline $TIME_DAEMON_BASELINE. Fix new violations before merging." + exit 1 + fi + if [ "$OTHER_COUNT" -gt "$OTHER_BASELINE" ]; then + echo "::error::Clang-tidy violations outside score/time_daemon/ grew: $OTHER_COUNT > baseline $OTHER_BASELINE. Fix new violations before merging." exit 1 fi diff --git a/BUILD b/BUILD index c3780833..c6476148 100644 --- a/BUILD +++ b/BUILD @@ -49,5 +49,7 @@ exports_files( [ # Used by the @score_tooling coverage reporter to locate the workspace root. "MODULE.bazel", + # Referenced by //tools/lint:linters.bzl as a local_configs entry for the clang-tidy aspect. + ".clang-tidy", ], ) diff --git a/MODULE.bazel b/MODULE.bazel index 256d1057..32ce7e51 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -111,6 +111,7 @@ llvm = use_extension( ) llvm.toolchain( llvm_version = "19.1.7", + stdlib = {"": "stdc++"}, ) # Coverage-only Clang instance (covmap instrumentation for the LLVM coverage diff --git a/score/time_daemon/src/application/job_runner/job_runner.cpp b/score/time_daemon/src/application/job_runner/job_runner.cpp index 9f3f40a5..69c7ee84 100644 --- a/score/time_daemon/src/application/job_runner/job_runner.cpp +++ b/score/time_daemon/src/application/job_runner/job_runner.cpp @@ -13,22 +13,23 @@ #include "score/time_daemon/src/application/job_runner/job_runner.h" #include "score/concurrency/interruptible_wait.h" #include "score/mw/log/logging.h" +#include "score/stop_token.hpp" #include "score/time_daemon/src/common/logging_contexts.h" +#include +#include +#include +#include +#include -namespace score -{ -namespace td +namespace score::td { -JobRunner::JobRunner(std::vector jobs, const std::string name) - : jobs_(std::move(jobs)), name_(name), status_{Result::kIdle} -{ -} +JobRunner::JobRunner(std::vector jobs, std::string name) : jobs_(std::move(jobs)), name_(std::move(name)) {} void JobRunner::Start(const score::cpp::stop_token& token) { { - std::lock_guard lock(status_mutex_); + const std::lock_guard lock(status_mutex_); if (status_ != Result::kIdle) { return; // Already running @@ -41,9 +42,9 @@ void JobRunner::Start(const score::cpp::stop_token& token) const auto thread_name = "td_" + name_ + "_worker"; worker_thread_ = score::cpp::jthread(score::cpp::jthread::name_hint{thread_name}, [this, &token]() { - bool success = RunJobs(token); + const bool success = RunJobs(token); { - std::lock_guard lock(status_mutex_); + const std::lock_guard lock(status_mutex_); status_ = success ? Result::kSucceed : Result::kFailed; } }); @@ -83,7 +84,10 @@ bool JobRunner::RunJobs(const score::cpp::stop_token& token) } if (!jobs_.empty()) - score::concurrency::wait_for(token, std::chrono::milliseconds(10)); + { + constexpr auto kJobPollInterval = std::chrono::milliseconds(10); + score::concurrency::wait_for(token, kJobPollInterval); + } } // If the loop exited due to stop token, mark as failure if (token.stop_requested()) @@ -96,9 +100,8 @@ bool JobRunner::RunJobs(const score::cpp::stop_token& token) JobRunner::Result JobRunner::GetResult() const { - std::lock_guard lock(status_mutex_); + const std::lock_guard lock(status_mutex_); return status_; } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/application/job_runner/job_runner.h b/score/time_daemon/src/application/job_runner/job_runner.h index 25c5728a..4e9ca283 100644 --- a/score/time_daemon/src/application/job_runner/job_runner.h +++ b/score/time_daemon/src/application/job_runner/job_runner.h @@ -16,13 +16,13 @@ #include #include #include +#include #include +#include #include #include -namespace score -{ -namespace td +namespace score::td { /** @@ -33,7 +33,7 @@ struct Job std::function fn; std::string name; std::chrono::seconds timeout; - std::chrono::steady_clock::time_point start{}; + std::chrono::steady_clock::time_point start; }; /** @@ -51,12 +51,12 @@ class JobRunner * @param jobs Vector of jobs to run. * @param name name of the job. */ - JobRunner(std::vector jobs, const std::string name); + JobRunner(std::vector jobs, std::string name); /** * @brief Represents the jobs status */ - enum class Result + enum class Result : std::uint8_t { kIdle, kInProgress, @@ -89,12 +89,11 @@ class JobRunner std::vector jobs_; const std::string name_; - Result status_; + Result status_{Result::kIdle}; mutable std::mutex status_mutex_; score::cpp::jthread worker_thread_; }; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_APPLICATION_JOB_RUNNER_JOB_RUNNER_H diff --git a/score/time_daemon/src/application/job_runner/job_runner_test.cpp b/score/time_daemon/src/application/job_runner/job_runner_test.cpp index bbae144c..124cb70b 100644 --- a/score/time_daemon/src/application/job_runner/job_runner_test.cpp +++ b/score/time_daemon/src/application/job_runner/job_runner_test.cpp @@ -18,9 +18,7 @@ #include #include -namespace score -{ -namespace td +namespace score::td { /** @@ -179,5 +177,4 @@ TEST_F(JobRunnerTest, StopMultipleJobsEarly) EXPECT_LE(counter.load(), 2); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/application/svt/factory.cpp b/score/time_daemon/src/application/svt/factory.cpp index 5d082e1b..273892b0 100644 --- a/score/time_daemon/src/application/svt/factory.cpp +++ b/score/time_daemon/src/application/svt/factory.cpp @@ -13,10 +13,10 @@ #include "score/time_daemon/src/application/svt/factory.h" #include "score/time_daemon/src/application/svt/svt_handler.h" +#include "score/time_daemon/src/application/timebase_handler.h" +#include -namespace score -{ -namespace td +namespace score::td { std::unique_ptr CreateSvtTimebase() @@ -24,5 +24,4 @@ std::unique_ptr CreateSvtTimebase() return std::make_unique(); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/application/svt/factory.h b/score/time_daemon/src/application/svt/factory.h index be6b69f1..122ed8c6 100644 --- a/score/time_daemon/src/application/svt/factory.h +++ b/score/time_daemon/src/application/svt/factory.h @@ -17,9 +17,7 @@ #include -namespace score -{ -namespace td +namespace score::td { /// \brief Creates a new SVT timebase handler @@ -27,7 +25,6 @@ namespace td /// \return std::unique_ptr New SVT timebase handler std::unique_ptr CreateSvtTimebase(); -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_APPLICATION_FACTORY_H diff --git a/score/time_daemon/src/application/svt/svt_handler.cpp b/score/time_daemon/src/application/svt/svt_handler.cpp index 847bb687..2dce4de6 100644 --- a/score/time_daemon/src/application/svt/svt_handler.cpp +++ b/score/time_daemon/src/application/svt/svt_handler.cpp @@ -11,23 +11,31 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ #include "score/time_daemon/src/application/svt/svt_handler.h" -#include "score/concurrency/interruptible_wait.h" #include "score/mw/log/logging.h" +#include "score/stop_token.hpp" +#include "score/time_daemon/src/application/job_runner/job_runner.h" +#include "score/time_daemon/src/application/timebase_handler.h" +#include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include "score/time_daemon/src/common/logging_contexts.h" #include "score/time_daemon/src/control_flow_divider/ptp/factory.h" #include "score/time_daemon/src/ipc/svt/publisher/factory.h" -#include "score/time_daemon/src/msg_broker/subscription.h" +#include "score/time_daemon/src/msg_broker/msg_broker.h" #include "score/time_daemon/src/msg_broker/topic.h" #include "score/time_daemon/src/ptp_machine/shm/factory.h" #include "score/time_daemon/src/verification_machine/svt/factory.h" - #include -#include +#include +#include +#include -namespace score +namespace score::td { -namespace td + +namespace { +constexpr auto kCtrlFlowDividerTimeout = std::chrono::milliseconds{250}; +constexpr auto kJobInitTimeout = std::chrono::seconds(20); +} // namespace SvtHandler::SvtHandler() noexcept : job_runner_{nullptr}, @@ -35,36 +43,35 @@ SvtHandler::SvtHandler() noexcept gptp_machine_{nullptr}, verification_machine_{nullptr}, ipc_publisher_{nullptr}, - ctrl_flow_divider_{nullptr}, - handler_status_{TimebaseHandler::Status::kIdle} + ctrl_flow_divider_{nullptr} { msg_broker_ = std::make_shared>(); gptp_machine_ = CreateGPTPShmMachine("ptp_worker"); verification_machine_ = CreateSvtVerificationMachine("time_verification_worker"); ipc_publisher_ = CreateSvtPublisher("svt_ipc_publisher"); - ctrl_flow_divider_ = CreatePtpControlFlowDivider("ptp_control_flow_divider", std::chrono::milliseconds{250}); + ctrl_flow_divider_ = CreatePtpControlFlowDivider("ptp_control_flow_divider", kCtrlFlowDividerTimeout); std::vector jobs = { {[this] { return gptp_machine_->Init(); }, gptp_machine_->GetName(), - std::chrono::seconds(20)}, + kJobInitTimeout}, {[this] { return verification_machine_->Init(); }, verification_machine_->GetName(), - std::chrono::seconds(20)}, + kJobInitTimeout}, {[this] { return ipc_publisher_->Init(); }, ipc_publisher_->GetName(), - std::chrono::seconds(20)}, + kJobInitTimeout}, {[this] { return ctrl_flow_divider_->Init(); }, ctrl_flow_divider_->GetName(), - std::chrono::seconds(20)}, + kJobInitTimeout}, }; job_runner_ = std::make_unique(std::move(jobs), "svt_init"); @@ -145,5 +152,4 @@ void SvtHandler::Stop() noexcept } } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/application/svt/svt_handler.h b/score/time_daemon/src/application/svt/svt_handler.h index 5fef4d01..dd6bc281 100644 --- a/score/time_daemon/src/application/svt/svt_handler.h +++ b/score/time_daemon/src/application/svt/svt_handler.h @@ -23,9 +23,7 @@ #include -namespace score -{ -namespace td +namespace score::td { /// \brief Concrete implementation of a TimebaseHandler for SVT. @@ -41,7 +39,7 @@ class SvtHandler : public TimebaseHandler { public: SvtHandler() noexcept; - virtual ~SvtHandler() noexcept = default; + ~SvtHandler() noexcept override = default; SvtHandler(const SvtHandler&) = delete; SvtHandler(SvtHandler&&) = delete; SvtHandler& operator=(const SvtHandler&) = delete; @@ -52,7 +50,7 @@ class SvtHandler : public TimebaseHandler /// This function sets up all necessary subsystems and prepares the handler /// for running. It overrides the abstract Initialize method from /// TimebaseHandler. - virtual void Initialize() noexcept override; + void Initialize() noexcept override; /// \brief Runs once the SVT timebase handler main functionality /// @@ -61,25 +59,24 @@ class SvtHandler : public TimebaseHandler /// operation is non blocking /// /// \param token Stop token used to safely terminate the run loop - virtual void RunOnce(const score::cpp::stop_token& token) noexcept override; + void RunOnce(const score::cpp::stop_token& token) noexcept override; /// \brief Stops the SVT timebase handler /// /// Safely stops the timebase operations and releases any resources. /// Overrides the abstract Stop method from TimebaseHandler. - virtual void Stop() noexcept override; + void Stop() noexcept override; private: - std::unique_ptr job_runner_; ///< Manages periodic jobs and tasks - std::shared_ptr> msg_broker_; ///< Handles message communication - std::shared_ptr gptp_machine_; ///< Manages GPTP synchronization - std::shared_ptr verification_machine_; ///< Handles SVT verification - std::shared_ptr ipc_publisher_; ///< Publishes SVT data via IPC - std::shared_ptr ctrl_flow_divider_; ///< Divides PTP control flow - TimebaseHandler::Status handler_status_; ///< Current status of the handler + std::unique_ptr job_runner_; ///< Manages periodic jobs and tasks + std::shared_ptr> msg_broker_; ///< Handles message communication + std::shared_ptr gptp_machine_; ///< Manages GPTP synchronization + std::shared_ptr verification_machine_; ///< Handles SVT verification + std::shared_ptr ipc_publisher_; ///< Publishes SVT data via IPC + std::shared_ptr ctrl_flow_divider_; ///< Divides PTP control flow + TimebaseHandler::Status handler_status_{TimebaseHandler::Status::kIdle}; ///< Current status of the handler }; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_APPLICATION_SVT_HANDLER_H diff --git a/score/time_daemon/src/application/time_daemon.cpp b/score/time_daemon/src/application/time_daemon.cpp index 9638c1cc..67569fac 100644 --- a/score/time_daemon/src/application/time_daemon.cpp +++ b/score/time_daemon/src/application/time_daemon.cpp @@ -11,23 +11,26 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ #include "score/time_daemon/src/application/time_daemon.h" +#include "score/mw/lifecycle/applicationcontext.h" #include "score/time_daemon/src/application/svt/factory.h" #include "score/time_daemon/src/common/logging_contexts.h" #include "score/concurrency/interruptible_wait.h" #include "score/mw/log/logging.h" +#include "score/stop_token.hpp" +#include +#include +#include -namespace score -{ -namespace td +namespace score::td { -TimeDaemon::TimeDaemon() : score::mw::lifecycle::Application() +TimeDaemon::TimeDaemon() { svt_timebase_handler_ = CreateSvtTimebase(); } -std::int32_t TimeDaemon::Initialize(const score::mw::lifecycle::ApplicationContext&) +std::int32_t TimeDaemon::Initialize(const score::mw::lifecycle::ApplicationContext& /*context*/) { score::mw::log::LogInfo(kAppContext) << "TimeDaemon initializing..."; @@ -41,10 +44,11 @@ std::int32_t TimeDaemon::Run(const score::cpp::stop_token& token) { score::mw::log::LogInfo(kAppContext) << "Run() started"; + constexpr auto kRunLoopPollInterval = std::chrono::milliseconds(100); while (!token.stop_requested()) { svt_timebase_handler_->RunOnce(token); - score::concurrency::wait_for(token, std::chrono::milliseconds(100)); + score::concurrency::wait_for(token, kRunLoopPollInterval); } svt_timebase_handler_->Stop(); @@ -53,5 +57,4 @@ std::int32_t TimeDaemon::Run(const score::cpp::stop_token& token) return EXIT_SUCCESS; } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/application/time_daemon.h b/score/time_daemon/src/application/time_daemon.h index 91108263..02f69457 100644 --- a/score/time_daemon/src/application/time_daemon.h +++ b/score/time_daemon/src/application/time_daemon.h @@ -17,9 +17,7 @@ #include "score/mw/lifecycle/application.h" -namespace score -{ -namespace td +namespace score::td { class TimeDaemon final : public score::mw::lifecycle::Application @@ -40,7 +38,6 @@ class TimeDaemon final : public score::mw::lifecycle::Application std::unique_ptr svt_timebase_handler_; }; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_APPLICATION_TIME_DAEMON_H diff --git a/score/time_daemon/src/application/timebase_handler.h b/score/time_daemon/src/application/timebase_handler.h index 518faf66..74b8f406 100644 --- a/score/time_daemon/src/application/timebase_handler.h +++ b/score/time_daemon/src/application/timebase_handler.h @@ -14,11 +14,10 @@ #define SCORE_TIME_DAEMON_SRC_APPLICATION_TIMEBASE_HANDLER_H #include +#include #include -namespace score -{ -namespace td +namespace score::td { /// \brief Abstract base class to handle timebase operations @@ -48,7 +47,7 @@ class TimebaseHandler TimebaseHandler& operator=(TimebaseHandler&&) = delete; /// \brief Status of the timebase handler - enum class Status + enum class Status : std::uint8_t { kIdle = 0, ///< Handler is idle, not initialized kInitialize, ///< Handle is initializing @@ -76,7 +75,6 @@ class TimebaseHandler virtual void Stop() noexcept = 0; }; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_APPLICATION_TIMEBASE_HANDLER_H diff --git a/score/time_daemon/src/common/data_flow/consumer.h b/score/time_daemon/src/common/data_flow/consumer.h index 60bfc55e..7bb31bb6 100644 --- a/score/time_daemon/src/common/data_flow/consumer.h +++ b/score/time_daemon/src/common/data_flow/consumer.h @@ -16,9 +16,7 @@ #include #include -namespace score -{ -namespace td +namespace score::td { /** @@ -50,7 +48,6 @@ class Consumer Consumer& operator=(Consumer&&) = default; }; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_COMMON_DATA_FLOW_CONSUMER_H diff --git a/score/time_daemon/src/common/data_flow/producer.h b/score/time_daemon/src/common/data_flow/producer.h index 47230a2e..d6814cc5 100644 --- a/score/time_daemon/src/common/data_flow/producer.h +++ b/score/time_daemon/src/common/data_flow/producer.h @@ -15,9 +15,7 @@ #include -namespace score -{ -namespace td +namespace score::td { /** @@ -63,7 +61,6 @@ class Producer virtual void Publish(const T& data) = 0; }; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_COMMON_DATA_FLOW_PRODUCER_H diff --git a/score/time_daemon/src/common/data_flow/producer_consumer_test.cpp b/score/time_daemon/src/common/data_flow/producer_consumer_test.cpp index 237ed590..9c65f5ef 100644 --- a/score/time_daemon/src/common/data_flow/producer_consumer_test.cpp +++ b/score/time_daemon/src/common/data_flow/producer_consumer_test.cpp @@ -16,13 +16,12 @@ #include "gmock/gmock.h" #include -#include +#include +#include using ::testing::_; -namespace score -{ -namespace td +namespace score::td { namespace test { @@ -94,7 +93,7 @@ class FakeConsumerProducerMachine : public Consumer, public Produc } // Consumer interface - virtual void OnMessage(FakeTimeInfo data) override + void OnMessage(FakeTimeInfo data) override { Publish(std::move(data)); } @@ -221,5 +220,4 @@ TEST_F(ProducerConsumerTest, TestProducerConsumerNotificationChain) initialProducer.Publish(testData); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/common/data_types/ptp_time_info.cpp b/score/time_daemon/src/common/data_types/ptp_time_info.cpp index 2d2bf3db..a470bc4a 100644 --- a/score/time_daemon/src/common/data_types/ptp_time_info.cpp +++ b/score/time_daemon/src/common/data_types/ptp_time_info.cpp @@ -12,14 +12,12 @@ ********************************************************************************/ #include "score/time_daemon/src/common/data_types/ptp_time_info.h" -#include #include #include +#include #include -namespace score -{ -namespace td +namespace score::td { namespace @@ -113,25 +111,24 @@ bool operator!=(const PtpTimeInfo& first, const PtpTimeInfo& second) noexcept } /// \brief gtest compatibility: -void PrintTo(const PtpStatus& status, std::ostream* os) +void PrintTo(const PtpStatus& status, std::ostream* out_stream) { - std::ignore = PrintTo(status, *os); + std::ignore = PrintTo(status, *out_stream); } -void PrintTo(const SyncFupData& data, std::ostream* os) +void PrintTo(const SyncFupData& data, std::ostream* out_stream) { - std::ignore = PrintTo(data, *os); + std::ignore = PrintTo(data, *out_stream); } -void PrintTo(const PDelayData& data, std::ostream* os) +void PrintTo(const PDelayData& data, std::ostream* out_stream) { - std::ignore = PrintTo(data, *os); + std::ignore = PrintTo(data, *out_stream); } -void PrintTo(const PtpTimeInfo& info, std::ostream* os) +void PrintTo(const PtpTimeInfo& info, std::ostream* out_stream) { - std::ignore = PrintTo(info, *os); + std::ignore = PrintTo(info, *out_stream); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/common/data_types/ptp_time_info.h b/score/time_daemon/src/common/data_types/ptp_time_info.h index 10a8a879..419ff4a5 100644 --- a/score/time_daemon/src/common/data_types/ptp_time_info.h +++ b/score/time_daemon/src/common/data_types/ptp_time_info.h @@ -19,9 +19,7 @@ #include "score/time/high_res_steady_time/src/high_res_steady_clock.h" -namespace score -{ -namespace td +namespace score::td { /** @@ -101,69 +99,70 @@ bool operator!=(const PtpTimeInfo& first, const PtpTimeInfo& second) noexcept; /// \brief PrintTo and stream operators: template -inline auto& PrintTo(const PtpStatus& status, OutputStream& os) +inline auto& PrintTo(const PtpStatus& status, OutputStream& out_stream) { - return os << "Status: [" << status.is_synchronized << "|" << status.is_timeout << "|" << status.is_time_jump_future - << "|" << status.is_time_jump_past << "|" << status.is_correct << "]"; + return out_stream << "Status: [" << status.is_synchronized << "|" << status.is_timeout << "|" + << status.is_time_jump_future << "|" << status.is_time_jump_past << "|" << status.is_correct + << "]"; } template -inline auto& operator<<(OutputStream& os, const PtpStatus& status) +inline auto& operator<<(OutputStream& out_stream, const PtpStatus& status) { - return PrintTo(status, os); + return PrintTo(status, out_stream); } template -inline auto& PrintTo(const SyncFupData& data, OutputStream& os) +inline auto& PrintTo(const SyncFupData& data, OutputStream& out_stream) { - return os << "SyncFupData:" << "[" << data.precise_origin_timestamp << "|" << data.reference_global_timestamp << "|" - << data.reference_local_timestamp << "|" << data.sync_ingress_timestamp << "|" << data.correction_field - << "|" << data.sequence_id << "|" << data.pdelay << "|" << data.port_number << "|" << data.clock_identity - << "]"; + return out_stream << "SyncFupData:" << "[" << data.precise_origin_timestamp << "|" + << data.reference_global_timestamp << "|" << data.reference_local_timestamp << "|" + << data.sync_ingress_timestamp << "|" << data.correction_field << "|" << data.sequence_id << "|" + << data.pdelay << "|" << data.port_number << "|" << data.clock_identity << "]"; } template -inline auto& operator<<(OutputStream& os, const SyncFupData& data) +inline auto& operator<<(OutputStream& out_stream, const SyncFupData& data) { - return PrintTo(data, os); + return PrintTo(data, out_stream); } template -inline auto& PrintTo(const PDelayData& data, OutputStream& os) +inline auto& PrintTo(const PDelayData& data, OutputStream& out_stream) { - return os << "PDelayData:" << "[" << data.request_origin_timestamp << "|" << data.request_receipt_timestamp << "|" - << data.response_origin_timestamp << "|" << data.response_receipt_timestamp << "|" - << data.reference_global_timestamp << "|" << data.reference_local_timestamp << "|" << data.sequence_id - << "|" << data.pdelay << "|" << data.req_port_number << "|" << data.req_clock_identity << "|" - << data.resp_port_number << "|" << data.resp_clock_identity << "]"; + return out_stream << "PDelayData:" << "[" << data.request_origin_timestamp << "|" << data.request_receipt_timestamp + << "|" << data.response_origin_timestamp << "|" << data.response_receipt_timestamp << "|" + << data.reference_global_timestamp << "|" << data.reference_local_timestamp << "|" + << data.sequence_id << "|" << data.pdelay << "|" << data.req_port_number << "|" + << data.req_clock_identity << "|" << data.resp_port_number << "|" << data.resp_clock_identity + << "]"; } template -inline auto& operator<<(OutputStream& os, const PDelayData& data) +inline auto& operator<<(OutputStream& out_stream, const PDelayData& data) { - return PrintTo(data, os); + return PrintTo(data, out_stream); } template -inline auto& PrintTo(const PtpTimeInfo& info, OutputStream& os) +inline auto& PrintTo(const PtpTimeInfo& info, OutputStream& out_stream) { - return os << "[" << info.ptp_assumed_time.count() << "|" << info.local_time.time_since_epoch().count() << "|" - << info.status << "|" << info.sync_fup_data << "|" << info.pdelay_data << "]"; + return out_stream << "[" << info.ptp_assumed_time.count() << "|" << info.local_time.time_since_epoch().count() + << "|" << info.status << "|" << info.sync_fup_data << "|" << info.pdelay_data << "]"; } template -inline auto& operator<<(OutputStream& os, const PtpTimeInfo& info) +inline auto& operator<<(OutputStream& out_stream, const PtpTimeInfo& info) { - return PrintTo(info, os); + return PrintTo(info, out_stream); } /// \brief gtest compatibility: -void PrintTo(const PtpStatus& status, std::ostream* os); -void PrintTo(const SyncFupData& data, std::ostream* os); -void PrintTo(const PDelayData& data, std::ostream* os); -void PrintTo(const PtpTimeInfo& info, std::ostream* os); +void PrintTo(const PtpStatus& status, std::ostream* out_stream); +void PrintTo(const SyncFupData& data, std::ostream* out_stream); +void PrintTo(const PDelayData& data, std::ostream* out_stream); +void PrintTo(const PtpTimeInfo& info, std::ostream* out_stream); -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_COMMON_DATA_TYPES_PTP_TIME_INFO_H diff --git a/score/time_daemon/src/common/data_types/ptp_time_info_test.cpp b/score/time_daemon/src/common/data_types/ptp_time_info_test.cpp index a224bbac..938dc932 100644 --- a/score/time_daemon/src/common/data_types/ptp_time_info_test.cpp +++ b/score/time_daemon/src/common/data_types/ptp_time_info_test.cpp @@ -12,17 +12,14 @@ ********************************************************************************/ #include "score/time_daemon/src/common/data_types/ptp_time_info.h" -#include #include #include +#include #include -#include #include -namespace score -{ -namespace td +namespace score::td { namespace @@ -347,5 +344,4 @@ INSTANTIATE_TEST_SUITE_P( }}), FieldMutationName); -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/common/logging_contexts.h b/score/time_daemon/src/common/logging_contexts.h index 85a7c589..0f60cd05 100644 --- a/score/time_daemon/src/common/logging_contexts.h +++ b/score/time_daemon/src/common/logging_contexts.h @@ -15,9 +15,7 @@ #include -namespace score -{ -namespace td +namespace score::td { // Application context @@ -38,7 +36,6 @@ constexpr auto kVerificationMachineContext = "VERM"; // Control Flow Divider context constexpr auto kControlFlowDividerContext = "CFDV"; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_COMMON_LOGGING_CONTEXTS_H diff --git a/score/time_daemon/src/common/machines/base_machine.cpp b/score/time_daemon/src/common/machines/base_machine.cpp index 326e378b..41b7eb77 100644 --- a/score/time_daemon/src/common/machines/base_machine.cpp +++ b/score/time_daemon/src/common/machines/base_machine.cpp @@ -11,13 +11,12 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ #include "score/time_daemon/src/common/machines/base_machine.h" +#include +#include -namespace score -{ -namespace td +namespace score::td { -BaseMachine::BaseMachine(const std::string& name) : name_(name) {} +BaseMachine::BaseMachine(std::string name) : name_(std::move(name)) {} -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/common/machines/base_machine.h b/score/time_daemon/src/common/machines/base_machine.h index 87f10507..7ca71900 100644 --- a/score/time_daemon/src/common/machines/base_machine.h +++ b/score/time_daemon/src/common/machines/base_machine.h @@ -15,9 +15,7 @@ #include -namespace score -{ -namespace td +namespace score::td { /** @@ -35,11 +33,12 @@ class BaseMachine * * @param name The name of the machine. */ - explicit BaseMachine(const std::string& name); + explicit BaseMachine(std::string name); virtual ~BaseMachine() = default; - inline std::string GetName() const noexcept + // NOLINTNEXTLINE(modernize-use-nodiscard) + std::string GetName() const noexcept { return name_; } @@ -51,7 +50,8 @@ class BaseMachine **/ virtual bool Init() = 0; - protected: + // Kept public and deleted (not protected) so misuse fails with a clear "call to deleted + // function" diagnostic instead of a confusing "is protected within this context" one. BaseMachine(const BaseMachine& other) = delete; BaseMachine& operator=(const BaseMachine& other) = delete; BaseMachine(BaseMachine&& other) noexcept = delete; @@ -61,7 +61,6 @@ class BaseMachine const std::string name_; }; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_COMMON_MACHINES_BASE_MACHINE_H diff --git a/score/time_daemon/src/common/machines/base_machine_test.cpp b/score/time_daemon/src/common/machines/base_machine_test.cpp index 7f7b36b4..35b318cd 100644 --- a/score/time_daemon/src/common/machines/base_machine_test.cpp +++ b/score/time_daemon/src/common/machines/base_machine_test.cpp @@ -13,10 +13,9 @@ #include "score/time_daemon/src/common/machines/base_machine.h" #include +#include -namespace score -{ -namespace td +namespace score::td { class FakeMachine : public BaseMachine @@ -36,5 +35,4 @@ TEST(BaseMachineTest, Construction) EXPECT_EQ(machine.GetName(), "TestMachine"); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/common/machines/event_driven_machine.cpp b/score/time_daemon/src/common/machines/event_driven_machine.cpp index 27ca88c4..de43fa81 100644 --- a/score/time_daemon/src/common/machines/event_driven_machine.cpp +++ b/score/time_daemon/src/common/machines/event_driven_machine.cpp @@ -11,14 +11,18 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ #include "score/time_daemon/src/common/machines/event_driven_machine.h" +#include "score/stop_token.hpp" +#include "score/time_daemon/src/common/machines/proactive_machine.h" +#include "score/utility.hpp" +#include +#include +#include -namespace score -{ -namespace td +namespace score::td { EventDrivenMachine::EventDrivenMachine(const std::string& name, const std::chrono::milliseconds timeout) - : ProactiveMachine(name), cv_mutex_{}, cv_{}, worker_{}, kTimeout_(timeout), event_pending_{false} + : ProactiveMachine(name), kTimeout_(timeout) { } @@ -26,17 +30,20 @@ void EventDrivenMachine::Start() noexcept { const auto thread_name = "td_" + GetName() + "_worker"; worker_ = score::cpp::jthread{score::cpp::jthread::name_hint{thread_name}, - [this](const score::cpp::stop_token token) noexcept { + [this](const score::cpp::stop_token& token) noexcept { WorkerFunction(token); }}; } +// join()/notify_one() escaping here means shutdown is broken beyond recovery; terminating via +// noexcept is the intended behavior, not swallowed here. +// NOLINTNEXTLINE(bugprone-exception-escape) void EventDrivenMachine::Stop() noexcept { if (worker_.joinable()) { { - std::lock_guard guard{cv_mutex_}; + const std::lock_guard guard{cv_mutex_}; score::cpp::ignore = worker_.request_stop(); cv_.notify_one(); } @@ -47,7 +54,7 @@ void EventDrivenMachine::Stop() noexcept void EventDrivenMachine::NotifyEvent() noexcept { - std::lock_guard guard{cv_mutex_}; + const std::lock_guard guard{cv_mutex_}; event_pending_ = true; cv_.notify_one(); } @@ -88,5 +95,4 @@ void EventDrivenMachine::WorkerFunction(const score::cpp::stop_token& stop_token } } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/common/machines/event_driven_machine.h b/score/time_daemon/src/common/machines/event_driven_machine.h index af483d7b..10ce80f8 100644 --- a/score/time_daemon/src/common/machines/event_driven_machine.h +++ b/score/time_daemon/src/common/machines/event_driven_machine.h @@ -20,9 +20,7 @@ #include #include -namespace score -{ -namespace td +namespace score::td { /** @@ -46,7 +44,7 @@ class EventDrivenMachine : public ProactiveMachine * @param name The name of the machine instance. * @param timeout The timeout duration in milliseconds for waiting for events. */ - explicit EventDrivenMachine(const std::string& name, const std::chrono::milliseconds timeout); + explicit EventDrivenMachine(const std::string& name, std::chrono::milliseconds timeout); EventDrivenMachine(const EventDrivenMachine&) = delete; EventDrivenMachine& operator=(const EventDrivenMachine&) = delete; @@ -103,10 +101,9 @@ class EventDrivenMachine : public ProactiveMachine score::cpp::jthread worker_; const std::chrono::milliseconds kTimeout_; - bool event_pending_; + bool event_pending_{false}; }; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_COMMON_MACHINES_EVENT_DRIVEN_MACHINE_H diff --git a/score/time_daemon/src/common/machines/event_driven_machine_test.cpp b/score/time_daemon/src/common/machines/event_driven_machine_test.cpp index c5f2d9bf..6764440d 100644 --- a/score/time_daemon/src/common/machines/event_driven_machine_test.cpp +++ b/score/time_daemon/src/common/machines/event_driven_machine_test.cpp @@ -14,10 +14,10 @@ #include "gmock/gmock.h" #include +#include +#include -namespace score -{ -namespace td +namespace score::td { namespace test { @@ -151,5 +151,4 @@ TEST_F(EventDrivenMachineTest, NotificationOnEvent) sut_->Stop(); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/common/machines/periodic_machine.cpp b/score/time_daemon/src/common/machines/periodic_machine.cpp index afc26b6f..a78e1081 100644 --- a/score/time_daemon/src/common/machines/periodic_machine.cpp +++ b/score/time_daemon/src/common/machines/periodic_machine.cpp @@ -11,14 +11,18 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ #include "score/time_daemon/src/common/machines/periodic_machine.h" +#include "score/stop_token.hpp" +#include "score/time_daemon/src/common/machines/proactive_machine.h" +#include "score/utility.hpp" +#include +#include +#include -namespace score -{ -namespace td +namespace score::td { PeriodicMachine::PeriodicMachine(const std::string& name, const std::chrono::milliseconds threadCycle) - : ProactiveMachine(name), cv_mutex_{}, cv_{}, worker_{}, kCycleTime_(threadCycle) + : ProactiveMachine(name), kCycleTime_(threadCycle) { } @@ -26,17 +30,20 @@ void PeriodicMachine::Start() noexcept { const auto thread_name = "td_" + GetName() + "_worker"; worker_ = score::cpp::jthread{score::cpp::jthread::name_hint{thread_name}, - [this](const score::cpp::stop_token token) noexcept { + [this](const score::cpp::stop_token& token) noexcept { WorkerFunction(token); }}; } +// join()/notify_one() escaping here means shutdown is broken beyond recovery; terminating via +// noexcept is the intended behavior, not swallowed here. +// NOLINTNEXTLINE(bugprone-exception-escape) void PeriodicMachine::Stop() noexcept { if (worker_.joinable()) { { - std::lock_guard guard{cv_mutex_}; + const std::lock_guard guard{cv_mutex_}; score::cpp::ignore = worker_.request_stop(); cv_.notify_one(); } @@ -62,5 +69,4 @@ void PeriodicMachine::WorkerFunction(const score::cpp::stop_token& stop_token) n } } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/common/machines/periodic_machine.h b/score/time_daemon/src/common/machines/periodic_machine.h index 5c2f48bb..98ac7054 100644 --- a/score/time_daemon/src/common/machines/periodic_machine.h +++ b/score/time_daemon/src/common/machines/periodic_machine.h @@ -20,9 +20,7 @@ #include #include -namespace score -{ -namespace td +namespace score::td { /** @@ -42,7 +40,7 @@ class PeriodicMachine : public ProactiveMachine * @param name The name of the machine instance * @param threadCycle The periodic execution interval in milliseconds */ - explicit PeriodicMachine(const std::string& name, const std::chrono::milliseconds threadCycle); + explicit PeriodicMachine(const std::string& name, std::chrono::milliseconds threadCycle); PeriodicMachine(const PeriodicMachine&) = delete; PeriodicMachine& operator=(const PeriodicMachine&) = delete; @@ -91,7 +89,6 @@ class PeriodicMachine : public ProactiveMachine const std::chrono::milliseconds kCycleTime_; }; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_COMMON_MACHINES_PERIODIC_MACHINE_H diff --git a/score/time_daemon/src/common/machines/periodic_machine_test.cpp b/score/time_daemon/src/common/machines/periodic_machine_test.cpp index 9fb5d990..a59c10ec 100644 --- a/score/time_daemon/src/common/machines/periodic_machine_test.cpp +++ b/score/time_daemon/src/common/machines/periodic_machine_test.cpp @@ -14,10 +14,10 @@ #include "gmock/gmock.h" #include +#include +#include -namespace score -{ -namespace td +namespace score::td { namespace test { @@ -127,5 +127,4 @@ TEST_F(PeriodicMachineTest, NoActionsWithoutStartButWithStop) std::this_thread::sleep_for(std::chrono::milliseconds(500)); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/common/machines/proactive_machine.h b/score/time_daemon/src/common/machines/proactive_machine.h index 689dc724..f08a62e3 100644 --- a/score/time_daemon/src/common/machines/proactive_machine.h +++ b/score/time_daemon/src/common/machines/proactive_machine.h @@ -20,9 +20,7 @@ #include #include -namespace score -{ -namespace td +namespace score::td { /** @@ -63,7 +61,6 @@ class ProactiveMachine : public BaseMachine virtual void Stop() noexcept = 0; }; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_COMMON_MACHINES_PROACTIVE_MACHINE_H diff --git a/score/time_daemon/src/common/machines/reactive_machine.h b/score/time_daemon/src/common/machines/reactive_machine.h index a3a8c0a3..c39d4dcc 100644 --- a/score/time_daemon/src/common/machines/reactive_machine.h +++ b/score/time_daemon/src/common/machines/reactive_machine.h @@ -15,9 +15,7 @@ #include "score/time_daemon/src/common/machines/base_machine.h" -namespace score -{ -namespace td +namespace score::td { /** @@ -40,7 +38,6 @@ class ReactiveMachine : public BaseMachine using BaseMachine::BaseMachine; }; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_COMMON_MACHINES_REACTIVE_MACHINE_H diff --git a/score/time_daemon/src/control_flow_divider/core/control_flow_divider.h b/score/time_daemon/src/control_flow_divider/core/control_flow_divider.h index b6e1a9e3..3ac70000 100644 --- a/score/time_daemon/src/control_flow_divider/core/control_flow_divider.h +++ b/score/time_daemon/src/control_flow_divider/core/control_flow_divider.h @@ -27,9 +27,7 @@ #include #include -namespace score -{ -namespace td +namespace score::td { /** @@ -108,20 +106,14 @@ class ControlFlowDivider final : public EventDrivenMachine, public Consumer data_buffer_; /** @brief Callback function for publishing data */ - std::function publish_callback_; + std::function publish_callback_{nullptr}; - DataType last_data_; + DataType last_data_{}; }; template ControlFlowDivider::ControlFlowDivider(const std::string& name, std::chrono::milliseconds timeout) - : EventDrivenMachine(name, timeout), - Consumer(), - Producer(), - data_buffer_mutex_{}, - data_buffer_{}, - publish_callback_{nullptr}, - last_data_{} + : EventDrivenMachine(name, timeout), Consumer(), Producer(), data_buffer_{} { score::mw::log::LogInfo(kControlFlowDividerContext) << "ControlFlowDivider created with timeout: " << timeout.count() << "ms"; @@ -204,7 +196,6 @@ void ControlFlowDivider::Publish(const DataType& data) } } -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_CONTROL_FLOW_DIVIDER_CORE_CONTROL_FLOW_DIVIDER_H diff --git a/score/time_daemon/src/control_flow_divider/core/control_flow_divider_test.cpp b/score/time_daemon/src/control_flow_divider/core/control_flow_divider_test.cpp index afb91fa9..73800645 100644 --- a/score/time_daemon/src/control_flow_divider/core/control_flow_divider_test.cpp +++ b/score/time_daemon/src/control_flow_divider/core/control_flow_divider_test.cpp @@ -15,17 +15,14 @@ #include #include -#include -#include +#include #include #include #include using namespace std::chrono_literals; -namespace score -{ -namespace td +namespace score::td { using ::testing::_; @@ -210,5 +207,4 @@ TEST_F(ControlFlowDividerTest, TestNormalQueueBehavior) } } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/control_flow_divider/ptp/factory.cpp b/score/time_daemon/src/control_flow_divider/ptp/factory.cpp index 1c4dc925..0aed5eb9 100644 --- a/score/time_daemon/src/control_flow_divider/ptp/factory.cpp +++ b/score/time_daemon/src/control_flow_divider/ptp/factory.cpp @@ -11,13 +11,13 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ #include "score/time_daemon/src/control_flow_divider/ptp/factory.h" -#include "score/time_daemon/src/common/logging_contexts.h" -#include "score/mw/log/logging.h" +#include "score/time_daemon/src/control_flow_divider/ptp/ptp_control_flow_divider.h" +#include +#include +#include -namespace score -{ -namespace td +namespace score::td { std::shared_ptr CreatePtpControlFlowDivider(const std::string& name, @@ -26,5 +26,4 @@ std::shared_ptr CreatePtpControlFlowDivider(const std::st return std::make_shared(name, timeout); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/control_flow_divider/ptp/factory.h b/score/time_daemon/src/control_flow_divider/ptp/factory.h index cac2c848..1b79fd2f 100644 --- a/score/time_daemon/src/control_flow_divider/ptp/factory.h +++ b/score/time_daemon/src/control_flow_divider/ptp/factory.h @@ -19,9 +19,7 @@ #include #include -namespace score -{ -namespace td +namespace score::td { /** @@ -38,7 +36,6 @@ namespace td std::shared_ptr CreatePtpControlFlowDivider(const std::string& name, std::chrono::milliseconds timeout); -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_CONTROL_FLOW_DIVIDER_PTP_FACTORY_H diff --git a/score/time_daemon/src/control_flow_divider/ptp/factory_test.cpp b/score/time_daemon/src/control_flow_divider/ptp/factory_test.cpp index b1f05b19..1e1f32fd 100644 --- a/score/time_daemon/src/control_flow_divider/ptp/factory_test.cpp +++ b/score/time_daemon/src/control_flow_divider/ptp/factory_test.cpp @@ -11,19 +11,12 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ #include "score/time_daemon/src/control_flow_divider/ptp/factory.h" -#include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include -#include -#include -#include - using namespace std::chrono_literals; -namespace score -{ -namespace td +namespace score::td { class PtpControlFlowDividerFactoryTest : public ::testing::Test @@ -60,5 +53,4 @@ TEST_F(PtpControlFlowDividerFactoryTest, InitializeCreatedInstance) EXPECT_TRUE(divider->Init()); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/control_flow_divider/ptp/ptp_control_flow_divider.h b/score/time_daemon/src/control_flow_divider/ptp/ptp_control_flow_divider.h index 966dd25c..6377d02e 100644 --- a/score/time_daemon/src/control_flow_divider/ptp/ptp_control_flow_divider.h +++ b/score/time_daemon/src/control_flow_divider/ptp/ptp_control_flow_divider.h @@ -18,9 +18,7 @@ #include -namespace score -{ -namespace td +namespace score::td { /** @@ -31,7 +29,6 @@ namespace td constexpr size_t kBufferSize = 10U; using PtpControlFlowDivider = ControlFlowDivider; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_CONTROL_FLOW_DIVIDER_PTP_PTP_CONTROL_FLOW_DIVIDER_H diff --git a/score/time_daemon/src/control_flow_divider/ptp/ptp_control_flow_divider_test.cpp b/score/time_daemon/src/control_flow_divider/ptp/ptp_control_flow_divider_test.cpp index aa378fdd..9f8e2072 100644 --- a/score/time_daemon/src/control_flow_divider/ptp/ptp_control_flow_divider_test.cpp +++ b/score/time_daemon/src/control_flow_divider/ptp/ptp_control_flow_divider_test.cpp @@ -10,21 +10,21 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ +#include "score/time_daemon/src/control_flow_divider/ptp/ptp_control_flow_divider.h" #include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include "score/time_daemon/src/control_flow_divider/ptp/factory.h" #include #include +#include #include #include #include using namespace std::chrono_literals; -namespace score -{ -namespace td +namespace score::td { class PtpControlFlowDividerTest : public ::testing::Test @@ -174,5 +174,4 @@ TEST_F(PtpControlFlowDividerTest, TestTimeoutBehavior) } } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/ipc/core/publisher_impl.h b/score/time_daemon/src/ipc/core/publisher_impl.h index 40ed78ed..e45f52bd 100644 --- a/score/time_daemon/src/ipc/core/publisher_impl.h +++ b/score/time_daemon/src/ipc/core/publisher_impl.h @@ -20,9 +20,7 @@ #include "score/time_daemon/src/ipc/core/shared_memory_handler.h" #include "score/time_daemon/src/ipc/data_converter.h" -namespace score -{ -namespace td +namespace score::td { /// @@ -63,7 +61,6 @@ void PublisherImpl::OnMessage(DataType data) shm_handler_.Send(ipc_data); } -} // namespace td -} // namespace score +} // namespace score::td #endif // #ifndef SCORE_TIME_DAEMON_SRC_IPC_CORE_PUBLISHER_IMPL_H diff --git a/score/time_daemon/src/ipc/core/publisher_impl_test.cpp b/score/time_daemon/src/ipc/core/publisher_impl_test.cpp index f794f335..fc504f17 100644 --- a/score/time_daemon/src/ipc/core/publisher_impl_test.cpp +++ b/score/time_daemon/src/ipc/core/publisher_impl_test.cpp @@ -10,15 +10,15 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#include "score/time_daemon/src/ipc/core/publisher_impl.h" -#include "score/time_daemon/src/ipc/core/shared_memory_handler.h" #include "score/time_daemon/src/ipc/core/test_types.h" +#include "score/memory/shared/shared_memory_factory.h" +#include "score/time_daemon/src/ipc/core/publisher_impl.h" +#include "score/time_daemon/src/ipc/core/shared_memory_handler.h" #include +#include -namespace score -{ -namespace td +namespace score::td { class PublisherTest : public ::testing::Test @@ -73,5 +73,4 @@ TEST_F(PublisherTest, TestWriteWithoutInit) EXPECT_NE(data.value(), input_data); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/ipc/core/receiver_impl.h b/score/time_daemon/src/ipc/core/receiver_impl.h index 1cc905fc..ad2ddb54 100644 --- a/score/time_daemon/src/ipc/core/receiver_impl.h +++ b/score/time_daemon/src/ipc/core/receiver_impl.h @@ -17,9 +17,7 @@ #include "score/time_daemon/src/ipc/core/shared_memory_handler.h" -namespace score -{ -namespace td +namespace score::td { /// @@ -60,7 +58,6 @@ std::optional ReceiverImpl::Receive() noexcept return shm_handler_.Receive(); } -} // namespace td -} // namespace score +} // namespace score::td #endif // #ifndef SCORE_TIME_DAEMON_SRC_IPC_CORE_RECEIVER_IMPL_H diff --git a/score/time_daemon/src/ipc/core/receiver_impl_test.cpp b/score/time_daemon/src/ipc/core/receiver_impl_test.cpp index 9f1cc37d..8452c8bb 100644 --- a/score/time_daemon/src/ipc/core/receiver_impl_test.cpp +++ b/score/time_daemon/src/ipc/core/receiver_impl_test.cpp @@ -10,15 +10,15 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#include "score/time_daemon/src/ipc/core/receiver_impl.h" -#include "score/time_daemon/src/ipc/core/shared_memory_handler.h" #include "score/time_daemon/src/ipc/core/test_types.h" +#include "score/memory/shared/shared_memory_factory.h" +#include "score/time_daemon/src/ipc/core/receiver_impl.h" +#include "score/time_daemon/src/ipc/core/shared_memory_handler.h" #include +#include -namespace score -{ -namespace td +namespace score::td { class ReceiverTest : public ::testing::Test @@ -72,5 +72,4 @@ TEST_F(ReceiverTest, TestReadWithoutInit) EXPECT_FALSE(receiver.Receive().has_value()); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/ipc/core/shared_memory_handler.h b/score/time_daemon/src/ipc/core/shared_memory_handler.h index 207edbda..73c77adb 100644 --- a/score/time_daemon/src/ipc/core/shared_memory_handler.h +++ b/score/time_daemon/src/ipc/core/shared_memory_handler.h @@ -22,9 +22,7 @@ #include #include -namespace score -{ -namespace td +namespace score::td { /// @@ -35,10 +33,8 @@ class SharedMemoryHandler { public: explicit SharedMemoryHandler(const std::string& shared_memory_path) - : shared_memory_path_{shared_memory_path}, - shared_memory_resource_{}, - shared_memory_data_{nullptr}, - max_number_of_read_retries_{10U} + : shared_memory_path_{shared_memory_path}, shared_memory_resource_{} + { } @@ -94,8 +90,8 @@ class SharedMemoryHandler const std::string shared_memory_path_; std::shared_ptr shared_memory_resource_; - SharedMemoryHandler::SharedData* shared_memory_data_; - const std::size_t max_number_of_read_retries_; + SharedMemoryHandler::SharedData* shared_memory_data_{nullptr}; + const std::size_t max_number_of_read_retries_{10U}; }; template @@ -181,7 +177,6 @@ void SharedMemoryHandler::Send(const DataType& data) } } -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_MSG_BROKER_SHARED_DATA_H diff --git a/score/time_daemon/src/ipc/core/shared_memory_handler_test.cpp b/score/time_daemon/src/ipc/core/shared_memory_handler_test.cpp index 22cfe201..cbf43dfb 100644 --- a/score/time_daemon/src/ipc/core/shared_memory_handler_test.cpp +++ b/score/time_daemon/src/ipc/core/shared_memory_handler_test.cpp @@ -10,14 +10,14 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#include "score/time_daemon/src/ipc/core/shared_memory_handler.h" #include "score/time_daemon/src/ipc/core/test_types.h" +#include "score/memory/shared/shared_memory_factory.h" +#include "score/time_daemon/src/ipc/core/shared_memory_handler.h" #include +#include -namespace score -{ -namespace td +namespace score::td { class SharedMemoryHandlerTest : public ::testing::Test @@ -67,5 +67,4 @@ TEST_F(SharedMemoryHandlerTest, TestWriteWithoutInit) EXPECT_FALSE(data.has_value()); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/ipc/core/test_types.h b/score/time_daemon/src/ipc/core/test_types.h index f0ad7559..a2e95dd5 100644 --- a/score/time_daemon/src/ipc/core/test_types.h +++ b/score/time_daemon/src/ipc/core/test_types.h @@ -17,9 +17,7 @@ #include "score/time_daemon/src/ipc/data_converter.h" -namespace score -{ -namespace td +namespace score::td { namespace test { @@ -109,7 +107,6 @@ struct DataConverter } }; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_IPC_CORE_TEST_TYPES_H diff --git a/score/time_daemon/src/ipc/data_converter.h b/score/time_daemon/src/ipc/data_converter.h index 6f76ea3b..5a35ca90 100644 --- a/score/time_daemon/src/ipc/data_converter.h +++ b/score/time_daemon/src/ipc/data_converter.h @@ -15,9 +15,7 @@ #include -namespace score -{ -namespace td +namespace score::td { template @@ -45,7 +43,6 @@ inline Dst ConvertToIpcData(const Src& src) return DataConverter::Convert(src); } -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_IPC_DATA_CONVERTER_H diff --git a/score/time_daemon/src/ipc/receiver.h b/score/time_daemon/src/ipc/receiver.h index 90a6cd6c..45a634fc 100644 --- a/score/time_daemon/src/ipc/receiver.h +++ b/score/time_daemon/src/ipc/receiver.h @@ -15,9 +15,7 @@ #include -namespace score -{ -namespace td +namespace score::td { /// @@ -46,7 +44,6 @@ class Receiver virtual std::optional Receive() noexcept = 0; }; -} // namespace td -} // namespace score +} // namespace score::td #endif // #ifndef SCORE_TIME_DAEMON_SRC_IPC_RECEIVER_H diff --git a/score/time_daemon/src/ipc/receiver_mock.h b/score/time_daemon/src/ipc/receiver_mock.h index 6ef5985a..bc307cf6 100644 --- a/score/time_daemon/src/ipc/receiver_mock.h +++ b/score/time_daemon/src/ipc/receiver_mock.h @@ -17,9 +17,7 @@ #include -namespace score -{ -namespace td +namespace score::td { /// @@ -36,7 +34,6 @@ class ReceiverMock : public Receiver MOCK_METHOD(std::optional, Receive, (), (noexcept, override)); }; -} // namespace td -} // namespace score +} // namespace score::td #endif // #ifndef SCORE_TIME_DAEMON_SRC_IPC_RECEIVER_MOCK_H diff --git a/score/time_daemon/src/ipc/svt/common_factory_test.cpp b/score/time_daemon/src/ipc/svt/common_factory_test.cpp index f552e75e..7df8ff84 100644 --- a/score/time_daemon/src/ipc/svt/common_factory_test.cpp +++ b/score/time_daemon/src/ipc/svt/common_factory_test.cpp @@ -10,14 +10,14 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ +#include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include "score/time_daemon/src/ipc/svt/publisher/factory.h" #include "score/time_daemon/src/ipc/svt/receiver/factory.h" #include +#include -namespace score -{ -namespace td +namespace score::td { TEST(FactoryImplTest, TestReadAndWrite) @@ -41,5 +41,4 @@ TEST(FactoryImplTest, TestReadAndWrite) EXPECT_EQ(receiver->Receive().value(), input_data); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/ipc/svt/config.h b/score/time_daemon/src/ipc/svt/config.h index 9261cd9e..118ada0d 100644 --- a/score/time_daemon/src/ipc/svt/config.h +++ b/score/time_daemon/src/ipc/svt/config.h @@ -15,9 +15,7 @@ #include -namespace score -{ -namespace td +namespace score::td { /// @@ -25,7 +23,6 @@ namespace td /// const std::string kSvtShmemPath{"/svt_shmem_path"}; -} // namespace td -} // namespace score +} // namespace score::td #endif // #ifndef SCORE_TIME_DAEMON_SRC_IPC_SVT_SHMEM_PATH_H diff --git a/score/time_daemon/src/ipc/svt/publisher/factory.cpp b/score/time_daemon/src/ipc/svt/publisher/factory.cpp index 01302db2..a47881e4 100644 --- a/score/time_daemon/src/ipc/svt/publisher/factory.cpp +++ b/score/time_daemon/src/ipc/svt/publisher/factory.cpp @@ -12,10 +12,11 @@ ********************************************************************************/ #include "score/time_daemon/src/ipc/svt/publisher/factory.h" #include "score/time_daemon/src/ipc/svt/config.h" +#include "score/time_daemon/src/ipc/svt/publisher/svt_publisher.h" +#include +#include -namespace score -{ -namespace td +namespace score::td { std::shared_ptr CreateSvtPublisher(const std::string& machine_name) @@ -23,5 +24,4 @@ std::shared_ptr CreateSvtPublisher(const std::string& machine_name return std::make_shared(machine_name, kSvtShmemPath); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/ipc/svt/publisher/factory.h b/score/time_daemon/src/ipc/svt/publisher/factory.h index a7f88513..a320ca18 100644 --- a/score/time_daemon/src/ipc/svt/publisher/factory.h +++ b/score/time_daemon/src/ipc/svt/publisher/factory.h @@ -17,9 +17,7 @@ #include -namespace score -{ -namespace td +namespace score::td { /// @@ -29,7 +27,6 @@ namespace td /// std::shared_ptr CreateSvtPublisher(const std::string& machine_name); -} // namespace td -} // namespace score +} // namespace score::td #endif // #ifndef SCORE_TIME_DAEMON_SRC_IPC_SVT_PUBLISHER_FACTORY_H diff --git a/score/time_daemon/src/ipc/svt/publisher/svt_publisher.h b/score/time_daemon/src/ipc/svt/publisher/svt_publisher.h index 67c62288..e02b788f 100644 --- a/score/time_daemon/src/ipc/svt/publisher/svt_publisher.h +++ b/score/time_daemon/src/ipc/svt/publisher/svt_publisher.h @@ -17,9 +17,7 @@ #include "score/time_daemon/src/ipc/core/publisher_impl.h" #include "score/time_daemon/src/ipc/svt/svt_time_info.h" -namespace score -{ -namespace td +namespace score::td { /** @@ -27,7 +25,6 @@ namespace td */ using SvtPublisher = PublisherImpl; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_IPC_SVT_SVT_PUBLISHER_H diff --git a/score/time_daemon/src/ipc/svt/receiver/factory.cpp b/score/time_daemon/src/ipc/svt/receiver/factory.cpp index 774fa425..a659b6d9 100644 --- a/score/time_daemon/src/ipc/svt/receiver/factory.cpp +++ b/score/time_daemon/src/ipc/svt/receiver/factory.cpp @@ -13,16 +13,18 @@ #include "score/time_daemon/src/ipc/core/receiver_impl.h" #include "score/time_daemon/src/ipc/svt/config.h" #include "score/time_daemon/src/ipc/svt/receiver/svt_receiver.h" +#include "score/time_daemon/src/ipc/svt/svt_time_info.h" +#include -namespace score -{ -namespace td +namespace score::td { +// Declared in factory.h; this is one of two alternate definitions (see factory_stub.cpp) +// selected via Bazel target, so it must stay externally linked. +// NOLINTNEXTLINE(misc-use-internal-linkage) std::shared_ptr CreateSvtReceiver() { return std::make_shared>(kSvtShmemPath); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/ipc/svt/receiver/factory.h b/score/time_daemon/src/ipc/svt/receiver/factory.h index edcde037..b42bacb6 100644 --- a/score/time_daemon/src/ipc/svt/receiver/factory.h +++ b/score/time_daemon/src/ipc/svt/receiver/factory.h @@ -17,9 +17,7 @@ #include -namespace score -{ -namespace td +namespace score::td { /// @@ -29,7 +27,6 @@ namespace td /// std::shared_ptr CreateSvtReceiver(); -} // namespace td -} // namespace score +} // namespace score::td #endif // #ifndef SCORE_TIME_DAEMON_SRC_IPC_SVT_RECEIVER_FACTORY_H diff --git a/score/time_daemon/src/ipc/svt/receiver/factory_stub.cpp b/score/time_daemon/src/ipc/svt/receiver/factory_stub.cpp index a9bc079a..ef24c777 100644 --- a/score/time_daemon/src/ipc/svt/receiver/factory_stub.cpp +++ b/score/time_daemon/src/ipc/svt/receiver/factory_stub.cpp @@ -13,17 +13,18 @@ #include "score/time_daemon/src/ipc/receiver_mock.h" #include "score/time_daemon/src/ipc/svt/receiver/svt_receiver.h" #include "score/time_daemon/src/ipc/svt/svt_time_info.h" +#include -namespace score -{ -namespace td +namespace score::td { +// Declared in factory.h; this is one of two alternate definitions (see factory.cpp) +// selected via Bazel target, so it must stay externally linked. +// NOLINTNEXTLINE(misc-use-internal-linkage) std::shared_ptr CreateSvtReceiver() { static auto receiver = std::make_shared>(); return receiver; } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/ipc/svt/receiver/svt_receiver.h b/score/time_daemon/src/ipc/svt/receiver/svt_receiver.h index 424408be..5ceb2406 100644 --- a/score/time_daemon/src/ipc/svt/receiver/svt_receiver.h +++ b/score/time_daemon/src/ipc/svt/receiver/svt_receiver.h @@ -16,9 +16,7 @@ #include "score/time_daemon/src/ipc/receiver.h" #include "score/time_daemon/src/ipc/svt/svt_time_info.h" -namespace score -{ -namespace td +namespace score::td { /** @@ -26,7 +24,6 @@ namespace td */ using SvtReceiver = Receiver; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_IPC_SVT_SVT_RECEIVER_H diff --git a/score/time_daemon/src/ipc/svt/svt_time_info.cpp b/score/time_daemon/src/ipc/svt/svt_time_info.cpp index a28c1ff9..ac6c9e96 100644 --- a/score/time_daemon/src/ipc/svt/svt_time_info.cpp +++ b/score/time_daemon/src/ipc/svt/svt_time_info.cpp @@ -12,18 +12,16 @@ ********************************************************************************/ #include "score/time_daemon/src/ipc/svt/svt_time_info.h" +#include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include -#include #include +#include #include +#include #include -namespace score -{ -namespace td -{ -namespace svt +namespace score::td::svt { namespace @@ -203,26 +201,24 @@ bool operator!=(const TimeBaseSnapshot& ipcdata, const PtpTimeInfo& data) noexce } /// \brief gtest compatibility: -void PrintTo(const TimeBaseStatus& status, std::ostream* os) +void PrintTo(const TimeBaseStatus& status, std::ostream* out_stream) { - std::ignore = PrintTo(status, *os); + std::ignore = PrintTo(status, *out_stream); } -void PrintTo(const SyncFupSnapshot& data, std::ostream* os) +void PrintTo(const SyncFupSnapshot& data, std::ostream* out_stream) { - std::ignore = PrintTo(data, *os); + std::ignore = PrintTo(data, *out_stream); } -void PrintTo(const PDelayDataSnapshot& data, std::ostream* os) +void PrintTo(const PDelayDataSnapshot& data, std::ostream* out_stream) { - std::ignore = PrintTo(data, *os); + std::ignore = PrintTo(data, *out_stream); } -void PrintTo(const TimeBaseSnapshot& info, std::ostream* os) +void PrintTo(const TimeBaseSnapshot& info, std::ostream* out_stream) { - std::ignore = PrintTo(info, *os); + std::ignore = PrintTo(info, *out_stream); } -} // namespace svt -} // namespace td -} // namespace score +} // namespace score::td::svt diff --git a/score/time_daemon/src/ipc/svt/svt_time_info.h b/score/time_daemon/src/ipc/svt/svt_time_info.h index afa49d75..e2b3565d 100644 --- a/score/time_daemon/src/ipc/svt/svt_time_info.h +++ b/score/time_daemon/src/ipc/svt/svt_time_info.h @@ -20,9 +20,7 @@ #include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include "score/time_daemon/src/ipc/data_converter.h" -namespace score -{ -namespace td +namespace score::td { namespace svt { @@ -86,12 +84,16 @@ struct PDelayDataSnapshot /// \brief General type class to store and pass all necessary data struct TimeBaseSnapshot { + // NOLINTBEGIN(misc-non-private-member-variables-in-classes) — plain data aggregate, like the + // sibling *Snapshot structs above; CreateFrom() is a factory that fills the fields, it doesn't + // maintain any invariant over them that would require encapsulation. uint64_t ptp_assumed_time; uint64_t local_time; double rate_deviation; TimeBaseStatus status; SyncFupSnapshot sync_fup_data; PDelayDataSnapshot pdelay_data; + // NOLINTEND(misc-non-private-member-variables-in-classes) void CreateFrom(const PtpTimeInfo& info); }; @@ -111,67 +113,69 @@ bool operator!=(const TimeBaseSnapshot& first, const TimeBaseSnapshot& second) n /// \brief PrintTo and stream operators: template -inline auto& PrintTo(const TimeBaseStatus& status, OutputStream& os) +inline auto& PrintTo(const TimeBaseStatus& status, OutputStream& out_stream) { - return os << "Status: [" << status.is_synchronized << "|" << status.is_timeout << "|" << status.is_time_jump_future - << "|" << status.is_time_jump_past << "|" << status.is_correct << "]"; + return out_stream << "Status: [" << status.is_synchronized << "|" << status.is_timeout << "|" + << status.is_time_jump_future << "|" << status.is_time_jump_past << "|" << status.is_correct + << "]"; } template -inline auto& operator<<(OutputStream& os, const TimeBaseStatus& status) +inline auto& operator<<(OutputStream& out_stream, const TimeBaseStatus& status) { - return PrintTo(status, os); + return PrintTo(status, out_stream); } template -inline auto& PrintTo(const SyncFupSnapshot& data, OutputStream& os) +inline auto& PrintTo(const SyncFupSnapshot& data, OutputStream& out_stream) { - return os << "SyncFupSnapshot:" << "[" << data.precise_origin_timestamp << "|" << data.reference_global_timestamp - << "|" << data.reference_local_timestamp << "|" << data.sync_ingress_timestamp << "|" - << data.correction_field << "|" << data.sequence_id << "|" << data.pdelay << "|" << data.port_number - << "|" << data.clock_identity << "]"; + return out_stream << "SyncFupSnapshot:" << "[" << data.precise_origin_timestamp << "|" + << data.reference_global_timestamp << "|" << data.reference_local_timestamp << "|" + << data.sync_ingress_timestamp << "|" << data.correction_field << "|" << data.sequence_id << "|" + << data.pdelay << "|" << data.port_number << "|" << data.clock_identity << "]"; } template -inline auto& operator<<(OutputStream& os, const SyncFupSnapshot& data) +inline auto& operator<<(OutputStream& out_stream, const SyncFupSnapshot& data) { - return PrintTo(data, os); + return PrintTo(data, out_stream); } template -inline auto& PrintTo(const PDelayDataSnapshot& data, OutputStream& os) -{ - return os << "PDelayDataSnapshot:" << "[" << data.request_origin_timestamp << "|" << data.request_receipt_timestamp - << "|" << data.response_origin_timestamp << "|" << data.response_receipt_timestamp << "|" - << data.reference_global_timestamp << "|" << data.reference_local_timestamp << "|" << data.sequence_id - << "|" << data.pdelay << "|" << data.req_port_number << "|" << data.req_clock_identity << "|" - << data.resp_port_number << "|" << data.resp_clock_identity << "]"; +inline auto& PrintTo(const PDelayDataSnapshot& data, OutputStream& out_stream) +{ + return out_stream << "PDelayDataSnapshot:" << "[" << data.request_origin_timestamp << "|" + << data.request_receipt_timestamp << "|" << data.response_origin_timestamp << "|" + << data.response_receipt_timestamp << "|" << data.reference_global_timestamp << "|" + << data.reference_local_timestamp << "|" << data.sequence_id << "|" << data.pdelay << "|" + << data.req_port_number << "|" << data.req_clock_identity << "|" << data.resp_port_number << "|" + << data.resp_clock_identity << "]"; } template -inline auto& operator<<(OutputStream& os, const PDelayDataSnapshot& data) +inline auto& operator<<(OutputStream& out_stream, const PDelayDataSnapshot& data) { - return PrintTo(data, os); + return PrintTo(data, out_stream); } template -inline auto& PrintTo(const TimeBaseSnapshot& info, OutputStream& os) +inline auto& PrintTo(const TimeBaseSnapshot& info, OutputStream& out_stream) { - return os << "[" << info.ptp_assumed_time << "|" << info.local_time << "|" << info.status << "|" - << info.sync_fup_data << "|" << info.pdelay_data << "]"; + return out_stream << "[" << info.ptp_assumed_time << "|" << info.local_time << "|" << info.status << "|" + << info.sync_fup_data << "|" << info.pdelay_data << "]"; } template -inline auto& operator<<(OutputStream& os, const TimeBaseSnapshot& info) +inline auto& operator<<(OutputStream& out_stream, const TimeBaseSnapshot& info) { - return PrintTo(info, os); + return PrintTo(info, out_stream); } /// \brief gtest compatibility: -void PrintTo(const TimeBaseStatus& status, std::ostream* os); -void PrintTo(const SyncFupSnapshot& data, std::ostream* os); -void PrintTo(const PDelayDataSnapshot& data, std::ostream* os); -void PrintTo(const TimeBaseSnapshot& info, std::ostream* os); +void PrintTo(const TimeBaseStatus& status, std::ostream* out_stream); +void PrintTo(const SyncFupSnapshot& data, std::ostream* out_stream); +void PrintTo(const PDelayDataSnapshot& data, std::ostream* out_stream); +void PrintTo(const TimeBaseSnapshot& info, std::ostream* out_stream); } // namespace svt @@ -189,7 +193,6 @@ struct DataConverter } }; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_IPC_SVT_SVT_TIME_INFO_H diff --git a/score/time_daemon/src/ipc/svt/svt_time_info_test.cpp b/score/time_daemon/src/ipc/svt/svt_time_info_test.cpp index 373069a7..a7ec499b 100644 --- a/score/time_daemon/src/ipc/svt/svt_time_info_test.cpp +++ b/score/time_daemon/src/ipc/svt/svt_time_info_test.cpp @@ -12,16 +12,12 @@ ********************************************************************************/ #include "score/time_daemon/src/ipc/svt/svt_time_info.h" -#include -#include #include -#include +#include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include -namespace score -{ -namespace td +namespace score::td { namespace @@ -482,5 +478,4 @@ TEST(TimeBaseSnapshotTest, NotEqualsWhenEachTopLevelFieldDiffers) } } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/msg_broker/msg_broker.h b/score/time_daemon/src/msg_broker/msg_broker.h index 6aac807d..6fe1d802 100644 --- a/score/time_daemon/src/msg_broker/msg_broker.h +++ b/score/time_daemon/src/msg_broker/msg_broker.h @@ -23,9 +23,7 @@ #include #include -namespace score -{ -namespace td +namespace score::td { /// @@ -105,7 +103,6 @@ void MessageBroker::OnNewData(const Topic& topic, const T& data) const Publish(topic, data); } -} // namespace td -} // namespace score +} // namespace score::td #endif // #ifndef SCORE_TIME_DAEMON_SRC_MSG_BROKER_MSG_BROKER_H diff --git a/score/time_daemon/src/msg_broker/msg_broker_test.cpp b/score/time_daemon/src/msg_broker/msg_broker_test.cpp index 19ab3d96..3df6a656 100644 --- a/score/time_daemon/src/msg_broker/msg_broker_test.cpp +++ b/score/time_daemon/src/msg_broker/msg_broker_test.cpp @@ -14,14 +14,14 @@ #include "score/time_daemon/src/common/data_flow/consumer.h" #include "score/time_daemon/src/common/data_flow/producer.h" +#include "score/time_daemon/src/msg_broker/topic.h" #include #include +#include #include #include -namespace score -{ -namespace td +namespace score::td { template @@ -54,7 +54,9 @@ class MockProducer : public Producer void Publish(const T& data) override { if (publish_callback_) + { publish_callback_(data); + } } void Produce(const T& data) @@ -129,11 +131,15 @@ TEST_F(MessageBrokerTest, MultipleDataProduction) broker->AddProducer(Topic("topic1"), producer); for (int i = 0; i < 5; ++i) + { producer->Produce(i); + } ASSERT_EQ(consumer->received_data.size(), 5); for (int i = 0; i < 5; ++i) + { EXPECT_EQ(consumer->received_data[i], i); + } } TEST_F(MessageBrokerTest, ExpiredSubscriberDoesNotReceiveData) @@ -202,5 +208,4 @@ TEST(MessageBrokerTopicTest, TopicComparisonOperators) EXPECT_TRUE(a < c); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/msg_broker/subscription.h b/score/time_daemon/src/msg_broker/subscription.h index 16f8e9ac..b142e31a 100644 --- a/score/time_daemon/src/msg_broker/subscription.h +++ b/score/time_daemon/src/msg_broker/subscription.h @@ -15,9 +15,7 @@ #include -namespace score -{ -namespace td +namespace score::td { /// @@ -37,7 +35,6 @@ class Subscription std::function callback_; }; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_MSG_BROKER_SUBSCRIPTION_H diff --git a/score/time_daemon/src/msg_broker/topic.cpp b/score/time_daemon/src/msg_broker/topic.cpp index 9f588ef9..d3377293 100644 --- a/score/time_daemon/src/msg_broker/topic.cpp +++ b/score/time_daemon/src/msg_broker/topic.cpp @@ -13,10 +13,9 @@ #include "score/time_daemon/src/msg_broker/topic.h" #include "score/mw/log/logging.h" +#include -namespace score -{ -namespace td +namespace score::td { Topic::Topic(const std::string& name) noexcept @@ -54,5 +53,4 @@ bool operator<(const Topic& lhs, const Topic& rhs) noexcept return lhs.Name() < rhs.Name(); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/msg_broker/topic.h b/score/time_daemon/src/msg_broker/topic.h index 8841cdac..f8b2d017 100644 --- a/score/time_daemon/src/msg_broker/topic.h +++ b/score/time_daemon/src/msg_broker/topic.h @@ -17,9 +17,7 @@ #include #include -namespace score -{ -namespace td +namespace score::td { /// @@ -37,19 +35,18 @@ class Topic Topic& operator=(Topic&&) noexcept = delete; ~Topic() noexcept = default; - const std::string& Name() const noexcept; + [[nodiscard]] const std::string& Name() const noexcept; private: std::string name_; - const std::size_t kMaxLength{32U}; + static constexpr std::size_t kMaxLength{32U}; }; bool operator==(const Topic& lhs, const Topic& rhs) noexcept; bool operator!=(const Topic& lhs, const Topic& rhs) noexcept; bool operator<(const Topic& lhs, const Topic& rhs) noexcept; -} // namespace td -} // namespace score +} // namespace score::td // Specialize hash for score::td::Topic namespace std @@ -57,9 +54,9 @@ namespace std template <> struct hash { - std::size_t operator()(const score::td::Topic& t) const noexcept + std::size_t operator()(const score::td::Topic& topic) const noexcept { - return std::hash()(t.Name()); + return std::hash()(topic.Name()); } }; } // namespace std diff --git a/score/time_daemon/src/ptp_machine/core/ptp_engine_mock.h b/score/time_daemon/src/ptp_machine/core/ptp_engine_mock.h index b8df0cc1..960c674c 100644 --- a/score/time_daemon/src/ptp_machine/core/ptp_engine_mock.h +++ b/score/time_daemon/src/ptp_machine/core/ptp_engine_mock.h @@ -19,11 +19,7 @@ #include -namespace score -{ -namespace td -{ -namespace testing +namespace score::td::testing { class PTPEngineMockInterface @@ -102,8 +98,6 @@ class FakePTPEngine } }; -} // namespace testing -} // namespace td -} // namespace score +} // namespace score::td::testing #endif // SCORE_TIME_DAEMON_SRC_PTP_MACHINE_CORE_PTP_ENGINE_MOCK_H diff --git a/score/time_daemon/src/ptp_machine/core/ptp_machine.h b/score/time_daemon/src/ptp_machine/core/ptp_machine.h index 5a3dcd28..f4a87805 100644 --- a/score/time_daemon/src/ptp_machine/core/ptp_machine.h +++ b/score/time_daemon/src/ptp_machine/core/ptp_machine.h @@ -22,9 +22,7 @@ #include -namespace score -{ -namespace td +namespace score::td { /** @@ -51,8 +49,8 @@ class PTPMachine final : public PeriodicMachine, public Producer : PeriodicMachine(name, updateInterval), Producer(), publish_callback_(nullptr), - engine_impl_(std::make_unique(std::forward(args)...)), - is_initialized_(false) + engine_impl_(std::make_unique(std::forward(args)...)) + { score::mw::log::LogInfo(kPtpMachineContext) << "PTPMachine created with update interval: " << updateInterval.count() << "ms"; @@ -114,7 +112,7 @@ class PTPMachine final : public PeriodicMachine, public Producer std::unique_ptr engine_impl_; - bool is_initialized_; + bool is_initialized_{false}; }; template @@ -191,7 +189,6 @@ void PTPMachine::Publish(const PtpTimeInfo& data) } } -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_PTP_MACHINE_CORE_PTP_PTP_MACHINE_H diff --git a/score/time_daemon/src/ptp_machine/core/ptp_machine_test.cpp b/score/time_daemon/src/ptp_machine/core/ptp_machine_test.cpp index 398a2adc..1788e735 100644 --- a/score/time_daemon/src/ptp_machine/core/ptp_machine_test.cpp +++ b/score/time_daemon/src/ptp_machine/core/ptp_machine_test.cpp @@ -11,6 +11,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ #include "score/time_daemon/src/ptp_machine/core/ptp_machine.h" +#include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include "score/time_daemon/src/ptp_machine/core/ptp_engine_mock.h" #include @@ -22,9 +23,7 @@ using namespace std::chrono_literals; -namespace score -{ -namespace td +namespace score::td { using ::testing::_; @@ -170,5 +169,4 @@ TEST(PTPMachineStandaloneTest, PublishWithoutCallbackDoesNotCrash) machine.Stop(); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/ptp_machine/shm/details/shm_ptp_engine.cpp b/score/time_daemon/src/ptp_machine/shm/details/shm_ptp_engine.cpp index a96c82fb..15db392a 100644 --- a/score/time_daemon/src/ptp_machine/shm/details/shm_ptp_engine.cpp +++ b/score/time_daemon/src/ptp_machine/shm/details/shm_ptp_engine.cpp @@ -11,16 +11,15 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ #include "score/time_daemon/src/ptp_machine/shm/details/shm_ptp_engine.h" +#include "score/time_daemon/src/common/logging_contexts.h" #include "score/mw/log/logging.h" -#include "score/time_daemon/src/common/logging_contexts.h" +#include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include "score/ts_client/src/gptp_ipc_data.h" +#include +#include -namespace score -{ -namespace td -{ -namespace details +namespace score::td::details { ShmPTPEngine::ShmPTPEngine(std::string ipc_name) noexcept : ipc_name_{std::move(ipc_name)} {} @@ -28,7 +27,9 @@ ShmPTPEngine::ShmPTPEngine(std::string ipc_name) noexcept : ipc_name_{std::move( bool ShmPTPEngine::Initialize() { if (initialized_) + { return true; + } initialized_ = receiver_.Open(ipc_name_); if (initialized_) @@ -55,45 +56,47 @@ bool ShmPTPEngine::Deinitialize() bool ShmPTPEngine::ReadPTPSnapshot(PtpTimeInfo& info) { if (!initialized_) + { return false; + } auto result = receiver_.Receive(); if (!result.has_value()) + { return false; + } - const score::ts::GptpIpcData& d = result.value(); - info.ptp_assumed_time = d.ptp_assumed_time; - info.local_time = PtpTimeInfo::ReferenceClock::time_point{d.local_time}; - info.rate_deviation = d.rate_deviation; - info.status.is_synchronized = d.status.is_synchronized; - info.status.is_timeout = d.status.is_timeout; - info.status.is_time_jump_future = d.status.is_time_jump_future; - info.status.is_time_jump_past = d.status.is_time_jump_past; - info.status.is_correct = d.status.is_correct; - info.sync_fup_data.precise_origin_timestamp = d.sync_fup_data.precise_origin_timestamp; - info.sync_fup_data.reference_global_timestamp = d.sync_fup_data.reference_global_timestamp; - info.sync_fup_data.reference_local_timestamp = d.sync_fup_data.reference_local_timestamp; - info.sync_fup_data.sync_ingress_timestamp = d.sync_fup_data.sync_ingress_timestamp; - info.sync_fup_data.correction_field = d.sync_fup_data.correction_field; - info.sync_fup_data.sequence_id = d.sync_fup_data.sequence_id; - info.sync_fup_data.pdelay = d.sync_fup_data.pdelay; - info.sync_fup_data.port_number = d.sync_fup_data.port_number; - info.sync_fup_data.clock_identity = d.sync_fup_data.clock_identity; - info.pdelay_data.request_origin_timestamp = d.pdelay_data.request_origin_timestamp; - info.pdelay_data.request_receipt_timestamp = d.pdelay_data.request_receipt_timestamp; - info.pdelay_data.response_origin_timestamp = d.pdelay_data.response_origin_timestamp; - info.pdelay_data.response_receipt_timestamp = d.pdelay_data.response_receipt_timestamp; - info.pdelay_data.reference_global_timestamp = d.pdelay_data.reference_global_timestamp; - info.pdelay_data.reference_local_timestamp = d.pdelay_data.reference_local_timestamp; - info.pdelay_data.sequence_id = d.pdelay_data.sequence_id; - info.pdelay_data.pdelay = d.pdelay_data.pdelay; - info.pdelay_data.req_port_number = d.pdelay_data.req_port_number; - info.pdelay_data.req_clock_identity = d.pdelay_data.req_clock_identity; - info.pdelay_data.resp_port_number = d.pdelay_data.resp_port_number; - info.pdelay_data.resp_clock_identity = d.pdelay_data.resp_clock_identity; + const score::ts::GptpIpcData& ipc_data = result.value(); + info.ptp_assumed_time = ipc_data.ptp_assumed_time; + info.local_time = PtpTimeInfo::ReferenceClock::time_point{ipc_data.local_time}; + info.rate_deviation = ipc_data.rate_deviation; + info.status.is_synchronized = ipc_data.status.is_synchronized; + info.status.is_timeout = ipc_data.status.is_timeout; + info.status.is_time_jump_future = ipc_data.status.is_time_jump_future; + info.status.is_time_jump_past = ipc_data.status.is_time_jump_past; + info.status.is_correct = ipc_data.status.is_correct; + info.sync_fup_data.precise_origin_timestamp = ipc_data.sync_fup_data.precise_origin_timestamp; + info.sync_fup_data.reference_global_timestamp = ipc_data.sync_fup_data.reference_global_timestamp; + info.sync_fup_data.reference_local_timestamp = ipc_data.sync_fup_data.reference_local_timestamp; + info.sync_fup_data.sync_ingress_timestamp = ipc_data.sync_fup_data.sync_ingress_timestamp; + info.sync_fup_data.correction_field = ipc_data.sync_fup_data.correction_field; + info.sync_fup_data.sequence_id = ipc_data.sync_fup_data.sequence_id; + info.sync_fup_data.pdelay = ipc_data.sync_fup_data.pdelay; + info.sync_fup_data.port_number = ipc_data.sync_fup_data.port_number; + info.sync_fup_data.clock_identity = ipc_data.sync_fup_data.clock_identity; + info.pdelay_data.request_origin_timestamp = ipc_data.pdelay_data.request_origin_timestamp; + info.pdelay_data.request_receipt_timestamp = ipc_data.pdelay_data.request_receipt_timestamp; + info.pdelay_data.response_origin_timestamp = ipc_data.pdelay_data.response_origin_timestamp; + info.pdelay_data.response_receipt_timestamp = ipc_data.pdelay_data.response_receipt_timestamp; + info.pdelay_data.reference_global_timestamp = ipc_data.pdelay_data.reference_global_timestamp; + info.pdelay_data.reference_local_timestamp = ipc_data.pdelay_data.reference_local_timestamp; + info.pdelay_data.sequence_id = ipc_data.pdelay_data.sequence_id; + info.pdelay_data.pdelay = ipc_data.pdelay_data.pdelay; + info.pdelay_data.req_port_number = ipc_data.pdelay_data.req_port_number; + info.pdelay_data.req_clock_identity = ipc_data.pdelay_data.req_clock_identity; + info.pdelay_data.resp_port_number = ipc_data.pdelay_data.resp_port_number; + info.pdelay_data.resp_clock_identity = ipc_data.pdelay_data.resp_clock_identity; return true; } -} // namespace details -} // namespace td -} // namespace score +} // namespace score::td::details diff --git a/score/time_daemon/src/ptp_machine/shm/details/shm_ptp_engine.h b/score/time_daemon/src/ptp_machine/shm/details/shm_ptp_engine.h index 4fdf9c3b..2f3b51d7 100644 --- a/score/time_daemon/src/ptp_machine/shm/details/shm_ptp_engine.h +++ b/score/time_daemon/src/ptp_machine/shm/details/shm_ptp_engine.h @@ -18,11 +18,7 @@ #include -namespace score -{ -namespace td -{ -namespace details +namespace score::td::details { /** @@ -35,6 +31,9 @@ namespace details class ShmPTPEngine final { public: + // kGptpIpcName is a char-array constant used as a default arg for a std::string param; + // ordinary literal decay, not raw pointer/buffer use. + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay) explicit ShmPTPEngine(std::string ipc_name = score::ts::details::kGptpIpcName) noexcept; ~ShmPTPEngine() noexcept = default; @@ -55,8 +54,6 @@ class ShmPTPEngine final bool initialized_{false}; }; -} // namespace details -} // namespace td -} // namespace score +} // namespace score::td::details #endif // SCORE_TIME_DAEMON_SRC_PTP_MACHINE_SHM_DETAILS_SHM_PTP_ENGINE_H diff --git a/score/time_daemon/src/ptp_machine/shm/details/shm_ptp_engine_test.cpp b/score/time_daemon/src/ptp_machine/shm/details/shm_ptp_engine_test.cpp index 8ac1a997..c1ec8cfd 100644 --- a/score/time_daemon/src/ptp_machine/shm/details/shm_ptp_engine_test.cpp +++ b/score/time_daemon/src/ptp_machine/shm/details/shm_ptp_engine_test.cpp @@ -10,20 +10,18 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#include "score/time_daemon/src/ptp_machine/shm/details/shm_ptp_engine.h" +#include "score/time_daemon/src/ptp_machine/shm/details/shm_ptp_engine.h" +#include "score/time_daemon/src/common/data_types/ptp_time_info.h" +#include "score/ts_client/src/gptp_ipc_data.h" #include "score/ts_client/src/gptp_ipc_publisher.h" #include #include -#include +#include -namespace score -{ -namespace td -{ -namespace details +namespace score::td::details { namespace @@ -211,6 +209,4 @@ TEST_F(ShmPTPEngineTest, ReadPTPSnapshot_CopiesPDelayDataCorrectly) EXPECT_EQ(result.pdelay_data.resp_clock_identity, src.pdelay_data.resp_clock_identity); } -} // namespace details -} // namespace td -} // namespace score +} // namespace score::td::details diff --git a/score/time_daemon/src/ptp_machine/shm/factory.cpp b/score/time_daemon/src/ptp_machine/shm/factory.cpp index b427f981..0709133e 100644 --- a/score/time_daemon/src/ptp_machine/shm/factory.cpp +++ b/score/time_daemon/src/ptp_machine/shm/factory.cpp @@ -11,10 +11,12 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ #include "score/time_daemon/src/ptp_machine/shm/factory.h" +#include "score/time_daemon/src/ptp_machine/shm/gptp_shm_machine.h" +#include +#include +#include -namespace score -{ -namespace td +namespace score::td { std::shared_ptr CreateGPTPShmMachine(const std::string& name, const std::string& ipc_name) @@ -23,5 +25,4 @@ std::shared_ptr CreateGPTPShmMachine(const std::string& name, co return std::make_shared(name, updateInterval, ipc_name); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/ptp_machine/shm/factory.h b/score/time_daemon/src/ptp_machine/shm/factory.h index 51557ebe..7829e3e1 100644 --- a/score/time_daemon/src/ptp_machine/shm/factory.h +++ b/score/time_daemon/src/ptp_machine/shm/factory.h @@ -19,9 +19,7 @@ #include #include -namespace score -{ -namespace td +namespace score::td { /** @@ -35,10 +33,13 @@ namespace td * @param ipc_name IPC channel name (default: kGptpIpcName). * @return A fully configured GPTPShmMachine instance. */ -std::shared_ptr CreateGPTPShmMachine(const std::string& name, - const std::string& ipc_name = score::ts::details::kGptpIpcName); +// kGptpIpcName is a char-array constant used as a default arg for a const std::string&; the +// decay is just the ordinary literal-to-temporary-std::string construction, not raw pointer use. +std::shared_ptr CreateGPTPShmMachine( + const std::string& name, + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay) + const std::string& ipc_name = score::ts::details::kGptpIpcName); -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_PTP_MACHINE_SHM_FACTORY_H diff --git a/score/time_daemon/src/ptp_machine/shm/gptp_shm_machine.h b/score/time_daemon/src/ptp_machine/shm/gptp_shm_machine.h index dc788c3e..fb4f618f 100644 --- a/score/time_daemon/src/ptp_machine/shm/gptp_shm_machine.h +++ b/score/time_daemon/src/ptp_machine/shm/gptp_shm_machine.h @@ -16,9 +16,7 @@ #include "score/time_daemon/src/ptp_machine/core/ptp_machine.h" #include "score/time_daemon/src/ptp_machine/shm/details/shm_ptp_engine.h" -namespace score -{ -namespace td +namespace score::td { /// @brief PTPMachine instantiated with the shared-memory gPTP engine. @@ -32,7 +30,6 @@ namespace td /// @endcode using GPTPShmMachine = PTPMachine; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_PTP_MACHINE_SHM_GPTP_SHM_MACHINE_H diff --git a/score/time_daemon/src/ptp_machine/shm/gptp_shm_machine_test.cpp b/score/time_daemon/src/ptp_machine/shm/gptp_shm_machine_test.cpp index fffa2a7a..2e2d6282 100644 --- a/score/time_daemon/src/ptp_machine/shm/gptp_shm_machine_test.cpp +++ b/score/time_daemon/src/ptp_machine/shm/gptp_shm_machine_test.cpp @@ -11,19 +11,20 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ #include "score/time_daemon/src/ptp_machine/shm/gptp_shm_machine.h" +#include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include "score/time_daemon/src/ptp_machine/shm/factory.h" +#include "score/ts_client/src/gptp_ipc_data.h" #include "score/ts_client/src/gptp_ipc_publisher.h" #include #include -#include #include +#include #include +#include -namespace score -{ -namespace td +namespace score::td { namespace @@ -123,5 +124,4 @@ TEST_F(GPTPShmMachineIntegrationTest, Init_CalledTwice_SecondCallReturnsSameResu EXPECT_TRUE(machine_->Init()); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/ptp_machine/stub/details/stub_ptp_engine.cpp b/score/time_daemon/src/ptp_machine/stub/details/stub_ptp_engine.cpp index 04037a65..831e5c76 100644 --- a/score/time_daemon/src/ptp_machine/stub/details/stub_ptp_engine.cpp +++ b/score/time_daemon/src/ptp_machine/stub/details/stub_ptp_engine.cpp @@ -12,23 +12,22 @@ ********************************************************************************/ #include "score/time_daemon/src/ptp_machine/stub/details/stub_ptp_engine.h" #include "score/mw/log/logging.h" +#include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include "score/time_daemon/src/common/logging_contexts.h" -#include -#include +#include +#include -namespace score -{ -namespace td -{ -namespace details +namespace score::td::details { namespace { - -std::uint16_t sequence_id_{0U}; - +// Simulated one-way propagation delay used by both the Sync and PDelay stub readings below. +constexpr std::uint64_t kOnewayDelayNs{1'000U}; +// Arbitrary, fixed clock identities used to make stub PTP frames look plausible. +constexpr std::uint64_t kStubClockIdentityA{0xAABBCCDDEEFF0011ULL}; +constexpr std::uint64_t kStubClockIdentityB{0x1122334455667788ULL}; } // namespace StubPTPEngine::StubPTPEngine(PtpTimeInfo::ReferenceClock local_clock) noexcept : local_clock_{std::move(local_clock)} @@ -36,6 +35,10 @@ StubPTPEngine::StubPTPEngine(PtpTimeInfo::ReferenceClock local_clock) noexcept : score::mw::log::LogInfo(kGPtpMachineContext) << "StubPTPEngine created!"; } +// Not static: kept as an instance method to match PTPEngineMockInterface/ShmPTPEngine, even +// though this stub body doesn't touch instance state — PTPEngine implementations are meant to +// be interchangeable. +// NOLINTNEXTLINE(readability-convert-member-functions-to-static) bool StubPTPEngine::Initialize() const { score::mw::log::LogInfo(kGPtpMachineContext) << "StubPTPEngine initialization succeeded!"; @@ -43,6 +46,7 @@ bool StubPTPEngine::Initialize() const return true; } +// NOLINTNEXTLINE(readability-convert-member-functions-to-static) bool StubPTPEngine::Deinitialize() const { score::mw::log::LogInfo(kGPtpMachineContext) << "StubPTPEngine deinitialization succeeded!"; @@ -82,9 +86,9 @@ bool StubPTPEngine::ReadSyncMeasurementData(PtpTimeInfo& time_info) const noexce time_info.sync_fup_data.sync_ingress_timestamp = now_ns; time_info.sync_fup_data.correction_field = 0U; time_info.sync_fup_data.sequence_id = sequence_id_; - time_info.sync_fup_data.pdelay = 1'000U; // 1 µs simulated pdelay + time_info.sync_fup_data.pdelay = kOnewayDelayNs; time_info.sync_fup_data.port_number = 1U; - time_info.sync_fup_data.clock_identity = 0xAABBCCDDEEFF0011ULL; + time_info.sync_fup_data.clock_identity = kStubClockIdentityA; return true; } @@ -93,24 +97,22 @@ bool StubPTPEngine::ReadPDelayMeasurementData(PtpTimeInfo& time_info) const noex { // Stub: simulate a round-trip with 1 µs one-way pdelay anchored to local clock const auto now_ns = static_cast(local_clock_.Now().TimeSinceEpoch().count()); - constexpr std::uint64_t kOnewayDelayNs{1'000U}; // 1 µs simulated one-way pdelay + constexpr std::uint64_t kRoundTripDelayNs{2U * kOnewayDelayNs}; time_info.pdelay_data.request_origin_timestamp = now_ns; time_info.pdelay_data.request_receipt_timestamp = now_ns + kOnewayDelayNs; time_info.pdelay_data.response_origin_timestamp = now_ns + kOnewayDelayNs; - time_info.pdelay_data.response_receipt_timestamp = now_ns + 2U * kOnewayDelayNs; + time_info.pdelay_data.response_receipt_timestamp = now_ns + kRoundTripDelayNs; time_info.pdelay_data.reference_global_timestamp = now_ns; time_info.pdelay_data.reference_local_timestamp = now_ns; time_info.pdelay_data.sequence_id = sequence_id_; time_info.pdelay_data.pdelay = kOnewayDelayNs; time_info.pdelay_data.req_port_number = 1U; - time_info.pdelay_data.req_clock_identity = 0xAABBCCDDEEFF0011ULL; + time_info.pdelay_data.req_clock_identity = kStubClockIdentityA; time_info.pdelay_data.resp_port_number = 2U; - time_info.pdelay_data.resp_clock_identity = 0x1122334455667788ULL; + time_info.pdelay_data.resp_clock_identity = kStubClockIdentityB; return true; } -} // namespace details -} // namespace td -} // namespace score +} // namespace score::td::details diff --git a/score/time_daemon/src/ptp_machine/stub/details/stub_ptp_engine.h b/score/time_daemon/src/ptp_machine/stub/details/stub_ptp_engine.h index fc5b66aa..bef9331e 100644 --- a/score/time_daemon/src/ptp_machine/stub/details/stub_ptp_engine.h +++ b/score/time_daemon/src/ptp_machine/stub/details/stub_ptp_engine.h @@ -16,13 +16,10 @@ #include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include +#include #include -namespace score -{ -namespace td -{ -namespace details +namespace score::td::details { /** @@ -48,12 +45,13 @@ class StubPTPEngine final /// /// \return true - initialize success, otherwise false /// - bool Initialize() const; + [[nodiscard]] bool Initialize() const; /// \brief Method to deinitialize libgptp client /// /// \return true - deinitialize success, otherwise false /// + // NOLINTNEXTLINE(modernize-use-nodiscard) bool Deinitialize() const; /// \brief Method that reads PTP snapshot from libgptp @@ -82,10 +80,9 @@ class StubPTPEngine final private: PtpTimeInfo::ReferenceClock local_clock_; + std::uint16_t sequence_id_{0U}; }; -} // namespace details -} // namespace td -} // namespace score +} // namespace score::td::details #endif // SCORE_TIME_DAEMON_SRC_PTP_MACHINE_STUB_DETAILS_STUB_PTP_ENGINE_H diff --git a/score/time_daemon/src/ptp_machine/stub/factory.cpp b/score/time_daemon/src/ptp_machine/stub/factory.cpp index 5040a361..bf968956 100644 --- a/score/time_daemon/src/ptp_machine/stub/factory.cpp +++ b/score/time_daemon/src/ptp_machine/stub/factory.cpp @@ -12,10 +12,12 @@ ********************************************************************************/ #include "score/time_daemon/src/ptp_machine/stub/factory.h" #include "score/time/high_res_steady_time/src/high_res_steady_clock.h" +#include "score/time_daemon/src/ptp_machine/stub/gptp_stub_machine.h" +#include +#include +#include -namespace score -{ -namespace td +namespace score::td { std::shared_ptr CreateGPTPStubMachine(const std::string& name) @@ -24,5 +26,4 @@ std::shared_ptr CreateGPTPStubMachine(const std::string& name) return std::make_shared(name, updateInterval, score::time::HighResSteadyClock::GetInstance()); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/ptp_machine/stub/factory.h b/score/time_daemon/src/ptp_machine/stub/factory.h index 0c10545e..ef391d7d 100644 --- a/score/time_daemon/src/ptp_machine/stub/factory.h +++ b/score/time_daemon/src/ptp_machine/stub/factory.h @@ -15,9 +15,7 @@ #include "score/time_daemon/src/ptp_machine/stub/gptp_stub_machine.h" -namespace score -{ -namespace td +namespace score::td { /** @@ -29,7 +27,6 @@ namespace td */ std::shared_ptr CreateGPTPStubMachine(const std::string& name); -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_PTP_MACHINE_STUB_FACTORY_H diff --git a/score/time_daemon/src/ptp_machine/stub/gptp_stub_machine.h b/score/time_daemon/src/ptp_machine/stub/gptp_stub_machine.h index cec31104..9b2e9c6e 100644 --- a/score/time_daemon/src/ptp_machine/stub/gptp_stub_machine.h +++ b/score/time_daemon/src/ptp_machine/stub/gptp_stub_machine.h @@ -24,14 +24,11 @@ #include #include -namespace score -{ -namespace td +namespace score::td { using GPTPStubMachine = PTPMachine; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_PTP_MACHINE_STUB_GPTP_STUB_MACHINE_H diff --git a/score/time_daemon/src/ptp_machine/stub/gptp_stub_machine_integration_test.cpp b/score/time_daemon/src/ptp_machine/stub/gptp_stub_machine_integration_test.cpp index a90c2e93..37f0e752 100644 --- a/score/time_daemon/src/ptp_machine/stub/gptp_stub_machine_integration_test.cpp +++ b/score/time_daemon/src/ptp_machine/stub/gptp_stub_machine_integration_test.cpp @@ -10,20 +10,18 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#include "score/time/high_res_steady_time/src/high_res_steady_clock.h" -#include "score/time_daemon/src/ptp_machine/stub/details/stub_ptp_engine.h" +#include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include "score/time_daemon/src/ptp_machine/stub/factory.h" +#include "score/time_daemon/src/ptp_machine/stub/gptp_stub_machine.h" #include #include -#include +#include #include +#include #include -#include -namespace score -{ -namespace td +namespace score::td { class GPTPStubMachineIntegrationTest : public ::testing::Test @@ -124,5 +122,4 @@ TEST_F(GPTPStubMachineIntegrationTest, GetSynchronizedDataTest) } } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/verification_machine/core/verification_machine.h b/score/time_daemon/src/verification_machine/core/verification_machine.h index 345e7899..3e153502 100644 --- a/score/time_daemon/src/verification_machine/core/verification_machine.h +++ b/score/time_daemon/src/verification_machine/core/verification_machine.h @@ -24,9 +24,7 @@ #include #include -namespace score -{ -namespace td +namespace score::td { /** @@ -201,7 +199,6 @@ void VerificationMachine::SetupPipeline(const std::vector #include -namespace score -{ -namespace td +namespace score::td { class VerificationMachineTest : public ::testing::Test @@ -147,5 +145,4 @@ TEST_F(VerificationMachineDeathTest, FactoryReturningNullptrAborts) ""); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/verification_machine/core/verification_stage.h b/score/time_daemon/src/verification_machine/core/verification_stage.h index 3a6310e5..a151426b 100644 --- a/score/time_daemon/src/verification_machine/core/verification_stage.h +++ b/score/time_daemon/src/verification_machine/core/verification_stage.h @@ -15,9 +15,7 @@ #include -namespace score -{ -namespace td +namespace score::td { /** @@ -93,7 +91,6 @@ void VerificationStage::SetNext(std::unique_ptr -namespace score -{ -namespace td +namespace score::td { struct ValidatorMockData @@ -50,7 +48,6 @@ class VerificationStageMock : public VerificationStage size_t id_{0}; }; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_VERIFICATION_MACHINE_CORE_VERIFICATION_STAGE_MOCK_H diff --git a/score/time_daemon/src/verification_machine/svt/factory.cpp b/score/time_daemon/src/verification_machine/svt/factory.cpp index 2296bf26..72614012 100644 --- a/score/time_daemon/src/verification_machine/svt/factory.cpp +++ b/score/time_daemon/src/verification_machine/svt/factory.cpp @@ -12,14 +12,22 @@ ********************************************************************************/ #include "score/time_daemon/src/verification_machine/svt/factory.h" #include "score/time/high_res_steady_time/src/high_res_steady_clock.h" +#include "score/time_daemon/src/verification_machine/svt/svt_verification_machine.h" #include "score/time_daemon/src/verification_machine/svt/validators/synchronization_validator.h" #include "score/time_daemon/src/verification_machine/svt/validators/time_jumps_validator.h" #include "score/time_daemon/src/verification_machine/svt/validators/timeout_validator.h" +#include +#include -namespace score +namespace score::td { -namespace td +namespace { +constexpr auto kTimeoutThreshold = std::chrono::nanoseconds{3'300'000'000}; +constexpr auto kTimeJumpThreshold = std::chrono::nanoseconds{500'000}; +constexpr auto kSyncDebounceThreshold = std::chrono::nanoseconds{5'000'000'000}; +constexpr auto kValidFramesThreshold = 2U; +} // namespace std::shared_ptr CreateSvtVerificationMachine(const std::string& name) { @@ -30,17 +38,16 @@ std::shared_ptr CreateSvtVerificationMachine(const std:: }, []() { return std::make_unique(score::time::HighResSteadyClock::GetInstance(), - std::chrono::nanoseconds{3'300'000'000}); + kTimeoutThreshold); }, []() { return std::make_unique(score::time::HighResSteadyClock::GetInstance(), - std::chrono::nanoseconds(500'000), - std::chrono::nanoseconds(5'000'000'000), - 2U); + kTimeJumpThreshold, + kValidFramesThreshold, + kSyncDebounceThreshold); }); return machine; } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/verification_machine/svt/factory.h b/score/time_daemon/src/verification_machine/svt/factory.h index a3ac7f53..90c5511a 100644 --- a/score/time_daemon/src/verification_machine/svt/factory.h +++ b/score/time_daemon/src/verification_machine/svt/factory.h @@ -15,9 +15,7 @@ #include "score/time_daemon/src/verification_machine/svt/svt_verification_machine.h" -namespace score -{ -namespace td +namespace score::td { /** @@ -29,7 +27,6 @@ namespace td */ std::shared_ptr CreateSvtVerificationMachine(const std::string& name); -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_VERIFICATION_MACHINE_SVT_FACTORY_H diff --git a/score/time_daemon/src/verification_machine/svt/svt_verification_machine.h b/score/time_daemon/src/verification_machine/svt/svt_verification_machine.h index 2f8382da..868a49a9 100644 --- a/score/time_daemon/src/verification_machine/svt/svt_verification_machine.h +++ b/score/time_daemon/src/verification_machine/svt/svt_verification_machine.h @@ -19,9 +19,7 @@ #include "score/time_daemon/src/verification_machine/svt/validators/time_jumps_validator.h" #include "score/time_daemon/src/verification_machine/svt/validators/timeout_validator.h" -namespace score -{ -namespace td +namespace score::td { /** @@ -29,7 +27,6 @@ namespace td */ using SvtVerificationMachine = VerificationMachine; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_VERIFICATION_MACHINE_SVT_SVT_VERIFICATION_MACHINE_H diff --git a/score/time_daemon/src/verification_machine/svt/svt_verification_machine_test.cpp b/score/time_daemon/src/verification_machine/svt/svt_verification_machine_test.cpp index b71b0823..c70ad42d 100644 --- a/score/time_daemon/src/verification_machine/svt/svt_verification_machine_test.cpp +++ b/score/time_daemon/src/verification_machine/svt/svt_verification_machine_test.cpp @@ -11,14 +11,15 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ #include "score/time_daemon/src/verification_machine/svt/svt_verification_machine.h" +#include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include "score/time_daemon/src/verification_machine/svt/factory.h" #include #include +#include +#include -namespace score -{ -namespace td +namespace score::td { class SvtVerificationMachineTest : public ::testing::Test @@ -63,5 +64,4 @@ TEST_F(SvtVerificationMachineTest, HandlesPipelineValidation) EXPECT_EQ(published_data, test_data); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/verification_machine/svt/validators/synchronization_validator.cpp b/score/time_daemon/src/verification_machine/svt/validators/synchronization_validator.cpp index 604d0e65..3cec4a71 100644 --- a/score/time_daemon/src/verification_machine/svt/validators/synchronization_validator.cpp +++ b/score/time_daemon/src/verification_machine/svt/validators/synchronization_validator.cpp @@ -12,14 +12,11 @@ ********************************************************************************/ #include "score/time_daemon/src/verification_machine/svt/validators/synchronization_validator.h" #include "score/mw/log/logging.h" +#include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include "score/time_daemon/src/common/logging_contexts.h" -namespace score +namespace score::td { -namespace td -{ - -SynchronizationValidator::SynchronizationValidator() : is_synchronized_{false} {} void SynchronizationValidator::DoValidation(PtpTimeInfo& data) { @@ -40,5 +37,4 @@ void SynchronizationValidator::DoValidation(PtpTimeInfo& data) } } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/verification_machine/svt/validators/synchronization_validator.h b/score/time_daemon/src/verification_machine/svt/validators/synchronization_validator.h index 71a4f70d..dd55e854 100644 --- a/score/time_daemon/src/verification_machine/svt/validators/synchronization_validator.h +++ b/score/time_daemon/src/verification_machine/svt/validators/synchronization_validator.h @@ -16,9 +16,7 @@ #include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include "score/time_daemon/src/verification_machine/core/verification_stage.h" -namespace score -{ -namespace td +namespace score::td { /** @@ -27,7 +25,7 @@ namespace td class SynchronizationValidator : public VerificationStage { public: - SynchronizationValidator(); + SynchronizationValidator() = default; protected: /** @@ -36,10 +34,9 @@ class SynchronizationValidator : public VerificationStage void DoValidation(PtpTimeInfo& data) override; private: - bool is_synchronized_; + bool is_synchronized_{false}; }; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_VERIFICATION_MACHINE_SVT_VALIDATORS_SYNCHRONIZATION_VALIDATOR_H diff --git a/score/time_daemon/src/verification_machine/svt/validators/synchronization_validator_test.cpp b/score/time_daemon/src/verification_machine/svt/validators/synchronization_validator_test.cpp index b3db83e6..9017d39b 100644 --- a/score/time_daemon/src/verification_machine/svt/validators/synchronization_validator_test.cpp +++ b/score/time_daemon/src/verification_machine/svt/validators/synchronization_validator_test.cpp @@ -15,9 +15,7 @@ #include "gmock/gmock.h" #include -namespace score -{ -namespace td +namespace score::td { struct TestParams @@ -61,5 +59,4 @@ TEST_P(SynchronizationValidatorParamTest, ValidationTest) } } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/verification_machine/svt/validators/time_jumps_validator.cpp b/score/time_daemon/src/verification_machine/svt/validators/time_jumps_validator.cpp index 5d9a1cab..fff68f5c 100644 --- a/score/time_daemon/src/verification_machine/svt/validators/time_jumps_validator.cpp +++ b/score/time_daemon/src/verification_machine/svt/validators/time_jumps_validator.cpp @@ -12,26 +12,26 @@ ********************************************************************************/ #include "score/time_daemon/src/verification_machine/svt/validators/time_jumps_validator.h" #include "score/mw/log/logging.h" +#include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include "score/time_daemon/src/common/logging_contexts.h" +#include +#include +#include +#include -namespace score -{ -namespace td +namespace score::td { TimeJumpsValidator::TimeJumpsValidator(PtpTimeInfo::ReferenceClock debouncing_clock, std::chrono::nanoseconds max_time_jump_allowed, - std::chrono::nanoseconds sync_debounce_threshold, - std::uint8_t valid_frames_threshold) + std::uint8_t valid_frames_threshold, + std::chrono::nanoseconds sync_debounce_threshold) : max_time_jump_allowed_{max_time_jump_allowed}, sync_debounce_threshold_{sync_debounce_threshold}, valid_frames_threshold_{valid_frames_threshold}, - time_jump_state_{TimeJumpState::kNoTimeJump}, - current_state_{ProcessingStates::kIdle}, last_sync_frame_{std::nullopt}, sync_debouncing_init_time_{std::chrono::nanoseconds::zero()}, - debouncing_clock_{std::move(debouncing_clock)}, - valid_frames_cnt_{0U} + debouncing_clock_{std::move(debouncing_clock)} { } @@ -57,6 +57,11 @@ bool TimeJumpsValidator::IsTimeJumpDetected(const PtpTimeInfo& data) { bool is_time_jump_detected{false}; + if (!last_sync_frame_.has_value()) + { + return false; + } + if (data.sync_fup_data.sync_ingress_timestamp > last_sync_frame_.value().sync_fup_data.sync_ingress_timestamp) { // calculate t2 rx timestamp diff, between last and current frames @@ -189,5 +194,4 @@ void TimeJumpsValidator::GoToTimeJumpHandling() score::mw::log::LogDebug(kVerificationMachineContext) << "TimeJumpsValidator: Switch to kTimeJumpHandling state"; } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/verification_machine/svt/validators/time_jumps_validator.h b/score/time_daemon/src/verification_machine/svt/validators/time_jumps_validator.h index d5526596..4af0d9b6 100644 --- a/score/time_daemon/src/verification_machine/svt/validators/time_jumps_validator.h +++ b/score/time_daemon/src/verification_machine/svt/validators/time_jumps_validator.h @@ -19,9 +19,7 @@ #include #include -namespace score -{ -namespace td +namespace score::td { /** @@ -29,17 +27,17 @@ namespace td * @param debouncing_clock - reference clock object - used to calculate time between when SYNC flag is set to the moment * when time jump validation is enabled * @param max_time_jump_allowed - threshold in nanoseconds to define max allowed time jump value - * @param sync_debounce_threshold - threshold in nanoseconds to define max sync debounce time * @param valid_frames_threshold - threshold to define number of valid packages to receive to swith from time jump state * to normal + * @param sync_debounce_threshold - threshold in nanoseconds to define max sync debounce time */ class TimeJumpsValidator : public VerificationStage { public: TimeJumpsValidator(PtpTimeInfo::ReferenceClock debouncing_clock, std::chrono::nanoseconds max_time_jump_allowed, - std::chrono::nanoseconds sync_debounce_threshold, - std::uint8_t valid_frames_threshold); + std::uint8_t valid_frames_threshold, + std::chrono::nanoseconds sync_debounce_threshold); protected: void DoValidation(PtpTimeInfo& data) override; @@ -70,15 +68,14 @@ class TimeJumpsValidator : public VerificationStage const std::chrono::nanoseconds max_time_jump_allowed_; const std::chrono::nanoseconds sync_debounce_threshold_; const std::uint8_t valid_frames_threshold_; - TimeJumpState time_jump_state_; - ProcessingStates current_state_; + TimeJumpState time_jump_state_{TimeJumpState::kNoTimeJump}; + ProcessingStates current_state_{ProcessingStates::kIdle}; std::optional last_sync_frame_; PtpTimeInfo::ReferenceClock::duration sync_debouncing_init_time_; PtpTimeInfo::ReferenceClock debouncing_clock_; - std::uint8_t valid_frames_cnt_; + std::uint8_t valid_frames_cnt_{0U}; }; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_VERIFICATION_MACHINE_SVT_VALIDATORS_TIME_JUMPS_VALIDATOR_H diff --git a/score/time_daemon/src/verification_machine/svt/validators/time_jumps_validator_test.cpp b/score/time_daemon/src/verification_machine/svt/validators/time_jumps_validator_test.cpp index 2b67e5a4..017c59d7 100644 --- a/score/time_daemon/src/verification_machine/svt/validators/time_jumps_validator_test.cpp +++ b/score/time_daemon/src/verification_machine/svt/validators/time_jumps_validator_test.cpp @@ -15,11 +15,12 @@ #include "score/time/high_res_steady_time/src/high_res_steady_clock_backend_mock.h" #include "gmock/gmock.h" +#include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include +#include +#include -namespace score -{ -namespace td +namespace score::td { using namespace std::chrono_literals; @@ -65,8 +66,8 @@ TEST_P(TimeJumpsValidatorParamTest, ValidationTest) TimeJumpsValidator validator(score::time::test_utils::ClockTestFactory::Make(mock), std::chrono::nanoseconds(500'000), - std::chrono::nanoseconds(5'000'000), - 2U); + 2U, + std::chrono::nanoseconds(5'000'000)); // Pass synchronized state debouncing EXPECT_CALL(*mock, Now()) @@ -106,8 +107,8 @@ TEST(TimeJumpsValidatorTest, JumpToPastWithinThresholdIsNotFlagged) TimeJumpsValidator validator(score::time::test_utils::ClockTestFactory::Make(mock), std::chrono::nanoseconds(500'000), - std::chrono::nanoseconds(5'000'000), - 2U); + 2U, + std::chrono::nanoseconds(5'000'000)); // Pass synchronized state debouncing EXPECT_CALL(*mock, Now()) @@ -152,8 +153,8 @@ TEST(TimeJumpsValidatorTest, JumpToFutureWithinThresholdIsNotFlagged) TimeJumpsValidator validator(score::time::test_utils::ClockTestFactory::Make(mock), std::chrono::nanoseconds(500'000), - std::chrono::nanoseconds(5'000'000), - 2U); + 2U, + std::chrono::nanoseconds(5'000'000)); // Pass synchronized state debouncing EXPECT_CALL(*mock, Now()) @@ -198,8 +199,8 @@ TEST(TimeJumpsValidatorTest, StaysInInitialSyncDebouncingWhenThresholdNotElapsed TimeJumpsValidator validator(score::time::test_utils::ClockTestFactory::Make(mock), std::chrono::nanoseconds(500'000), - std::chrono::nanoseconds(5'000'000), - 2U); + 2U, + std::chrono::nanoseconds(5'000'000)); EXPECT_CALL(*mock, Now()) // Enter kInitialSyncDebouncing @@ -232,5 +233,4 @@ TEST(TimeJumpsValidatorTest, StaysInInitialSyncDebouncingWhenThresholdNotElapsed EXPECT_FALSE(result.status.is_time_jump_past); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/verification_machine/svt/validators/timeout_validator.cpp b/score/time_daemon/src/verification_machine/svt/validators/timeout_validator.cpp index 49293a14..02fdaeb8 100644 --- a/score/time_daemon/src/verification_machine/svt/validators/timeout_validator.cpp +++ b/score/time_daemon/src/verification_machine/svt/validators/timeout_validator.cpp @@ -12,18 +12,20 @@ ********************************************************************************/ #include "score/time_daemon/src/verification_machine/svt/validators/timeout_validator.h" #include "score/mw/log/logging.h" +#include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include "score/time_daemon/src/common/logging_contexts.h" +#include +#include -namespace score -{ -namespace td +namespace score::td { TimeoutValidator::TimeoutValidator(PtpTimeInfo::ReferenceClock timeout_clock, std::chrono::nanoseconds reception_timeout) - : threshold_{reception_timeout}, timeout_clock_{std::move(timeout_clock)} + : threshold_{reception_timeout}, + timeout_clock_{std::move(timeout_clock)}, + reception_time_{timeout_clock_.Now().TimeSinceEpoch()} { - reception_time_ = timeout_clock_.Now().TimeSinceEpoch(); } void TimeoutValidator::DoValidation(PtpTimeInfo& data) @@ -92,5 +94,4 @@ bool TimeoutValidator::IsNewFrameReceived(const PtpTimeInfo& data) return is_new_frame; } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/score/time_daemon/src/verification_machine/svt/validators/timeout_validator.h b/score/time_daemon/src/verification_machine/svt/validators/timeout_validator.h index b984e274..9a421591 100644 --- a/score/time_daemon/src/verification_machine/svt/validators/timeout_validator.h +++ b/score/time_daemon/src/verification_machine/svt/validators/timeout_validator.h @@ -18,9 +18,7 @@ #include -namespace score -{ -namespace td +namespace score::td { /** @@ -32,7 +30,6 @@ class TimeoutValidator : public VerificationStage { public: explicit TimeoutValidator(PtpTimeInfo::ReferenceClock timeout_clock, std::chrono::nanoseconds reception_timeout); - virtual ~TimeoutValidator() = default; protected: void DoValidation(PtpTimeInfo& data) override; @@ -46,7 +43,6 @@ class TimeoutValidator : public VerificationStage std::optional last_received_data_; }; -} // namespace td -} // namespace score +} // namespace score::td #endif // SCORE_TIME_DAEMON_SRC_VERIFICATION_MACHINE_SVT_VALIDATORS_TIMEOUT_VALIDATOR_H diff --git a/score/time_daemon/src/verification_machine/svt/validators/timeout_validator_test.cpp b/score/time_daemon/src/verification_machine/svt/validators/timeout_validator_test.cpp index 12c824f9..504ab5cf 100644 --- a/score/time_daemon/src/verification_machine/svt/validators/timeout_validator_test.cpp +++ b/score/time_daemon/src/verification_machine/svt/validators/timeout_validator_test.cpp @@ -15,11 +15,12 @@ #include "score/time/high_res_steady_time/src/high_res_steady_clock_backend_mock.h" #include "gmock/gmock.h" +#include "score/time_daemon/src/common/data_types/ptp_time_info.h" #include +#include +#include -namespace score -{ -namespace td +namespace score::td { using namespace std::chrono_literals; @@ -146,5 +147,4 @@ TEST(TimeoutValidatorTest, LogsErrorWhenClockAppearsToGoBackward) EXPECT_FALSE(second_result.status.is_timeout); } -} // namespace td -} // namespace score +} // namespace score::td diff --git a/tools/lint/linters.bzl b/tools/lint/linters.bzl index 355cb388..07d2f82c 100644 --- a/tools/lint/linters.bzl +++ b/tools/lint/linters.bzl @@ -21,7 +21,7 @@ load("@score_cpp_policies//clang_tidy:defs.bzl", "make_clang_tidy_aspect", "make clang_tidy_aspect = make_clang_tidy_aspect( binary = Label("@llvm_toolchain//:clang-tidy"), - # No local_configs: use only the S-CORE baseline from score_cpp_policies. + local_configs = [Label("//:.clang-tidy")], ) clang_tidy_test = make_clang_tidy_test(aspect = clang_tidy_aspect)