diff options
| author | Michael Brown | 2015-07-22 15:29:20 +0200 |
|---|---|---|
| committer | Michael Brown | 2015-07-22 22:17:47 +0200 |
| commit | 89816af2a4b7dfc42aef880912dad8fad28e974b (patch) | |
| tree | 9014cc1eb6accdd79b77c4dbdb0b8bb3523694fc /src/include | |
| parent | [fault] Generalise NETDEV_DISCARD_RATE fault injection mechanism (diff) | |
| download | ipxe-89816af2a4b7dfc42aef880912dad8fad28e974b.tar.gz ipxe-89816af2a4b7dfc42aef880912dad8fad28e974b.tar.xz ipxe-89816af2a4b7dfc42aef880912dad8fad28e974b.zip | |
[fault] Add inject_corruption() to randomly corrupt data
Provide an inject_corruption() function that can be used to randomly
corrupt data bytes with configurable probabilities.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/ipxe/fault.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/include/ipxe/fault.h b/src/include/ipxe/fault.h index 32aa06484..356296c35 100644 --- a/src/include/ipxe/fault.h +++ b/src/include/ipxe/fault.h @@ -9,9 +9,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); +#include <stdint.h> #include <config/fault.h> extern int inject_fault_nonzero ( unsigned int rate ); +extern void inject_corruption_nonzero ( unsigned int rate, const void *data, + size_t len ); /** * Inject fault with a specified probability @@ -29,4 +32,22 @@ inject_fault ( unsigned int rate ) { return inject_fault_nonzero ( rate ); } +/** + * Corrupt data with a specified probability + * + * @v rate Reciprocal of fault probability (zero for no faults) + * @v data Data + * @v len Length of data + * @ret rc Return status code + */ +static inline __attribute__ (( always_inline )) void +inject_corruption ( unsigned int rate, const void *data, size_t len ) { + + /* Force dead code elimination in non-fault-injecting builds */ + if ( rate == 0 ) + return; + + return inject_corruption_nonzero ( rate, data, len ); +} + #endif /* _IPXE_FAULT_H */ |
