Define RCUTILS_FAULT_INJECTION_TEST
Defined in File fault_injection.h
Define Documentation
-
RCUTILS_FAULT_INJECTION_TEST(code)
The fault injection macro for use with unit tests to check that
code
can tolerate injected failures at all points along the execution path where the indicating macrosRCUTILS_CAN_RETURN_WITH_ERROR_OF
andRCUTILS_CAN_FAIL_WITH
are located.This macro is intended to be used within a gtest function macro like ‘TEST’, ‘TEST_F’, etc.
code
is executed within a do-while loop and therefore any variables declared within are in their own scope block.Here’s a simple example: RCUTILS_FAULT_INJECTION_TEST( rcl_ret_t ret = rcl_init(argc, argv, options, context); if (RCL_RET_OK == ret) { ret = rcl_shutdown(context); } });
In this example, you will need have conditional execution based on the return value of
rcl_init
. If it failed, then it wouldn’t make sense to call rcl_shutdown. In your own test, there might be similar logic that requires conditional checks. The goal of writing this test is less about checking the behavior is consistent, but instead that failures do not cause program crashes, memory errors, or unnecessary memory leaks.