CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
Loading...
Searching...
No Matches
test_unit_timeout.c File Reference

This file contains definitions and implementation of various unit tests for checking the functionality of the timeout.c API functions. More...

#include "cdi_logger_api.h"
#include "cdi_os_api.h"
#include "timeout.h"

Data Structures

struct  CallBackUserData
 A structure to be used by the unit test callback function to signal to the test when the callback occurred and whether the callback was successful. More...
 

Typedefs

typedef struct CallBackUserData CallBackUserData
 A structure to be used by the unit test callback function to signal to the test when the callback occurred and whether the callback was successful.
 

Functions

static void TimerCallback (const CdiTimeoutCbData *data_ptr)
 A callback function to be executed when a timer expires. This function checks the time when the timer callback occurs and compares the callback time with the expected timer expiration time that was stored when the timer was originally set. If the actual time is within a specified range of the expected time then callback user data has its pass field set as true.
 
static bool OneShotTimeoutTest (int timeout_ms)
 A test to create a timeout instance add a timer to it, let it expire and check the callback.
 
static bool MultipleTimersTest (unsigned int num_timers, bool reverse)
 A test to set multiple timers.
 
static bool TimersSetAndClear (uint32_t num_timers)
 A test to set multiple timers, let them expire in order and check the callback values.
 
CdiReturnStatus TestUnitTimeout (void)
 Main routine to test the timeout function.
 

Detailed Description

This file contains definitions and implementation of various unit tests for checking the functionality of the timeout.c API functions.

Function Documentation

◆ MultipleTimersTest()

static bool MultipleTimersTest ( unsigned int num_timers,
bool reverse )
static

A test to set multiple timers.

Parameters
num_timerssets how many timers are added to the timeout instance
reverseif true, each successive timer object has an earlier deadline as the list is built.
Returns
true if passes, false if failed

Check the pass status of all of the user_data structures sent to the callback function. The callback function logged errors for additional detail into the actual failure. Checking here as well to catch any user data structures where the callback didn't occur at all.

◆ OneShotTimeoutTest()

static bool OneShotTimeoutTest ( int timeout_ms)
static

A test to create a timeout instance add a timer to it, let it expire and check the callback.

Parameters
timeout_msis a timeout to set for the created timer
Returns
true if test pass, false if failure

◆ TestUnitTimeout()

CdiReturnStatus TestUnitTimeout ( void )

Main routine to test the timeout function.

External declarations.

◆ TimerCallback()

static void TimerCallback ( const CdiTimeoutCbData * data_ptr)
static

A callback function to be executed when a timer expires. This function checks the time when the timer callback occurs and compares the callback time with the expected timer expiration time that was stored when the timer was originally set. If the actual time is within a specified range of the expected time then callback user data has its pass field set as true.

Parameters
data_ptris a pointer to the CdiTimeoutCbData that is used for timeout callbacks. This structure contains a user data pointer to CallBackUserData which stores the expected expiration time and the pass signal that was mentioned above

◆ TimersSetAndClear()

static bool TimersSetAndClear ( uint32_t num_timers)
static

A test to set multiple timers, let them expire in order and check the callback values.

Parameters
num_timerssets how many timers to add and remove from the timeout instance
Returns
true for pass, false for test failure