Increase rcl_lifecycle test coverage and add more safety checks (#649)

* Increase test coverage and add more safety checks

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

* More coverage

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

* Concatenating error messages

Signed-off-by: Stephen Brawner <stephenbrawner@verbsurgical.com>

* PR Fixup

Signed-off-by: Stephen Brawner <stephenbrawner@verbsurgical.com>

* Forgot a

Signed-off-by: Stephen Brawner <stephenbrawner@verbsurgical.com>

* PR Fixup

Signed-off-by: Stephen Brawner <stephenbrawner@verbsurgical.com>

* Moving var to top

Signed-off-by: Stephen Brawner <stephenbrawner@verbsurgical.com>

Co-authored-by: Stephen Brawner <stephenbrawner@verbsurgical.com>
This commit is contained in:
brawner 2020-05-22 14:44:11 -07:00 committed by GitHub
parent 30e0536a1d
commit 7146919c3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 591 additions and 19 deletions

View file

@ -40,6 +40,8 @@ rcl_lifecycle_get_zero_initialized_state()
rcl_lifecycle_state_t state;
state.id = 0;
state.label = NULL;
state.valid_transitions = NULL;
state.valid_transition_size = 0;
return state;
}
@ -58,6 +60,10 @@ rcl_lifecycle_state_init(
RCL_SET_ERROR_MSG("state pointer is null\n");
return RCL_RET_ERROR;
}
if (!label) {
RCL_SET_ERROR_MSG("State label is null\n");
return RCL_RET_ERROR;
}
state->id = id;
state->label = rcutils_strndup(label, strlen(label), *allocator);
@ -118,7 +124,22 @@ rcl_lifecycle_transition_init(
if (!transition) {
RCL_SET_ERROR_MSG("transition pointer is null\n");
return RCL_RET_OK;
return RCL_RET_ERROR;
}
if (!label) {
RCL_SET_ERROR_MSG("label pointer is null\n");
return RCL_RET_ERROR;
}
if (!start) {
RCL_SET_ERROR_MSG("start state pointer is null\n");
return RCL_RET_ERROR;
}
if (!goal) {
RCL_SET_ERROR_MSG("goal state pointer is null\n");
return RCL_RET_ERROR;
}
transition->start = start;
@ -140,7 +161,7 @@ rcl_lifecycle_transition_fini(
const rcl_allocator_t * allocator)
{
if (!allocator) {
RCL_SET_ERROR_MSG("can't initialize transition, no allocator given\n");
RCL_SET_ERROR_MSG("can't finalize transition, no allocator given\n");
return RCL_RET_ERROR;
}
// it is already NULL
@ -192,6 +213,14 @@ rcl_lifecycle_state_machine_init(
bool default_states,
const rcl_allocator_t * allocator)
{
if (!state_machine) {
RCL_SET_ERROR_MSG("State machine is null\n");
return RCL_RET_ERROR;
}
if (!node_handle) {
RCL_SET_ERROR_MSG("Node handle is null\n");
return RCL_RET_ERROR;
}
if (!allocator) {
RCL_SET_ERROR_MSG("can't initialize state machine, no allocator given\n");
return RCL_RET_ERROR;
@ -207,15 +236,12 @@ rcl_lifecycle_state_machine_init(
}
if (default_states) {
rcl_ret_t ret =
rcl_lifecycle_init_default_state_machine(state_machine, allocator);
ret = rcl_lifecycle_init_default_state_machine(state_machine, allocator);
if (ret != RCL_RET_OK) {
// init default state machine might have allocated memory,
// so we have to call fini
if (rcl_lifecycle_state_machine_fini(state_machine, node_handle, allocator) != RCL_RET_OK) {
// error already set
return RCL_RET_ERROR;
}
ret = rcl_lifecycle_state_machine_fini(state_machine, node_handle, allocator);
return RCL_RET_ERROR;
}
}