Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
FFF extensions

This module provides extensions to FFF for simplifying the configuration and usage of fakes. More...

Macros

#define RETURN_HANDLED_CONTEXT(FUNCNAME, CONTEXTTYPE, RESULTFIELD, CONTEXTPTRNAME, HANDLERBODY)
 Wrap custom fake body to extract defined context struct.
 

Detailed Description

This module provides extensions to FFF for simplifying the configuration and usage of fakes.

Macro Definition Documentation

◆ RETURN_HANDLED_CONTEXT

#define RETURN_HANDLED_CONTEXT ( FUNCNAME,
CONTEXTTYPE,
RESULTFIELD,
CONTEXTPTRNAME,
HANDLERBODY )

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/include/zephyr/fff_extensions.h>

Value:
if (FUNCNAME##_fake.return_val_seq_len) { \
CONTEXTTYPE * const contexts = \
CONTAINER_OF(FUNCNAME##_fake.return_val_seq, \
CONTEXTTYPE, RESULTFIELD); \
size_t const seq_idx = (FUNCNAME##_fake.return_val_seq_idx < \
FUNCNAME##_fake.return_val_seq_len) ? \
FUNCNAME##_fake.return_val_seq_idx++ :\
FUNCNAME##_fake.return_val_seq_idx - 1;\
CONTEXTTYPE * const CONTEXTPTRNAME = &contexts[seq_idx]; \
HANDLERBODY; \
} \
return FUNCNAME##_fake.return_val

Wrap custom fake body to extract defined context struct.

Add extension macro for simplified creation of fake functions needing call-specific context data.

This macro enables a fake to be implemented as follows and requires no familiarity with the inner workings of FFF.

struct FUNCNAME##_custom_fake_context
{
struct instance * const instance;
int result;
};
int FUNCNAME##_custom_fake(
const struct instance **instance_out)
{
FUNCNAME,
struct FUNCNAME##_custom_fake_context,
result,
context,
{
if (context != NULL)
{
if (context->result == 0)
{
if (instance_out != NULL)
{
*instance_out = context->instance;
}
}
return context->result;
}
return FUNCNAME##_fake.return_val;
}
);
}
#define RETURN_HANDLED_CONTEXT(FUNCNAME, CONTEXTTYPE, RESULTFIELD, CONTEXTPTRNAME, HANDLERBODY)
Wrap custom fake body to extract defined context struct.
Definition fff_extensions.h:79
Parameters
FUNCNAMEName of function being faked
CONTEXTTYPEtype of custom defined fake context struct
RESULTFIELDname of field holding the return type & value
CONTEXTPTRNAMEexpected name of pointer to custom defined fake context struct
HANDLERBODYin-line custom fake handling logic