Zephyr C++ Toolkit
|
Mock implementation of the watchdog interface for testing. More...
#include <WatchdogMock.hpp>
Classes | |
struct | TimeoutChannel |
Structure to hold information about an installed timeout channel. More... | |
Public Member Functions | |
WatchdogMock (const char *name) | |
Constructor. | |
~WatchdogMock () | |
Destructor. | |
int | installTimeout (uint32_t timeoutMs, CallbackFn callback=nullptr, void *userData=nullptr, ResetFlag flags=ResetFlag::ResetSoc) override |
Install a watchdog timeout configuration. | |
int | setup (Option options=Option::None) override |
Setup the watchdog with global configuration. | |
int | feed (int channelId) override |
Feed (service) a watchdog channel to prevent timeout. | |
int | disable () override |
Disable the watchdog instance. | |
const struct device * | getRawDevice () const override |
Get the raw watchdog device pointer. | |
void | mockTriggerTimeout (int channelId) |
Manually trigger a timeout for a specific channel. | |
bool | mockIsSetup () const |
Check if the watchdog has been set up. | |
bool | mockIsDisabled () const |
Check if the watchdog is disabled. | |
size_t | mockGetChannelCount () const |
Get the number of installed timeout channels. | |
const TimeoutChannel * | mockGetChannelInfo (int channelId) const |
Get information about a specific channel. | |
bool | mockIsChannelExpired (int channelId) const |
Check if a channel is expired (past its timeout). | |
int64_t | mockGetTimeRemainingMs (int channelId) const |
Get the time remaining until timeout for a channel. | |
uint32_t | mockGetFeedCount (int channelId) const |
Get the number of times a channel has been fed. | |
void | mockReset () |
Reset all mock state (useful for test setup). | |
![]() | |
IWatchdog (const char *name) | |
Constructor. | |
virtual | ~IWatchdog ()=default |
Virtual destructor. | |
const char * | getName () const |
Get the name of this watchdog instance. | |
Private Attributes | |
std::vector< TimeoutChannel > | m_channels |
Installed timeout channels. | |
std::vector< uint32_t > | m_feedCounts |
Feed count per channel. | |
bool | m_isSetup |
Whether setup() has been called. | |
bool | m_isDisabled |
Whether disable() has been called. | |
Option | m_globalOptions |
Global watchdog options. | |
int | m_nextChannelId |
Next channel ID to assign. | |
Additional Inherited Members | |
![]() | |
enum class | Option : uint8_t { None = 0 , PauseInSleep = 1 , PauseHaltedByDebug = 2 } |
Watchdog configuration options. More... | |
enum class | ResetFlag : uint8_t { None = 0 , ResetCpuCore = 1 , ResetSoc = 2 } |
Watchdog reset behavior flags. More... | |
using | CallbackFn = std::function< void(int channelId, void *userData)> |
Watchdog callback function type. | |
![]() | |
const char * | m_name |
Name of this watchdog instance. | |
Mock implementation of the watchdog interface for testing.
This class simulates watchdog behavior in software for unit testing purposes.
zct::WatchdogMock::WatchdogMock | ( | const char * | name | ) |
Constructor.
name | Name of the watchdog instance for logging purposes |
zct::WatchdogMock::~WatchdogMock | ( | ) |
Destructor.
|
overridevirtual |
Disable the watchdog instance.
Implements zct::IWatchdog.
|
overridevirtual |
Feed (service) a watchdog channel to prevent timeout.
channelId | Channel ID to feed |
Implements zct::IWatchdog.
|
overridevirtual |
|
overridevirtual |
Install a watchdog timeout configuration.
timeoutMs | Timeout value in milliseconds |
callback | Callback function to execute on timeout (optional) |
userData | User data to pass to callback (optional) |
flags | Reset behavior flags |
options | Configuration options |
Implements zct::IWatchdog.
|
inline |
Get the number of installed timeout channels.
const WatchdogMock::TimeoutChannel * zct::WatchdogMock::mockGetChannelInfo | ( | int | channelId | ) | const |
Get information about a specific channel.
channelId | Channel ID to query |
uint32_t zct::WatchdogMock::mockGetFeedCount | ( | int | channelId | ) | const |
Get the number of times a channel has been fed.
channelId | Channel ID to check |
int64_t zct::WatchdogMock::mockGetTimeRemainingMs | ( | int | channelId | ) | const |
Get the time remaining until timeout for a channel.
channelId | Channel ID to check |
bool zct::WatchdogMock::mockIsChannelExpired | ( | int | channelId | ) | const |
Check if a channel is expired (past its timeout).
channelId | Channel ID to check |
|
inline |
Check if the watchdog is disabled.
|
inline |
Check if the watchdog has been set up.
void zct::WatchdogMock::mockReset | ( | ) |
Reset all mock state (useful for test setup).
void zct::WatchdogMock::mockTriggerTimeout | ( | int | channelId | ) |
Manually trigger a timeout for a specific channel.
channelId | Channel ID to trigger timeout for |
|
overridevirtual |
Setup the watchdog with global configuration.
options | Global watchdog options |
Implements zct::IWatchdog.
|
private |
Installed timeout channels.
|
private |
Feed count per channel.
|
private |
Global watchdog options.
|
private |
Whether disable() has been called.
|
private |
Whether setup() has been called.
|
private |
Next channel ID to assign.