libfiu (internal) 0.90
Defines | Typedefs | Functions
fiu-control.h File Reference

This header contains the control API. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define FIU_ONETIME   1
 Only fail once; the point of failure will be automatically disabled afterwards.

Typedefs

typedef int external_cb_t (const char *name, int *failnum, void **failinfo, unsigned int *flags)
 Type of external callback functions.

Functions

int fiu_enable (const char *name, int failnum, void *failinfo, unsigned int flags)
 Enables the given point of failure unconditionally.
int fiu_enable_random (const char *name, int failnum, void *failinfo, unsigned int flags, float probability)
 Enables the given point of failure, with the given probability.
int fiu_enable_external (const char *name, int failnum, void *failinfo, unsigned int flags, external_cb_t *external_cb)
 Enables the given point of failure, leaving the decision whether to fail or not to the given external function.
int fiu_enable_stack (const char *name, int failnum, void *failinfo, unsigned int flags, void *func, int func_pos_in_stack)
int fiu_enable_stack_by_name (const char *name, int failnum, void *failinfo, unsigned int flags, const char *func_name, int func_pos_in_stack)
 Enables the given point of failure, but only if 'func_name' is in the stack at 'func_pos_in_stack'.
int fiu_disable (const char *name)
 Disables the given point of failure.
int fiu_rc_fifo (const char *basename)
 Enables remote control over a named pipe.
int fiu_rc_string (const char *cmd, char **const error)
 Applies a remote control command given via a string.

Detailed Description

This header contains the control API.

It should be used for controlling the injection of failures, usually when writing tests.

Definition in file fiu-control.h.


Define Documentation

#define FIU_ONETIME   1

Only fail once; the point of failure will be automatically disabled afterwards.

Definition at line 21 of file fiu-control.h.

Referenced by fiu_fail(), and fiu_rc_string().


Typedef Documentation

typedef int external_cb_t(const char *name, int *failnum, void **failinfo, unsigned int *flags)

Type of external callback functions.

They must return 0 to indicate not to fail, != 0 to indicate otherwise. Can modify failnum, failinfo and flags, in order to alter the values of the point of failure.

Definition at line 56 of file fiu-control.h.


Function Documentation

int fiu_enable ( const char *  name,
int  failnum,
void *  failinfo,
unsigned int  flags 
)

Enables the given point of failure unconditionally.

Parameters:
nameName of the point of failure to enable.
failnumWhat will fiu_fail() return, must be != 0.
failinfoWhat will fiu_failinfo() return.
flagsFlags.
Returns:
0 if success, < 0 otherwise.

Definition at line 469 of file fiu.c.

Referenced by fiu_rc_string().

Here is the call graph for this function:

Here is the caller graph for this function:

int fiu_enable_random ( const char *  name,
int  failnum,
void *  failinfo,
unsigned int  flags,
float  probability 
)

Enables the given point of failure, with the given probability.

That makes it fail with the given probability.

Parameters:
nameName of the point of failure to enable.
failnumWhat will fiu_fail() return, must be != 0.
failinfoWhat will fiu_failinfo() return.
flagsFlags.
probabilityProbability a fiu_fail() call will return failnum, between 0 (never fail) and 1 (always fail). As a special fast case, -1 can also be used to always fail.
Returns:
0 if success, < 0 otherwise.

Definition at line 482 of file fiu.c.

Referenced by fiu_rc_string().

Here is the call graph for this function:

Here is the caller graph for this function:

int fiu_enable_external ( const char *  name,
int  failnum,
void *  failinfo,
unsigned int  flags,
external_cb_t external_cb 
)

Enables the given point of failure, leaving the decision whether to fail or not to the given external function.

Parameters:
nameName of the point of failure to enable.
failnumWhat will fiu_fail() return, must be != 0.
failinfoWhat will fiu_failinfo() return.
flagsFlags.
external_cbFunction to call to determine whether to fail or not.
Returns:
0 if success, < 0 otherwise.

Definition at line 496 of file fiu.c.

Here is the call graph for this function:

int fiu_enable_stack ( const char *  name,
int  failnum,
void *  failinfo,
unsigned int  flags,
void *  func,
int  func_pos_in_stack 
)

Definition at line 511 of file fiu.c.

Referenced by fiu_enable_stack_by_name().

Here is the call graph for this function:

Here is the caller graph for this function:

int fiu_enable_stack_by_name ( const char *  name,
int  failnum,
void *  failinfo,
unsigned int  flags,
const char *  func_name,
int  func_pos_in_stack 
)

Enables the given point of failure, but only if 'func_name' is in the stack at 'func_pos_in_stack'.

This function relies on GNU extensions such as backtrace() and dladdr(), so if your platform does not support them, it will always return failure.

It is exactly like fiu_enable_stack() but takes a function name, it will ask the dynamic linker to find the corresponding function pointer.

Parameters:
nameName of the point of failure to enable.
failnumWhat will fiu_fail() return, must be != 0.
failinfoWhat will fiu_failinfo() return.
flagsFlags.
func_nameName of the function.
func_pos_in_stackPosition where we expect the function to be; use -1 for "any". Values other than -1 are not supported at the moment, but will be in the future.
Returns:
0 if success, < 0 otherwise.

Definition at line 531 of file fiu.c.

Referenced by fiu_rc_string().

Here is the call graph for this function:

Here is the caller graph for this function:

int fiu_disable ( const char *  name)

Disables the given point of failure.

That makes it NOT fail.

Parameters:
nameName of the point of failure to disable.
Returns:
0 if success, < 0 otherwise.

Definition at line 546 of file fiu.c.

Referenced by fiu_rc_string().

Here is the call graph for this function:

Here is the caller graph for this function:

int fiu_rc_fifo ( const char *  basename)

Enables remote control over a named pipe.

The name pipe path will begin with the given basename. "-$PID" will be appended to it to form the final path. After the process dies, the pipe will be removed. If the process forks, a new pipe will be created.

Once this function has been called, the fiu-ctrl utility can be used to control the points of failure externally.

Parameters:
basenameBase path to use in the creation of the named pipes.
Returns:
0 on success, -1 on errors.

Definition at line 323 of file fiu-rc.c.

Here is the call graph for this function:

int fiu_rc_string ( const char *  cmd,
char **const  error 
)

Applies a remote control command given via a string.

The format of the string is not stable and is still subject to change. At the moment, this function is exported for consumption by the libfiu utilities.

Parameters:
cmd,:A zero-terminated string with the command to apply.
error,:In case of an error, it will point to a human-readable error message.
Returns:
0 if success, < 0 otherwise.

Definition at line 82 of file fiu-rc.c.

Referenced by rc_do_command().

Here is the call graph for this function:

Here is the caller graph for this function: