rcutils
master
C API providing common utilities and data structures.
|
Go to the documentation of this file.
15 #ifndef RCUTILS__TESTING__FAULT_INJECTION_H_
16 #define RCUTILS__TESTING__FAULT_INJECTION_H_
29 #define RCUTILS_FAULT_INJECTION_NEVER_FAIL -1
31 #define RCUTILS_FAULT_INJECTION_FAIL_NOW 0
102 #define RCUTILS_FAULT_INJECTION_MAYBE_RETURN_ERROR(return_value_on_error) \
103 if (RCUTILS_FAULT_INJECTION_FAIL_NOW == _rcutils_fault_injection_maybe_fail()) { \
105 "%s:%d Injecting fault and returning " #return_value_on_error "\n", __FILE__, __LINE__); \
106 return return_value_on_error; \
126 #define RCUTILS_FAULT_INJECTION_MAYBE_FAIL(failure_code) \
127 if (RCUTILS_FAULT_INJECTION_FAIL_NOW == _rcutils_fault_injection_maybe_fail()) { \
129 "%s:%d Injecting fault and executing " #failure_code "\n", __FILE__, __LINE__); \
160 #define RCUTILS_FAULT_INJECTION_TEST(code) \
162 int fault_injection_count = 0; \
164 rcutils_fault_injection_set_count(fault_injection_count++); \
166 } while (!rcutils_fault_injection_is_test_complete()); \
167 rcutils_fault_injection_set_count(RCUTILS_FAULT_INJECTION_NEVER_FAIL); \
194 #define RCUTILS_NO_FAULT_INJECTION(code) \
196 int64_t no_fault_injection_count = rcutils_fault_injection_get_count(); \
197 rcutils_fault_injection_set_count(RCUTILS_FAULT_INJECTION_NEVER_FAIL); \
199 rcutils_fault_injection_set_count(no_fault_injection_count); \
206 #endif // RCUTILS__TESTING__FAULT_INJECTION_H_
bool rcutils_fault_injection_is_test_complete(void)
#define RCUTILS_WARN_UNUSED
A macro to make the compiler warn when the return value of a function is not used.
Definition: macros.h:27
int_least64_t _rcutils_fault_injection_maybe_fail(void)
Implementation of fault injection decrementer.
#define RCUTILS_PUBLIC
Definition: visibility_control.h:23
void rcutils_fault_injection_set_count(int_least64_t count)
Atomically set the fault injection counter.
int_least64_t rcutils_fault_injection_get_count(void)
Atomically get the fault injection counter value.