Skip to content
Open
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
4 changes: 2 additions & 2 deletions score/health_monitor/src/cpp/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#ifndef SCORE_HM_COMMON_H
#define SCORE_HM_COMMON_H

#include <cassert>
#include <score/assert.hpp>
#include <chrono>
#include <optional>

Expand Down Expand Up @@ -95,7 +95,7 @@ class TimeRange
public:
TimeRange(std::chrono::milliseconds min_ms, std::chrono::milliseconds max_ms) : min_ms_(min_ms), max_ms_(max_ms)
{
assert(min_ms_ <= max_ms_);
SCORE_LANGUAGE_FUTURECPP_PRECONDITION(min_ms_ <= max_ms_);
}

const uint32_t min_ms() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ cc_library(
include_prefix = "score/mw/launch_manager/alive_monitor/details/common",
strip_include_prefix = "/score/launch_manager/src/daemon/src/alive_monitor/details/common",
visibility = ["//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__"],
deps = ["@score_baselibs//score/language/futurecpp"],
)

cc_library(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#ifndef OBSERVER_HPP_INCLUDED
#define OBSERVER_HPP_INCLUDED

#include <score/assert.hpp>
#include <algorithm>
#include <cassert>
#include <cstdint>

#include <vector>
Expand All @@ -38,7 +38,7 @@ namespace common
template <typename Type_Observable>
class Observer
{
public:
public:
/// @brief Constructor
Observer() = default;

Expand All @@ -57,7 +57,7 @@ class Observer
/// @param [in] f_observable_r Observable as reference.
virtual void updateData(const Type_Observable& f_observable_r) noexcept(true) = 0;

protected:
protected:
/// @brief Move Constructor
Observer(Observer&&) = default;
};
Expand All @@ -72,7 +72,7 @@ class Observer
template <typename Type_Observable>
class Observable
{
public:
public:
/// @brief Default Constructor
Observable(void) = default;

Expand Down Expand Up @@ -107,7 +107,7 @@ class Observable
observers.erase(eraseFirstItConst, observers.cend());
}

protected:
protected:
/// @brief Move Constructor
/// Cannot be noexcept, since the std::vector move constructor is not noexcept
Observable(Observable&&) = default;
Expand All @@ -120,12 +120,12 @@ class Observable
{
// We can be sure that *this is of type Type_Observable, anything else would be a programming error.
// The runtime checks performed by dynamic_cast are not necessary.
assert((dynamic_cast<Type_Observable*>(this)) != NULL);
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD((dynamic_cast<Type_Observable*>(this)) != NULL);
observer->updateData(static_cast<Type_Observable&>(*this));
}
}

private:
private:
/// Observers attached to the observable object
std::vector<Observer<Type_Observable>*> observers{};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,71 @@
#include <cstdint>
#include <iostream>

#include <score/assert.hpp>

#include "score/mw/launch_manager/alive_monitor/details/daemon/AliveMonitorImpl.hpp"
#include "score/mw/launch_manager/alive_monitor/details/logging/PhmLogger.hpp"
#include "score/mw/launch_manager/alive_monitor/details/watchdog/WatchdogImpl.hpp"

namespace score {
namespace lcm {
namespace saf {
namespace daemon {
namespace score
{
namespace lcm
{
namespace saf
{
namespace daemon
{

AliveMonitorImpl::AliveMonitorImpl(std::shared_ptr<score::lcm::IRecoveryClient> recovery_client, std::unique_ptr<watchdog::IWatchdogIf> watchdog, std::unique_ptr<score::lcm::IProcessStateReceiver> process_state_receiver)
: m_recovery_client(recovery_client), m_watchdog(std::move(watchdog)), m_logger{score::lcm::saf::logging::PhmLogger::getLogger(score::lcm::saf::logging::PhmLogger::EContext::factory)}, m_process_state_receiver{std::move(process_state_receiver)} {}
AliveMonitorImpl::AliveMonitorImpl(std::shared_ptr<score::lcm::IRecoveryClient> recovery_client,
std::unique_ptr<watchdog::IWatchdogIf> watchdog,
std::unique_ptr<score::lcm::IProcessStateReceiver> process_state_receiver)
: m_recovery_client(recovery_client),
m_watchdog(std::move(watchdog)),
m_logger{score::lcm::saf::logging::PhmLogger::getLogger(score::lcm::saf::logging::PhmLogger::EContext::factory)},
m_process_state_receiver{std::move(process_state_receiver)}
{
}

EInitCode AliveMonitorImpl::init() noexcept {
EInitCode AliveMonitorImpl::init() noexcept
{
score::lcm::saf::daemon::EInitCode initResult{score::lcm::saf::daemon::EInitCode::kGeneralError};
try {
try
{
m_osClock.startMeasurement();

m_daemon = std::make_unique<score::lcm::saf::daemon::PhmDaemon>(m_osClock, m_logger, std::move(m_watchdog), std::move(m_process_state_receiver));
m_daemon = std::make_unique<score::lcm::saf::daemon::PhmDaemon>(
m_osClock, m_logger, std::move(m_watchdog), std::move(m_process_state_receiver));
initResult = m_daemon->init(m_recovery_client);

if (initResult == score::lcm::saf::daemon::EInitCode::kNoError) {
if (initResult == score::lcm::saf::daemon::EInitCode::kNoError)
{
const long ms{m_osClock.endMeasurement()};
m_logger.LogDebug() << "AliveMonitor: Initialization took " << ms << " ms";
} else {
m_logger.LogError() << "AliveMonitor: Initialization failed with error code:" << static_cast<int>(initResult);
}
} catch (const std::exception& e) {
else
{
m_logger.LogError() << "AliveMonitor: Initialization failed with error code:"
<< static_cast<int>(initResult);
}
}
catch (const std::exception& e)
{
std::cerr << "AliveMonitor: Initialization failed due to standard exception: " << e.what() << ".\n";
initResult = EInitCode::kGeneralError;
} catch (...) {
}
catch (...)
{
std::cerr << "AliveMonitor: Initialization failed due to exception!\n";
initResult = EInitCode::kGeneralError;
}

return initResult;
}

bool AliveMonitorImpl::run(std::atomic_bool& cancel_thread) noexcept {
assert(m_daemon != nullptr && "HealthMonitor: Instance is not initialized!");
bool AliveMonitorImpl::run(std::atomic_bool& cancel_thread) noexcept
{
SCORE_LANGUAGE_FUTURECPP_PRECONDITION_PRD_MESSAGE(m_daemon != nullptr,
"HealthMonitor: Instance is not initialized!");
return m_daemon->startCyclicExec(cancel_thread);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ cc_library(
":i_health_monitor",
"//score/launch_manager/src/daemon/src/alive_monitor/details/logging:phm_logging",
"//score/launch_manager/src/daemon/src/alive_monitor/details/watchdog:watchdog_impl",
"@score_baselibs//score/language/futurecpp",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ cc_library(
"//score/launch_manager/src/daemon/src/alive_monitor/details/timers:timers_os_clock",
"//score/launch_manager/src/daemon/src/alive_monitor/details/watchdog:i_device_config_factory",
"@flatbuffers",
"@score_baselibs//score/language/futurecpp",
] + select({
"@platforms//os:qnx": [],
"@platforms//os:linux": ["//externals/acl"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
********************************************************************************/
#include "score/mw/launch_manager/alive_monitor/details/factory/MachineConfigFactory.hpp"

#include <fstream>
#include <limits>
#include <string_view>
#include <fstream>
#include "score/mw/launch_manager/alive_monitor/details/timers/TimeConversion.hpp"
#include "score/mw/launch_manager/alive_monitor/config/hmcore_flatcfg_generated.h"
#include "flatbuffers/flatbuffers.h"

#include "flatbuffers/flatbuffers.h"
#include "score/mw/launch_manager/alive_monitor/config/hmcore_flatcfg_generated.h"
#include "score/mw/launch_manager/alive_monitor/details/timers/TimeConversion.hpp"
#include <score/assert.hpp>

namespace score
{
Expand All @@ -33,7 +34,7 @@ namespace
{
/// @brief Prefix for all log messages
// coverity[autosar_cpp14_a2_10_4_violation:FALSE] Empty namespace ensures uniqueness for cpp file scope
static constexpr char const* kLogPrefix{"Factory for FlatCfg MachineConfig:"};
static constexpr const char* kLogPrefix{"Factory for FlatCfg MachineConfig:"};

/// @brief Update a field in case the provided value is not the flatbuffer default value
/// @note In case of optional integer values in flatbuffer files, the flatbuffer API will just return 0 if the value was
Expand All @@ -50,12 +51,14 @@ void updateNonDefaultValue(std::uint16_t& f_field_r, const std::uint16_t f_value
}
}

std::unique_ptr<char[]> read_flatbuffer_file(const std::string& f_filename_r) {
std::unique_ptr<char[]> read_flatbuffer_file(const std::string& f_filename_r)
{
const std::string configFilePath = std::string("etc/") + f_filename_r.c_str();

std::ifstream infile;
infile.open(configFilePath, std::ios::binary | std::ios::in);
if (!infile.is_open()) {
if (!infile.is_open())
{
return nullptr;
}
infile.seekg(0, std::ios::end);
Expand All @@ -68,14 +71,13 @@ std::unique_ptr<char[]> read_flatbuffer_file(const std::string& f_filename_r) {
}
} // namespace

MachineConfigFactory::MachineConfigFactory() noexcept(true) : watchdog::IDeviceConfigFactory()
{
}
MachineConfigFactory::MachineConfigFactory() noexcept(true) : watchdog::IDeviceConfigFactory() {}

bool MachineConfigFactory::init() noexcept(false)
{
std::unique_ptr<char[]> loadBuffer_p = read_flatbuffer_file("hmcore.bin");
if(!loadBuffer_p) {
if (!loadBuffer_p)
{
logger_r.LogInfo() << kLogPrefix << "No HM Machine Configuration found. Using default configuration.";
logConfiguration();
return true;
Expand Down Expand Up @@ -116,7 +118,7 @@ void MachineConfigFactory::loadWatchdogDevices(const HMCOREFlatBuffer::HMCOREEcu
{
watchdog::DeviceConfig config{};

assert(wdg->maxTimeout() <= std::numeric_limits<std::uint16_t>::max());
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(wdg->maxTimeout() <= std::numeric_limits<std::uint16_t>::max());
// coverity[autosar_cpp14_a4_7_1_violation] SDG definitions guarantee uint16 boundaries
config.timeoutMax = static_cast<std::uint16_t>(wdg->maxTimeout());

Expand Down Expand Up @@ -161,8 +163,8 @@ void MachineConfigFactory::loadHmSettings(const HMCOREFlatBuffer::HMCOREEcuCfg&
}
}

std::optional<watchdog::IDeviceConfigFactory::DeviceConfigurations>
MachineConfigFactory::getDeviceConfigurations() const
std::optional<watchdog::IDeviceConfigFactory::DeviceConfigurations> MachineConfigFactory::getDeviceConfigurations()
const
{
return watchdogConfigs;
}
Expand All @@ -180,7 +182,8 @@ const MachineConfigFactory::SupervisionBufferConfig& MachineConfigFactory::getSu

void MachineConfigFactory::logConfiguration() noexcept(true)
{
/* RULECHECKER_comment(0, 18, check_conditional_as_sub_expression, "Ternary operation is very simple", true_no_defect) */
/* RULECHECKER_comment(0, 18, check_conditional_as_sub_expression, "Ternary operation is very simple",
* true_no_defect) */
logger_r.LogDebug() << kLogPrefix << "Alive Supervision buffer size:" << supBufferCfg.bufferSizeAliveSupervision;
logger_r.LogDebug() << kLogPrefix << "Monitor buffer size:" << supBufferCfg.bufferSizeMonitor;
logger_r.LogDebug() << kLogPrefix << "Periodicity:" << getCycleTimeInNs() << "ns";
Expand All @@ -195,7 +198,8 @@ void MachineConfigFactory::logConfiguration() noexcept(true)
logger_r.LogDebug() << kLogPrefix << "Watchdog" << wdgCount << "- needs magic close:" << wdgMagicCloseBool;
logger_r.LogDebug() << kLogPrefix << "Watchdog" << wdgCount
<< "- deactivate on hm shutdown:" << wdgDeactivatedBool;
// coverity[autosar_cpp14_a4_7_1_violation] Value limited by amount of watchdog configurations, which is smaller.
// coverity[autosar_cpp14_a4_7_1_violation] Value limited by amount of watchdog configurations, which is
// smaller.
++wdgCount;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "score/mw/launch_manager/alive_monitor/details/supervision/Alive.hpp"

#include <cassert>
#include <score/assert.hpp>
#include <string_view>

#include "score/mw/launch_manager/alive_monitor/details/common/Types.hpp"
Expand Down Expand Up @@ -43,12 +43,14 @@ Alive::Alive(const AliveSupervisionCfg& f_aliveCfg_r)
timeSortingUpdateEventBuffer(common::TimeSortingBuffer<TimeSortedUpdateEvent>(f_aliveCfg_r.checkpointBufferSize))
{
f_aliveCfg_r.checkpoint_r.attachObserver(*this);
assert((k_aliveReferenceCycle != 0U) && "k_aliveReferenceCycle=0 causes infinite loop during evaluation.");
SCORE_LANGUAGE_FUTURECPP_PRECONDITION_PRD_MESSAGE(
(k_aliveReferenceCycle != 0U), "k_aliveReferenceCycle=0 causes infinite loop during evaluation.");

assert((aliveStatus == EStatus::kDeactivated) &&
("Alive Supervision must start in deactivated state, see SWS_PHM_00204"));
SCORE_LANGUAGE_FUTURECPP_PRECONDITION_PRD_MESSAGE(
(aliveStatus == EStatus::kDeactivated), "Alive Supervision must start in deactivated state, see SWS_PHM_00204");

assert((recoveryClient_p != nullptr) && "Recovery client must be provided");
SCORE_LANGUAGE_FUTURECPP_PRECONDITION_PRD_MESSAGE((recoveryClient_p != nullptr),
"Recovery client must be provided");
}

// coverity[exn_spec_violation:FALSE] std::length_error is not thrown from push() which uses fixed-size-vector
Expand Down Expand Up @@ -78,10 +80,9 @@ void Alive::updateData(const ifexm::ProcessState& f_observable_r) noexcept(true)
{
const ifexm::ProcessState::EProcState state{f_observable_r.getState()};

const bool isRelevant =
(state == ifexm::ProcessState::EProcState::running) ||
(state == ifexm::ProcessState::EProcState::sigterm) ||
(state == ifexm::ProcessState::EProcState::off);
const bool isRelevant = (state == ifexm::ProcessState::EProcState::running) ||
(state == ifexm::ProcessState::EProcState::sigterm) ||
(state == ifexm::ProcessState::EProcState::off);

if (isRelevant)
{
Expand Down Expand Up @@ -122,8 +123,9 @@ void Alive::evaluate(const timers::NanoSecondType f_syncTimestamp)
while (sortedUpdateEvent_p != nullptr)
{
timers::NanoSecondType timestampOfUpdateEvent{getTimestampOfUpdateEvent(*sortedUpdateEvent_p)};
assert((timestampOfUpdateEvent <= f_syncTimestamp) &&
"Alive supervision: Checkpoint events are reported beyond syncTimestamp.");
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(
(timestampOfUpdateEvent <= f_syncTimestamp),
"Alive supervision: Checkpoint events are reported beyond syncTimestamp.");

// Check if evaluation is to be triggered before processing current sorted update event
const bool isEvaluationEvent{detectEvaluationEvent(timestampOfUpdateEvent, *sortedUpdateEvent_p)};
Expand Down Expand Up @@ -290,7 +292,7 @@ Alive::EUpdateEventType Alive::getAliveEventType(bool f_isEvaluationEvent,
}

// SyncSnapshot
assert(std::holds_alternative<SyncSnapshot>(f_updateEvent));
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(std::holds_alternative<SyncSnapshot>(f_updateEvent));
return EUpdateEventType::kSync;
}

Expand Down Expand Up @@ -489,7 +491,7 @@ void Alive::switchToExpired(Alive::EReason reason) noexcept(true)
<< ") switched to EXPIRED, due to buffer overflow.";
break;
default:
assert(dataLossReason != EDataLossReason::kNoDataLoss);
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(dataLossReason != EDataLossReason::kNoDataLoss);
logger_r.LogError() << "Alive Supervision (" << getConfigName()
<< ") switched to EXPIRED, due to unknown data loss case.";
break;
Expand Down Expand Up @@ -593,7 +595,7 @@ timers::NanoSecondType Alive::getTimestampOfUpdateEvent(const TimeSortedUpdateEv
}
else
{
assert(std::holds_alternative<SyncSnapshot>(f_updateEvent));
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(std::holds_alternative<SyncSnapshot>(f_updateEvent));
// coverity[cert_exp34_c_violation] SyncSnapshot type is stored also check assert above
// coverity[dereference] SyncSnapshot type is stored also check assert above
timestamp = std::get<SyncSnapshot>(f_updateEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ cc_library(
"//score/launch_manager/src/daemon/src/alive_monitor/details/logging:phm_logging",
"//score/launch_manager/src/daemon/src/alive_monitor/details/timers:timers_os_clock",
"//score/launch_manager/src/daemon/src/recovery_client",
"@score_baselibs//score/language/futurecpp",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ cc_library(
include_prefix = "score/mw/launch_manager/alive_monitor/details/watchdog",
strip_include_prefix = "/score/launch_manager/src/daemon/src/alive_monitor/details/watchdog",
visibility = ["//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__"],
deps = ["@score_baselibs//score/language/futurecpp"],
)

cc_library(
Expand All @@ -60,5 +61,6 @@ cc_library(
":watchdog",
"//score/launch_manager/src/daemon/src/alive_monitor/details/logging:phm_logging",
"//score/launch_manager/src/daemon/src/alive_monitor/details/timers:os_clock_interface",
"@score_baselibs//score/language/futurecpp",
],
)
Loading
Loading