Skip to content
7 changes: 4 additions & 3 deletions score/time_daemon/src/application/svt/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,23 @@ 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 [
(
"svt_handler",
False,
[
"//score/time_daemon/src/ptp_machine:stub_ptp_machine",
"//score/time_daemon/src/ptp_machine/shm:gptp_shm_machine",
"//score/time_daemon/src/verification_machine/svt:svt_verification_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",
"//score/time_daemon/src/verification_machine/svt:svt_verification_machine_for_utests",
],
),
]
Expand Down
4 changes: 2 additions & 2 deletions score/time_daemon/src/application/svt/svt_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -39,7 +39,7 @@ SvtHandler::SvtHandler() noexcept
handler_status_{TimebaseHandler::Status::kIdle}
{
msg_broker_ = std::make_shared<MessageBroker<PtpTimeInfo>>();
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});
Expand Down
4 changes: 2 additions & 2 deletions score/time_daemon/src/application/svt/svt_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
Expand Down Expand Up @@ -72,7 +72,7 @@ class SvtHandler : public TimebaseHandler
private:
std::unique_ptr<JobRunner> job_runner_; ///< Manages periodic jobs and tasks
std::shared_ptr<MessageBroker<PtpTimeInfo>> msg_broker_; ///< Handles message communication
std::shared_ptr<GPTPStubMachine> gptp_machine_; ///< Manages GPTP synchronization
std::shared_ptr<GPTPShmMachine> gptp_machine_; ///< Manages GPTP synchronization
std::shared_ptr<SvtVerificationMachine> verification_machine_; ///< Handles SVT verification
std::shared_ptr<SvtPublisher> ipc_publisher_; ///< Publishes SVT data via IPC
std::shared_ptr<PtpControlFlowDivider> ctrl_flow_divider_; ///< Divides PTP control flow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ShmPTPEngineTest : public ::testing::Test
void TearDown() override
{
engine_->Deinitialize();
pub_.Destroy();
pub_.Close();
}

std::string name_;
Expand All @@ -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
}
Expand All @@ -121,22 +121,22 @@ 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());
}

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());
Expand All @@ -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());

Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand All @@ -73,7 +73,7 @@ class GPTPShmMachineIntegrationTest : public ::testing::Test
{
machine_->Stop();
machine_.reset();
pub_.Destroy();
pub_.Close();
}

std::string name_;
Expand Down
62 changes: 40 additions & 22 deletions score/time_daemon/src/verification_machine/svt/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions score/time_slave/src/application/time_slave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 10 additions & 6 deletions score/ts_client/src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
"//score/time_daemon:__subpackages__",
"//score/time_slave:__subpackages__",
],
deps = [
"@score_baselibs//score/memory/shared",
],
)

cc_test(
Expand All @@ -48,6 +49,7 @@ cc_test(
":gptp_ipc",
"@googletest//:gtest",
"@googletest//:gtest_main",
"@score_baselibs//score/mw/log:console_only_backend",
],
)

Expand All @@ -62,6 +64,7 @@ cc_test(
":gptp_ipc",
"@googletest//:gtest",
"@googletest//:gtest_main",
"@score_baselibs//score/mw/log:console_only_backend",
],
)

Expand All @@ -76,6 +79,7 @@ cc_test(
":gptp_ipc",
"@googletest//:gtest",
"@googletest//:gtest_main",
"@score_baselibs//score/mw/log:console_only_backend",
],
)

Expand Down
2 changes: 1 addition & 1 deletion score/ts_client/src/gptp_ipc_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace ts
namespace details
{

/// Default POSIX shared memory name for the gPTP IPC channel.
/// Default shared memory name for the gPTP IPC channel.
constexpr char kGptpIpcName[] = "/gptp_ptp_info";
Comment thread
gordon9901 marked this conversation as resolved.

/// Magic number to validate the shared memory region ('GPTP').
Expand Down
8 changes: 1 addition & 7 deletions score/ts_client/src/gptp_ipc_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ struct GptpIpcStatus
bool is_correct;
};

/**
* @brief IPC-layer Sync+FollowUp measurement data.
*/
struct GptpIpcSyncFupData
{
std::uint64_t precise_origin_timestamp;
Expand All @@ -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;
Expand All @@ -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 ts_client and intentionally decoupled from
* score::td::PtpTimeInfo. Callers are responsible for mapping between the two.
*/
struct GptpIpcData
Expand Down
Loading
Loading