From 7c692e8facda7d35edc908dad16c7d6b7f762a57 Mon Sep 17 00:00:00 2001 From: "chenhao.gao" Date: Wed, 3 Jun 2026 09:49:38 +0800 Subject: [PATCH 1/7] Replace mmap-based IPC with SharedMemoryFactory in ts_client --- .../src/application/svt/factory_shm.cpp | 27 ++++ .../src/application/svt/factory_shm.h | 34 ++++ .../src/application/svt/svt_handler_shm.cpp | 149 ++++++++++++++++++ .../src/application/svt/svt_handler_shm.h | 62 ++++++++ score/ts_client/src/BUILD | 16 +- score/ts_client/src/gptp_ipc.h | 6 +- score/ts_client/src/gptp_ipc_channel.h | 7 +- score/ts_client/src/gptp_ipc_data.h | 14 +- score/ts_client/src/gptp_ipc_publisher.cpp | 51 ++---- score/ts_client/src/gptp_ipc_publisher.h | 16 +- score/ts_client/src/gptp_ipc_receiver.cpp | 46 ++---- score/ts_client/src/gptp_ipc_receiver.h | 17 +- .../ts_client/src/gptp_ipc_roundtrip_test.cpp | 2 +- score/ts_client/src/gptp_ipc_test_utils.h | 58 +++---- 14 files changed, 358 insertions(+), 147 deletions(-) create mode 100644 score/time_daemon/src/application/svt/factory_shm.cpp create mode 100644 score/time_daemon/src/application/svt/factory_shm.h create mode 100644 score/time_daemon/src/application/svt/svt_handler_shm.cpp create mode 100644 score/time_daemon/src/application/svt/svt_handler_shm.h diff --git a/score/time_daemon/src/application/svt/factory_shm.cpp b/score/time_daemon/src/application/svt/factory_shm.cpp new file mode 100644 index 00000000..c40a3ee5 --- /dev/null +++ b/score/time_daemon/src/application/svt/factory_shm.cpp @@ -0,0 +1,27 @@ +/******************************************************************************** + * Copyright (c) 2026 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +#include "score/TimeDaemon/code/application/svt/factory_shm.h" +#include "score/TimeDaemon/code/application/svt/svt_handler_shm.h" + +namespace score +{ +namespace td +{ + +std::unique_ptr CreateSvtTimebaseShm() +{ + return std::make_unique(); +} + +} // namespace td +} // namespace score diff --git a/score/time_daemon/src/application/svt/factory_shm.h b/score/time_daemon/src/application/svt/factory_shm.h new file mode 100644 index 00000000..68dc731c --- /dev/null +++ b/score/time_daemon/src/application/svt/factory_shm.h @@ -0,0 +1,34 @@ +/******************************************************************************** + * Copyright (c) 2026 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +#ifndef SCORE_TIMEDAEMON_CODE_APPLICATION_SVT_FACTORY_SHM_H +#define SCORE_TIMEDAEMON_CODE_APPLICATION_SVT_FACTORY_SHM_H + +#include "score/TimeDaemon/code/application/timebase_handler.h" + +#include + +namespace score +{ +namespace td +{ + +/// \brief Creates an SVT timebase handler backed by the shared-memory gPTP engine. +/// +/// Reads live gPTP data written by TimeSlave via GptpIpcPublisher. +/// Use in place of CreateSvtTimebase() when running alongside a real TimeSlave. +std::unique_ptr CreateSvtTimebaseShm(); + +} // namespace td +} // namespace score + +#endif // SCORE_TIMEDAEMON_CODE_APPLICATION_SVT_FACTORY_SHM_H diff --git a/score/time_daemon/src/application/svt/svt_handler_shm.cpp b/score/time_daemon/src/application/svt/svt_handler_shm.cpp new file mode 100644 index 00000000..64259940 --- /dev/null +++ b/score/time_daemon/src/application/svt/svt_handler_shm.cpp @@ -0,0 +1,149 @@ +/******************************************************************************** + * Copyright (c) 2026 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +#include "score/TimeDaemon/code/application/svt/svt_handler_shm.h" +#include "score/TimeDaemon/code/common/logging_contexts.h" +#include "score/TimeDaemon/code/control_flow_divider/ptp/factory.h" +#include "score/TimeDaemon/code/ipc/svt/publisher/factory.h" +#include "score/TimeDaemon/code/msg_broker/subscription.h" +#include "score/TimeDaemon/code/msg_broker/topic.h" +#include "score/TimeDaemon/code/ptp_machine/shm/factory.h" +#include "score/TimeDaemon/code/verification_machine/svt/factory.h" +#include "score/concurrency/interruptible_wait.h" +#include "score/mw/log/logging.h" + +#include +#include + +namespace score +{ +namespace td +{ + +SvtHandlerShm::SvtHandlerShm() noexcept + : job_runner_{nullptr}, + msg_broker_{nullptr}, + gptp_machine_{nullptr}, + verification_machine_{nullptr}, + ipc_publisher_{nullptr}, + ctrl_flow_divider_{nullptr}, + handler_status_{TimebaseHandler::Status::kIdle} +{ + 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}); + + std::vector jobs = { + {[this] { + return gptp_machine_->Init(); + }, + gptp_machine_->GetName(), + std::chrono::seconds(20)}, + {[this] { + return verification_machine_->Init(); + }, + verification_machine_->GetName(), + std::chrono::seconds(20)}, + {[this] { + return ipc_publisher_->Init(); + }, + ipc_publisher_->GetName(), + std::chrono::seconds(20)}, + {[this] { + return ctrl_flow_divider_->Init(); + }, + ctrl_flow_divider_->GetName(), + std::chrono::seconds(20)}, + }; + job_runner_ = std::make_unique(std::move(jobs), "svt_init"); + + score::mw::log::LogInfo(kTimeBaseHandlerSvt) << "SvtHandlerShm created!"; +} + +void SvtHandlerShm::Initialize() noexcept +{ + const auto input_ptp_data_topic = Topic("in_ptp_data"); + const auto raw_ptp_data_topic = Topic("raw_ptp_data"); + const auto validated_ptp_data_topic = Topic("validated_ptp_data"); + + msg_broker_->AddSubscriber(input_ptp_data_topic, ctrl_flow_divider_); + msg_broker_->AddSubscriber(raw_ptp_data_topic, verification_machine_); + msg_broker_->AddSubscriber(validated_ptp_data_topic, ipc_publisher_); + + msg_broker_->AddProducer(input_ptp_data_topic, gptp_machine_); + msg_broker_->AddProducer(raw_ptp_data_topic, ctrl_flow_divider_); + msg_broker_->AddProducer(validated_ptp_data_topic, verification_machine_); + + score::mw::log::LogInfo(kTimeBaseHandlerSvt) << "SvtHandlerShm msg broker initialized!"; +} + +void SvtHandlerShm::RunOnce(const score::cpp::stop_token& token) noexcept +{ + switch (handler_status_) + { + case TimebaseHandler::Status::kIdle: + { + job_runner_->Start(token); + handler_status_ = TimebaseHandler::Status::kInitialize; + score::mw::log::LogInfo(kTimeBaseHandlerSvt) << "SvtHandlerShm initialization started"; + break; + } + case TimebaseHandler::Status::kInitialize: + { + auto status = job_runner_->GetResult(); + switch (status) + { + case JobRunner::Result::kSucceed: + { + score::mw::log::LogInfo(kTimeBaseHandlerSvt) + << "SvtHandlerShm initialization done, starting proactive machines!"; + job_runner_.reset(); + ctrl_flow_divider_->Start(); + gptp_machine_->Start(); + handler_status_ = TimebaseHandler::Status::kWorking; + score::mw::log::LogInfo(kTimeBaseHandlerSvt) << "SvtHandlerShm is working"; + break; + } + case JobRunner::Result::kFailed: + { + handler_status_ = TimebaseHandler::Status::kFailed; + score::mw::log::LogError(kTimeBaseHandlerSvt) << "SvtHandlerShm initialization failed!!"; + break; + } + case JobRunner::Result::kIdle: + case JobRunner::Result::kInProgress: + default: + break; + } + break; + } + case TimebaseHandler::Status::kWorking: + case TimebaseHandler::Status::kFailed: + default: + break; + } +} + +void SvtHandlerShm::Stop() noexcept +{ + if (handler_status_ == TimebaseHandler::Status::kWorking) + { + gptp_machine_->Stop(); + ctrl_flow_divider_->Stop(); + score::mw::log::LogInfo(kTimeBaseHandlerSvt) << "SvtHandlerShm stopping proactive machines!"; + } +} + +} // namespace td +} // namespace score diff --git a/score/time_daemon/src/application/svt/svt_handler_shm.h b/score/time_daemon/src/application/svt/svt_handler_shm.h new file mode 100644 index 00000000..df1d8f2e --- /dev/null +++ b/score/time_daemon/src/application/svt/svt_handler_shm.h @@ -0,0 +1,62 @@ +/******************************************************************************** + * Copyright (c) 2026 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +#ifndef SCORE_TIMEDAEMON_CODE_APPLICATION_SVT_SHM_HANDLER_H +#define SCORE_TIMEDAEMON_CODE_APPLICATION_SVT_SHM_HANDLER_H + +#include "score/TimeDaemon/code/application/job_runner/job_runner.h" +#include "score/TimeDaemon/code/application/timebase_handler.h" +#include "score/TimeDaemon/code/control_flow_divider/ptp/ptp_control_flow_divider.h" +#include "score/TimeDaemon/code/ipc/svt/publisher/svt_publisher.h" +#include "score/TimeDaemon/code/msg_broker/msg_broker.h" +#include "score/TimeDaemon/code/ptp_machine/shm/gptp_shm_machine.h" +#include "score/TimeDaemon/code/verification_machine/svt/svt_verification_machine.h" + +#include + +namespace score +{ +namespace td +{ + +/// \brief SVT timebase handler backed by the shared-memory gPTP engine. +/// +/// Reads live gPTP data written by TimeSlave via GptpIpcPublisher, processing +/// it through the same verification and IPC-publish pipeline as SvtHandler. +class SvtHandlerShm : public TimebaseHandler +{ + public: + SvtHandlerShm() noexcept; + virtual ~SvtHandlerShm() noexcept = default; + SvtHandlerShm(const SvtHandlerShm&) = delete; + SvtHandlerShm(SvtHandlerShm&&) = delete; + SvtHandlerShm& operator=(const SvtHandlerShm&) = delete; + SvtHandlerShm& operator=(SvtHandlerShm&&) = delete; + + virtual void Initialize() noexcept override; + virtual void RunOnce(const score::cpp::stop_token& token) noexcept override; + virtual void Stop() noexcept override; + + private: + std::unique_ptr job_runner_; + std::shared_ptr> msg_broker_; + std::shared_ptr gptp_machine_; + std::shared_ptr verification_machine_; + std::shared_ptr ipc_publisher_; + std::shared_ptr ctrl_flow_divider_; + TimebaseHandler::Status handler_status_; +}; + +} // namespace td +} // namespace score + +#endif // SCORE_TIMEDAEMON_CODE_APPLICATION_SVT_SHM_HANDLER_H diff --git a/score/ts_client/src/BUILD b/score/ts_client/src/BUILD index 445363dd..0aa4f88d 100644 --- a/score/ts_client/src/BUILD +++ b/score/ts_client/src/BUILD @@ -28,13 +28,14 @@ cc_library( "gptp_ipc_receiver.h", ], features = COMPILER_WARNING_FEATURES, - linkopts = select({ - "@platforms//os:qnx": [], - "//conditions:default": ["-lrt"], - }), tags = ["QM"], - visibility = ["//score:__subpackages__"], - deps = [], + visibility = [ + "//examples:__subpackages__", + "//score:__subpackages__", + ], + deps = [ + "@score_baselibs//score/memory/shared", + ], ) cc_test( @@ -48,6 +49,7 @@ cc_test( ":gptp_ipc", "@googletest//:gtest", "@googletest//:gtest_main", + "@score_baselibs//score/mw/log:console_only_backend", ], ) @@ -62,6 +64,7 @@ cc_test( ":gptp_ipc", "@googletest//:gtest", "@googletest//:gtest_main", + "@score_baselibs//score/mw/log:console_only_backend", ], ) @@ -76,6 +79,7 @@ cc_test( ":gptp_ipc", "@googletest//:gtest", "@googletest//:gtest_main", + "@score_baselibs//score/mw/log:console_only_backend", ], ) diff --git a/score/ts_client/src/gptp_ipc.h b/score/ts_client/src/gptp_ipc.h index 87fe0ab4..6d18bbbb 100644 --- a/score/ts_client/src/gptp_ipc.h +++ b/score/ts_client/src/gptp_ipc.h @@ -10,11 +10,11 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_H -#define SCORE_TS_CLIENT_SRC_GPTP_IPC_H +#ifndef SCORE_TS_CLIENT_GPTP_IPC_H +#define SCORE_TS_CLIENT_GPTP_IPC_H #include "score/ts_client/src/gptp_ipc_channel.h" #include "score/ts_client/src/gptp_ipc_publisher.h" #include "score/ts_client/src/gptp_ipc_receiver.h" -#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_H +#endif // SCORE_TS_CLIENT_GPTP_IPC_H diff --git a/score/ts_client/src/gptp_ipc_channel.h b/score/ts_client/src/gptp_ipc_channel.h index 96f97927..c3bbd926 100644 --- a/score/ts_client/src/gptp_ipc_channel.h +++ b/score/ts_client/src/gptp_ipc_channel.h @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_CHANNEL_H -#define SCORE_TS_CLIENT_SRC_GPTP_IPC_CHANNEL_H +#ifndef SCORE_TS_CLIENT_GPTP_IPC_CHANNEL_H +#define SCORE_TS_CLIENT_GPTP_IPC_CHANNEL_H #include "score/ts_client/src/gptp_ipc_data.h" @@ -25,7 +25,6 @@ namespace ts namespace details { -/// Default POSIX shared memory name for the gPTP IPC channel. constexpr char kGptpIpcName[] = "/gptp_ptp_info"; /// Magic number to validate the shared memory region ('GPTP'). @@ -53,4 +52,4 @@ struct alignas(64) GptpIpcRegion } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_CHANNEL_H +#endif // SCORE_TS_CLIENT_GPTP_IPC_CHANNEL_H diff --git a/score/ts_client/src/gptp_ipc_data.h b/score/ts_client/src/gptp_ipc_data.h index f210cae9..31eb860a 100644 --- a/score/ts_client/src/gptp_ipc_data.h +++ b/score/ts_client/src/gptp_ipc_data.h @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_DATA_H -#define SCORE_TS_CLIENT_SRC_GPTP_IPC_DATA_H +#ifndef SCORE_TS_CLIENT_GPTP_IPC_DATA_H +#define SCORE_TS_CLIENT_GPTP_IPC_DATA_H #include #include @@ -33,9 +33,6 @@ struct GptpIpcStatus bool is_correct; }; -/** - * @brief IPC-layer Sync+FollowUp measurement data. - */ struct GptpIpcSyncFupData { std::uint64_t precise_origin_timestamp; @@ -49,9 +46,6 @@ struct GptpIpcSyncFupData std::uint64_t clock_identity; }; -/** - * @brief IPC-layer peer-delay measurement data. - */ struct GptpIpcPDelayData { std::uint64_t request_origin_timestamp; @@ -71,7 +65,7 @@ struct GptpIpcPDelayData /** * @brief IPC data snapshot written by TimeSlave and read by TimeDaemon. * - * This type is internal to ts_client/src and intentionally decoupled from + * This type is internal to libTSClient and intentionally decoupled from * score::td::PtpTimeInfo. Callers are responsible for mapping between the two. */ struct GptpIpcData @@ -87,4 +81,4 @@ struct GptpIpcData } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_DATA_H +#endif // SCORE_TS_CLIENT_GPTP_IPC_DATA_H diff --git a/score/ts_client/src/gptp_ipc_publisher.cpp b/score/ts_client/src/gptp_ipc_publisher.cpp index 8e8c58bb..04cd8f23 100644 --- a/score/ts_client/src/gptp_ipc_publisher.cpp +++ b/score/ts_client/src/gptp_ipc_publisher.cpp @@ -12,9 +12,6 @@ ********************************************************************************/ #include "score/ts_client/src/gptp_ipc_publisher.h" -#include -#include -#include #include #include @@ -35,34 +32,23 @@ GptpIpcPublisher::~GptpIpcPublisher() bool GptpIpcPublisher::Init(const std::string& ipc_name) { - if (region_ != nullptr) + if (shm_resource_ != nullptr) return true; ipc_name_ = ipc_name; - (void)::shm_unlink(ipc_name_.c_str()); + score::memory::shared::SharedMemoryFactory::Remove(ipc_name_); + score::memory::shared::SharedMemoryFactory::RemoveStaleArtefacts(ipc_name_); - shm_fd_ = ::shm_open(ipc_name_.c_str(), O_CREAT | O_RDWR, 0600); - if (shm_fd_ < 0) - return false; + shm_resource_ = score::memory::shared::SharedMemoryFactory::Create( + ipc_name_, + [this](std::shared_ptr res) { + region_ = res->construct(); + }, + sizeof(GptpIpcRegion) + alignof(GptpIpcRegion) - 1U, + score::memory::shared::permission::WorldWritable{}); - if (::ftruncate(shm_fd_, static_cast(sizeof(GptpIpcRegion))) != 0) - { - ::close(shm_fd_); // LCOV_EXCL_LINE - shm_fd_ = -1; // LCOV_EXCL_LINE - return false; // LCOV_EXCL_LINE - } - - void* ptr = ::mmap(nullptr, sizeof(GptpIpcRegion), PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd_, 0); - if (ptr == MAP_FAILED) - { - ::close(shm_fd_); // LCOV_EXCL_LINE - shm_fd_ = -1; // LCOV_EXCL_LINE - return false; // LCOV_EXCL_LINE - } - - region_ = new (ptr) GptpIpcRegion{}; - return true; + return (shm_resource_ != nullptr) && (region_ != nullptr); } void GptpIpcPublisher::Publish(const score::ts::GptpIpcData& data) @@ -85,22 +71,13 @@ void GptpIpcPublisher::Publish(const score::ts::GptpIpcData& data) void GptpIpcPublisher::Destroy() { - if (region_ != nullptr) - { - region_->~GptpIpcRegion(); - ::munmap(region_, sizeof(GptpIpcRegion)); - region_ = nullptr; - } - if (shm_fd_ >= 0) - { - ::close(shm_fd_); - shm_fd_ = -1; - } if (!ipc_name_.empty()) { - ::shm_unlink(ipc_name_.c_str()); + score::memory::shared::SharedMemoryFactory::Remove(ipc_name_); ipc_name_.clear(); } + shm_resource_.reset(); + region_ = nullptr; } } // namespace details diff --git a/score/ts_client/src/gptp_ipc_publisher.h b/score/ts_client/src/gptp_ipc_publisher.h index 59abccba..dc5fe157 100644 --- a/score/ts_client/src/gptp_ipc_publisher.h +++ b/score/ts_client/src/gptp_ipc_publisher.h @@ -10,11 +10,13 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_PUBLISHER_H -#define SCORE_TS_CLIENT_SRC_GPTP_IPC_PUBLISHER_H +#ifndef SCORE_TS_CLIENT_GPTP_IPC_PUBLISHER_H +#define SCORE_TS_CLIENT_GPTP_IPC_PUBLISHER_H #include "score/ts_client/src/gptp_ipc_channel.h" +#include "score/memory/shared/shared_memory_factory.h" +#include #include namespace score @@ -39,19 +41,13 @@ class GptpIpcPublisher final GptpIpcPublisher(const GptpIpcPublisher&) = delete; GptpIpcPublisher& operator=(const GptpIpcPublisher&) = delete; - /// Create and map the shared memory segment. - /// @return true on success. bool Init(const std::string& ipc_name = kGptpIpcName); - - /// Publish a GptpIpcData snapshot using seqlock. void Publish(const score::ts::GptpIpcData& data); - - /// Unmap and unlink the shared memory segment. void Destroy(); private: GptpIpcRegion* region_{nullptr}; - int shm_fd_{-1}; + std::shared_ptr shm_resource_; std::string ipc_name_; }; @@ -59,4 +55,4 @@ class GptpIpcPublisher final } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_PUBLISHER_H +#endif // SCORE_TS_CLIENT_GPTP_IPC_PUBLISHER_H diff --git a/score/ts_client/src/gptp_ipc_receiver.cpp b/score/ts_client/src/gptp_ipc_receiver.cpp index ee6ee838..347697da 100644 --- a/score/ts_client/src/gptp_ipc_receiver.cpp +++ b/score/ts_client/src/gptp_ipc_receiver.cpp @@ -12,11 +12,8 @@ ********************************************************************************/ #include "score/ts_client/src/gptp_ipc_receiver.h" -#include -#include -#include -#include #include +#include namespace score { @@ -34,31 +31,24 @@ GptpIpcReceiver::~GptpIpcReceiver() bool GptpIpcReceiver::Init(const std::string& ipc_name) { - if (region_ != nullptr) + if (shm_resource_ != nullptr) return true; - shm_fd_ = ::shm_open(ipc_name.c_str(), O_RDONLY, 0); - if (shm_fd_ < 0) + shm_resource_ = score::memory::shared::SharedMemoryFactory::Open(ipc_name, false); + if (shm_resource_ == nullptr) return false; + // construct() on the publisher side aligns the object to + // alignof(GptpIpcRegion) within the usable region. We must apply the same + // alignment here so that both sides point to the same address. + void* ptr = shm_resource_->getUsableBaseAddress(); + std::size_t space = sizeof(GptpIpcRegion) + alignof(GptpIpcRegion); + ptr = std::align(alignof(GptpIpcRegion), sizeof(GptpIpcRegion), ptr, space); + if (ptr == nullptr) { - struct ::stat st{}; - if (::fstat(shm_fd_, &st) != 0 || static_cast(st.st_size) < sizeof(GptpIpcRegion)) - { - ::close(shm_fd_); - shm_fd_ = -1; - return false; - } - } - - void* ptr = ::mmap(nullptr, sizeof(GptpIpcRegion), PROT_READ, MAP_SHARED, shm_fd_, 0); - if (ptr == MAP_FAILED) - { - ::close(shm_fd_); - shm_fd_ = -1; + Close(); return false; } - region_ = static_cast(ptr); if (region_->magic.load(std::memory_order_acquire) != kGptpIpcMagic) @@ -106,16 +96,8 @@ std::optional GptpIpcReceiver::Receive() void GptpIpcReceiver::Close() { - if (region_ != nullptr) - { - ::munmap(const_cast(region_), sizeof(GptpIpcRegion)); - region_ = nullptr; - } - if (shm_fd_ >= 0) - { - ::close(shm_fd_); - shm_fd_ = -1; - } + shm_resource_.reset(); + region_ = nullptr; } } // namespace details diff --git a/score/ts_client/src/gptp_ipc_receiver.h b/score/ts_client/src/gptp_ipc_receiver.h index a9fd98ee..38ca6656 100644 --- a/score/ts_client/src/gptp_ipc_receiver.h +++ b/score/ts_client/src/gptp_ipc_receiver.h @@ -10,11 +10,13 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_RECEIVER_H -#define SCORE_TS_CLIENT_SRC_GPTP_IPC_RECEIVER_H +#ifndef SCORE_TS_CLIENT_GPTP_IPC_RECEIVER_H +#define SCORE_TS_CLIENT_GPTP_IPC_RECEIVER_H #include "score/ts_client/src/gptp_ipc_channel.h" +#include "score/memory/shared/shared_memory_factory.h" +#include #include #include @@ -40,24 +42,17 @@ class GptpIpcReceiver final GptpIpcReceiver(const GptpIpcReceiver&) = delete; GptpIpcReceiver& operator=(const GptpIpcReceiver&) = delete; - /// Open and map the shared memory segment (read-only). - /// @return true on success. bool Init(const std::string& ipc_name = kGptpIpcName); - - /// Read a GptpIpcData snapshot using seqlock (up to 20 retries). - /// @return The data if consistent, or std::nullopt on contention failure. std::optional Receive(); - - /// Unmap the shared memory segment. void Close(); private: const GptpIpcRegion* region_{nullptr}; - int shm_fd_{-1}; + std::shared_ptr shm_resource_; }; } // namespace details } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_RECEIVER_H +#endif // SCORE_TS_CLIENT_GPTP_IPC_RECEIVER_H diff --git a/score/ts_client/src/gptp_ipc_roundtrip_test.cpp b/score/ts_client/src/gptp_ipc_roundtrip_test.cpp index 844ba7aa..a32c1b74 100644 --- a/score/ts_client/src/gptp_ipc_roundtrip_test.cpp +++ b/score/ts_client/src/gptp_ipc_roundtrip_test.cpp @@ -182,7 +182,7 @@ TEST_F(GptpIpcRoundtripTest, ReceiverInit_WrongMagic_ReturnsFalse) new (shm.Region()) GptpIpcRegion{}; const std::uint32_t bad = 0xDEADBEEFU; - std::memcpy(shm.ptr, &bad, sizeof(bad)); + std::memcpy(shm.Region(), &bad, sizeof(bad)); EXPECT_FALSE(rx_.Init(name_)); } diff --git a/score/ts_client/src/gptp_ipc_test_utils.h b/score/ts_client/src/gptp_ipc_test_utils.h index b3b34ea0..1fbe115e 100644 --- a/score/ts_client/src/gptp_ipc_test_utils.h +++ b/score/ts_client/src/gptp_ipc_test_utils.h @@ -10,15 +10,15 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_TEST_UTILS_H -#define SCORE_TS_CLIENT_SRC_GPTP_IPC_TEST_UTILS_H +#ifndef SCORE_TS_CLIENT_GPTP_IPC_TEST_UTILS_H +#define SCORE_TS_CLIENT_GPTP_IPC_TEST_UTILS_H #include "score/ts_client/src/gptp_ipc_channel.h" +#include "score/memory/shared/shared_memory_factory.h" -#include -#include #include #include +#include #include namespace score @@ -28,7 +28,6 @@ namespace ts namespace details { -/// Generate a unique POSIX shm name per invocation (avoids cross-test pollution). inline std::string UniqueShmName() { static std::atomic counter{0}; @@ -36,47 +35,40 @@ inline std::string UniqueShmName() std::to_string(counter.fetch_add(1, std::memory_order_relaxed)); } -/// RAII helper: creates shm manually (without GptpIpcPublisher) for edge-case -/// testing; cleans up in destructor. +/// RAII helper: creates SHM via SharedMemoryFactory (same layout as GptpIpcPublisher) +/// so that GptpIpcReceiver can open it. Gives direct access to the region for +/// edge-case tests that need to corrupt seq/magic. struct ManualShm { - std::string name; - void* ptr = MAP_FAILED; - std::size_t size = sizeof(GptpIpcRegion); + std::shared_ptr resource_; + GptpIpcRegion* region_{nullptr}; + std::string name_; - explicit ManualShm(const std::string& n) : name{n} + explicit ManualShm(const std::string& n) : name_{n} { - const int fd = ::shm_open(name.c_str(), O_CREAT | O_RDWR, 0666); - if (fd < 0) - return; - if (::ftruncate(fd, static_cast(size)) != 0) - { - ::close(fd); - return; - } - ptr = ::mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - ::close(fd); + score::memory::shared::SharedMemoryFactory::Remove(n); + score::memory::shared::SharedMemoryFactory::RemoveStaleArtefacts(n); + resource_ = score::memory::shared::SharedMemoryFactory::Create( + n, + [this](std::shared_ptr res) { + region_ = res->construct(); + }, + sizeof(GptpIpcRegion) + alignof(GptpIpcRegion) - 1U, + score::memory::shared::permission::WorldWritable{}); } ~ManualShm() { - if (ptr != MAP_FAILED) - ::munmap(ptr, size); - ::shm_unlink(name.c_str()); + resource_.reset(); + score::memory::shared::SharedMemoryFactory::Remove(name_); } - bool Valid() const - { - return ptr != MAP_FAILED; - } - GptpIpcRegion* Region() - { - return static_cast(ptr); - } + bool Valid() const { return resource_ != nullptr && region_ != nullptr; } + GptpIpcRegion* Region() { return region_; } }; } // namespace details } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_TEST_UTILS_H +#endif // SCORE_TS_CLIENT_GPTP_IPC_TEST_UTILS_H From e14098ebc636eada966b77e597d96be2cb4992eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gordon=20=5C=20Chenhao=20Gao=20=5C=20=E9=AB=98=E6=99=A8?= =?UTF-8?q?=E6=B5=A9?= Date: Wed, 17 Jun 2026 17:49:10 +0800 Subject: [PATCH 2/7] rename Init/Destroy, drop svt_handler_shm --- score/time_daemon/src/application/svt/BUILD | 4 +- .../src/application/svt/factory_shm.cpp | 27 ---- .../src/application/svt/factory_shm.h | 34 ---- .../src/application/svt/svt_handler.cpp | 4 +- .../src/application/svt/svt_handler.h | 4 +- .../src/application/svt/svt_handler_shm.cpp | 149 ------------------ .../src/application/svt/svt_handler_shm.h | 62 -------- .../shm/details/shm_ptp_engine.cpp | 2 +- .../shm/details/shm_ptp_engine_test.cpp | 20 +-- .../ptp_machine/shm/gptp_shm_machine_test.cpp | 4 +- .../time_slave/src/application/time_slave.cpp | 4 +- score/ts_client/src/gptp_ipc_channel.h | 1 + score/ts_client/src/gptp_ipc_data.h | 2 +- score/ts_client/src/gptp_ipc_publisher.cpp | 6 +- score/ts_client/src/gptp_ipc_publisher.h | 4 +- .../ts_client/src/gptp_ipc_publisher_test.cpp | 24 +-- score/ts_client/src/gptp_ipc_receiver.cpp | 2 +- score/ts_client/src/gptp_ipc_receiver.h | 2 +- .../ts_client/src/gptp_ipc_receiver_test.cpp | 20 +-- .../ts_client/src/gptp_ipc_roundtrip_test.cpp | 40 ++--- score/ts_client/src/gptp_ipc_test.cpp | 84 +++++----- 21 files changed, 114 insertions(+), 385 deletions(-) delete mode 100644 score/time_daemon/src/application/svt/factory_shm.cpp delete mode 100644 score/time_daemon/src/application/svt/factory_shm.h delete mode 100644 score/time_daemon/src/application/svt/svt_handler_shm.cpp delete mode 100644 score/time_daemon/src/application/svt/svt_handler_shm.h diff --git a/score/time_daemon/src/application/svt/BUILD b/score/time_daemon/src/application/svt/BUILD index f0f1088c..514a7851 100644 --- a/score/time_daemon/src/application/svt/BUILD +++ b/score/time_daemon/src/application/svt/BUILD @@ -42,14 +42,14 @@ load("@score_baselibs//score/language/safecpp:toolchain_features.bzl", "COMPILER "svt_handler", False, [ - "//score/time_daemon/src/ptp_machine:stub_ptp_machine", + "//score/time_daemon/src/ptp_machine/shm:gptp_shm_machine", ], ), ( "svt_handler_for_utests", True, [ - "//score/time_daemon/src/ptp_machine:stub_ptp_machine", + "//score/time_daemon/src/ptp_machine/shm:gptp_shm_machine", ], ), ] diff --git a/score/time_daemon/src/application/svt/factory_shm.cpp b/score/time_daemon/src/application/svt/factory_shm.cpp deleted file mode 100644 index c40a3ee5..00000000 --- a/score/time_daemon/src/application/svt/factory_shm.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ -#include "score/TimeDaemon/code/application/svt/factory_shm.h" -#include "score/TimeDaemon/code/application/svt/svt_handler_shm.h" - -namespace score -{ -namespace td -{ - -std::unique_ptr CreateSvtTimebaseShm() -{ - return std::make_unique(); -} - -} // namespace td -} // namespace score diff --git a/score/time_daemon/src/application/svt/factory_shm.h b/score/time_daemon/src/application/svt/factory_shm.h deleted file mode 100644 index 68dc731c..00000000 --- a/score/time_daemon/src/application/svt/factory_shm.h +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ -#ifndef SCORE_TIMEDAEMON_CODE_APPLICATION_SVT_FACTORY_SHM_H -#define SCORE_TIMEDAEMON_CODE_APPLICATION_SVT_FACTORY_SHM_H - -#include "score/TimeDaemon/code/application/timebase_handler.h" - -#include - -namespace score -{ -namespace td -{ - -/// \brief Creates an SVT timebase handler backed by the shared-memory gPTP engine. -/// -/// Reads live gPTP data written by TimeSlave via GptpIpcPublisher. -/// Use in place of CreateSvtTimebase() when running alongside a real TimeSlave. -std::unique_ptr CreateSvtTimebaseShm(); - -} // namespace td -} // namespace score - -#endif // SCORE_TIMEDAEMON_CODE_APPLICATION_SVT_FACTORY_SHM_H diff --git a/score/time_daemon/src/application/svt/svt_handler.cpp b/score/time_daemon/src/application/svt/svt_handler.cpp index 52739d44..1c26a165 100644 --- a/score/time_daemon/src/application/svt/svt_handler.cpp +++ b/score/time_daemon/src/application/svt/svt_handler.cpp @@ -16,7 +16,7 @@ #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/topic.h" -#include "score/time_daemon/src/ptp_machine/stub/factory.h" +#include "score/time_daemon/src/ptp_machine/shm/factory.h" #include "score/time_daemon/src/verification_machine/svt/factory.h" #include "score/concurrency/interruptible_wait.h" #include "score/mw/log/logging.h" @@ -39,7 +39,7 @@ SvtHandler::SvtHandler() noexcept handler_status_{TimebaseHandler::Status::kIdle} { msg_broker_ = std::make_shared>(); - gptp_machine_ = CreateGPTPStubMachine("ptp_worker"); + 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}); diff --git a/score/time_daemon/src/application/svt/svt_handler.h b/score/time_daemon/src/application/svt/svt_handler.h index 63663225..5fef4d01 100644 --- a/score/time_daemon/src/application/svt/svt_handler.h +++ b/score/time_daemon/src/application/svt/svt_handler.h @@ -18,7 +18,7 @@ #include "score/time_daemon/src/control_flow_divider/ptp/ptp_control_flow_divider.h" #include "score/time_daemon/src/ipc/svt/publisher/svt_publisher.h" #include "score/time_daemon/src/msg_broker/msg_broker.h" -#include "score/time_daemon/src/ptp_machine/stub/gptp_stub_machine.h" +#include "score/time_daemon/src/ptp_machine/shm/gptp_shm_machine.h" #include "score/time_daemon/src/verification_machine/svt/svt_verification_machine.h" #include @@ -72,7 +72,7 @@ class SvtHandler : public TimebaseHandler 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 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 diff --git a/score/time_daemon/src/application/svt/svt_handler_shm.cpp b/score/time_daemon/src/application/svt/svt_handler_shm.cpp deleted file mode 100644 index 64259940..00000000 --- a/score/time_daemon/src/application/svt/svt_handler_shm.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ -#include "score/TimeDaemon/code/application/svt/svt_handler_shm.h" -#include "score/TimeDaemon/code/common/logging_contexts.h" -#include "score/TimeDaemon/code/control_flow_divider/ptp/factory.h" -#include "score/TimeDaemon/code/ipc/svt/publisher/factory.h" -#include "score/TimeDaemon/code/msg_broker/subscription.h" -#include "score/TimeDaemon/code/msg_broker/topic.h" -#include "score/TimeDaemon/code/ptp_machine/shm/factory.h" -#include "score/TimeDaemon/code/verification_machine/svt/factory.h" -#include "score/concurrency/interruptible_wait.h" -#include "score/mw/log/logging.h" - -#include -#include - -namespace score -{ -namespace td -{ - -SvtHandlerShm::SvtHandlerShm() noexcept - : job_runner_{nullptr}, - msg_broker_{nullptr}, - gptp_machine_{nullptr}, - verification_machine_{nullptr}, - ipc_publisher_{nullptr}, - ctrl_flow_divider_{nullptr}, - handler_status_{TimebaseHandler::Status::kIdle} -{ - 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}); - - std::vector jobs = { - {[this] { - return gptp_machine_->Init(); - }, - gptp_machine_->GetName(), - std::chrono::seconds(20)}, - {[this] { - return verification_machine_->Init(); - }, - verification_machine_->GetName(), - std::chrono::seconds(20)}, - {[this] { - return ipc_publisher_->Init(); - }, - ipc_publisher_->GetName(), - std::chrono::seconds(20)}, - {[this] { - return ctrl_flow_divider_->Init(); - }, - ctrl_flow_divider_->GetName(), - std::chrono::seconds(20)}, - }; - job_runner_ = std::make_unique(std::move(jobs), "svt_init"); - - score::mw::log::LogInfo(kTimeBaseHandlerSvt) << "SvtHandlerShm created!"; -} - -void SvtHandlerShm::Initialize() noexcept -{ - const auto input_ptp_data_topic = Topic("in_ptp_data"); - const auto raw_ptp_data_topic = Topic("raw_ptp_data"); - const auto validated_ptp_data_topic = Topic("validated_ptp_data"); - - msg_broker_->AddSubscriber(input_ptp_data_topic, ctrl_flow_divider_); - msg_broker_->AddSubscriber(raw_ptp_data_topic, verification_machine_); - msg_broker_->AddSubscriber(validated_ptp_data_topic, ipc_publisher_); - - msg_broker_->AddProducer(input_ptp_data_topic, gptp_machine_); - msg_broker_->AddProducer(raw_ptp_data_topic, ctrl_flow_divider_); - msg_broker_->AddProducer(validated_ptp_data_topic, verification_machine_); - - score::mw::log::LogInfo(kTimeBaseHandlerSvt) << "SvtHandlerShm msg broker initialized!"; -} - -void SvtHandlerShm::RunOnce(const score::cpp::stop_token& token) noexcept -{ - switch (handler_status_) - { - case TimebaseHandler::Status::kIdle: - { - job_runner_->Start(token); - handler_status_ = TimebaseHandler::Status::kInitialize; - score::mw::log::LogInfo(kTimeBaseHandlerSvt) << "SvtHandlerShm initialization started"; - break; - } - case TimebaseHandler::Status::kInitialize: - { - auto status = job_runner_->GetResult(); - switch (status) - { - case JobRunner::Result::kSucceed: - { - score::mw::log::LogInfo(kTimeBaseHandlerSvt) - << "SvtHandlerShm initialization done, starting proactive machines!"; - job_runner_.reset(); - ctrl_flow_divider_->Start(); - gptp_machine_->Start(); - handler_status_ = TimebaseHandler::Status::kWorking; - score::mw::log::LogInfo(kTimeBaseHandlerSvt) << "SvtHandlerShm is working"; - break; - } - case JobRunner::Result::kFailed: - { - handler_status_ = TimebaseHandler::Status::kFailed; - score::mw::log::LogError(kTimeBaseHandlerSvt) << "SvtHandlerShm initialization failed!!"; - break; - } - case JobRunner::Result::kIdle: - case JobRunner::Result::kInProgress: - default: - break; - } - break; - } - case TimebaseHandler::Status::kWorking: - case TimebaseHandler::Status::kFailed: - default: - break; - } -} - -void SvtHandlerShm::Stop() noexcept -{ - if (handler_status_ == TimebaseHandler::Status::kWorking) - { - gptp_machine_->Stop(); - ctrl_flow_divider_->Stop(); - score::mw::log::LogInfo(kTimeBaseHandlerSvt) << "SvtHandlerShm stopping proactive machines!"; - } -} - -} // namespace td -} // namespace score diff --git a/score/time_daemon/src/application/svt/svt_handler_shm.h b/score/time_daemon/src/application/svt/svt_handler_shm.h deleted file mode 100644 index df1d8f2e..00000000 --- a/score/time_daemon/src/application/svt/svt_handler_shm.h +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2026 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ -#ifndef SCORE_TIMEDAEMON_CODE_APPLICATION_SVT_SHM_HANDLER_H -#define SCORE_TIMEDAEMON_CODE_APPLICATION_SVT_SHM_HANDLER_H - -#include "score/TimeDaemon/code/application/job_runner/job_runner.h" -#include "score/TimeDaemon/code/application/timebase_handler.h" -#include "score/TimeDaemon/code/control_flow_divider/ptp/ptp_control_flow_divider.h" -#include "score/TimeDaemon/code/ipc/svt/publisher/svt_publisher.h" -#include "score/TimeDaemon/code/msg_broker/msg_broker.h" -#include "score/TimeDaemon/code/ptp_machine/shm/gptp_shm_machine.h" -#include "score/TimeDaemon/code/verification_machine/svt/svt_verification_machine.h" - -#include - -namespace score -{ -namespace td -{ - -/// \brief SVT timebase handler backed by the shared-memory gPTP engine. -/// -/// Reads live gPTP data written by TimeSlave via GptpIpcPublisher, processing -/// it through the same verification and IPC-publish pipeline as SvtHandler. -class SvtHandlerShm : public TimebaseHandler -{ - public: - SvtHandlerShm() noexcept; - virtual ~SvtHandlerShm() noexcept = default; - SvtHandlerShm(const SvtHandlerShm&) = delete; - SvtHandlerShm(SvtHandlerShm&&) = delete; - SvtHandlerShm& operator=(const SvtHandlerShm&) = delete; - SvtHandlerShm& operator=(SvtHandlerShm&&) = delete; - - virtual void Initialize() noexcept override; - virtual void RunOnce(const score::cpp::stop_token& token) noexcept override; - virtual void Stop() noexcept override; - - private: - std::unique_ptr job_runner_; - std::shared_ptr> msg_broker_; - std::shared_ptr gptp_machine_; - std::shared_ptr verification_machine_; - std::shared_ptr ipc_publisher_; - std::shared_ptr ctrl_flow_divider_; - TimebaseHandler::Status handler_status_; -}; - -} // namespace td -} // namespace score - -#endif // SCORE_TIMEDAEMON_CODE_APPLICATION_SVT_SHM_HANDLER_H 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 836eca62..15278fb8 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 @@ -30,7 +30,7 @@ bool ShmPTPEngine::Initialize() if (initialized_) return true; - initialized_ = receiver_.Init(ipc_name_); + initialized_ = receiver_.Open(ipc_name_); if (initialized_) { score::mw::log::LogInfo(kGPtpMachineContext) << "ShmPTPEngine: connected to IPC channel " << ipc_name_; 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 6b74e1c8..8ac1a997 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 @@ -86,7 +86,7 @@ class ShmPTPEngineTest : public ::testing::Test void TearDown() override { engine_->Deinitialize(); - pub_.Destroy(); + pub_.Close(); } std::string name_; @@ -103,13 +103,13 @@ TEST_F(ShmPTPEngineTest, Initialize_WhenShmNotExist_ReturnsFalse) TEST_F(ShmPTPEngineTest, Initialize_WhenShmExists_ReturnsTrue) { - ASSERT_TRUE(pub_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); EXPECT_TRUE(engine_->Initialize()); } TEST_F(ShmPTPEngineTest, Initialize_CalledTwiceWhenInitialized_ReturnsTrue) { - ASSERT_TRUE(pub_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); ASSERT_TRUE(engine_->Initialize()); EXPECT_TRUE(engine_->Initialize()); // idempotent } @@ -121,14 +121,14 @@ TEST_F(ShmPTPEngineTest, Deinitialize_WhenNotInitialized_ReturnsTrue) TEST_F(ShmPTPEngineTest, Deinitialize_AfterInitialize_ReturnsTrue) { - ASSERT_TRUE(pub_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); ASSERT_TRUE(engine_->Initialize()); EXPECT_TRUE(engine_->Deinitialize()); } TEST_F(ShmPTPEngineTest, Deinitialize_CalledTwice_BothReturnTrue) { - ASSERT_TRUE(pub_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); ASSERT_TRUE(engine_->Initialize()); EXPECT_TRUE(engine_->Deinitialize()); EXPECT_TRUE(engine_->Deinitialize()); @@ -136,7 +136,7 @@ TEST_F(ShmPTPEngineTest, Deinitialize_CalledTwice_BothReturnTrue) TEST_F(ShmPTPEngineTest, ReInitialize_AfterDeinitialize_Succeeds) { - ASSERT_TRUE(pub_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); ASSERT_TRUE(engine_->Initialize()); ASSERT_TRUE(engine_->Deinitialize()); EXPECT_TRUE(engine_->Initialize()); @@ -152,7 +152,7 @@ TEST_F(ShmPTPEngineTest, ReadPTPSnapshot_WhenNotInitialized_ReturnsFalse) TEST_F(ShmPTPEngineTest, ReadPTPSnapshot_WithPublishedData_ReturnsTrue) { - ASSERT_TRUE(pub_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); pub_.Publish(MakeTestIpcData()); ASSERT_TRUE(engine_->Initialize()); @@ -162,7 +162,7 @@ TEST_F(ShmPTPEngineTest, ReadPTPSnapshot_WithPublishedData_ReturnsTrue) TEST_F(ShmPTPEngineTest, ReadPTPSnapshot_CopiesTimeAndStatusCorrectly) { - ASSERT_TRUE(pub_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); const score::ts::GptpIpcData src = MakeTestIpcData(); pub_.Publish(src); ASSERT_TRUE(engine_->Initialize()); @@ -179,7 +179,7 @@ TEST_F(ShmPTPEngineTest, ReadPTPSnapshot_CopiesTimeAndStatusCorrectly) TEST_F(ShmPTPEngineTest, ReadPTPSnapshot_CopiesSyncFupDataCorrectly) { - ASSERT_TRUE(pub_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); const score::ts::GptpIpcData src = MakeTestIpcData(); pub_.Publish(src); ASSERT_TRUE(engine_->Initialize()); @@ -196,7 +196,7 @@ TEST_F(ShmPTPEngineTest, ReadPTPSnapshot_CopiesSyncFupDataCorrectly) TEST_F(ShmPTPEngineTest, ReadPTPSnapshot_CopiesPDelayDataCorrectly) { - ASSERT_TRUE(pub_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); const score::ts::GptpIpcData src = MakeTestIpcData(); pub_.Publish(src); ASSERT_TRUE(engine_->Initialize()); 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 1e27a715..fffa2a7a 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 @@ -56,7 +56,7 @@ class GPTPShmMachineIntegrationTest : public ::testing::Test void SetUp() override { name_ = UniqueShmName(); - ASSERT_TRUE(pub_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); pub_.Publish(MakePublishedInfo()); machine_ = CreateGPTPShmMachine("ShmPTPMachine", name_); @@ -73,7 +73,7 @@ class GPTPShmMachineIntegrationTest : public ::testing::Test { machine_->Stop(); machine_.reset(); - pub_.Destroy(); + pub_.Close(); } std::string name_; diff --git a/score/time_slave/src/application/time_slave.cpp b/score/time_slave/src/application/time_slave.cpp index 0aa477ca..426402d2 100644 --- a/score/time_slave/src/application/time_slave.cpp +++ b/score/time_slave/src/application/time_slave.cpp @@ -42,7 +42,7 @@ std::int32_t TimeSlave::Initialize(const score::mw::lifecycle::ApplicationContex return kInitFailure; } - if (!publisher_.Init()) + if (!publisher_.Open()) { score::mw::log::LogError(kTimeSlaveAppContext) << "TimeSlave: shared memory publisher initialization failed"; return kInitFailure; @@ -71,7 +71,7 @@ std::int32_t TimeSlave::Run(const score::cpp::stop_token& token) } engine_->Deinitialize(); - publisher_.Destroy(); + publisher_.Close(); score::mw::log::LogInfo(kTimeSlaveAppContext) << "TimeSlave stopped"; return kInitSuccess; diff --git a/score/ts_client/src/gptp_ipc_channel.h b/score/ts_client/src/gptp_ipc_channel.h index c3bbd926..5c0a9ca3 100644 --- a/score/ts_client/src/gptp_ipc_channel.h +++ b/score/ts_client/src/gptp_ipc_channel.h @@ -25,6 +25,7 @@ namespace ts namespace details { +/// Default shared memory name for the gPTP IPC channel. constexpr char kGptpIpcName[] = "/gptp_ptp_info"; /// Magic number to validate the shared memory region ('GPTP'). diff --git a/score/ts_client/src/gptp_ipc_data.h b/score/ts_client/src/gptp_ipc_data.h index 31eb860a..6fdb0003 100644 --- a/score/ts_client/src/gptp_ipc_data.h +++ b/score/ts_client/src/gptp_ipc_data.h @@ -65,7 +65,7 @@ struct GptpIpcPDelayData /** * @brief IPC data snapshot written by TimeSlave and read by TimeDaemon. * - * This type is internal to libTSClient and intentionally decoupled from + * This type is internal to ts_client and intentionally decoupled from * score::td::PtpTimeInfo. Callers are responsible for mapping between the two. */ struct GptpIpcData diff --git a/score/ts_client/src/gptp_ipc_publisher.cpp b/score/ts_client/src/gptp_ipc_publisher.cpp index 04cd8f23..55b73a65 100644 --- a/score/ts_client/src/gptp_ipc_publisher.cpp +++ b/score/ts_client/src/gptp_ipc_publisher.cpp @@ -27,10 +27,10 @@ namespace details GptpIpcPublisher::~GptpIpcPublisher() { - Destroy(); + Close(); } -bool GptpIpcPublisher::Init(const std::string& ipc_name) +bool GptpIpcPublisher::Open(const std::string& ipc_name) { if (shm_resource_ != nullptr) return true; @@ -69,7 +69,7 @@ void GptpIpcPublisher::Publish(const score::ts::GptpIpcData& data) region_->seq.store(next + 1U, std::memory_order_release); } -void GptpIpcPublisher::Destroy() +void GptpIpcPublisher::Close() { if (!ipc_name_.empty()) { diff --git a/score/ts_client/src/gptp_ipc_publisher.h b/score/ts_client/src/gptp_ipc_publisher.h index dc5fe157..977751f7 100644 --- a/score/ts_client/src/gptp_ipc_publisher.h +++ b/score/ts_client/src/gptp_ipc_publisher.h @@ -41,9 +41,9 @@ class GptpIpcPublisher final GptpIpcPublisher(const GptpIpcPublisher&) = delete; GptpIpcPublisher& operator=(const GptpIpcPublisher&) = delete; - bool Init(const std::string& ipc_name = kGptpIpcName); + bool Open(const std::string& ipc_name = kGptpIpcName); void Publish(const score::ts::GptpIpcData& data); - void Destroy(); + void Close(); private: GptpIpcRegion* region_{nullptr}; diff --git a/score/ts_client/src/gptp_ipc_publisher_test.cpp b/score/ts_client/src/gptp_ipc_publisher_test.cpp index b4f7d41e..843b525a 100644 --- a/score/ts_client/src/gptp_ipc_publisher_test.cpp +++ b/score/ts_client/src/gptp_ipc_publisher_test.cpp @@ -27,15 +27,15 @@ class GptpIpcPublisherTest : public ::testing::Test protected: void TearDown() override { - pub_.Destroy(); + pub_.Close(); } GptpIpcPublisher pub_; }; -TEST_F(GptpIpcPublisherTest, Init_ValidName_ReturnsTrue) +TEST_F(GptpIpcPublisherTest, Open_ValidName_ReturnsTrue) { - EXPECT_TRUE(pub_.Init(UniqueShmName())); + EXPECT_TRUE(pub_.Open(UniqueShmName())); } TEST_F(GptpIpcPublisherTest, Publish_WithoutInit_DoesNotCrash) @@ -44,23 +44,23 @@ TEST_F(GptpIpcPublisherTest, Publish_WithoutInit_DoesNotCrash) EXPECT_NO_THROW(pub_.Publish(data)); } -TEST_F(GptpIpcPublisherTest, Destroy_CalledTwice_DoesNotCrash) +TEST_F(GptpIpcPublisherTest, Close_CalledTwice_DoesNotCrash) { - ASSERT_TRUE(pub_.Init(UniqueShmName())); - pub_.Destroy(); - EXPECT_NO_THROW(pub_.Destroy()); + ASSERT_TRUE(pub_.Open(UniqueShmName())); + pub_.Close(); + EXPECT_NO_THROW(pub_.Close()); } -TEST_F(GptpIpcPublisherTest, Destroy_WithoutInit_DoesNotCrash) +TEST_F(GptpIpcPublisherTest, Close_WithoutOpen_DoesNotCrash) { - EXPECT_NO_THROW(pub_.Destroy()); + EXPECT_NO_THROW(pub_.Close()); } -TEST_F(GptpIpcPublisherTest, Init_CalledTwice_ReturnsTrueOnSecondCall) +TEST_F(GptpIpcPublisherTest, Open_CalledTwice_ReturnsTrueOnSecondCall) { // region_ != nullptr after first Init → second call returns true immediately. - ASSERT_TRUE(pub_.Init(UniqueShmName())); - EXPECT_TRUE(pub_.Init(UniqueShmName())); + ASSERT_TRUE(pub_.Open(UniqueShmName())); + EXPECT_TRUE(pub_.Open(UniqueShmName())); } } // namespace details diff --git a/score/ts_client/src/gptp_ipc_receiver.cpp b/score/ts_client/src/gptp_ipc_receiver.cpp index 347697da..a0c27133 100644 --- a/score/ts_client/src/gptp_ipc_receiver.cpp +++ b/score/ts_client/src/gptp_ipc_receiver.cpp @@ -29,7 +29,7 @@ GptpIpcReceiver::~GptpIpcReceiver() Close(); } -bool GptpIpcReceiver::Init(const std::string& ipc_name) +bool GptpIpcReceiver::Open(const std::string& ipc_name) { if (shm_resource_ != nullptr) return true; diff --git a/score/ts_client/src/gptp_ipc_receiver.h b/score/ts_client/src/gptp_ipc_receiver.h index 38ca6656..f7ecea94 100644 --- a/score/ts_client/src/gptp_ipc_receiver.h +++ b/score/ts_client/src/gptp_ipc_receiver.h @@ -42,7 +42,7 @@ class GptpIpcReceiver final GptpIpcReceiver(const GptpIpcReceiver&) = delete; GptpIpcReceiver& operator=(const GptpIpcReceiver&) = delete; - bool Init(const std::string& ipc_name = kGptpIpcName); + bool Open(const std::string& ipc_name = kGptpIpcName); std::optional Receive(); void Close(); diff --git a/score/ts_client/src/gptp_ipc_receiver_test.cpp b/score/ts_client/src/gptp_ipc_receiver_test.cpp index 5f481997..06d1861e 100644 --- a/score/ts_client/src/gptp_ipc_receiver_test.cpp +++ b/score/ts_client/src/gptp_ipc_receiver_test.cpp @@ -38,9 +38,9 @@ class GptpIpcReceiverTest : public ::testing::Test GptpIpcReceiver rx_; }; -TEST_F(GptpIpcReceiverTest, Init_ShmNotExist_ReturnsFalse) +TEST_F(GptpIpcReceiverTest, Open_ShmNotExist_ReturnsFalse) { - EXPECT_FALSE(rx_.Init("/gptp_nonexistent_" + std::to_string(::getpid()))); + EXPECT_FALSE(rx_.Open("/gptp_nonexistent_" + std::to_string(::getpid()))); } TEST_F(GptpIpcReceiverTest, Close_WithoutInit_DoesNotCrash) @@ -59,18 +59,18 @@ TEST_F(GptpIpcReceiverTest, Receive_WithoutInit_ReturnsNullopt) EXPECT_FALSE(rx_.Receive().has_value()); } -TEST_F(GptpIpcReceiverTest, Init_CalledTwice_ReturnsTrueOnSecondCall) +TEST_F(GptpIpcReceiverTest, Open_CalledTwice_ReturnsTrueOnSecondCall) { - // region_ != nullptr after first Init → second call returns true immediately. + // region_ != nullptr after first Open → second call returns true immediately. GptpIpcPublisher pub; const std::string name = UniqueShmName(); - ASSERT_TRUE(pub.Init(name)); - ASSERT_TRUE(rx_.Init(name)); - EXPECT_TRUE(rx_.Init(name)); - pub.Destroy(); + ASSERT_TRUE(pub.Open(name)); + ASSERT_TRUE(rx_.Open(name)); + EXPECT_TRUE(rx_.Open(name)); + pub.Close(); } -TEST_F(GptpIpcReceiverTest, Init_TooSmallShm_ReturnsFalse) +TEST_F(GptpIpcReceiverTest, Open_TooSmallShm_ReturnsFalse) { // Create a shm segment smaller than GptpIpcRegion so the fstat size check fails. const std::string name = UniqueShmName(); @@ -79,7 +79,7 @@ TEST_F(GptpIpcReceiverTest, Init_TooSmallShm_ReturnsFalse) ASSERT_EQ(::ftruncate(fd, 1), 0); ::close(fd); - EXPECT_FALSE(rx_.Init(name)); + EXPECT_FALSE(rx_.Open(name)); ::shm_unlink(name.c_str()); } diff --git a/score/ts_client/src/gptp_ipc_roundtrip_test.cpp b/score/ts_client/src/gptp_ipc_roundtrip_test.cpp index a32c1b74..f27a0f9f 100644 --- a/score/ts_client/src/gptp_ipc_roundtrip_test.cpp +++ b/score/ts_client/src/gptp_ipc_roundtrip_test.cpp @@ -35,7 +35,7 @@ class GptpIpcRoundtripTest : public ::testing::Test void TearDown() override { rx_.Close(); - pub_.Destroy(); + pub_.Close(); } std::string name_; @@ -43,16 +43,16 @@ class GptpIpcRoundtripTest : public ::testing::Test GptpIpcReceiver rx_; }; -TEST_F(GptpIpcRoundtripTest, ReceiverInit_AfterPublisherInit_ReturnsTrue) +TEST_F(GptpIpcRoundtripTest, ReceiverOpen_AfterPublisherOpen_ReturnsTrue) { - ASSERT_TRUE(pub_.Init(name_)); - EXPECT_TRUE(rx_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); + EXPECT_TRUE(rx_.Open(name_)); } TEST_F(GptpIpcRoundtripTest, ReceiverReceive_BeforeAnyPublish_ReturnsNullopt) { - ASSERT_TRUE(pub_.Init(name_)); - ASSERT_TRUE(rx_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); + ASSERT_TRUE(rx_.Open(name_)); // seq_confirm is initialised to 1 (≠ seq=0) by GptpIpcRegion's constructor, // so the seqlock always mismatches before the first Publish() call. EXPECT_FALSE(rx_.Receive().has_value()); @@ -60,8 +60,8 @@ TEST_F(GptpIpcRoundtripTest, ReceiverReceive_BeforeAnyPublish_ReturnsNullopt) TEST_F(GptpIpcRoundtripTest, PublishReceive_BasicFields_RoundtripCorrectly) { - ASSERT_TRUE(pub_.Init(name_)); - ASSERT_TRUE(rx_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); + ASSERT_TRUE(rx_.Open(name_)); score::ts::GptpIpcData data{}; data.ptp_assumed_time = std::chrono::nanoseconds{1'234'567'890LL}; @@ -84,8 +84,8 @@ TEST_F(GptpIpcRoundtripTest, PublishReceive_BasicFields_RoundtripCorrectly) TEST_F(GptpIpcRoundtripTest, PublishReceive_StatusFlags_RoundtripCorrectly) { - ASSERT_TRUE(pub_.Init(name_)); - ASSERT_TRUE(rx_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); + ASSERT_TRUE(rx_.Open(name_)); score::ts::GptpIpcData data{}; data.status.is_timeout = true; @@ -105,8 +105,8 @@ TEST_F(GptpIpcRoundtripTest, PublishReceive_StatusFlags_RoundtripCorrectly) TEST_F(GptpIpcRoundtripTest, PublishReceive_SyncFupData_RoundtripCorrectly) { - ASSERT_TRUE(pub_.Init(name_)); - ASSERT_TRUE(rx_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); + ASSERT_TRUE(rx_.Open(name_)); score::ts::GptpIpcData data{}; data.sync_fup_data.precise_origin_timestamp = 100'000'000'000ULL; @@ -132,8 +132,8 @@ TEST_F(GptpIpcRoundtripTest, PublishReceive_SyncFupData_RoundtripCorrectly) TEST_F(GptpIpcRoundtripTest, PublishReceive_PDelayData_RoundtripCorrectly) { - ASSERT_TRUE(pub_.Init(name_)); - ASSERT_TRUE(rx_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); + ASSERT_TRUE(rx_.Open(name_)); score::ts::GptpIpcData data{}; data.pdelay_data.request_origin_timestamp = 1'000'000'000ULL; @@ -158,8 +158,8 @@ TEST_F(GptpIpcRoundtripTest, PublishReceive_PDelayData_RoundtripCorrectly) TEST_F(GptpIpcRoundtripTest, MultiplePublish_LastValueIsVisible) { - ASSERT_TRUE(pub_.Init(name_)); - ASSERT_TRUE(rx_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); + ASSERT_TRUE(rx_.Open(name_)); for (int i = 1; i <= 5; ++i) { @@ -175,7 +175,7 @@ TEST_F(GptpIpcRoundtripTest, MultiplePublish_LastValueIsVisible) // ── Edge cases via ManualShm ────────────────────────────────────────────────── -TEST_F(GptpIpcRoundtripTest, ReceiverInit_WrongMagic_ReturnsFalse) +TEST_F(GptpIpcRoundtripTest, ReceiverOpen_WrongMagic_ReturnsFalse) { ManualShm shm{name_}; ASSERT_TRUE(shm.Valid()); @@ -184,7 +184,7 @@ TEST_F(GptpIpcRoundtripTest, ReceiverInit_WrongMagic_ReturnsFalse) const std::uint32_t bad = 0xDEADBEEFU; std::memcpy(shm.Region(), &bad, sizeof(bad)); - EXPECT_FALSE(rx_.Init(name_)); + EXPECT_FALSE(rx_.Open(name_)); } TEST_F(GptpIpcRoundtripTest, Receive_PersistentOddSeq_ExhaustsRetriesAndReturnsNullopt) @@ -196,7 +196,7 @@ TEST_F(GptpIpcRoundtripTest, Receive_PersistentOddSeq_ExhaustsRetriesAndReturnsN region->seq.store(1U, std::memory_order_relaxed); region->seq_confirm.store(0U, std::memory_order_relaxed); - ASSERT_TRUE(rx_.Init(name_)); + ASSERT_TRUE(rx_.Open(name_)); EXPECT_FALSE(rx_.Receive().has_value()); } @@ -209,7 +209,7 @@ TEST_F(GptpIpcRoundtripTest, Receive_SeqConfirmMismatch_ExhaustsRetriesAndReturn region->seq.store(4U, std::memory_order_relaxed); region->seq_confirm.store(2U, std::memory_order_relaxed); - ASSERT_TRUE(rx_.Init(name_)); + ASSERT_TRUE(rx_.Open(name_)); EXPECT_FALSE(rx_.Receive().has_value()); } diff --git a/score/ts_client/src/gptp_ipc_test.cpp b/score/ts_client/src/gptp_ipc_test.cpp index eadae9b3..7c7ce66e 100644 --- a/score/ts_client/src/gptp_ipc_test.cpp +++ b/score/ts_client/src/gptp_ipc_test.cpp @@ -88,15 +88,15 @@ class GptpIpcPublisherTest : public ::testing::Test protected: void TearDown() override { - pub_.Destroy(); + pub_.Close(); } GptpIpcPublisher pub_; }; -TEST_F(GptpIpcPublisherTest, Init_ValidName_ReturnsTrue) +TEST_F(GptpIpcPublisherTest, Open_ValidName_ReturnsTrue) { - EXPECT_TRUE(pub_.Init(UniqueShmName())); + EXPECT_TRUE(pub_.Open(UniqueShmName())); } TEST_F(GptpIpcPublisherTest, Publish_WithoutInit_DoesNotCrash) @@ -106,23 +106,23 @@ TEST_F(GptpIpcPublisherTest, Publish_WithoutInit_DoesNotCrash) EXPECT_NO_THROW(pub_.Publish(info)); } -TEST_F(GptpIpcPublisherTest, Destroy_CalledTwice_DoesNotCrash) +TEST_F(GptpIpcPublisherTest, Close_CalledTwice_DoesNotCrash) { - ASSERT_TRUE(pub_.Init(UniqueShmName())); - pub_.Destroy(); - EXPECT_NO_THROW(pub_.Destroy()); + ASSERT_TRUE(pub_.Open(UniqueShmName())); + pub_.Close(); + EXPECT_NO_THROW(pub_.Close()); } -TEST_F(GptpIpcPublisherTest, Destroy_WithoutInit_DoesNotCrash) +TEST_F(GptpIpcPublisherTest, Close_WithoutOpen_DoesNotCrash) { - EXPECT_NO_THROW(pub_.Destroy()); + EXPECT_NO_THROW(pub_.Close()); } -TEST_F(GptpIpcPublisherTest, Init_CalledTwice_ReturnsTrueOnSecondCall) +TEST_F(GptpIpcPublisherTest, Open_CalledTwice_ReturnsTrueOnSecondCall) { - // region_ != nullptr after first Init → second call returns true immediately. - ASSERT_TRUE(pub_.Init(UniqueShmName())); - EXPECT_TRUE(pub_.Init(UniqueShmName())); + // region_ != nullptr after first Open → second call returns true immediately. + ASSERT_TRUE(pub_.Open(UniqueShmName())); + EXPECT_TRUE(pub_.Open(UniqueShmName())); } // ── GptpIpcReceiver ─────────────────────────────────────────────────────────── @@ -138,9 +138,9 @@ class GptpIpcReceiverTest : public ::testing::Test GptpIpcReceiver rx_; }; -TEST_F(GptpIpcReceiverTest, Init_ShmNotExist_ReturnsFalse) +TEST_F(GptpIpcReceiverTest, Open_ShmNotExist_ReturnsFalse) { - EXPECT_FALSE(rx_.Init("/gptp_nonexistent_" + std::to_string(::getpid()))); + EXPECT_FALSE(rx_.Open("/gptp_nonexistent_" + std::to_string(::getpid()))); } TEST_F(GptpIpcReceiverTest, Close_WithoutInit_DoesNotCrash) @@ -159,18 +159,18 @@ TEST_F(GptpIpcReceiverTest, Receive_WithoutInit_ReturnsNullopt) EXPECT_FALSE(rx_.Receive().has_value()); } -TEST_F(GptpIpcReceiverTest, Init_CalledTwice_ReturnsTrueOnSecondCall) +TEST_F(GptpIpcReceiverTest, Open_CalledTwice_ReturnsTrueOnSecondCall) { - // region_ != nullptr after first Init → second call returns true immediately. + // region_ != nullptr after first Open → second call returns true immediately. GptpIpcPublisher pub; const std::string name = UniqueShmName(); - ASSERT_TRUE(pub.Init(name)); - ASSERT_TRUE(rx_.Init(name)); - EXPECT_TRUE(rx_.Init(name)); - pub.Destroy(); + ASSERT_TRUE(pub.Open(name)); + ASSERT_TRUE(rx_.Open(name)); + EXPECT_TRUE(rx_.Open(name)); + pub.Close(); } -TEST_F(GptpIpcReceiverTest, Init_TooSmallShm_ReturnsFalse) +TEST_F(GptpIpcReceiverTest, Open_TooSmallShm_ReturnsFalse) { // Create a shm segment smaller than GptpIpcRegion so the fstat size check fails. const std::string name = UniqueShmName(); @@ -179,7 +179,7 @@ TEST_F(GptpIpcReceiverTest, Init_TooSmallShm_ReturnsFalse) ASSERT_EQ(::ftruncate(fd, 1), 0); ::close(fd); - EXPECT_FALSE(rx_.Init(name)); + EXPECT_FALSE(rx_.Open(name)); ::shm_unlink(name.c_str()); } @@ -196,7 +196,7 @@ class GptpIpcRoundtripTest : public ::testing::Test void TearDown() override { rx_.Close(); - pub_.Destroy(); + pub_.Close(); } std::string name_; @@ -204,16 +204,16 @@ class GptpIpcRoundtripTest : public ::testing::Test GptpIpcReceiver rx_; }; -TEST_F(GptpIpcRoundtripTest, ReceiverInit_AfterPublisherInit_ReturnsTrue) +TEST_F(GptpIpcRoundtripTest, ReceiverOpen_AfterPublisherOpen_ReturnsTrue) { - ASSERT_TRUE(pub_.Init(name_)); - EXPECT_TRUE(rx_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); + EXPECT_TRUE(rx_.Open(name_)); } TEST_F(GptpIpcRoundtripTest, ReceiverReceive_BeforeAnyPublish_ReturnsNullopt) { - ASSERT_TRUE(pub_.Init(name_)); - ASSERT_TRUE(rx_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); + ASSERT_TRUE(rx_.Open(name_)); // seq_confirm is initialised to 1 (≠ seq=0) by GptpIpcRegion's constructor, // so the seqlock always mismatches before the first Publish() call. // Receive() must exhaust its retries and return std::nullopt. @@ -222,8 +222,8 @@ TEST_F(GptpIpcRoundtripTest, ReceiverReceive_BeforeAnyPublish_ReturnsNullopt) TEST_F(GptpIpcRoundtripTest, PublishReceive_BasicFields_RoundtripCorrectly) { - ASSERT_TRUE(pub_.Init(name_)); - ASSERT_TRUE(rx_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); + ASSERT_TRUE(rx_.Open(name_)); score::td::PtpTimeInfo info{}; info.ptp_assumed_time = std::chrono::nanoseconds{1'234'567'890LL}; @@ -246,8 +246,8 @@ TEST_F(GptpIpcRoundtripTest, PublishReceive_BasicFields_RoundtripCorrectly) TEST_F(GptpIpcRoundtripTest, PublishReceive_StatusFlags_RoundtripCorrectly) { - ASSERT_TRUE(pub_.Init(name_)); - ASSERT_TRUE(rx_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); + ASSERT_TRUE(rx_.Open(name_)); score::td::PtpTimeInfo info{}; info.status.is_timeout = true; @@ -268,8 +268,8 @@ TEST_F(GptpIpcRoundtripTest, PublishReceive_StatusFlags_RoundtripCorrectly) TEST_F(GptpIpcRoundtripTest, PublishReceive_SyncFupData_RoundtripCorrectly) { - ASSERT_TRUE(pub_.Init(name_)); - ASSERT_TRUE(rx_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); + ASSERT_TRUE(rx_.Open(name_)); score::td::PtpTimeInfo info{}; info.sync_fup_data.precise_origin_timestamp = 100'000'000'000ULL; @@ -295,8 +295,8 @@ TEST_F(GptpIpcRoundtripTest, PublishReceive_SyncFupData_RoundtripCorrectly) TEST_F(GptpIpcRoundtripTest, PublishReceive_PDelayData_RoundtripCorrectly) { - ASSERT_TRUE(pub_.Init(name_)); - ASSERT_TRUE(rx_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); + ASSERT_TRUE(rx_.Open(name_)); score::td::PtpTimeInfo info{}; info.pdelay_data.request_origin_timestamp = 1'000'000'000ULL; @@ -321,8 +321,8 @@ TEST_F(GptpIpcRoundtripTest, PublishReceive_PDelayData_RoundtripCorrectly) TEST_F(GptpIpcRoundtripTest, MultiplePublish_LastValueIsVisible) { - ASSERT_TRUE(pub_.Init(name_)); - ASSERT_TRUE(rx_.Init(name_)); + ASSERT_TRUE(pub_.Open(name_)); + ASSERT_TRUE(rx_.Open(name_)); for (int i = 1; i <= 5; ++i) { @@ -348,7 +348,7 @@ TEST_F(GptpIpcRoundtripTest, ReceiverInit_WrongMagic_ReturnsFalse) const std::uint32_t bad = 0xDEADBEEFU; std::memcpy(shm.ptr, &bad, sizeof(bad)); - EXPECT_FALSE(rx_.Init(name_)); + EXPECT_FALSE(rx_.Open(name_)); } TEST_F(GptpIpcRoundtripTest, Receive_PersistentOddSeq_ExhaustsRetriesAndReturnsNullopt) @@ -361,7 +361,7 @@ TEST_F(GptpIpcRoundtripTest, Receive_PersistentOddSeq_ExhaustsRetriesAndReturnsN region->seq.store(1U, std::memory_order_relaxed); region->seq_confirm.store(0U, std::memory_order_relaxed); - ASSERT_TRUE(rx_.Init(name_)); + ASSERT_TRUE(rx_.Open(name_)); EXPECT_FALSE(rx_.Receive().has_value()); } @@ -375,7 +375,7 @@ TEST_F(GptpIpcRoundtripTest, Receive_SeqConfirmMismatch_ExhaustsRetriesAndReturn region->seq.store(4U, std::memory_order_relaxed); region->seq_confirm.store(2U, std::memory_order_relaxed); - ASSERT_TRUE(rx_.Init(name_)); + ASSERT_TRUE(rx_.Open(name_)); EXPECT_FALSE(rx_.Receive().has_value()); } From 8c6827d65cc842f2cedba3fb3b5346666536e140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gordon=20=5C=20Chenhao=20Gao=20=5C=20=E9=AB=98=E6=99=A8?= =?UTF-8?q?=E6=B5=A9?= Date: Wed, 24 Jun 2026 13:53:09 +0800 Subject: [PATCH 3/7] Revert include guards to match physical include path --- score/ts_client/src/gptp_ipc.h | 6 +++--- score/ts_client/src/gptp_ipc_channel.h | 6 +++--- score/ts_client/src/gptp_ipc_data.h | 6 +++--- score/ts_client/src/gptp_ipc_publisher.h | 6 +++--- score/ts_client/src/gptp_ipc_receiver.h | 6 +++--- score/ts_client/src/gptp_ipc_test_utils.h | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/score/ts_client/src/gptp_ipc.h b/score/ts_client/src/gptp_ipc.h index 6d18bbbb..87fe0ab4 100644 --- a/score/ts_client/src/gptp_ipc.h +++ b/score/ts_client/src/gptp_ipc.h @@ -10,11 +10,11 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_GPTP_IPC_H -#define SCORE_TS_CLIENT_GPTP_IPC_H +#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_H +#define SCORE_TS_CLIENT_SRC_GPTP_IPC_H #include "score/ts_client/src/gptp_ipc_channel.h" #include "score/ts_client/src/gptp_ipc_publisher.h" #include "score/ts_client/src/gptp_ipc_receiver.h" -#endif // SCORE_TS_CLIENT_GPTP_IPC_H +#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_H diff --git a/score/ts_client/src/gptp_ipc_channel.h b/score/ts_client/src/gptp_ipc_channel.h index 5c0a9ca3..37d078e5 100644 --- a/score/ts_client/src/gptp_ipc_channel.h +++ b/score/ts_client/src/gptp_ipc_channel.h @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_GPTP_IPC_CHANNEL_H -#define SCORE_TS_CLIENT_GPTP_IPC_CHANNEL_H +#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_CHANNEL_H +#define SCORE_TS_CLIENT_SRC_GPTP_IPC_CHANNEL_H #include "score/ts_client/src/gptp_ipc_data.h" @@ -53,4 +53,4 @@ struct alignas(64) GptpIpcRegion } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_GPTP_IPC_CHANNEL_H +#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_CHANNEL_H diff --git a/score/ts_client/src/gptp_ipc_data.h b/score/ts_client/src/gptp_ipc_data.h index 6fdb0003..3b2030f5 100644 --- a/score/ts_client/src/gptp_ipc_data.h +++ b/score/ts_client/src/gptp_ipc_data.h @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_GPTP_IPC_DATA_H -#define SCORE_TS_CLIENT_GPTP_IPC_DATA_H +#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_DATA_H +#define SCORE_TS_CLIENT_SRC_GPTP_IPC_DATA_H #include #include @@ -81,4 +81,4 @@ struct GptpIpcData } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_GPTP_IPC_DATA_H +#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_DATA_H diff --git a/score/ts_client/src/gptp_ipc_publisher.h b/score/ts_client/src/gptp_ipc_publisher.h index 977751f7..5808c357 100644 --- a/score/ts_client/src/gptp_ipc_publisher.h +++ b/score/ts_client/src/gptp_ipc_publisher.h @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_GPTP_IPC_PUBLISHER_H -#define SCORE_TS_CLIENT_GPTP_IPC_PUBLISHER_H +#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_PUBLISHER_H +#define SCORE_TS_CLIENT_SRC_GPTP_IPC_PUBLISHER_H #include "score/ts_client/src/gptp_ipc_channel.h" #include "score/memory/shared/shared_memory_factory.h" @@ -55,4 +55,4 @@ class GptpIpcPublisher final } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_GPTP_IPC_PUBLISHER_H +#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_PUBLISHER_H diff --git a/score/ts_client/src/gptp_ipc_receiver.h b/score/ts_client/src/gptp_ipc_receiver.h index f7ecea94..bc86d4da 100644 --- a/score/ts_client/src/gptp_ipc_receiver.h +++ b/score/ts_client/src/gptp_ipc_receiver.h @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_GPTP_IPC_RECEIVER_H -#define SCORE_TS_CLIENT_GPTP_IPC_RECEIVER_H +#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_RECEIVER_H +#define SCORE_TS_CLIENT_SRC_GPTP_IPC_RECEIVER_H #include "score/ts_client/src/gptp_ipc_channel.h" #include "score/memory/shared/shared_memory_factory.h" @@ -55,4 +55,4 @@ class GptpIpcReceiver final } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_GPTP_IPC_RECEIVER_H +#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_RECEIVER_H diff --git a/score/ts_client/src/gptp_ipc_test_utils.h b/score/ts_client/src/gptp_ipc_test_utils.h index 1fbe115e..c8669579 100644 --- a/score/ts_client/src/gptp_ipc_test_utils.h +++ b/score/ts_client/src/gptp_ipc_test_utils.h @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_GPTP_IPC_TEST_UTILS_H -#define SCORE_TS_CLIENT_GPTP_IPC_TEST_UTILS_H +#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_TEST_UTILS_H +#define SCORE_TS_CLIENT_SRC_GPTP_IPC_TEST_UTILS_H #include "score/ts_client/src/gptp_ipc_channel.h" #include "score/memory/shared/shared_memory_factory.h" @@ -71,4 +71,4 @@ struct ManualShm } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_GPTP_IPC_TEST_UTILS_H +#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_TEST_UTILS_H From ddfbd8b5718d327a4fc9b8173c20a955a6f02a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gordon=20=5C=20Chenhao=20Gao=20=5C=20=E9=AB=98=E6=99=A8?= =?UTF-8?q?=E6=B5=A9?= Date: Wed, 24 Jun 2026 15:29:34 +0800 Subject: [PATCH 4/7] Revert "Revert include guards to match physical include path" This reverts commit 8c6827d65cc842f2cedba3fb3b5346666536e140. --- score/ts_client/src/gptp_ipc.h | 6 +++--- score/ts_client/src/gptp_ipc_channel.h | 6 +++--- score/ts_client/src/gptp_ipc_data.h | 6 +++--- score/ts_client/src/gptp_ipc_publisher.h | 6 +++--- score/ts_client/src/gptp_ipc_receiver.h | 6 +++--- score/ts_client/src/gptp_ipc_test_utils.h | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/score/ts_client/src/gptp_ipc.h b/score/ts_client/src/gptp_ipc.h index 87fe0ab4..6d18bbbb 100644 --- a/score/ts_client/src/gptp_ipc.h +++ b/score/ts_client/src/gptp_ipc.h @@ -10,11 +10,11 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_H -#define SCORE_TS_CLIENT_SRC_GPTP_IPC_H +#ifndef SCORE_TS_CLIENT_GPTP_IPC_H +#define SCORE_TS_CLIENT_GPTP_IPC_H #include "score/ts_client/src/gptp_ipc_channel.h" #include "score/ts_client/src/gptp_ipc_publisher.h" #include "score/ts_client/src/gptp_ipc_receiver.h" -#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_H +#endif // SCORE_TS_CLIENT_GPTP_IPC_H diff --git a/score/ts_client/src/gptp_ipc_channel.h b/score/ts_client/src/gptp_ipc_channel.h index 37d078e5..5c0a9ca3 100644 --- a/score/ts_client/src/gptp_ipc_channel.h +++ b/score/ts_client/src/gptp_ipc_channel.h @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_CHANNEL_H -#define SCORE_TS_CLIENT_SRC_GPTP_IPC_CHANNEL_H +#ifndef SCORE_TS_CLIENT_GPTP_IPC_CHANNEL_H +#define SCORE_TS_CLIENT_GPTP_IPC_CHANNEL_H #include "score/ts_client/src/gptp_ipc_data.h" @@ -53,4 +53,4 @@ struct alignas(64) GptpIpcRegion } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_CHANNEL_H +#endif // SCORE_TS_CLIENT_GPTP_IPC_CHANNEL_H diff --git a/score/ts_client/src/gptp_ipc_data.h b/score/ts_client/src/gptp_ipc_data.h index 3b2030f5..6fdb0003 100644 --- a/score/ts_client/src/gptp_ipc_data.h +++ b/score/ts_client/src/gptp_ipc_data.h @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_DATA_H -#define SCORE_TS_CLIENT_SRC_GPTP_IPC_DATA_H +#ifndef SCORE_TS_CLIENT_GPTP_IPC_DATA_H +#define SCORE_TS_CLIENT_GPTP_IPC_DATA_H #include #include @@ -81,4 +81,4 @@ struct GptpIpcData } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_DATA_H +#endif // SCORE_TS_CLIENT_GPTP_IPC_DATA_H diff --git a/score/ts_client/src/gptp_ipc_publisher.h b/score/ts_client/src/gptp_ipc_publisher.h index 5808c357..977751f7 100644 --- a/score/ts_client/src/gptp_ipc_publisher.h +++ b/score/ts_client/src/gptp_ipc_publisher.h @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_PUBLISHER_H -#define SCORE_TS_CLIENT_SRC_GPTP_IPC_PUBLISHER_H +#ifndef SCORE_TS_CLIENT_GPTP_IPC_PUBLISHER_H +#define SCORE_TS_CLIENT_GPTP_IPC_PUBLISHER_H #include "score/ts_client/src/gptp_ipc_channel.h" #include "score/memory/shared/shared_memory_factory.h" @@ -55,4 +55,4 @@ class GptpIpcPublisher final } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_PUBLISHER_H +#endif // SCORE_TS_CLIENT_GPTP_IPC_PUBLISHER_H diff --git a/score/ts_client/src/gptp_ipc_receiver.h b/score/ts_client/src/gptp_ipc_receiver.h index bc86d4da..f7ecea94 100644 --- a/score/ts_client/src/gptp_ipc_receiver.h +++ b/score/ts_client/src/gptp_ipc_receiver.h @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_RECEIVER_H -#define SCORE_TS_CLIENT_SRC_GPTP_IPC_RECEIVER_H +#ifndef SCORE_TS_CLIENT_GPTP_IPC_RECEIVER_H +#define SCORE_TS_CLIENT_GPTP_IPC_RECEIVER_H #include "score/ts_client/src/gptp_ipc_channel.h" #include "score/memory/shared/shared_memory_factory.h" @@ -55,4 +55,4 @@ class GptpIpcReceiver final } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_RECEIVER_H +#endif // SCORE_TS_CLIENT_GPTP_IPC_RECEIVER_H diff --git a/score/ts_client/src/gptp_ipc_test_utils.h b/score/ts_client/src/gptp_ipc_test_utils.h index c8669579..1fbe115e 100644 --- a/score/ts_client/src/gptp_ipc_test_utils.h +++ b/score/ts_client/src/gptp_ipc_test_utils.h @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_TEST_UTILS_H -#define SCORE_TS_CLIENT_SRC_GPTP_IPC_TEST_UTILS_H +#ifndef SCORE_TS_CLIENT_GPTP_IPC_TEST_UTILS_H +#define SCORE_TS_CLIENT_GPTP_IPC_TEST_UTILS_H #include "score/ts_client/src/gptp_ipc_channel.h" #include "score/memory/shared/shared_memory_factory.h" @@ -71,4 +71,4 @@ struct ManualShm } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_TEST_UTILS_H +#endif // SCORE_TS_CLIENT_GPTP_IPC_TEST_UTILS_H From 7d251f0d66b3d609da7e74985fd418ab9bfdf640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gordon=20=5C=20Chenhao=20Gao=20=5C=20=E9=AB=98=E6=99=A8?= =?UTF-8?q?=E6=B5=A9?= Date: Mon, 29 Jun 2026 15:34:17 +0800 Subject: [PATCH 5/7] Reapply "Revert include guards to match physical include path" This reverts commit ddfbd8b5718d327a4fc9b8173c20a955a6f02a7e. --- score/ts_client/src/gptp_ipc.h | 6 +++--- score/ts_client/src/gptp_ipc_channel.h | 6 +++--- score/ts_client/src/gptp_ipc_data.h | 6 +++--- score/ts_client/src/gptp_ipc_publisher.h | 6 +++--- score/ts_client/src/gptp_ipc_receiver.h | 6 +++--- score/ts_client/src/gptp_ipc_test_utils.h | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/score/ts_client/src/gptp_ipc.h b/score/ts_client/src/gptp_ipc.h index 6d18bbbb..87fe0ab4 100644 --- a/score/ts_client/src/gptp_ipc.h +++ b/score/ts_client/src/gptp_ipc.h @@ -10,11 +10,11 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_GPTP_IPC_H -#define SCORE_TS_CLIENT_GPTP_IPC_H +#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_H +#define SCORE_TS_CLIENT_SRC_GPTP_IPC_H #include "score/ts_client/src/gptp_ipc_channel.h" #include "score/ts_client/src/gptp_ipc_publisher.h" #include "score/ts_client/src/gptp_ipc_receiver.h" -#endif // SCORE_TS_CLIENT_GPTP_IPC_H +#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_H diff --git a/score/ts_client/src/gptp_ipc_channel.h b/score/ts_client/src/gptp_ipc_channel.h index 5c0a9ca3..37d078e5 100644 --- a/score/ts_client/src/gptp_ipc_channel.h +++ b/score/ts_client/src/gptp_ipc_channel.h @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_GPTP_IPC_CHANNEL_H -#define SCORE_TS_CLIENT_GPTP_IPC_CHANNEL_H +#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_CHANNEL_H +#define SCORE_TS_CLIENT_SRC_GPTP_IPC_CHANNEL_H #include "score/ts_client/src/gptp_ipc_data.h" @@ -53,4 +53,4 @@ struct alignas(64) GptpIpcRegion } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_GPTP_IPC_CHANNEL_H +#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_CHANNEL_H diff --git a/score/ts_client/src/gptp_ipc_data.h b/score/ts_client/src/gptp_ipc_data.h index 6fdb0003..3b2030f5 100644 --- a/score/ts_client/src/gptp_ipc_data.h +++ b/score/ts_client/src/gptp_ipc_data.h @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_GPTP_IPC_DATA_H -#define SCORE_TS_CLIENT_GPTP_IPC_DATA_H +#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_DATA_H +#define SCORE_TS_CLIENT_SRC_GPTP_IPC_DATA_H #include #include @@ -81,4 +81,4 @@ struct GptpIpcData } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_GPTP_IPC_DATA_H +#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_DATA_H diff --git a/score/ts_client/src/gptp_ipc_publisher.h b/score/ts_client/src/gptp_ipc_publisher.h index 977751f7..5808c357 100644 --- a/score/ts_client/src/gptp_ipc_publisher.h +++ b/score/ts_client/src/gptp_ipc_publisher.h @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_GPTP_IPC_PUBLISHER_H -#define SCORE_TS_CLIENT_GPTP_IPC_PUBLISHER_H +#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_PUBLISHER_H +#define SCORE_TS_CLIENT_SRC_GPTP_IPC_PUBLISHER_H #include "score/ts_client/src/gptp_ipc_channel.h" #include "score/memory/shared/shared_memory_factory.h" @@ -55,4 +55,4 @@ class GptpIpcPublisher final } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_GPTP_IPC_PUBLISHER_H +#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_PUBLISHER_H diff --git a/score/ts_client/src/gptp_ipc_receiver.h b/score/ts_client/src/gptp_ipc_receiver.h index f7ecea94..bc86d4da 100644 --- a/score/ts_client/src/gptp_ipc_receiver.h +++ b/score/ts_client/src/gptp_ipc_receiver.h @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_GPTP_IPC_RECEIVER_H -#define SCORE_TS_CLIENT_GPTP_IPC_RECEIVER_H +#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_RECEIVER_H +#define SCORE_TS_CLIENT_SRC_GPTP_IPC_RECEIVER_H #include "score/ts_client/src/gptp_ipc_channel.h" #include "score/memory/shared/shared_memory_factory.h" @@ -55,4 +55,4 @@ class GptpIpcReceiver final } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_GPTP_IPC_RECEIVER_H +#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_RECEIVER_H diff --git a/score/ts_client/src/gptp_ipc_test_utils.h b/score/ts_client/src/gptp_ipc_test_utils.h index 1fbe115e..c8669579 100644 --- a/score/ts_client/src/gptp_ipc_test_utils.h +++ b/score/ts_client/src/gptp_ipc_test_utils.h @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_TS_CLIENT_GPTP_IPC_TEST_UTILS_H -#define SCORE_TS_CLIENT_GPTP_IPC_TEST_UTILS_H +#ifndef SCORE_TS_CLIENT_SRC_GPTP_IPC_TEST_UTILS_H +#define SCORE_TS_CLIENT_SRC_GPTP_IPC_TEST_UTILS_H #include "score/ts_client/src/gptp_ipc_channel.h" #include "score/memory/shared/shared_memory_factory.h" @@ -71,4 +71,4 @@ struct ManualShm } // namespace ts } // namespace score -#endif // SCORE_TS_CLIENT_GPTP_IPC_TEST_UTILS_H +#endif // SCORE_TS_CLIENT_SRC_GPTP_IPC_TEST_UTILS_H From 9f4b2b18be4c3e33734bf9557338897d8df5ff92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gordon=20=5C=20Chenhao=20Gao=20=5C=20=E9=AB=98=E6=99=A8?= =?UTF-8?q?=E6=B5=A9?= Date: Tue, 30 Jun 2026 09:55:00 +0800 Subject: [PATCH 6/7] Narrow gptp_ipc visibility to time_daemon and time_slave --- score/ts_client/src/BUILD | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/score/ts_client/src/BUILD b/score/ts_client/src/BUILD index 0aa4f88d..3fcc0a90 100644 --- a/score/ts_client/src/BUILD +++ b/score/ts_client/src/BUILD @@ -30,8 +30,8 @@ cc_library( features = COMPILER_WARNING_FEATURES, tags = ["QM"], visibility = [ - "//examples:__subpackages__", - "//score:__subpackages__", + "//score/time_daemon:__subpackages__", + "//score/time_slave:__subpackages__", ], deps = [ "@score_baselibs//score/memory/shared", From fcf8913891ed6c08cc028b3024eebb87bc80759e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gordon=20=5C=20Chenhao=20Gao=20=5C=20=E9=AB=98=E6=99=A8?= =?UTF-8?q?=E6=B5=A9?= Date: Tue, 30 Jun 2026 15:34:32 +0800 Subject: [PATCH 7/7] Fix svt_verification_machine missing high_res_steady_time backend dep --- score/time_daemon/src/application/svt/BUILD | 3 +- .../src/verification_machine/svt/BUILD | 62 ++++++++++++------- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/score/time_daemon/src/application/svt/BUILD b/score/time_daemon/src/application/svt/BUILD index 514a7851..44f97731 100644 --- a/score/time_daemon/src/application/svt/BUILD +++ b/score/time_daemon/src/application/svt/BUILD @@ -34,7 +34,6 @@ load("@score_baselibs//score/language/safecpp:toolchain_features.bzl", "COMPILER "//score/time_daemon/src/control_flow_divider/ptp:ptp_control_flow_divider", "//score/time_daemon/src/ipc/svt/publisher:factory", "//score/time_daemon/src/msg_broker", - "//score/time_daemon/src/verification_machine/svt:svt_verification_machine", ] + deps, ) for name, testonly, deps in [ @@ -43,6 +42,7 @@ load("@score_baselibs//score/language/safecpp:toolchain_features.bzl", "COMPILER False, [ "//score/time_daemon/src/ptp_machine/shm:gptp_shm_machine", + "//score/time_daemon/src/verification_machine/svt:svt_verification_machine", ], ), ( @@ -50,6 +50,7 @@ load("@score_baselibs//score/language/safecpp:toolchain_features.bzl", "COMPILER True, [ "//score/time_daemon/src/ptp_machine/shm:gptp_shm_machine", + "//score/time_daemon/src/verification_machine/svt:svt_verification_machine_for_utests", ], ), ] diff --git a/score/time_daemon/src/verification_machine/svt/BUILD b/score/time_daemon/src/verification_machine/svt/BUILD index 4ebd4cdc..02c2f49b 100644 --- a/score/time_daemon/src/verification_machine/svt/BUILD +++ b/score/time_daemon/src/verification_machine/svt/BUILD @@ -14,26 +14,45 @@ load("@score_baselibs//:bazel/unit_tests.bzl", "cc_unit_test_suites_for_host_and_qnx") load("@score_baselibs//score/language/safecpp:toolchain_features.bzl", "COMPILER_WARNING_FEATURES") -cc_library( - name = "svt_verification_machine", - srcs = [ - "factory.cpp", - ], - hdrs = [ - "factory.h", - "svt_verification_machine.h", - ], - features = COMPILER_WARNING_FEATURES, - tags = ["QM"], - visibility = ["//score/time_daemon:__subpackages__"], - deps = [ - "//score/time_daemon/src/common/data_types:ptp_time_info", - "//score/time_daemon/src/common/machines", - "//score/time_daemon/src/verification_machine/core:verification_machine", - "//score/time_daemon/src/verification_machine/svt/validators", - "@score_baselibs//score/mw/log:frontend", - ], -) +[ + cc_library( + name = name, + testonly = testonly, + srcs = [ + "factory.cpp", + ], + hdrs = [ + "factory.h", + "svt_verification_machine.h", + ], + features = COMPILER_WARNING_FEATURES, + tags = ["QM"], + visibility = ["//score/time_daemon:__subpackages__"], + deps = [ + "//score/time_daemon/src/common/data_types:ptp_time_info", + "//score/time_daemon/src/common/machines", + "//score/time_daemon/src/verification_machine/core:verification_machine", + "//score/time_daemon/src/verification_machine/svt/validators", + "@score_baselibs//score/mw/log:frontend", + ] + deps, + ) + for name, testonly, deps in [ + ( + "svt_verification_machine", + False, + [ + "//score/time/high_res_steady_time:high_res_steady_time", + ], + ), + ( + "svt_verification_machine_for_utests", + True, + [ + "//score/time/high_res_steady_time:high_res_steady_time_mock", + ], + ), + ] +] cc_unit_test_suites_for_host_and_qnx( name = "unit_test_suite", @@ -51,8 +70,7 @@ cc_test( ], tags = ["unit"], deps = [ - ":svt_verification_machine", - "//score/time/high_res_steady_time:high_res_steady_time_mock", + ":svt_verification_machine_for_utests", "@googletest//:gtest", "@googletest//:gtest_main", "@score_baselibs//score/mw/log:console_only_backend",