Skip to content

Commit 9b1e6c9

Browse files
authored
Only compile the tests once. (#2590)
Even when we want to run them on multiple RMWs, we can do that by compiling once, then setting the environment variable appropriately. Signed-off-by: Chris Lalancette <clalancette@gmail.com>
1 parent a4d7210 commit 9b1e6c9

File tree

2 files changed

+61
-61
lines changed

2 files changed

+61
-61
lines changed

rclcpp/test/rclcpp/CMakeLists.txt

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,6 @@ ament_add_gtest(test_create_subscription test_create_subscription.cpp)
9999
if(TARGET test_create_subscription)
100100
target_link_libraries(test_create_subscription ${PROJECT_NAME} ${test_msgs_TARGETS})
101101
endif()
102-
function(test_add_callback_groups_to_executor_for_rmw_implementation)
103-
set(rmw_implementation_env_var RMW_IMPLEMENTATION=${rmw_implementation})
104-
ament_add_gmock(test_add_callback_groups_to_executor${target_suffix} test_add_callback_groups_to_executor.cpp
105-
ENV ${rmw_implementation_env_var}
106-
TIMEOUT 120
107-
)
108-
if(TARGET test_add_callback_groups_to_executor${target_suffix})
109-
target_link_libraries(test_add_callback_groups_to_executor${target_suffix} ${PROJECT_NAME} ${test_msgs_TARGETS})
110-
endif()
111-
endfunction()
112-
call_for_each_rmw_implementation(test_add_callback_groups_to_executor_for_rmw_implementation)
113102
ament_add_gtest(test_expand_topic_or_service_name test_expand_topic_or_service_name.cpp)
114103
ament_add_test_label(test_expand_topic_or_service_name mimick)
115104
if(TARGET test_expand_topic_or_service_name)
@@ -337,28 +326,6 @@ if(TARGET test_qos)
337326
rmw::rmw
338327
)
339328
endif()
340-
function(test_generic_pubsub_for_rmw_implementation)
341-
set(rmw_implementation_env_var RMW_IMPLEMENTATION=${rmw_implementation})
342-
ament_add_gmock(test_generic_pubsub${target_suffix} test_generic_pubsub.cpp
343-
ENV ${rmw_implementation_env_var}
344-
)
345-
if(TARGET test_generic_pubsub${target_suffix})
346-
target_link_libraries(test_generic_pubsub${target_suffix} ${PROJECT_NAME} rcl::rcl ${test_msgs_TARGETS})
347-
endif()
348-
endfunction()
349-
call_for_each_rmw_implementation(test_generic_pubsub_for_rmw_implementation)
350-
351-
function(test_qos_event_for_rmw_implementation)
352-
set(rmw_implementation_env_var RMW_IMPLEMENTATION=${rmw_implementation})
353-
ament_add_gmock(test_qos_event${target_suffix} test_qos_event.cpp
354-
ENV ${rmw_implementation_env_var}
355-
)
356-
ament_add_test_label(test_qos_event${target_suffix} mimick)
357-
if(TARGET test_qos_event${target_suffix})
358-
target_link_libraries(test_qos_event${target_suffix} ${PROJECT_NAME} mimick rcutils::rcutils rmw::rmw ${test_msgs_TARGETS})
359-
endif()
360-
endfunction()
361-
call_for_each_rmw_implementation(test_qos_event_for_rmw_implementation)
362329

363330
ament_add_gmock(test_qos_overriding_options test_qos_overriding_options.cpp)
364331
if(TARGET test_qos_overriding_options)
@@ -650,16 +617,51 @@ if(TARGET test_graph_listener)
650617
target_link_libraries(test_graph_listener ${PROJECT_NAME} mimick)
651618
endif()
652619

653-
function(test_subscription_content_filter_for_rmw_implementation)
620+
ament_add_gmock_executable(test_qos_event test_qos_event.cpp)
621+
if(TARGET test_qos_event)
622+
target_link_libraries(test_qos_event ${PROJECT_NAME} mimick rcutils::rcutils rmw::rmw ${test_msgs_TARGETS})
623+
endif()
624+
625+
ament_add_gmock_executable(test_generic_pubsub test_generic_pubsub.cpp)
626+
if(TARGET test_generic_pubsub)
627+
target_link_libraries(test_generic_pubsub ${PROJECT_NAME} rcl::rcl ${test_msgs_TARGETS})
628+
endif()
629+
630+
ament_add_gmock_executable(test_add_callback_groups_to_executor test_add_callback_groups_to_executor.cpp)
631+
if(TARGET test_add_callback_groups_to_executor)
632+
target_link_libraries(test_add_callback_groups_to_executor ${PROJECT_NAME} ${test_msgs_TARGETS})
633+
endif()
634+
635+
ament_add_gmock_executable(test_subscription_content_filter test_subscription_content_filter.cpp)
636+
if(TARGET test_subscription_content_filter)
637+
target_link_libraries(test_subscription_content_filter ${PROJECT_NAME} mimick ${test_msgs_TARGETS})
638+
endif()
639+
640+
function(test_on_all_rmws)
654641
set(rmw_implementation_env_var RMW_IMPLEMENTATION=${rmw_implementation})
655-
ament_add_gmock(test_subscription_content_filter${target_suffix}
656-
test_subscription_content_filter.cpp
642+
643+
ament_add_gmock_test(test_qos_event
644+
TEST_NAME test_qos_event${target_suffix}
645+
ENV ${rmw_implementation_env_var}
646+
)
647+
ament_add_test_label(test_qos_event${target_suffix} mimick)
648+
649+
ament_add_gmock_test(test_generic_pubsub
650+
TEST_NAME test_generic_pubsub${target_suffix}
651+
ENV ${rmw_implementation_env_var}
652+
)
653+
654+
ament_add_gmock_test(test_add_callback_groups_to_executor
655+
TEST_NAME test_add_callback_groups_to_executor${target_suffix}
656+
ENV ${rmw_implementation_env_var}
657+
TIMEOUT 120
658+
)
659+
660+
ament_add_gmock_test(test_subscription_content_filter
661+
TEST_NAME test_subscription_content_filter${target_suffix}
657662
ENV ${rmw_implementation_env_var}
658663
TIMEOUT 120
659664
)
660665
ament_add_test_label(test_subscription_content_filter${target_suffix} mimick)
661-
if(TARGET test_subscription_content_filter${target_suffix})
662-
target_link_libraries(test_subscription_content_filter${target_suffix} ${PROJECT_NAME} mimick ${test_msgs_TARGETS})
663-
endif()
664666
endfunction()
665-
call_for_each_rmw_implementation(test_subscription_content_filter_for_rmw_implementation)
667+
call_for_each_rmw_implementation(test_on_all_rmws)

rclcpp/test/rclcpp/test_subscription_content_filter.cpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,7 @@
3030

3131
#include "test_msgs/msg/basic_types.hpp"
3232

33-
#ifdef RMW_IMPLEMENTATION
34-
# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX
35-
# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX)
36-
#else
37-
# define CLASSNAME(NAME, SUFFIX) NAME
38-
#endif
39-
40-
class CLASSNAME (TestContentFilterSubscription, RMW_IMPLEMENTATION) : public ::testing::Test
33+
class TestContentFilterSubscription : public ::testing::Test
4134
{
4235
public:
4336
static void SetUpTestCase()
@@ -113,7 +106,8 @@ bool operator==(const test_msgs::msg::BasicTypes & m1, const test_msgs::msg::Bas
113106
m1.uint64_value == m2.uint64_value;
114107
}
115108

116-
TEST_F(CLASSNAME(TestContentFilterSubscription, RMW_IMPLEMENTATION), is_cft_enabled) {
109+
TEST_F(TestContentFilterSubscription, is_cft_enabled)
110+
{
117111
{
118112
auto mock = mocking_utils::patch_and_return(
119113
"lib:rclcpp", rcl_subscription_is_cft_enabled, false);
@@ -127,7 +121,8 @@ TEST_F(CLASSNAME(TestContentFilterSubscription, RMW_IMPLEMENTATION), is_cft_enab
127121
}
128122
}
129123

130-
TEST_F(CLASSNAME(TestContentFilterSubscription, RMW_IMPLEMENTATION), get_content_filter_error) {
124+
TEST_F(TestContentFilterSubscription, get_content_filter_error)
125+
{
131126
auto mock = mocking_utils::patch_and_return(
132127
"lib:rclcpp", rcl_subscription_get_content_filter, RCL_RET_ERROR);
133128

@@ -137,7 +132,8 @@ TEST_F(CLASSNAME(TestContentFilterSubscription, RMW_IMPLEMENTATION), get_content
137132
rclcpp::exceptions::RCLError);
138133
}
139134

140-
TEST_F(CLASSNAME(TestContentFilterSubscription, RMW_IMPLEMENTATION), set_content_filter_error) {
135+
TEST_F(TestContentFilterSubscription, set_content_filter_error)
136+
{
141137
auto mock = mocking_utils::patch_and_return(
142138
"lib:rclcpp", rcl_subscription_set_content_filter, RCL_RET_ERROR);
143139

@@ -148,7 +144,8 @@ TEST_F(CLASSNAME(TestContentFilterSubscription, RMW_IMPLEMENTATION), set_content
148144
rclcpp::exceptions::RCLError);
149145
}
150146

151-
TEST_F(CLASSNAME(TestContentFilterSubscription, RMW_IMPLEMENTATION), get_content_filter) {
147+
TEST_F(TestContentFilterSubscription, get_content_filter)
148+
{
152149
rclcpp::ContentFilterOptions options;
153150

154151
if (sub->is_cft_enabled()) {
@@ -164,7 +161,8 @@ TEST_F(CLASSNAME(TestContentFilterSubscription, RMW_IMPLEMENTATION), get_content
164161
}
165162
}
166163

167-
TEST_F(CLASSNAME(TestContentFilterSubscription, RMW_IMPLEMENTATION), set_content_filter) {
164+
TEST_F(TestContentFilterSubscription, set_content_filter)
165+
{
168166
if (sub->is_cft_enabled()) {
169167
EXPECT_NO_THROW(
170168
sub->set_content_filter(filter_expression_init, expression_parameters_2));
@@ -175,7 +173,8 @@ TEST_F(CLASSNAME(TestContentFilterSubscription, RMW_IMPLEMENTATION), set_content
175173
}
176174
}
177175

178-
TEST_F(CLASSNAME(TestContentFilterSubscription, RMW_IMPLEMENTATION), content_filter_get_begin) {
176+
TEST_F(TestContentFilterSubscription, content_filter_get_begin)
177+
{
179178
using namespace std::chrono_literals;
180179
{
181180
test_msgs::msg::BasicTypes msg;
@@ -217,7 +216,8 @@ TEST_F(CLASSNAME(TestContentFilterSubscription, RMW_IMPLEMENTATION), content_fil
217216
}
218217
}
219218

220-
TEST_F(CLASSNAME(TestContentFilterSubscription, RMW_IMPLEMENTATION), content_filter_get_later) {
219+
TEST_F(TestContentFilterSubscription, content_filter_get_later)
220+
{
221221
using namespace std::chrono_literals;
222222
{
223223
test_msgs::msg::BasicTypes msg;
@@ -264,7 +264,8 @@ TEST_F(CLASSNAME(TestContentFilterSubscription, RMW_IMPLEMENTATION), content_fil
264264
}
265265
}
266266

267-
TEST_F(CLASSNAME(TestContentFilterSubscription, RMW_IMPLEMENTATION), content_filter_reset) {
267+
TEST_F(TestContentFilterSubscription, content_filter_reset)
268+
{
268269
using namespace std::chrono_literals;
269270
{
270271
test_msgs::msg::BasicTypes msg;
@@ -311,11 +312,8 @@ TEST_F(CLASSNAME(TestContentFilterSubscription, RMW_IMPLEMENTATION), content_fil
311312
}
312313
}
313314

314-
TEST_F(
315-
CLASSNAME(
316-
TestContentFilterSubscription,
317-
RMW_IMPLEMENTATION), create_two_content_filters_with_same_topic_name_and_destroy) {
318-
315+
TEST_F(TestContentFilterSubscription, create_two_content_filters_with_same_topic_name_and_destroy)
316+
{
319317
// Create another content filter
320318
auto options = rclcpp::SubscriptionOptions();
321319

0 commit comments

Comments
 (0)