Skip to content

Commit

Permalink
Cleanups for uncrustify 0.78. (#1134)
Browse files Browse the repository at this point in the history
Mostly this is expanding macros, as this is just easier
to read anyway.  But we also mark one section as INDENT-OFF.

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette committed Mar 3, 2024
1 parent 061f546 commit 85f3548
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 40 deletions.
16 changes: 10 additions & 6 deletions rcl/src/rcl/rmw_implementation_identifier_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,32 @@ extern "C"

#include "rcl/rmw_implementation_identifier_check.h"

// *INDENT-OFF*

// Extracted this portable method of doing a "shared library constructor" from SO:
// http://stackoverflow.com/a/2390626/671658
// Initializer/finalizer sample for MSVC and GCC/Clang.
// 2010-2016 Joe Lowe. Released into the public domain.
#if defined(_MSC_VER)
#pragma section(".CRT$XCU", read)
#define INITIALIZER2_(f, p) \
static void f(void); \
__declspec(allocate(".CRT$XCU"))void(*f ## _)(void) = f; \
__pragma(comment(linker, "/include:" p #f "_")) \
static void f(void)
static void f(void); \
__declspec(allocate(".CRT$XCU"))void(*f ## _)(void) = f; \
__pragma(comment(linker, "/include:" p #f "_")) \
static void f(void)
#ifdef _WIN64
#define INITIALIZER(f) INITIALIZER2_(f, "")
#else
#define INITIALIZER(f) INITIALIZER2_(f, "_")
#endif
#else
#define INITIALIZER(f) \
static void f(void) __attribute__((constructor)); \
static void f(void)
static void f(void) __attribute__((constructor)); \
static void f(void)
#endif

// *INDENT-ON*

rcl_ret_t rcl_rmw_implementation_identifier_check(void)
{
// If the environment variable RMW_IMPLEMENTATION is set, or
Expand Down
90 changes: 68 additions & 22 deletions rcl/test/rcl/test_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1322,18 +1322,9 @@ TEST_F(TestGraphFixture, test_graph_query_functions)
* Note: this test could be impacted by other communications on the same ROS Domain.
*/
TEST_F(TestGraphFixture, test_graph_guard_condition_trigger_check) {
#define CHECK_GUARD_CONDITION_CHANGE(EXPECTED_RESULT, TIMEOUT) do { \
ret = rcl_wait_set_clear(&wait_set); \
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; \
ret = rcl_wait_set_add_guard_condition(&wait_set, graph_guard_condition, NULL); \
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; \
ret = rcl_wait(&wait_set, TIMEOUT.count()); \
ASSERT_EQ(EXPECTED_RESULT, ret) << rcl_get_error_string().str; \
} while (0)

rcl_ret_t ret;
std::chrono::nanoseconds timeout_1s = std::chrono::seconds(1);
std::chrono::nanoseconds timeout_3s = std::chrono::seconds(3);
static constexpr std::chrono::nanoseconds timeout_1s = std::chrono::seconds(1);
static constexpr std::chrono::nanoseconds timeout_3s = std::chrono::seconds(3);

rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
ret = rcl_wait_set_init(
Expand Down Expand Up @@ -1375,7 +1366,12 @@ TEST_F(TestGraphFixture, test_graph_guard_condition_trigger_check) {

{
SCOPED_TRACE("Check guard condition change failed !");
CHECK_GUARD_CONDITION_CHANGE(RCL_RET_OK, timeout_1s);
ret = rcl_wait_set_clear(&wait_set);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait_set_add_guard_condition(&wait_set, graph_guard_condition, NULL);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait(&wait_set, timeout_1s.count());
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
}

// Graph change since destroying the publisher
Expand All @@ -1384,7 +1380,12 @@ TEST_F(TestGraphFixture, test_graph_guard_condition_trigger_check) {

{
SCOPED_TRACE("Check guard condition change failed !");
CHECK_GUARD_CONDITION_CHANGE(RCL_RET_OK, timeout_1s);
ret = rcl_wait_set_clear(&wait_set);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait_set_add_guard_condition(&wait_set, graph_guard_condition, NULL);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait(&wait_set, timeout_1s.count());
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
}

// Graph change since creating the subscription
Expand All @@ -1397,7 +1398,12 @@ TEST_F(TestGraphFixture, test_graph_guard_condition_trigger_check) {

{
SCOPED_TRACE("Check guard condition change failed !");
CHECK_GUARD_CONDITION_CHANGE(RCL_RET_OK, timeout_1s);
ret = rcl_wait_set_clear(&wait_set);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait_set_add_guard_condition(&wait_set, graph_guard_condition, NULL);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait(&wait_set, timeout_1s.count());
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
}

// Graph change since destroying the subscription
Expand All @@ -1406,7 +1412,12 @@ TEST_F(TestGraphFixture, test_graph_guard_condition_trigger_check) {

{
SCOPED_TRACE("Check guard condition change failed !");
CHECK_GUARD_CONDITION_CHANGE(RCL_RET_OK, timeout_1s);
ret = rcl_wait_set_clear(&wait_set);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait_set_add_guard_condition(&wait_set, graph_guard_condition, NULL);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait(&wait_set, timeout_1s.count());
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
}

// Graph change since creating service
Expand All @@ -1422,7 +1433,12 @@ TEST_F(TestGraphFixture, test_graph_guard_condition_trigger_check) {

{
SCOPED_TRACE("Check guard condition change failed !");
CHECK_GUARD_CONDITION_CHANGE(RCL_RET_OK, timeout_1s);
ret = rcl_wait_set_clear(&wait_set);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait_set_add_guard_condition(&wait_set, graph_guard_condition, NULL);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait(&wait_set, timeout_1s.count());
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
}

// Graph change since destroy service
Expand All @@ -1431,7 +1447,12 @@ TEST_F(TestGraphFixture, test_graph_guard_condition_trigger_check) {

{
SCOPED_TRACE("Check guard condition change failed !");
CHECK_GUARD_CONDITION_CHANGE(RCL_RET_OK, timeout_1s);
ret = rcl_wait_set_clear(&wait_set);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait_set_add_guard_condition(&wait_set, graph_guard_condition, NULL);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait(&wait_set, timeout_1s.count());
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
}

// Graph change since creating client
Expand All @@ -1447,7 +1468,12 @@ TEST_F(TestGraphFixture, test_graph_guard_condition_trigger_check) {

{
SCOPED_TRACE("Check guard condition change failed !");
CHECK_GUARD_CONDITION_CHANGE(RCL_RET_OK, timeout_1s);
ret = rcl_wait_set_clear(&wait_set);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait_set_add_guard_condition(&wait_set, graph_guard_condition, NULL);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait(&wait_set, timeout_1s.count());
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
}

// Graph change since destroying client
Expand All @@ -1456,7 +1482,12 @@ TEST_F(TestGraphFixture, test_graph_guard_condition_trigger_check) {

{
SCOPED_TRACE("Check guard condition change failed !");
CHECK_GUARD_CONDITION_CHANGE(RCL_RET_OK, timeout_1s);
ret = rcl_wait_set_clear(&wait_set);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait_set_add_guard_condition(&wait_set, graph_guard_condition, NULL);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait(&wait_set, timeout_1s.count());
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
}

// Graph change since adding new node
Expand All @@ -1467,7 +1498,12 @@ TEST_F(TestGraphFixture, test_graph_guard_condition_trigger_check) {

{
SCOPED_TRACE("Check guard condition change failed !");
CHECK_GUARD_CONDITION_CHANGE(RCL_RET_OK, timeout_3s);
ret = rcl_wait_set_clear(&wait_set);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait_set_add_guard_condition(&wait_set, graph_guard_condition, NULL);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait(&wait_set, timeout_1s.count());
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
}

// Graph change since destroying new node
Expand All @@ -1476,13 +1512,23 @@ TEST_F(TestGraphFixture, test_graph_guard_condition_trigger_check) {

{
SCOPED_TRACE("Check guard condition change failed !");
CHECK_GUARD_CONDITION_CHANGE(RCL_RET_OK, timeout_1s);
ret = rcl_wait_set_clear(&wait_set);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait_set_add_guard_condition(&wait_set, graph_guard_condition, NULL);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait(&wait_set, timeout_1s.count());
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
}

// Should not get graph change if no change
{
SCOPED_TRACE("Check guard condition change failed !");
CHECK_GUARD_CONDITION_CHANGE(RCL_RET_TIMEOUT, timeout_1s);
ret = rcl_wait_set_clear(&wait_set);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait_set_add_guard_condition(&wait_set, graph_guard_condition, NULL);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
ret = rcl_wait(&wait_set, timeout_1s.count());
ASSERT_EQ(RCL_RET_TIMEOUT, ret) << rcl_get_error_string().str;
}
}

Expand Down
32 changes: 20 additions & 12 deletions rcl/test/rcl/test_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,13 +652,6 @@ MOCKING_UTILS_BOOL_OPERATOR_RETURNS_FALSE(rmw_time_t, >)

TEST_F(TestPublisherFixtureInit, test_mock_assert_wait_for_all_acked)
{
#define CHECK_PUBLISHER_WAIT_FOR_ALL_ACKED_RETURN(RMW_RET_RESULT, EXPECT_RET) do { \
rmw_publisher_wait_for_all_acked_return = RMW_RET_RESULT; \
ret = rcl_publisher_wait_for_all_acked(&publisher, 1000000); \
EXPECT_EQ(EXPECT_RET, ret); \
rcl_reset_error(); \
} while (0)

rcl_ret_t ret;
rmw_ret_t rmw_publisher_wait_for_all_acked_return;
auto mock = mocking_utils::patch_and_return(
Expand All @@ -668,35 +661,50 @@ TEST_F(TestPublisherFixtureInit, test_mock_assert_wait_for_all_acked)
// Now normal usage of the function rcl_publisher_wait_for_all_acked returning
// unexpected RMW_RET_TIMEOUT
SCOPED_TRACE("Check RCL return failed !");
CHECK_PUBLISHER_WAIT_FOR_ALL_ACKED_RETURN(RMW_RET_TIMEOUT, RCL_RET_TIMEOUT);
rmw_publisher_wait_for_all_acked_return = RMW_RET_TIMEOUT;
ret = rcl_publisher_wait_for_all_acked(&publisher, 1000000);
EXPECT_EQ(RCL_RET_TIMEOUT, ret);
rcl_reset_error();
}

{
// Now normal usage of the function rcl_publisher_wait_for_all_acked returning
// unexpected RMW_RET_UNSUPPORTED
SCOPED_TRACE("Check RCL return failed !");
CHECK_PUBLISHER_WAIT_FOR_ALL_ACKED_RETURN(RMW_RET_UNSUPPORTED, RCL_RET_UNSUPPORTED);
rmw_publisher_wait_for_all_acked_return = RMW_RET_UNSUPPORTED;
ret = rcl_publisher_wait_for_all_acked(&publisher, 1000000);
EXPECT_EQ(RCL_RET_UNSUPPORTED, ret);
rcl_reset_error();
}

{
// Now normal usage of the function rcl_publisher_wait_for_all_acked returning
// unexpected RMW_RET_INVALID_ARGUMENT
SCOPED_TRACE("Check RCL return failed !");
CHECK_PUBLISHER_WAIT_FOR_ALL_ACKED_RETURN(RMW_RET_INVALID_ARGUMENT, RCL_RET_ERROR);
rmw_publisher_wait_for_all_acked_return = RMW_RET_INVALID_ARGUMENT;
ret = rcl_publisher_wait_for_all_acked(&publisher, 1000000);
EXPECT_EQ(RCL_RET_ERROR, ret);
rcl_reset_error();
}

{
// Now normal usage of the function rcl_publisher_wait_for_all_acked returning
// unexpected RMW_RET_INCORRECT_RMW_IMPLEMENTATION
SCOPED_TRACE("Check RCL return failed !");
CHECK_PUBLISHER_WAIT_FOR_ALL_ACKED_RETURN(RMW_RET_INCORRECT_RMW_IMPLEMENTATION, RCL_RET_ERROR);
rmw_publisher_wait_for_all_acked_return = RMW_RET_INCORRECT_RMW_IMPLEMENTATION;
ret = rcl_publisher_wait_for_all_acked(&publisher, 1000000);
EXPECT_EQ(RCL_RET_ERROR, ret);
rcl_reset_error();
}

{
// Now normal usage of the function rcl_publisher_wait_for_all_acked returning
// unexpected RMW_RET_ERROR
SCOPED_TRACE("Check RCL return failed !");
CHECK_PUBLISHER_WAIT_FOR_ALL_ACKED_RETURN(RMW_RET_ERROR, RCL_RET_ERROR);
rmw_publisher_wait_for_all_acked_return = RMW_RET_ERROR;
ret = rcl_publisher_wait_for_all_acked(&publisher, 1000000);
EXPECT_EQ(RCL_RET_ERROR, ret);
rcl_reset_error();
}
}

Expand Down

0 comments on commit 85f3548

Please sign in to comment.