[fault] Generalise NETDEV_DISCARD_RATE fault injection mechanism

Provide a generic inject_fault() function that can be used to inject
random faults with configurable probabilities.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2015-07-22 02:56:49 +01:00
parent 9546b0c17b
commit d0325b1da6
6 changed files with 110 additions and 8 deletions

View File

@@ -68,6 +68,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#define ERRFILE_fbcon ( ERRFILE_CORE | 0x001c0000 )
#define ERRFILE_ansicol ( ERRFILE_CORE | 0x001d0000 )
#define ERRFILE_ansicoldef ( ERRFILE_CORE | 0x001e0000 )
#define ERRFILE_fault ( ERRFILE_CORE | 0x001f0000 )
#define ERRFILE_eisa ( ERRFILE_DRIVER | 0x00000000 )
#define ERRFILE_isa ( ERRFILE_DRIVER | 0x00010000 )

32
src/include/ipxe/fault.h Normal file
View File

@@ -0,0 +1,32 @@
#ifndef _IPXE_FAULT_H
#define _IPXE_FAULT_H
/** @file
*
* Fault injection
*
*/
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <config/fault.h>
extern int inject_fault_nonzero ( unsigned int rate );
/**
* Inject fault with a specified probability
*
* @v rate Reciprocal of fault probability (zero for no faults)
* @ret rc Return status code
*/
static inline __attribute__ (( always_inline )) int
inject_fault ( unsigned int rate ) {
/* Force dead code elimination in non-fault-injecting builds */
if ( rate == 0 )
return 0;
return inject_fault_nonzero ( rate );
}
#endif /* _IPXE_FAULT_H */