Skip to content

Commit 2addcde

Browse files
rootclaude
authored andcommitted
Replace assert() with baselibs futurecpp assert macros
Replaces all 37 plain assert() calls across 10 source files with the appropriate SCORE_LANGUAGE_FUTURECPP_* macros from score/assert.hpp, as required by project guidelines. Also adds the explicit @score_baselibs//score/language/futurecpp dep to 7 Bazel targets that now directly depend on the assert header. Macro selection follows existing codebase convention: - PRECONDITION[_PRD][_MESSAGE] for constructor/function-entry argument checks - ASSERT_PRD[_MESSAGE] for mid-function invariants in the safety-critical daemon - Default-level PRECONDITION (no PRD) for health_monitor, matching sibling files The _PRD variants guarantee checks survive any future NDEBUG or ASSERT_LEVEL_PRODUCTION build configuration, which is appropriate for the alive_monitor daemon (AUTOSAR PHM code referencing SWS_PHM_00204). Closes #263 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 60b26ed commit 2addcde

17 files changed

Lines changed: 58 additions & 48 deletions

File tree

score/health_monitor/src/cpp/common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#ifndef SCORE_HM_COMMON_H
1414
#define SCORE_HM_COMMON_H
1515

16-
#include <cassert>
16+
#include <score/assert.hpp>
1717
#include <chrono>
1818
#include <optional>
1919

@@ -95,7 +95,7 @@ class TimeRange
9595
public:
9696
TimeRange(std::chrono::milliseconds min_ms, std::chrono::milliseconds max_ms) : min_ms_(min_ms), max_ms_(max_ms)
9797
{
98-
assert(min_ms_ <= max_ms_);
98+
SCORE_LANGUAGE_FUTURECPP_PRECONDITION(min_ms_ <= max_ms_);
9999
}
100100

101101
const uint32_t min_ms() const

score/launch_manager/src/daemon/src/alive_monitor/details/common/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ cc_library(
2626
include_prefix = "score/mw/launch_manager/alive_monitor/details/common",
2727
strip_include_prefix = "/score/launch_manager/src/daemon/src/alive_monitor/details/common",
2828
visibility = ["//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__"],
29+
deps = ["@score_baselibs//score/language/futurecpp"],
2930
)
3031

3132
cc_library(

score/launch_manager/src/daemon/src/alive_monitor/details/common/Observer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#define OBSERVER_HPP_INCLUDED
1515

1616
#include <algorithm>
17-
#include <cassert>
17+
#include <score/assert.hpp>
1818
#include <cstdint>
1919

2020
#include <vector>
@@ -120,7 +120,7 @@ class Observable
120120
{
121121
// We can be sure that *this is of type Type_Observable, anything else would be a programming error.
122122
// The runtime checks performed by dynamic_cast are not necessary.
123-
assert((dynamic_cast<Type_Observable*>(this)) != NULL);
123+
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD((dynamic_cast<Type_Observable*>(this)) != NULL);
124124
observer->updateData(static_cast<Type_Observable&>(*this));
125125
}
126126
}

score/launch_manager/src/daemon/src/alive_monitor/details/daemon/AliveMonitorImpl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <cstdint>
1616
#include <iostream>
1717

18+
#include <score/assert.hpp>
19+
1820
#include "score/mw/launch_manager/alive_monitor/details/daemon/AliveMonitorImpl.hpp"
1921
#include "score/mw/launch_manager/alive_monitor/details/logging/PhmLogger.hpp"
2022
#include "score/mw/launch_manager/alive_monitor/details/watchdog/WatchdogImpl.hpp"
@@ -53,7 +55,7 @@ EInitCode AliveMonitorImpl::init() noexcept {
5355
}
5456

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

score/launch_manager/src/daemon/src/alive_monitor/details/daemon/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,6 @@ cc_library(
8686
":i_health_monitor",
8787
"//score/launch_manager/src/daemon/src/alive_monitor/details/logging:phm_logging",
8888
"//score/launch_manager/src/daemon/src/alive_monitor/details/watchdog:watchdog_impl",
89+
"@score_baselibs//score/language/futurecpp",
8990
],
9091
)

score/launch_manager/src/daemon/src/alive_monitor/details/factory/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ cc_library(
5151
"//score/launch_manager/src/daemon/src/alive_monitor/details/timers:timers_os_clock",
5252
"//score/launch_manager/src/daemon/src/alive_monitor/details/watchdog:i_device_config_factory",
5353
"@flatbuffers",
54+
"@score_baselibs//score/language/futurecpp",
5455
] + select({
5556
"@platforms//os:qnx": [],
5657
"@platforms//os:linux": ["//externals/acl"],

score/launch_manager/src/daemon/src/alive_monitor/details/factory/MachineConfigFactory.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <limits>
1616
#include <string_view>
1717
#include <fstream>
18+
19+
#include <score/assert.hpp>
1820
#include "score/mw/launch_manager/alive_monitor/details/timers/TimeConversion.hpp"
1921
#include "score/mw/launch_manager/alive_monitor/config/hmcore_flatcfg_generated.h"
2022
#include "flatbuffers/flatbuffers.h"
@@ -116,7 +118,7 @@ void MachineConfigFactory::loadWatchdogDevices(const HMCOREFlatBuffer::HMCOREEcu
116118
{
117119
watchdog::DeviceConfig config{};
118120

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

score/launch_manager/src/daemon/src/alive_monitor/details/supervision/Alive.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

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

16-
#include <cassert>
16+
#include <score/assert.hpp>
1717
#include <string_view>
1818

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

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

51-
assert((recoveryClient_p != nullptr) && "Recovery client must be provided");
50+
SCORE_LANGUAGE_FUTURECPP_PRECONDITION_PRD_MESSAGE((recoveryClient_p != nullptr), "Recovery client must be provided");
5251
}
5352

5453
// coverity[exn_spec_violation:FALSE] std::length_error is not thrown from push() which uses fixed-size-vector
@@ -122,8 +121,7 @@ void Alive::evaluate(const timers::NanoSecondType f_syncTimestamp)
122121
while (sortedUpdateEvent_p != nullptr)
123122
{
124123
timers::NanoSecondType timestampOfUpdateEvent{getTimestampOfUpdateEvent(*sortedUpdateEvent_p)};
125-
assert((timestampOfUpdateEvent <= f_syncTimestamp) &&
126-
"Alive supervision: Checkpoint events are reported beyond syncTimestamp.");
124+
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE((timestampOfUpdateEvent <= f_syncTimestamp), "Alive supervision: Checkpoint events are reported beyond syncTimestamp.");
127125

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

292290
// SyncSnapshot
293-
assert(std::holds_alternative<SyncSnapshot>(f_updateEvent));
291+
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(std::holds_alternative<SyncSnapshot>(f_updateEvent));
294292
return EUpdateEventType::kSync;
295293
}
296294

@@ -489,7 +487,7 @@ void Alive::switchToExpired(Alive::EReason reason) noexcept(true)
489487
<< ") switched to EXPIRED, due to buffer overflow.";
490488
break;
491489
default:
492-
assert(dataLossReason != EDataLossReason::kNoDataLoss);
490+
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(dataLossReason != EDataLossReason::kNoDataLoss);
493491
logger_r.LogError() << "Alive Supervision (" << getConfigName()
494492
<< ") switched to EXPIRED, due to unknown data loss case.";
495493
break;
@@ -593,7 +591,7 @@ timers::NanoSecondType Alive::getTimestampOfUpdateEvent(const TimeSortedUpdateEv
593591
}
594592
else
595593
{
596-
assert(std::holds_alternative<SyncSnapshot>(f_updateEvent));
594+
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(std::holds_alternative<SyncSnapshot>(f_updateEvent));
597595
// coverity[cert_exp34_c_violation] SyncSnapshot type is stored also check assert above
598596
// coverity[dereference] SyncSnapshot type is stored also check assert above
599597
timestamp = std::get<SyncSnapshot>(f_updateEvent);

score/launch_manager/src/daemon/src/alive_monitor/details/supervision/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ cc_library(
4848
":i_supervision",
4949
":supervision_cfg",
5050
"//score/launch_manager/src/daemon/src/alive_monitor/details/common:time_sorting_buffer",
51+
"@score_baselibs//score/language/futurecpp",
5152
"//score/launch_manager/src/daemon/src/alive_monitor/details/ifappl:checkpoint",
5253
"//score/launch_manager/src/daemon/src/alive_monitor/details/ifexm:process_state",
5354
"//score/launch_manager/src/daemon/src/alive_monitor/details/logging:phm_logging",

score/launch_manager/src/daemon/src/alive_monitor/details/watchdog/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ cc_library(
4444
include_prefix = "score/mw/launch_manager/alive_monitor/details/watchdog",
4545
strip_include_prefix = "/score/launch_manager/src/daemon/src/alive_monitor/details/watchdog",
4646
visibility = ["//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__"],
47+
deps = ["@score_baselibs//score/language/futurecpp"],
4748
)
4849

4950
cc_library(
@@ -60,5 +61,6 @@ cc_library(
6061
":watchdog",
6162
"//score/launch_manager/src/daemon/src/alive_monitor/details/logging:phm_logging",
6263
"//score/launch_manager/src/daemon/src/alive_monitor/details/timers:os_clock_interface",
64+
"@score_baselibs//score/language/futurecpp",
6365
],
6466
)

0 commit comments

Comments
 (0)