3535
3636#include " rcutils/logging_macros.h"
3737#include " rcutils/logging.h"
38- #include " rcutils/env.h"
3938
4039#include " test_msgs/msg/basic_types.h"
4140#include " test_msgs/srv/basic_types.h"
@@ -1234,6 +1233,15 @@ TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), test_graph_query_functio
12341233 * Note: this test could be impacted by other communications on the same ROS Domain.
12351234 */
12361235TEST_F (CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), test_graph_guard_condition_trigger_check) {
1236+ #define CHECK_GUARD_CONDITION_CHANGE (EXPECTED_RESULT ) do { \
1237+ ret = rcl_wait_set_clear (&wait_set); \
1238+ ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ; \
1239+ ret = rcl_wait_set_add_guard_condition (&wait_set, graph_guard_condition, NULL ); \
1240+ ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ; \
1241+ ret = rcl_wait (&wait_set, time_to_sleep.count ()); \
1242+ ASSERT_EQ (EXPECTED_RESULT, ret) << rcl_get_error_string ().str ; \
1243+ } while (0 )
1244+
12371245 rcl_ret_t ret;
12381246 std::chrono::nanoseconds time_to_sleep = std::chrono::milliseconds (400 );
12391247
@@ -1247,7 +1255,7 @@ TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), test_graph_guard_conditi
12471255 });
12481256
12491257 // Test in new ROS domain
1250- ret = rcl_init_options_set_domain_id (&init_options, 66 );
1258+ ret = rcl_init_options_set_domain_id (&init_options, 42 );
12511259 ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
12521260
12531261 rcl_context_t context = rcl_get_zero_initialized_context ();
@@ -1261,7 +1269,7 @@ TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), test_graph_guard_conditi
12611269
12621270 rcl_node_t node = rcl_get_zero_initialized_node ();
12631271 rcl_node_options_t node_options = rcl_node_get_default_options ();
1264- ret = rcl_node_init (&node, " test_graph" , " " , &context, &node_options);
1272+ ret = rcl_node_init (&node, " test_graph" , " / " , &context, &node_options);
12651273 ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
12661274 OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT (
12671275 {
@@ -1282,12 +1290,10 @@ TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), test_graph_guard_conditi
12821290 rcl_node_get_graph_guard_condition (&node);
12831291
12841292 // Graph change since first node created
1285- ret = rcl_wait_set_clear (&wait_set);
1286- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1287- ret = rcl_wait_set_add_guard_condition (&wait_set, graph_guard_condition, NULL );
1288- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1289- ret = rcl_wait (&wait_set, time_to_sleep.count ());
1290- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1293+ {
1294+ SCOPED_TRACE (" Check guard condition change failed !" );
1295+ CHECK_GUARD_CONDITION_CHANGE (RCL_RET_OK);
1296+ }
12911297
12921298 // Graph change since creating the publisher
12931299 rcl_publisher_t pub = rcl_get_zero_initialized_publisher ();
@@ -1297,23 +1303,19 @@ TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), test_graph_guard_conditi
12971303 " /chatter_test_graph_guard_condition_topics" , &pub_ops);
12981304 EXPECT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
12991305
1300- ret = rcl_wait_set_clear (&wait_set);
1301- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1302- ret = rcl_wait_set_add_guard_condition (&wait_set, graph_guard_condition, NULL );
1303- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1304- ret = rcl_wait (&wait_set, time_to_sleep.count ());
1305- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1306+ {
1307+ SCOPED_TRACE (" Check guard condition change failed !" );
1308+ CHECK_GUARD_CONDITION_CHANGE (RCL_RET_OK);
1309+ }
13061310
13071311 // Graph change since destroying the publisher
13081312 ret = rcl_publisher_fini (&pub, &node);
13091313 EXPECT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
13101314
1311- ret = rcl_wait_set_clear (&wait_set);
1312- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1313- ret = rcl_wait_set_add_guard_condition (&wait_set, graph_guard_condition, NULL );
1314- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1315- ret = rcl_wait (&wait_set, time_to_sleep.count ());
1316- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1315+ {
1316+ SCOPED_TRACE (" Check guard condition change failed !" );
1317+ CHECK_GUARD_CONDITION_CHANGE (RCL_RET_OK);
1318+ }
13171319
13181320 // Graph change since creating the subscription
13191321 rcl_subscription_t sub = rcl_get_zero_initialized_subscription ();
@@ -1323,23 +1325,19 @@ TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), test_graph_guard_conditi
13231325 " /chatter_test_graph_guard_condition_topics" , &sub_ops);
13241326 EXPECT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
13251327
1326- ret = rcl_wait_set_clear (&wait_set);
1327- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1328- ret = rcl_wait_set_add_guard_condition (&wait_set, graph_guard_condition, NULL );
1329- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1330- ret = rcl_wait (&wait_set, time_to_sleep.count ());
1331- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1328+ {
1329+ SCOPED_TRACE (" Check guard condition change failed !" );
1330+ CHECK_GUARD_CONDITION_CHANGE (RCL_RET_OK);
1331+ }
13321332
13331333 // Graph change since destroying the subscription
13341334 ret = rcl_subscription_fini (&sub, &node);
13351335 EXPECT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
13361336
1337- ret = rcl_wait_set_clear (&wait_set);
1338- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1339- ret = rcl_wait_set_add_guard_condition (&wait_set, graph_guard_condition, NULL );
1340- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1341- ret = rcl_wait (&wait_set, time_to_sleep.count ());
1342- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1337+ {
1338+ SCOPED_TRACE (" Check guard condition change failed !" );
1339+ CHECK_GUARD_CONDITION_CHANGE (RCL_RET_OK);
1340+ }
13431341
13441342 // Graph change since creating service
13451343 rcl_service_t service = rcl_get_zero_initialized_service ();
@@ -1352,23 +1350,19 @@ TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), test_graph_guard_conditi
13521350 &service_options);
13531351 ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
13541352
1355- ret = rcl_wait_set_clear (&wait_set);
1356- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1357- ret = rcl_wait_set_add_guard_condition (&wait_set, graph_guard_condition, NULL );
1358- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1359- ret = rcl_wait (&wait_set, time_to_sleep.count ());
1360- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1353+ {
1354+ SCOPED_TRACE (" Check guard condition change failed !" );
1355+ CHECK_GUARD_CONDITION_CHANGE (RCL_RET_OK);
1356+ }
13611357
13621358 // Graph change since destroy service
13631359 ret = rcl_service_fini (&service, &node);
13641360 EXPECT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
13651361
1366- ret = rcl_wait_set_clear (&wait_set);
1367- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1368- ret = rcl_wait_set_add_guard_condition (&wait_set, graph_guard_condition, NULL );
1369- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1370- ret = rcl_wait (&wait_set, time_to_sleep.count ());
1371- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1362+ {
1363+ SCOPED_TRACE (" Check guard condition change failed !" );
1364+ CHECK_GUARD_CONDITION_CHANGE (RCL_RET_OK);
1365+ }
13721366
13731367 // Graph change since creating client
13741368 rcl_client_t client = rcl_get_zero_initialized_client ();
@@ -1381,54 +1375,44 @@ TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), test_graph_guard_conditi
13811375 &client_options);
13821376 ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
13831377
1384- ret = rcl_wait_set_clear (&wait_set);
1385- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1386- ret = rcl_wait_set_add_guard_condition (&wait_set, graph_guard_condition, NULL );
1387- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1388- ret = rcl_wait (&wait_set, time_to_sleep.count ());
1389- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1378+ {
1379+ SCOPED_TRACE (" Check guard condition change failed !" );
1380+ CHECK_GUARD_CONDITION_CHANGE (RCL_RET_OK);
1381+ }
13901382
13911383 // Graph change since destroying client
13921384 ret = rcl_client_fini (&client, &node);
13931385 EXPECT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
13941386
1395- ret = rcl_wait_set_clear (&wait_set);
1396- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1397- ret = rcl_wait_set_add_guard_condition (&wait_set, graph_guard_condition, NULL );
1398- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1399- ret = rcl_wait (&wait_set, time_to_sleep.count ());
1400- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1387+ {
1388+ SCOPED_TRACE (" Check guard condition change failed !" );
1389+ CHECK_GUARD_CONDITION_CHANGE (RCL_RET_OK);
1390+ }
14011391
14021392 // Graph change since adding new node
14031393 rcl_node_t node_new = rcl_get_zero_initialized_node ();
14041394 ret = rcl_node_init (&node_new, " test_graph2" , " " , &context, &node_options);
14051395 ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
14061396
1407- ret = rcl_wait_set_clear (&wait_set);
1408- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1409- ret = rcl_wait_set_add_guard_condition (&wait_set, graph_guard_condition, NULL );
1410- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1411- ret = rcl_wait (&wait_set, time_to_sleep.count ());
1412- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1397+ {
1398+ SCOPED_TRACE (" Check guard condition change failed !" );
1399+ CHECK_GUARD_CONDITION_CHANGE (RCL_RET_OK);
1400+ }
14131401
14141402 // Graph change since destroying new node
14151403 ret = rcl_node_fini (&node_new);
14161404 ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
14171405
1418- ret = rcl_wait_set_clear (&wait_set);
1419- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1420- ret = rcl_wait_set_add_guard_condition (&wait_set, graph_guard_condition, NULL );
1421- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1422- ret = rcl_wait (&wait_set, time_to_sleep.count ());
1423- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1406+ {
1407+ SCOPED_TRACE (" Check guard condition change failed !" );
1408+ CHECK_GUARD_CONDITION_CHANGE (RCL_RET_OK);
1409+ }
14241410
14251411 // Should not get graph change if no change
1426- ret = rcl_wait_set_clear (&wait_set);
1427- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1428- ret = rcl_wait_set_add_guard_condition (&wait_set, graph_guard_condition, NULL );
1429- ASSERT_EQ (RCL_RET_OK, ret) << rcl_get_error_string ().str ;
1430- ret = rcl_wait (&wait_set, time_to_sleep.count ());
1431- ASSERT_EQ (RCL_RET_TIMEOUT, ret) << rcl_get_error_string ().str ;
1412+ {
1413+ SCOPED_TRACE (" Check guard condition change failed !" );
1414+ CHECK_GUARD_CONDITION_CHANGE (RCL_RET_TIMEOUT);
1415+ }
14321416}
14331417
14341418/* Test the rcl_service_server_is_available function.
0 commit comments