Skip to content

Commit

Permalink
Update definitions
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Brawner <brawner@gmail.com>
  • Loading branch information
brawner committed Aug 12, 2020
1 parent 9a72ee0 commit 0ad3845
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ target_include_directories(${PROJECT_NAME} PUBLIC
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(${PROJECT_NAME} PRIVATE "RCUTILS_BUILDING_DLL")

if (BUILD_TESTING AND NOT RCUTILS_DISABLE_FAULT_INJECTION)
target_compile_definitions(${PROJECT_NAME} PUBLIC RCUTILS_ENABLE_FAULT_INJECTION)
endif()

target_link_libraries(${PROJECT_NAME} ${CMAKE_DL_LIBS})

# Needed if pthread is used for thread local storage.
Expand Down
16 changes: 1 addition & 15 deletions include/rcutils/testing/fault_injection.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C"
{
Expand All @@ -34,8 +35,6 @@ int_least64_t _rcutils_fault_injection_get_count();

int _rcutils_fault_injection_maybe_fail();

#if defined RCUTILS_ENABLE_FAULT_INJECTION

/**
* \def RCUTILS_FAULT_INJECTION_MAYBE_RETURN_ERROR
* \brief This macro checks and decrements a static global variable atomic counter and returns
Expand Down Expand Up @@ -114,19 +113,6 @@ int _rcutils_fault_injection_maybe_fail();
RCUTILS_FAULT_INJECTION_SET_COUNT(RCUTILS_FAULT_INJECTION_NEVER_FAIL); \
} while (0)

#else // RCUTILS_ENABLE_FAULT_INJECTION

#define RCUTILS_FAULT_INJECTION_SET_COUNT(count)

// This needs to be set to an int for compatibility
#define RCUTILS_FAULT_INJECTION_GET_COUNT() RCUTILS_FAULT_INJECTION_NEVER_FAIL

#define RCUTILS_FAULT_INJECTION_MAYBE_RETURN_ERROR(msg, error_statement)

#define RCUTILS_FAULT_INJECTION_TEST(code) return;

#endif // defined RCUTILS_ENABLE_FAULT_INJECTION

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/testing/fault_injection.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ bool rcutils_fault_injection_is_test_complete()
{
#ifndef RCUTILS_ENABLE_FAULT_INJECTION
return true;
#endif // RCUTILS_ENABLE_FAULT_INJECTION

#else // RCUTILS_ENABLE_FAULT_INJECTION
return _rcutils_fault_injection_get_count() > RCUTILS_FAULT_INJECTION_NEVER_FAIL;
#endif // RCUTILS_ENABLE_FAULT_INJECTION
}

int _rcutils_fault_injection_maybe_fail()
Expand Down

0 comments on commit 0ad3845

Please sign in to comment.