Add fault injection macros and unit tests to rcl_lifecycle (#731)

* Add fault injection macros and unit tests to rcl_lifecycle

Signed-off-by: Stephen Brawner <brawner@gmail.com>

* Address feedback

Signed-off-by: Stephen Brawner <brawner@gmail.com>

* PR Fixup

Signed-off-by: Stephen Brawner <brawner@gmail.com>
This commit is contained in:
brawner 2020-08-31 12:59:19 -07:00 committed by Alejandro Hernández Cordero
parent b62b83b5cd
commit dd62d09042
5 changed files with 96 additions and 6 deletions

View file

@ -27,6 +27,7 @@ extern "C"
#include "rcl/error_handling.h"
#include "rcutils/logging_macros.h"
#include "rcutils/macros.h"
#include "rcutils/strdup.h"
#include "rcl_lifecycle/default_state_machine.h"
@ -80,6 +81,8 @@ rcl_lifecycle_state_fini(
rcl_lifecycle_state_t * state,
const rcl_allocator_t * allocator)
{
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RCL_RET_ERROR);
if (!allocator) {
RCL_SET_ERROR_MSG("can't free state, no allocator given\n");
return RCL_RET_ERROR;

View file

@ -22,6 +22,7 @@ extern "C"
#include <string.h>
#include "rcl/error_handling.h"
#include "rcl/macros.h"
#include "rcutils/format_string.h"
#include "rcl_lifecycle/transition_map.h"
@ -53,6 +54,7 @@ rcl_lifecycle_transition_map_fini(
rcl_lifecycle_transition_map_t * transition_map,
const rcutils_allocator_t * allocator)
{
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RCL_RET_ERROR);
if (!allocator) {
RCL_SET_ERROR_MSG("can't free transition map, no allocator given\n");
return RCL_RET_ERROR;
@ -85,6 +87,8 @@ rcl_lifecycle_register_state(
rcl_lifecycle_state_t state,
const rcutils_allocator_t * allocator)
{
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RCL_RET_ERROR);
if (rcl_lifecycle_get_state(transition_map, state.id) != NULL) {
RCL_SET_ERROR_MSG_WITH_FORMAT_STRING("state %u is already registered\n", state.id);
return RCL_RET_ERROR;
@ -116,6 +120,9 @@ rcl_lifecycle_register_transition(
rcl_lifecycle_transition_t transition,
const rcutils_allocator_t * allocator)
{
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RCL_RET_ERROR);
RCUTILS_CAN_RETURN_WITH_ERROR_OF(RCL_RET_BAD_ALLOC);
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(
allocator, "invalid allocator", return RCL_RET_ERROR)