Motr  M0
Fault Injection

Fault Injection API provides functions to set "fault points" inside the code, and functions to enable/disable the failure of those points. It's aimed at increasing code coverage by enabling execution of error-handling code paths, which are not covered otherwise by unit tests. More...

Data Structures

struct  m0_fi_fault_point
 
struct  m0_fi_fpoint_data
 

Macros

#define M0_FI_ENABLED(tag)
 

Typedefs

typedef bool(* m0_fi_fpoint_state_func_t) (void *data)
 

Enumerations

enum  m0_fi_fpoint_type {
  M0_FI_ALWAYS, M0_FI_ONESHOT, M0_FI_RANDOM, M0_FI_OFF_N_ON_M,
  M0_FI_FUNC, M0_FI_INVALID_TYPE, M0_FI_TYPES_NR
}
 

Functions

M0_INTERNAL int m0_fi_init (void)
 
M0_INTERNAL void m0_fi_fini (void)
 
M0_INTERNAL void m0_fi_print_info (void)
 
M0_INTERNAL void m0_fi_enable_generic (const char *fp_func, const char *fp_tag, const struct m0_fi_fpoint_data *fp_data)
 
static void m0_fi_enable (const char *func, const char *tag)
 
static void m0_fi_enable_once (const char *func, const char *tag)
 
static void m0_fi_enable_random (const char *func, const char *tag, uint32_t p)
 
static void m0_fi_enable_off_n_on_m (const char *func, const char *tag, uint32_t n, uint32_t m)
 
static void m0_fi_enable_each_nth_time (const char *func, const char *tag, uint32_t n)
 
static void m0_fi_enable_func (const char *func, const char *tag, m0_fi_fpoint_state_func_t trigger_func, void *data)
 
M0_INTERNAL void m0_fi_disable (const char *fp_func, const char *fp_tag)
 
void m0_fi_register (struct m0_fi_fault_point *fp)
 
bool m0_fi_enabled (struct m0_fi_fpoint_state *fps)
 
M0_INTERNAL enum m0_fi_fpoint_type m0_fi_fpoint_type_from_str (const char *type_name)
 
M0_INTERNAL int m0_fi_enable_fault_point (const char *str)
 
M0_INTERNAL int m0_fi_enable_fault_points_from_file (const char *file_name)
 

Detailed Description

Fault Injection API provides functions to set "fault points" inside the code, and functions to enable/disable the failure of those points. It's aimed at increasing code coverage by enabling execution of error-handling code paths, which are not covered otherwise by unit tests.

Macro Definition Documentation

◆ M0_FI_ENABLED

#define M0_FI_ENABLED (   tag)
Value:
({ \
static struct m0_fi_fault_point fp = { \
.fp_state = NULL, \
/* TODO: add some macro to automatically get name of current module */ \
.fp_module = "UNKNOWN", \
.fp_file = __FILE__, \
.fp_line_num = __LINE__, \
.fp_func = __func__, \
.fp_tag = (tag), \
}; \
if (unlikely(fp.fp_state == NULL)) { \
m0_fi_register(&fp); \
M0_ASSERT(fp.fp_state != NULL); \
} \
m0_fi_enabled(fp.fp_state); \
})
#define unlikely(x)
Definition: assert.h:74
#define NULL
Definition: misc.h:38
static uint64_t tag(uint8_t code, uint64_t id)
Definition: addb2.c:1047
if(value==NULL)
Definition: dir.c:350
bool m0_fi_enabled(struct m0_fi_fpoint_state *fps)
Definition: finject.c:445
Definition: rcv_session.c:58

Defines a fault point and checks if it's enabled.

FP registration occurs only once, during first time when this macro is "executed". m0_fi_register() is used to register FP in a global dynamic list, which may introduce some delay if this list already contains large amount of registered fault points.

A typical use case for this macro is:

void *m0_alloc(size_t n)
{
...
if (M0_FI_ENABLED("pretend_failure"))
return NULL;
...
}

It creates a fault point with tag "pretend_failure" in function "m0_alloc", which can be enabled/disabled from external code with something like the following:

m0_fi_enable_once("m0_alloc", "pretend_failure");
See also
m0_fi_enable_generic() for more details
Parameters
tagshort descriptive name of fault point, usually separated by and uniquely identifies this FP within a current function
Returns
true, if FP is enabled
false otherwise

Definition at line 231 of file finject.h.

Typedef Documentation

◆ m0_fi_fpoint_state_func_t

typedef bool(* m0_fi_fpoint_state_func_t) (void *data)

A prototype of user-supplied callback for M0_FI_FUNC fault points, which is used to to determine if FP should trigger or not.

Definition at line 121 of file finject.h.

Enumeration Type Documentation

◆ m0_fi_fpoint_type

Fault point types, which determine FP behavior in enabled state.

Enumerator
M0_FI_ALWAYS 

Always triggers when enabled

M0_FI_ONESHOT 

Triggers only on first hit, then becomes disabled automatically

M0_FI_RANDOM 

Triggers with a given probability

M0_FI_OFF_N_ON_M 

Doesn't trigger first N times, then triggers next M times, then repeats this cycle

M0_FI_FUNC 

Invokes a user-supplied callback of type m0_fi_fpoint_state_func_t to determine if FP should trigger or not

M0_FI_INVALID_TYPE 
M0_FI_TYPES_NR 

Number of fault point types

Definition at line 93 of file finject.h.

Function Documentation

◆ m0_fi_disable()

M0_INTERNAL void m0_fi_disable ( const char *  fp_func,
const char *  fp_tag 
)

Disables fault point, which identified by "func", "tag" pair.

Parameters
fp_funcName of function, which contains a target FP
fp_tagFP tag, which was specified as a parameter to M0_FI_ENABLED()

Definition at line 485 of file finject.c.

Here is the call graph for this function:

◆ m0_fi_enable()

static void m0_fi_enable ( const char *  func,
const char *  tag 
)
inlinestatic

Enables fault point, which identified by "func", "tag" pair, using M0_FI_ALWAYS FP type.

Parameters
funcName of function, which contains the target FP
tagFP tag, which was specified as a parameter to M0_FI_ENABLED()
See also
m0_fi_enable_generic() and m0_fi_fpoint_type for more details

Definition at line 276 of file finject.h.

Here is the call graph for this function:

◆ m0_fi_enable_each_nth_time()

static void m0_fi_enable_each_nth_time ( const char *  func,
const char *  tag,
uint32_t  n 
)
inlinestatic

A wrapper around m0_fi_enable_off_n_on_m() for a special case when N=n-1 and M=1, which simply means to trigger FP each n-th time.

Parameters
funcName of function, which contains the target FP
tagFP tag, which was specified as a parameter to M0_FI_ENABLED()
nA "frequency" with which FP is triggered

Definition at line 366 of file finject.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_fi_enable_fault_point()

M0_INTERNAL int m0_fi_enable_fault_point ( const char *  str)

Definition at line 103 of file finject_init.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_fi_enable_fault_points_from_file()

M0_INTERNAL int m0_fi_enable_fault_points_from_file ( const char *  file_name)

Definition at line 258 of file finject_init.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_fi_enable_func()

static void m0_fi_enable_func ( const char *  func,
const char *  tag,
m0_fi_fpoint_state_func_t  trigger_func,
void *  data 
)
inlinestatic

Enables fault point, which identified by "func", "tag" pair, using M0_FI_FUNC FP type.

Parameters
funcName of function, which contains the target FP
tagFP tag, which was specified as a parameter to M0_FI_ENABLED()
trigger_funcPointer to a user-supplied triggering function
dataPointer to store user's private data, which can be accessed from user-supplied triggering function
See also
m0_fi_enable_generic() and m0_fi_fpoint_data/m0_fi_fpoint_type for more details

Definition at line 387 of file finject.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_fi_enable_generic()

M0_INTERNAL void m0_fi_enable_generic ( const char *  fp_func,
const char *  fp_tag,
const struct m0_fi_fpoint_data fp_data 
)

Enables fault point, which identified by "func", "tag" pair.

It's not intended to be used on it's own, a set of m0_fi_enable_xxx() wrapper functions should be used instead.

Parameters
fp_funcName of function, which contains a target FP
fp_tagFP tag, which was specified as a parameter to M0_FI_ENABLED()
fp_typeSpecifies a type of "triggering algorithm" (
See also
enum m0_fi_fpoint_type)
Parameters
fp_dataParameters for "triggering algorithm", which controls FP behavior (
See also
struct m0_fi_fpoint_data)

Definition at line 462 of file finject.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_fi_enable_off_n_on_m()

static void m0_fi_enable_off_n_on_m ( const char *  func,
const char *  tag,
uint32_t  n,
uint32_t  m 
)
inlinestatic

Enables fault point, which identified by "func", "tag" pair, using M0_FI_OFF_N_ON_M FP type.

Parameters
funcName of function, which contains the target FP
tagFP tag, which was specified as a parameter to M0_FI_ENABLED()
nInteger values, used as initialized for fpd_n field of m0_fi_fpoint_data structure
mInteger values, used as initialized for fpd_m field of m0_fi_fpoint_data structure
See also
m0_fi_enable_generic() and m0_fi_fpoint_data/m0_fi_fpoint_type for more details

Definition at line 346 of file finject.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_fi_enable_once()

static void m0_fi_enable_once ( const char *  func,
const char *  tag 
)
inlinestatic

Enables fault point, which identified by "func", "tag" pair, using M0_FI_ONESHOT FP type.

Parameters
funcName of function, which contains the target FP
tagFP tag, which was specified as a parameter to M0_FI_ENABLED()
See also
m0_fi_enable_generic() and m0_fi_fpoint_type for more details

Definition at line 301 of file finject.h.

Here is the call graph for this function:

◆ m0_fi_enable_random()

static void m0_fi_enable_random ( const char *  func,
const char *  tag,
uint32_t  p 
)
inlinestatic

Enables fault point, which identified by "func", "tag" pair, using M0_FI_RANDOM FP type.

Parameters
funcName of function, which contains the target FP
tagFP tag, which was specified as a parameter to M0_FI_ENABLED()
pInteger number in range [1..100], which means a probability in percents, with which FP should be triggered on each hit
See also
m0_fi_enable_generic() and m0_fi_fpoint_data for more details

Definition at line 321 of file finject.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_fi_enabled()

bool m0_fi_enabled ( struct m0_fi_fpoint_state fps)

Checks if fault point should "trigger" or not.

It's not intended to be used on it's own, instead it's used as part of M0_FI_ENABLED() macro.

Parameters
fpsA pointer to fault point's state structure, which is linked with FP's "descriptor"
See also
M0_FI_ENABLED() for more information
Returns
true, if FP is enabled
false otherwise

Definition at line 445 of file finject.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_fi_fini()

M0_INTERNAL void m0_fi_fini ( void  )

Finalizes fault injection subsystem.

Definition at line 47 of file finject_init.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_fi_fpoint_type_from_str()

M0_INTERNAL enum m0_fi_fpoint_type m0_fi_fpoint_type_from_str ( const char *  type_name)

Definition at line 364 of file finject.c.

◆ m0_fi_init()

M0_INTERNAL int m0_fi_init ( void  )

Initializes fault injection subsystem.

Definition at line 40 of file finject_init.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_fi_print_info()

M0_INTERNAL void m0_fi_print_info ( void  )

Prints to stdout information about current state of fault points formatted as table.

Definition at line 78 of file finject_init.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_fi_register()

void m0_fi_register ( struct m0_fi_fault_point fp)

Registers fault point in a global list.

It's not intended to be used on it's own, instead it's used as part of M0_FI_ENABLED() macro.

Parameters
fpA fault point descriptor
See also
M0_FI_ENABLED() for more information

Definition at line 423 of file finject.c.

Here is the call graph for this function:
Here is the caller graph for this function: