diff --git a/rcl/src/rcl/rmw_implementation_identifier_check.c b/rcl/src/rcl/rmw_implementation_identifier_check.c index 235e3a4fb..440de3a7a 100644 --- a/rcl/src/rcl/rmw_implementation_identifier_check.c +++ b/rcl/src/rcl/rmw_implementation_identifier_check.c @@ -32,6 +32,8 @@ 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. @@ -39,10 +41,10 @@ extern "C" #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 @@ -50,10 +52,12 @@ extern "C" #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 diff --git a/rcl/test/rcl/test_graph.cpp b/rcl/test/rcl/test_graph.cpp index 2eb0d7612..99c21c760 100644 --- a/rcl/test/rcl/test_graph.cpp +++ b/rcl/test/rcl/test_graph.cpp @@ -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( @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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; } } diff --git a/rcl/test/rcl/test_publisher.cpp b/rcl/test/rcl/test_publisher.cpp index a303241e8..1564b5089 100644 --- a/rcl/test/rcl/test_publisher.cpp +++ b/rcl/test/rcl/test_publisher.cpp @@ -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( @@ -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(); } }