Skip to content

Commit

Permalink
Remove unncecessary dependencies in tests (#1114)
Browse files Browse the repository at this point in the history
* Remove unncecessary dependencies in tests

* Build service_fixture and client_fixture only once

* Only rebuild tests for each RMW implementation if necessary

* Remove unnecessary RMW_IMPLEMENTATION code.

Since we are just using the environment variables to test
now, we don't need all of this superfluous infrastructure
for generating different RMW implementations.

Signed-off-by: Christopher Wecht <[email protected]>
Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
cwecht authored Nov 16, 2023
1 parent f7efa0b commit cc0cd52
Show file tree
Hide file tree
Showing 24 changed files with 442 additions and 748 deletions.
353 changes: 200 additions & 153 deletions rcl/test/CMakeLists.txt

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions rcl/test/cmake/rcl_add_custom_launch_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ set(rcl_add_custom_launch_test_INCLUDED TRUE)

macro(rcl_add_custom_launch_test test_name executable1 executable2)
set(TEST_NAME "${test_name}")
set(TEST_EXECUTABLE1 "$<TARGET_FILE:${executable1}${target_suffix}>")
set(TEST_EXECUTABLE1 "$<TARGET_FILE:${executable1}>")
set(TEST_EXECUTABLE1_NAME "${executable1}")
set(TEST_EXECUTABLE2 "$<TARGET_FILE:${executable2}${target_suffix}>")
set(TEST_EXECUTABLE2 "$<TARGET_FILE:${executable2}>")
set(TEST_EXECUTABLE2_NAME "${executable2}")
configure_file(
rcl/test_two_executables.py.in
Expand All @@ -40,6 +40,6 @@ macro(rcl_add_custom_launch_test test_name executable1 executable2)
${ARGN}
)
if(TEST ${test_name}${target_suffix})
set_tests_properties(${test_name}${target_suffix} PROPERTIES DEPENDS "${executable1}${target_suffix} ${executable2}${target_suffix}")
set_tests_properties(${test_name}${target_suffix} PROPERTIES DEPENDS "${executable1} ${executable2}")
endif()
endmacro()
13 changes: 2 additions & 11 deletions rcl/test/rcl/test_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,9 @@

#include "../mocking_utils/patch.hpp"

#ifdef RMW_IMPLEMENTATION
# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX
# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX)
#else
# define CLASSNAME(NAME, SUFFIX) NAME
#endif

class CLASSNAME (TestContextFixture, RMW_IMPLEMENTATION) : public ::testing::Test {};

// Test the rcl_context_t's normal function.
// Note: that init/fini are tested in test_init.cpp.
TEST_F(CLASSNAME(TestContextFixture, RMW_IMPLEMENTATION), nominal) {
TEST(TestContext, nominal) {
osrf_testing_tools_cpp::memory_tools::ScopedQuickstartGtest scoped_quickstart_gtest;

// This prevents memory allocations when setting error states in the future.
Expand Down Expand Up @@ -151,7 +142,7 @@ TEST_F(CLASSNAME(TestContextFixture, RMW_IMPLEMENTATION), nominal) {
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
}

TEST_F(CLASSNAME(TestContextFixture, RMW_IMPLEMENTATION), bad_fini) {
TEST(TestContext, bad_fini) {
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_context_fini(nullptr));
rcl_reset_error();

Expand Down
15 changes: 3 additions & 12 deletions rcl/test/rcl/test_count_matched.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@

#include "rcl/error_handling.h"

#ifdef RMW_IMPLEMENTATION
# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX
# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX)
#else
# define CLASSNAME(NAME, SUFFIX) NAME
#endif

void check_state(
rcl_wait_set_t * wait_set_ptr,
rcl_publisher_t * publisher,
Expand Down Expand Up @@ -96,7 +89,7 @@ void check_state(
EXPECT_EQ(expected_subscriber_count, subscriber_count);
}

class CLASSNAME (TestCountFixture, RMW_IMPLEMENTATION) : public ::testing::Test
class TestCountFixture : public ::testing::Test
{
public:
rcl_node_t * node_ptr;
Expand Down Expand Up @@ -150,7 +143,7 @@ class CLASSNAME (TestCountFixture, RMW_IMPLEMENTATION) : public ::testing::Test
}
};

TEST_F(CLASSNAME(TestCountFixture, RMW_IMPLEMENTATION), test_count_matched_functions) {
TEST_F(TestCountFixture, test_count_matched_functions) {
std::string topic_name("/test_count_matched_functions__");
rcl_ret_t ret;

Expand Down Expand Up @@ -199,9 +192,7 @@ TEST_F(CLASSNAME(TestCountFixture, RMW_IMPLEMENTATION), test_count_matched_funct
rcl_reset_error();
}

TEST_F(
CLASSNAME(TestCountFixture, RMW_IMPLEMENTATION),
test_count_matched_functions_mismatched_qos) {
TEST_F(TestCountFixture, test_count_matched_functions_mismatched_qos) {
std::string topic_name("/test_count_matched_functions_mismatched_qos__");
rcl_ret_t ret;

Expand Down
12 changes: 1 addition & 11 deletions rcl/test/rcl/test_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ constexpr seconds LIVELINESS_LEASE_DURATION_IN_S = 1s;
constexpr seconds DEADLINE_PERIOD_IN_S = 2s;
constexpr seconds MAX_WAIT_PER_TESTCASE = 10s;

#ifdef RMW_IMPLEMENTATION
# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX
# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX)
#else
# define CLASSNAME(NAME, SUFFIX) NAME
#endif

#define EXPECT_OK(varname) EXPECT_EQ(varname, RCL_RET_OK) << rcl_get_error_string().str

struct TestIncompatibleQosEventParams
Expand All @@ -61,8 +54,7 @@ struct TestIncompatibleQosEventParams
std::string error_msg;
};

class CLASSNAME (TestEventFixture, RMW_IMPLEMENTATION)
: public ::testing::TestWithParam<TestIncompatibleQosEventParams>
class TestEventFixture : public ::testing::TestWithParam<TestIncompatibleQosEventParams>
{
public:
void SetUp()
Expand Down Expand Up @@ -240,8 +232,6 @@ class CLASSNAME (TestEventFixture, RMW_IMPLEMENTATION)
const rosidl_message_type_support_t * ts;
};

using TestEventFixture = CLASSNAME(TestEventFixture, RMW_IMPLEMENTATION);

const rmw_qos_profile_t TestEventFixture::default_qos_profile = {
RMW_QOS_POLICY_HISTORY_KEEP_LAST, // history
0, // depth
Expand Down
43 changes: 8 additions & 35 deletions rcl/test/rcl/test_get_actual_qos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,6 @@
#include "test_msgs/msg/basic_types.h"
#include "test_msgs/srv/basic_types.h"

#ifdef RMW_IMPLEMENTATION
# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX
# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX)
# define RMW_IMPLEMENTATION_STR RCUTILS_STRINGIFY(RMW_IMPLEMENTATION)
#else
# define CLASSNAME(NAME, SUFFIX) NAME
#endif

#define EXPAND(x) x
#define TEST_FIXTURE_P_RMW(test_fixture_name) CLASSNAME( \
test_fixture_name, RMW_IMPLEMENTATION)
#define APPLY(macro, ...) EXPAND(macro(__VA_ARGS__))
#define TEST_P_RMW(test_case_name, test_name) \
APPLY( \
TEST_P, \
CLASSNAME(test_case_name, RMW_IMPLEMENTATION), test_name)
#define INSTANTIATE_TEST_SUITE_P_RMW(instance_name, test_case_name, ...) \
EXPAND( \
APPLY( \
INSTANTIATE_TEST_SUITE_P, instance_name, \
CLASSNAME(test_case_name, RMW_IMPLEMENTATION), __VA_ARGS__))

/**
* Parameterized test.
* The first param are the NodeOptions used to create the nodes.
Expand Down Expand Up @@ -98,8 +76,7 @@ std::ostream & operator<<(
return out;
}

class TEST_FIXTURE_P_RMW (TestGetActualQoS)
: public ::testing::TestWithParam<TestParameters>
class TestGetActualQoS : public ::testing::TestWithParam<TestParameters>
{
public:
void SetUp() override
Expand Down Expand Up @@ -147,10 +124,9 @@ class TEST_FIXTURE_P_RMW (TestGetActualQoS)
};


class TEST_FIXTURE_P_RMW (TestPublisherGetActualQoS)
: public TEST_FIXTURE_P_RMW(TestGetActualQoS) {};
class TestPublisherGetActualQoS : public TestGetActualQoS {};

TEST_P_RMW(TestPublisherGetActualQoS, test_publisher_get_qos_settings)
TEST_P(TestPublisherGetActualQoS, test_publisher_get_qos_settings)
{
TestParameters parameters = GetParam();
std::string topic_name("/test_publisher_get_actual_qos__");
Expand Down Expand Up @@ -202,10 +178,9 @@ TEST_P_RMW(TestPublisherGetActualQoS, test_publisher_get_qos_settings)
}


class TEST_FIXTURE_P_RMW (TestSubscriptionGetActualQoS)
: public TEST_FIXTURE_P_RMW(TestGetActualQoS) {};
class TestSubscriptionGetActualQoS : public TestGetActualQoS {};

TEST_P_RMW(TestSubscriptionGetActualQoS, test_subscription_get_qos_settings)
TEST_P(TestSubscriptionGetActualQoS, test_subscription_get_qos_settings)
{
TestParameters parameters = GetParam();
std::string topic_name("/test_subscription_get_qos_settings");
Expand Down Expand Up @@ -396,8 +371,7 @@ get_parameters(bool for_publisher)
"default_qos"
});

#ifdef RMW_IMPLEMENTATION_STR
std::string rmw_implementation_str = RMW_IMPLEMENTATION_STR;
std::string rmw_implementation_str = std::string(rmw_get_implementation_identifier());
if (rmw_implementation_str == "rmw_fastrtps_cpp" ||
rmw_implementation_str == "rmw_fastrtps_dynamic_cpp")
{
Expand Down Expand Up @@ -464,18 +438,17 @@ get_parameters(bool for_publisher)
}
}
}
#endif

return parameters;
}

INSTANTIATE_TEST_SUITE_P_RMW(
INSTANTIATE_TEST_SUITE_P(
TestPublisherWithDifferentQoSSettings,
TestPublisherGetActualQoS,
::testing::ValuesIn(get_parameters(true)),
::testing::PrintToStringParamName());

INSTANTIATE_TEST_SUITE_P_RMW(
INSTANTIATE_TEST_SUITE_P(
TestSubscriptionWithDifferentQoSSettings,
TestSubscriptionGetActualQoS,
::testing::ValuesIn(get_parameters(false)),
Expand Down
14 changes: 3 additions & 11 deletions rcl/test/rcl/test_get_node_names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,9 @@

#include "rcl/error_handling.h"

#ifdef RMW_IMPLEMENTATION
# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX
# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX)
#else
# define CLASSNAME(NAME, SUFFIX) NAME
#endif

using namespace std::chrono_literals;

class CLASSNAME (TestGetNodeNames, RMW_IMPLEMENTATION) : public ::testing::Test
class TestGetNodeNames : public ::testing::Test
{
public:
void SetUp()
Expand All @@ -51,7 +44,7 @@ class CLASSNAME (TestGetNodeNames, RMW_IMPLEMENTATION) : public ::testing::Test
{}
};

TEST_F(CLASSNAME(TestGetNodeNames, RMW_IMPLEMENTATION), test_rcl_get_node_names) {
TEST_F(TestGetNodeNames, test_rcl_get_node_names) {
rcl_ret_t ret;
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
ret = rcl_init_options_init(&init_options, rcl_get_default_allocator());
Expand Down Expand Up @@ -164,8 +157,7 @@ TEST_F(CLASSNAME(TestGetNodeNames, RMW_IMPLEMENTATION), test_rcl_get_node_names)
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
}

TEST_F(
CLASSNAME(TestGetNodeNames, RMW_IMPLEMENTATION), test_rcl_get_node_names_with_enclave)
TEST_F(TestGetNodeNames, test_rcl_get_node_names_with_enclave)
{
rcl_ret_t ret;
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
Expand Down
20 changes: 4 additions & 16 deletions rcl/test/rcl/test_get_type_description_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@
#include "node_impl.h" // NOLINT
#include "wait_for_entity_helpers.hpp"

#ifdef RMW_IMPLEMENTATION
# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX
# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX)
#else
# define CLASSNAME(NAME, SUFFIX) NAME
#endif

constexpr char GET_TYPE_DESCRIPTION_SRV_TYPE_NAME[] =
"type_description_interfaces/srv/GetTypeDescription";

Expand Down Expand Up @@ -140,7 +133,7 @@ static bool service_not_exists(
return false;
}

class CLASSNAME (TestGetTypeDescSrvFixture, RMW_IMPLEMENTATION) : public ::testing::Test
class TestGetTypeDescSrvFixture : public ::testing::Test
{
public:
void SetUp()
Expand Down Expand Up @@ -190,9 +183,7 @@ class CLASSNAME (TestGetTypeDescSrvFixture, RMW_IMPLEMENTATION) : public ::testi


/* Test init and fini functions. */
TEST_F(
CLASSNAME(TestGetTypeDescSrvFixture, RMW_IMPLEMENTATION),
test_service_init_and_fini_functions) {
TEST_F(TestGetTypeDescSrvFixture, test_service_init_and_fini_functions) {
rcl_service_t service = rcl_get_zero_initialized_service();

// Service does not initially exist
Expand Down Expand Up @@ -220,7 +211,7 @@ TEST_F(
}

/* Basic nominal test of the ~/get_type_description service. */
TEST_F(CLASSNAME(TestGetTypeDescSrvFixture, RMW_IMPLEMENTATION), test_service_nominal) {
TEST_F(TestGetTypeDescSrvFixture, test_service_nominal) {
rcl_ret_t ret;
const rosidl_service_type_support_t * ts = ROSIDL_GET_SRV_TYPE_SUPPORT(
type_description_interfaces, srv, GetTypeDescription);
Expand Down Expand Up @@ -317,10 +308,7 @@ TEST_F(CLASSNAME(TestGetTypeDescSrvFixture, RMW_IMPLEMENTATION), test_service_no
}

/* Test calling ~/get_type_description service with invalid hash. */
TEST_F(
CLASSNAME(
TestGetTypeDescSrvFixture,
RMW_IMPLEMENTATION), test_service_invalid_hash) {
TEST_F(TestGetTypeDescSrvFixture, test_service_invalid_hash) {
rcl_ret_t ret;
const rosidl_service_type_support_t * ts = ROSIDL_GET_SRV_TYPE_SUPPORT(
type_description_interfaces, srv, GetTypeDescription);
Expand Down
Loading

0 comments on commit cc0cd52

Please sign in to comment.