Skip to content

Commit

Permalink
Add fault injection test
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Perez <jjperez@ekumenlabs.com>
  • Loading branch information
Blast545 committed Aug 31, 2020
1 parent 4306e2d commit 4c836b6
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions rcl/test/rcl/test_wait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,32 @@ TEST_F(CLASSNAME(WaitSetTestFixture, RMW_IMPLEMENTATION), wait_set_failed_fini)
rcl_reset_error();
}
}

// Test proper error handling with a fault injection test
TEST_F(CLASSNAME(WaitSetTestFixture, RMW_IMPLEMENTATION), wait_set_test_maybe_init_fail) {
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
rcl_ret_t ret = RCL_RET_OK;
rcl_allocator_t alloc = rcl_get_default_allocator();

RCUTILS_FAULT_INJECTION_TEST(
{
ret = rcl_wait_set_init(&wait_set, 1, 0, 0, 1, 1, 0, context_ptr, alloc);
if (RCL_RET_OK == ret) {
EXPECT_EQ(RCL_RET_OK, rcl_wait_set_fini(&wait_set));
} else {
EXPECT_TRUE(RCL_RET_WAIT_SET_INVALID == ret || RCL_RET_BAD_ALLOC == ret);
rcl_reset_error();
}
});

RCUTILS_FAULT_INJECTION_TEST(
{
ret = rcl_wait_set_init(&wait_set, 1, 1, 1, 1, 1, 1, context_ptr, alloc);
if (RCL_RET_OK == ret) {
EXPECT_EQ(RCL_RET_OK, rcl_wait_set_fini(&wait_set));
} else {
EXPECT_TRUE(RCL_RET_WAIT_SET_INVALID == ret || RCL_RET_BAD_ALLOC == ret);
rcl_reset_error();
}
});
}

0 comments on commit 4c836b6

Please sign in to comment.