Zephyr C++ Toolkit
Loading...
Searching...
No Matches
zct::WatchdogMock Class Reference

Mock implementation of the watchdog interface for testing. More...

#include <WatchdogMock.hpp>

Inheritance diagram for zct::WatchdogMock:
Collaboration diagram for zct::WatchdogMock:

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 TimeoutChannelmockGetChannelInfo (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).
 
- Public Member Functions inherited from zct::IWatchdog
 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< TimeoutChannelm_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

- Public Types inherited from zct::IWatchdog
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.
 
- Protected Attributes inherited from zct::IWatchdog
const char * m_name
 Name of this watchdog instance.
 

Detailed Description

Mock implementation of the watchdog interface for testing.

This class simulates watchdog behavior in software for unit testing purposes.

Constructor & Destructor Documentation

◆ WatchdogMock()

zct::WatchdogMock::WatchdogMock ( const char *  name)

Constructor.

Parameters
nameName of the watchdog instance for logging purposes

◆ ~WatchdogMock()

zct::WatchdogMock::~WatchdogMock ( )

Destructor.

Member Function Documentation

◆ disable()

int zct::WatchdogMock::disable ( )
overridevirtual

Disable the watchdog instance.

Returns
0 on success, negative error code on failure

Implements zct::IWatchdog.

◆ feed()

int zct::WatchdogMock::feed ( int  channelId)
overridevirtual

Feed (service) a watchdog channel to prevent timeout.

Parameters
channelIdChannel ID to feed
Returns
0 on success, negative error code on failure

Implements zct::IWatchdog.

◆ getRawDevice()

const struct device * zct::WatchdogMock::getRawDevice ( ) const
overridevirtual

Get the raw watchdog device pointer.

Returns
Raw watchdog device pointer

Implements zct::IWatchdog.

◆ installTimeout()

int zct::WatchdogMock::installTimeout ( uint32_t  timeoutMs,
CallbackFn  callback = nullptr,
void *  userData = nullptr,
ResetFlag  flags = ResetFlag::ResetSoc 
)
overridevirtual

Install a watchdog timeout configuration.

Parameters
timeoutMsTimeout value in milliseconds
callbackCallback function to execute on timeout (optional)
userDataUser data to pass to callback (optional)
flagsReset behavior flags
optionsConfiguration options
Returns
Channel ID on success, negative error code on failure

Implements zct::IWatchdog.

◆ mockGetChannelCount()

size_t zct::WatchdogMock::mockGetChannelCount ( ) const
inline

Get the number of installed timeout channels.

Returns
Number of channels

◆ mockGetChannelInfo()

const WatchdogMock::TimeoutChannel * zct::WatchdogMock::mockGetChannelInfo ( int  channelId) const

Get information about a specific channel.

Parameters
channelIdChannel ID to query
Returns
Pointer to channel info, or nullptr if channel doesn't exist

◆ mockGetFeedCount()

uint32_t zct::WatchdogMock::mockGetFeedCount ( int  channelId) const

Get the number of times a channel has been fed.

Parameters
channelIdChannel ID to check
Returns
Feed count for the channel

◆ mockGetTimeRemainingMs()

int64_t zct::WatchdogMock::mockGetTimeRemainingMs ( int  channelId) const

Get the time remaining until timeout for a channel.

Parameters
channelIdChannel ID to check
Returns
Time remaining in milliseconds, or -1 if channel doesn't exist

◆ mockIsChannelExpired()

bool zct::WatchdogMock::mockIsChannelExpired ( int  channelId) const

Check if a channel is expired (past its timeout).

Parameters
channelIdChannel ID to check
Returns
True if channel has expired

◆ mockIsDisabled()

bool zct::WatchdogMock::mockIsDisabled ( ) const
inline

Check if the watchdog is disabled.

Returns
True if disable() has been called

◆ mockIsSetup()

bool zct::WatchdogMock::mockIsSetup ( ) const
inline

Check if the watchdog has been set up.

Returns
True if setup() has been called successfully

◆ mockReset()

void zct::WatchdogMock::mockReset ( )

Reset all mock state (useful for test setup).

◆ mockTriggerTimeout()

void zct::WatchdogMock::mockTriggerTimeout ( int  channelId)

Manually trigger a timeout for a specific channel.

Parameters
channelIdChannel ID to trigger timeout for

◆ setup()

int zct::WatchdogMock::setup ( Option  options = Option::None)
overridevirtual

Setup the watchdog with global configuration.

Parameters
optionsGlobal watchdog options
Returns
0 on success, negative error code on failure

Implements zct::IWatchdog.

Member Data Documentation

◆ m_channels

std::vector<TimeoutChannel> zct::WatchdogMock::m_channels
private

Installed timeout channels.

◆ m_feedCounts

std::vector<uint32_t> zct::WatchdogMock::m_feedCounts
private

Feed count per channel.

◆ m_globalOptions

Option zct::WatchdogMock::m_globalOptions
private

Global watchdog options.

◆ m_isDisabled

bool zct::WatchdogMock::m_isDisabled
private

Whether disable() has been called.

◆ m_isSetup

bool zct::WatchdogMock::m_isSetup
private

Whether setup() has been called.

◆ m_nextChannelId

int zct::WatchdogMock::m_nextChannelId
private

Next channel ID to assign.


The documentation for this class was generated from the following files: