Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion score/launch_manager/src/daemon/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ cc_binary(
"//score/launch_manager/src/daemon/src/osal:ipc_comms",
"//score/launch_manager/src/daemon/src/process_group_manager",
"//score/launch_manager/src/daemon/src/process_group_manager:alive_monitor_thread",
"//score/launch_manager/src/daemon/src/process_state_client:process_state_notifier",
"//score/launch_manager/src/daemon/src/recovery_client",
"//score/launch_manager/src/daemon/src/supervision_control_client:supervision_control_notifier",
"//score/launch_manager/src/daemon/src/watchdog:watchdog_factory",
"@score_baselibs//score/language/futurecpp",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace daemon

AliveMonitorImpl::AliveMonitorImpl(
SptrIRecoveryClient recovery_client,
UptrIProcessStateReceiver process_state_receiver,
UptrISupervisionControlReceiver process_state_receiver,
const Config& config)
: m_recovery_client(recovery_client),
m_process_state_receiver(std::move(process_state_receiver)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace daemon
{

using SptrIRecoveryClient = std::shared_ptr<score::lcm::IRecoveryClient>;
using UptrIProcessStateReceiver = std::unique_ptr<score::lcm::IProcessStateReceiver>;
using UptrISupervisionControlReceiver = std::unique_ptr<score::lcm::ISupervisionControlReceiver>;
using UptrPhmDaemon = std::unique_ptr<score::lcm::saf::daemon::PhmDaemon>;
using OsClock = score::lcm::saf::timers::OsClockInterface;
using Config = score::mw::launch_manager::configuration::Config;
Expand All @@ -45,7 +45,7 @@ class AliveMonitorImpl : public IAliveMonitor
public:
AliveMonitorImpl(
SptrIRecoveryClient recovery_client,
UptrIProcessStateReceiver process_state_receiver,
UptrISupervisionControlReceiver process_state_receiver,
const Config& config);

EInitCode init() noexcept override;
Expand All @@ -56,7 +56,7 @@ class AliveMonitorImpl : public IAliveMonitor
SptrIRecoveryClient m_recovery_client{nullptr};
UptrPhmDaemon m_daemon{nullptr};
OsClock m_osClock{};
UptrIProcessStateReceiver m_process_state_receiver;
UptrISupervisionControlReceiver m_process_state_receiver;
AliveMonitorConfig m_config;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace daemon
true_no_defect) */
/* RULECHECKER_comment(0, 4, check_incomplete_data_member_construction, "Default constructor is used for\
processStateReader.", true_no_defect) */
PhmDaemon::PhmDaemon(OsClock& f_osClock, std::unique_ptr<ProcessStateReceiver> f_process_state_receiver)
PhmDaemon::PhmDaemon(OsClock& f_osClock, std::unique_ptr<ISupervisionControlReceiver> f_process_state_receiver)
: osClock{f_osClock},
cycleTimer{&osClock},
swClusterHandlers{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PhmDaemon
{
public:
using OsClock = score::lcm::saf::timers::OsClockInterface;
using ProcessStateReceiver = score::lcm::IProcessStateReceiver;
using SupervisionControlReceiver = score::lcm::ISupervisionControlReceiver;
using RecoveryClient = score::lcm::IRecoveryClient;
using SupervisionBufferConfig = factory::SupervisionBufferConfig;
using CycleTimer = score::lcm::saf::timers::CycleTimer;
Expand All @@ -70,7 +70,7 @@ class PhmDaemon
/// tests)
/* RULECHECKER_comment(3,1, check_expensive_to_copy_in_parameter, "Move only types cannot be passed by const ref",
true_no_defect) */
PhmDaemon(OsClock& f_osClock, std::unique_ptr<ProcessStateReceiver> f_process_state_receiver);
PhmDaemon(OsClock& f_osClock, std::unique_ptr<ISupervisionControlReceiver> f_process_state_receiver);

/* RULECHECKER_comment(0, 4, check_min_instructions, "Default destructor is not provided\
a function body", true_no_defect) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,19 @@ void MonitorIfDaemon::attachCheckpoint(Checkpoint& f_checkpoint_r) noexcept(fals

void MonitorIfDaemon::updateData(const ifexm::ProcessState& f_observable_r) noexcept(true)
{
ifexm::ProcessState::EProcState state{f_observable_r.getState()};
static constexpr ifexm::ProcessState::EProcState kInitState = ifexm::ProcessState::EProcState::starting;

if ((kInitState == state) || (ifexm::ProcessState::EProcState::running == state))
{
if (isDeactivateRequest)
{
isProcessRestarted = true;
}
isActivateRequest = true;
isDeactivateRequest = false;
}
else if (ifexm::ProcessState::EProcState::off == state)
{
isDeactivateRequest = true;
}
else
switch (f_observable_r.getEventType())
{
// do nothing
case score::lcm::SupervisionEventType::kActivation:
if (isDeactivateRequest)
{
isProcessRestarted = true;
}
isActivateRequest = true;
isDeactivateRequest = false;
break;
case score::lcm::SupervisionEventType::kDeactivation:
isDeactivateRequest = true;
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,19 @@ struct MonitorIfDaemonFixture
<< "CheckpointIpcServer init failed";
}

/// Drive the process to the 'running' state and notify observers.
/// Send an activation event and notify observers.
void activateProcess(timers::NanoSecondType ts)
{
processState.setTimestamp(ts);
processState.setState(ifexm::ProcessState::EProcState::running);
processState.setEventType(score::lcm::SupervisionEventType::kActivation);
processState.pushData();
}

/// Drive the process to the 'starting' state and notify observers.
void startProcess(timers::NanoSecondType ts)
{
processState.setTimestamp(ts);
processState.setState(ifexm::ProcessState::EProcState::starting);
processState.pushData();
}

/// Drive the process to the 'off' state and notify observers.
/// Send a deactivation event and notify observers.
void deactivateProcess(timers::NanoSecondType ts)
{
processState.setTimestamp(ts);
processState.setState(ifexm::ProcessState::EProcState::off);
processState.setEventType(score::lcm::SupervisionEventType::kDeactivation);
processState.pushData();
}

Expand Down Expand Up @@ -185,19 +177,19 @@ TEST_F(MonitorIfDaemonTest, InitiallyInactive_CheckForNewData_DoesNotNotifyCheck
{
RecordProperty(
"Description",
"Before any process-state update the monitor is kInactive; "
"Before any supervision event the monitor is kInactive; "
"checkForNewData must not forward any data.");

MonitorIfDaemonFixture fix;
EXPECT_CALL(fix.checkpointMock, updateData).Times(Exactly(0));
fix.monitor.checkForNewData(mockClock());
}

TEST_F(MonitorIfDaemonTest, ProcessOffBeforeActivation_RemainsInactive)
TEST_F(MonitorIfDaemonTest, DeactivationBeforeActivation_RemainsInactive)
{
RecordProperty(
"Description",
"A process-off event before the monitor has been activated "
"A deactivation event before the monitor has been activated "
"must not cause checkForNewData to read IPC data.");

MonitorIfDaemonFixture fix;
Expand All @@ -210,11 +202,11 @@ TEST_F(MonitorIfDaemonTest, ProcessOffBeforeActivation_RemainsInactive)
fix.monitor.checkForNewData(mockClock());
}

TEST_F(MonitorIfDaemonTest, ProcessRunning_ActivatesMonitorOnNextCheckForNewData)
TEST_F(MonitorIfDaemonTest, ActivationEvent_ActivatesMonitorOnNextCheckForNewData)
{
RecordProperty(
"Description",
"A running process-state update must set isActivateRequest so that "
"An activation event must set isActivateRequest so that "
"the next checkForNewData transitions the monitor to kActive.");

MonitorIfDaemonFixture fix;
Expand All @@ -228,29 +220,11 @@ TEST_F(MonitorIfDaemonTest, ProcessRunning_ActivatesMonitorOnNextCheckForNewData
EXPECT_EQ(fix.checkpoint.getTimestamp(), checkpoint_time);
}

TEST_F(MonitorIfDaemonTest, ProcessStarting_AlsoActivatesMonitor)
{
RecordProperty(
"Description",
"EProcState::starting must be treated as an activation trigger, "
"identical to running.");

MonitorIfDaemonFixture fix;
EXPECT_CALL(fix.checkpointMock, updateData).Times(1);
fix.initIpc();
fix.startProcess(mockClock());
const auto checkpoint_time = mockClockOffset();
fix.sendCheckpoint(MonitorIfDaemonFixture::kCheckpointId, checkpoint_time);
fix.monitor.checkForNewData(mockClock());

EXPECT_EQ(fix.checkpoint.getTimestamp(), checkpoint_time);
}

TEST_F(MonitorIfDaemonTest, ProcessOff_DeactivatesMonitor_NoFurtherDataForwarded)
TEST_F(MonitorIfDaemonTest, DeactivationEvent_DeactivatesMonitor_NoFurtherDataForwarded)
{
RecordProperty(
"Description",
"After a process-off event checkForNewData drains the IPC for the "
"After a deactivation event checkForNewData drains the IPC for the "
"current cycle, then transitions to kInactive. Subsequent cycles "
"must not forward data even when the IPC buffer is non-empty.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ cc_library(
"//score/launch_manager/src/daemon/src/alive_monitor/details/common:observer",
"//score/launch_manager/src/daemon/src/alive_monitor/details/common:types",
"//score/launch_manager/src/daemon/src/alive_monitor/details/timers:timers_os_clock",
"//score/launch_manager/src/daemon/src/process_state_client",
"//score/launch_manager/src/daemon/src/supervision_control_client",
],
)

Expand All @@ -53,6 +53,6 @@ cc_library(
"//score/launch_manager/src/daemon/src/alive_monitor/details/timers:time_conversion",
"//score/launch_manager/src/daemon/src/alive_monitor/details/timers:timers_os_clock",
"//score/launch_manager/src/daemon/src/common:log",
"//score/launch_manager/src/daemon/src/process_state_client",
"//score/launch_manager/src/daemon/src/supervision_control_client",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ common::ProcessId ProcessState::getProcessId() const noexcept
return k_processId;
}

ProcessState::EProcState ProcessState::getState() const noexcept
score::lcm::SupervisionEventType ProcessState::getEventType() const noexcept
{
return eProcState;
return eventType_;
}

void ProcessState::setState(ProcessState::EProcState f_processStateId) noexcept
void ProcessState::setEventType(score::lcm::SupervisionEventType f_eventType) noexcept
{
eProcState = f_processStateId;
eventType_ = f_eventType;
}

timers::NanoSecondType ProcessState::getTimestamp() const noexcept
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "score/mw/launch_manager/alive_monitor/details/timers/Timers_OsClock.hpp"
#include <string>

#include "score/mw/launch_manager/process_state_client/posix_process.hpp"
#include "score/mw/launch_manager/supervision_control_client/supervision_event.hpp"

namespace score
{
Expand All @@ -32,7 +32,7 @@ namespace ifexm
{

/// @brief Process State
/// @details The Process State class dispatches process state changes to the attached observers.
/// @details The Process State class dispatches supervision events to the attached observers.
class ProcessState : public saf::common::Observable<ProcessState>
{
public:
Expand Down Expand Up @@ -72,24 +72,13 @@ class ProcessState : public saf::common::Observable<ProcessState>
/// @return Returns process ID
common::ProcessId getProcessId(void) const noexcept;

/// @brief Enumeration of process states
enum class EProcState : uint8_t
{
idle = static_cast<uint8_t>(score::lcm::ProcessState::kIdle),
starting = static_cast<uint8_t>(score::lcm::ProcessState::kStarting),
running = static_cast<uint8_t>(score::lcm::ProcessState::kRunning),
sigterm = static_cast<uint8_t>(score::lcm::ProcessState::kTerminating),
off = static_cast<uint8_t>(score::lcm::ProcessState::kTerminated),
failed = static_cast<uint8_t>(score::lcm::ProcessState::kFailed)
};

/// @brief Get Process State
/// @return Returns Process State
EProcState getState() const noexcept;

/// @brief Set process state
/// @param [in] f_processStateId Process state id
void setState(ProcessState::EProcState f_processStateId) noexcept;
/// @brief Get supervision event type
/// @return Returns the current event type
score::lcm::SupervisionEventType getEventType() const noexcept;

/// @brief Set supervision event type
/// @param [in] f_eventType Supervision event type
void setEventType(score::lcm::SupervisionEventType f_eventType) noexcept;

/// @brief Get Timestamp for current event
/// @return Timestamp of current event
Expand All @@ -100,7 +89,7 @@ class ProcessState : public saf::common::Observable<ProcessState>
void setTimestamp(timers::NanoSecondType f_timestamp) noexcept;

/// @brief Push Data
/// @details Push process state related information, which shall be distribute to observers.
/// @details Push supervision event related information, which shall be distributed to observers.
void pushData(void) noexcept;

private:
Expand All @@ -110,8 +99,8 @@ class ProcessState : public saf::common::Observable<ProcessState>
/// @brief Process id
const common::ProcessId k_processId;

/// @brief Current process state
EProcState eProcState{ProcessState::EProcState::idle};
/// @brief Current supervision event type
score::lcm::SupervisionEventType eventType_{score::lcm::SupervisionEventType::kDeactivation};

/// @brief Current timestamp of process
timers::NanoSecondType timestamp{UINT64_MAX};
Expand Down
Loading
Loading