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...
|
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) |
|
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.
◆ M0_FI_ENABLED
#define M0_FI_ENABLED |
( |
|
tag | ) |
|
Value:({ \
\
.fp_module = "UNKNOWN", \
.fp_file = __FILE__, \
.fp_line_num = __LINE__, \
.fp_func = __func__, \
M0_ASSERT(
fp.fp_state !=
NULL); \
})
static uint64_t tag(uint8_t code, uint64_t id)
bool m0_fi_enabled(struct m0_fi_fpoint_state *fps)
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:
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:
- See also
- m0_fi_enable_generic() for more details
- Parameters
-
tag | short 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.
◆ 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.
◆ 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.
◆ 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_func | Name of function, which contains a target FP |
fp_tag | FP tag, which was specified as a parameter to M0_FI_ENABLED() |
Definition at line 485 of file finject.c.
◆ m0_fi_enable()
static void m0_fi_enable |
( |
const char * |
func, |
|
|
const char * |
tag |
|
) |
| |
|
inlinestatic |
◆ 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
-
func | Name of function, which contains the target FP |
tag | FP tag, which was specified as a parameter to M0_FI_ENABLED() |
n | A "frequency" with which FP is triggered |
Definition at line 366 of file finject.h.
◆ m0_fi_enable_fault_point()
M0_INTERNAL int m0_fi_enable_fault_point |
( |
const char * |
str | ) |
|
◆ m0_fi_enable_fault_points_from_file()
M0_INTERNAL int m0_fi_enable_fault_points_from_file |
( |
const char * |
file_name | ) |
|
◆ m0_fi_enable_func()
Enables fault point, which identified by "func", "tag" pair, using M0_FI_FUNC FP type.
- Parameters
-
func | Name of function, which contains the target FP |
tag | FP tag, which was specified as a parameter to M0_FI_ENABLED() |
trigger_func | Pointer to a user-supplied triggering function |
data | Pointer 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.
◆ 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_func | Name of function, which contains a target FP |
fp_tag | FP tag, which was specified as a parameter to M0_FI_ENABLED() |
fp_type | Specifies a type of "triggering algorithm" ( |
- See also
- enum m0_fi_fpoint_type)
- Parameters
-
fp_data | Parameters for "triggering algorithm", which controls FP behavior ( |
- See also
- struct m0_fi_fpoint_data)
Definition at line 462 of file finject.c.
◆ 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
-
func | Name of function, which contains the target FP |
tag | FP tag, which was specified as a parameter to M0_FI_ENABLED() |
n | Integer values, used as initialized for fpd_n field of m0_fi_fpoint_data structure |
m | Integer 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.
◆ m0_fi_enable_once()
static void m0_fi_enable_once |
( |
const char * |
func, |
|
|
const char * |
tag |
|
) |
| |
|
inlinestatic |
◆ 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
-
func | Name of function, which contains the target FP |
tag | FP tag, which was specified as a parameter to M0_FI_ENABLED() |
p | Integer 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.
◆ m0_fi_enabled()
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
-
fps | A 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.
◆ m0_fi_fini()
M0_INTERNAL void m0_fi_fini |
( |
void |
| ) |
|
Finalizes fault injection subsystem.
Definition at line 47 of file finject_init.c.
◆ m0_fi_fpoint_type_from_str()
M0_INTERNAL enum m0_fi_fpoint_type m0_fi_fpoint_type_from_str |
( |
const char * |
type_name | ) |
|
◆ m0_fi_init()
M0_INTERNAL int m0_fi_init |
( |
void |
| ) |
|
Initializes fault injection subsystem.
Definition at line 40 of file finject_init.c.
◆ 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.
◆ m0_fi_register()
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
-
fp | A fault point descriptor |
- See also
- M0_FI_ENABLED() for more information
Definition at line 423 of file finject.c.