Skip to content

Commit

Permalink
Compile the test_rmw_implementation tests fewer times. (#224)
Browse files Browse the repository at this point in the history
We really only need to compile them once, and then we can
run them with different RMW implementations.

This also neatly sidesteps an incompatibility between
current uncrustify and the newer one.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
  • Loading branch information
clalancette authored Feb 26, 2024
1 parent 2e9a28a commit 513f670
Show file tree
Hide file tree
Showing 17 changed files with 409 additions and 552 deletions.
419 changes: 235 additions & 184 deletions test_rmw_implementation/CMakeLists.txt

Large diffs are not rendered by default.

46 changes: 18 additions & 28 deletions test_rmw_implementation/test/test_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@
#include "./config.hpp"
#include "./testing_macros.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 (TestClient, RMW_IMPLEMENTATION) : public ::testing::Test
class TestClient : public ::testing::Test
{
protected:
void SetUp() override
Expand Down Expand Up @@ -72,7 +65,7 @@ class CLASSNAME (TestClient, RMW_IMPLEMENTATION) : public ::testing::Test
rmw_node_t * node{nullptr};
};

TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), create_and_destroy) {
TEST_F(TestClient, create_and_destroy) {
constexpr char service_name[] = "/test";
const rosidl_service_type_support_t * ts =
ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes);
Expand All @@ -83,7 +76,7 @@ TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), create_and_destroy) {
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str;
}

TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), create_and_destroy_native) {
TEST_F(TestClient, create_and_destroy_native) {
constexpr char service_name[] = "/test";
const rosidl_service_type_support_t * ts =
ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes);
Expand All @@ -96,7 +89,7 @@ TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), create_and_destroy_native) {
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str;
}

TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), create_with_bad_arguments) {
TEST_F(TestClient, create_with_bad_arguments) {
constexpr char service_name[] = "/test";
const rosidl_service_type_support_t * ts =
ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes);
Expand Down Expand Up @@ -159,7 +152,7 @@ TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), create_with_bad_arguments) {
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str;
}

TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), create_with_internal_errors) {
TEST_F(TestClient, create_with_internal_errors) {
constexpr char service_name[] = "/test";
const rosidl_service_type_support_t * ts =
ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes);
Expand All @@ -179,7 +172,7 @@ TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), create_with_internal_errors) {
});
}

TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), destroy_with_internal_errors) {
TEST_F(TestClient, destroy_with_internal_errors) {
constexpr char service_name[] = "/test";
const rosidl_service_type_support_t * ts =
ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes);
Expand All @@ -197,15 +190,12 @@ TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), destroy_with_internal_errors)
});
}

class CLASSNAME (TestClientUse, RMW_IMPLEMENTATION)
: public CLASSNAME(TestClient, RMW_IMPLEMENTATION)
class TestClientUse : public TestClient
{
protected:
using Base = CLASSNAME(TestClient, RMW_IMPLEMENTATION);

void SetUp() override
{
Base::SetUp();
TestClient::SetUp();
client = rmw_create_client(node, ts, service_name, &qos_profile);
ASSERT_NE(nullptr, client) << rmw_get_error_string().str;
}
Expand All @@ -214,7 +204,7 @@ class CLASSNAME (TestClientUse, RMW_IMPLEMENTATION)
{
rmw_ret_t ret = rmw_destroy_client(node, client);
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str;
Base::TearDown();
TestClient::TearDown();
}

rmw_client_t * client{nullptr};
Expand All @@ -224,19 +214,19 @@ class CLASSNAME (TestClientUse, RMW_IMPLEMENTATION)
rmw_qos_profile_t qos_profile{rmw_qos_profile_default};
};

TEST_F(CLASSNAME(TestClientUse, RMW_IMPLEMENTATION), destroy_with_null_node) {
TEST_F(TestClientUse, destroy_with_null_node) {
rmw_ret_t ret = rmw_destroy_client(nullptr, client);
EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, ret);
rmw_reset_error();
}

TEST_F(CLASSNAME(TestClientUse, RMW_IMPLEMENTATION), destroy_null_client) {
TEST_F(TestClientUse, destroy_null_client) {
rmw_ret_t ret = rmw_destroy_client(node, nullptr);
EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, ret);
rmw_reset_error();
}

TEST_F(CLASSNAME(TestClientUse, RMW_IMPLEMENTATION), destroy_with_node_of_another_impl) {
TEST_F(TestClientUse, destroy_with_node_of_another_impl) {
const char * implementation_identifier = node->implementation_identifier;
node->implementation_identifier = "not-an-rmw-implementation-identifier";
rmw_ret_t ret = rmw_destroy_client(node, client);
Expand All @@ -245,7 +235,7 @@ TEST_F(CLASSNAME(TestClientUse, RMW_IMPLEMENTATION), destroy_with_node_of_anothe
rmw_reset_error();
}

TEST_F(CLASSNAME(TestClientUse, RMW_IMPLEMENTATION), destroy_client_of_another_impl) {
TEST_F(TestClientUse, destroy_client_of_another_impl) {
const char * implementation_identifier = client->implementation_identifier;
client->implementation_identifier = "not-an-rmw-implementation-identifier";
rmw_ret_t ret = rmw_destroy_client(node, client);
Expand All @@ -254,7 +244,7 @@ TEST_F(CLASSNAME(TestClientUse, RMW_IMPLEMENTATION), destroy_client_of_another_i
rmw_reset_error();
}

TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), send_request_with_bad_arguments) {
TEST_F(TestClient, send_request_with_bad_arguments) {
constexpr char service_name[] = "/test";
const rosidl_service_type_support_t * ts =
ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes);
Expand Down Expand Up @@ -296,7 +286,7 @@ TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), send_request_with_bad_argument
rmw_reset_error();
}

TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), take_response_with_bad_arguments) {
TEST_F(TestClient, take_response_with_bad_arguments) {
constexpr char service_name[] = "/test";
const rosidl_service_type_support_t * ts =
ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes);
Expand Down Expand Up @@ -359,7 +349,7 @@ TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), take_response_with_bad_argumen
rmw_reset_error();
}

TEST_F(CLASSNAME(TestClientUse, RMW_IMPLEMENTATION), service_server_is_available_bad_args)
TEST_F(TestClientUse, service_server_is_available_bad_args)
{
bool is_available;
rmw_ret_t ret = rmw_service_server_is_available(nullptr, client, &is_available);
Expand All @@ -382,7 +372,7 @@ TEST_F(CLASSNAME(TestClientUse, RMW_IMPLEMENTATION), service_server_is_available
rmw_reset_error();
}

TEST_F(CLASSNAME(TestClientUse, RMW_IMPLEMENTATION), service_server_is_available_good_args)
TEST_F(TestClientUse, service_server_is_available_good_args)
{
bool is_available = false;
rmw_ret_t ret = rmw_service_server_is_available(node, client, &is_available);
Expand All @@ -409,7 +399,7 @@ TEST_F(CLASSNAME(TestClientUse, RMW_IMPLEMENTATION), service_server_is_available
ASSERT_TRUE(is_available);
}

TEST_F(CLASSNAME(TestClient, RMW_IMPLEMENTATION), check_qos) {
TEST_F(TestClient, check_qos) {
constexpr char service_name[] = "/test";
const rosidl_service_type_support_t * ts =
ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes);
Expand Down
32 changes: 8 additions & 24 deletions test_rmw_implementation/test/test_create_destroy_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,7 @@

#include "./testing_macros.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 (TestNodeConstructionDestruction, RMW_IMPLEMENTATION) : public ::testing::Test
class TestNodeConstructionDestruction : public ::testing::Test
{
protected:
void SetUp() override
Expand Down Expand Up @@ -61,7 +53,7 @@ class CLASSNAME (TestNodeConstructionDestruction, RMW_IMPLEMENTATION) : public :
rmw_context_t context;
};

TEST_F(CLASSNAME(TestNodeConstructionDestruction, RMW_IMPLEMENTATION), create_with_bad_arguments) {
TEST_F(TestNodeConstructionDestruction, create_with_bad_arguments) {
const char * const node_name = "my_node";
const char * const node_namespace = "/my_ns";

Expand Down Expand Up @@ -107,7 +99,7 @@ TEST_F(CLASSNAME(TestNodeConstructionDestruction, RMW_IMPLEMENTATION), create_wi
rmw_reset_error();
}

TEST_F(CLASSNAME(TestNodeConstructionDestruction, RMW_IMPLEMENTATION), destroy_with_bad_arguments) {
TEST_F(TestNodeConstructionDestruction, destroy_with_bad_arguments) {
rmw_ret_t ret = rmw_destroy_node(nullptr);
EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, ret);
rmw_reset_error();
Expand All @@ -128,16 +120,15 @@ TEST_F(CLASSNAME(TestNodeConstructionDestruction, RMW_IMPLEMENTATION), destroy_w
EXPECT_EQ(RMW_RET_OK, ret) << rmw_get_error_string().str;
}

TEST_F(CLASSNAME(TestNodeConstructionDestruction, RMW_IMPLEMENTATION), create_and_destroy) {
TEST_F(TestNodeConstructionDestruction, create_and_destroy) {
const char * const node_name = "my_node";
const char * const node_namespace = "/my_ns";
rmw_node_t * node = rmw_create_node(&context, node_name, node_namespace);
ASSERT_NE(nullptr, node) << rmw_get_error_string().str;
EXPECT_EQ(RMW_RET_OK, rmw_destroy_node(node)) << rmw_get_error_string().str;
}

class CLASSNAME (TestLocalhostNodeConstructionDestruction,
RMW_IMPLEMENTATION) : public ::testing::Test
class TestLocalhostNodeConstructionDestruction : public ::testing::Test
{
protected:
void SetUp() override
Expand Down Expand Up @@ -167,20 +158,15 @@ class CLASSNAME (TestLocalhostNodeConstructionDestruction,
rmw_context_t context;
};

TEST_F(
CLASSNAME(
TestLocalhostNodeConstructionDestruction,
RMW_IMPLEMENTATION), create_and_destroy) {
TEST_F(TestLocalhostNodeConstructionDestruction, create_and_destroy) {
const char * const node_name = "my_node";
const char * const node_namespace = "/my_ns";
rmw_node_t * node = rmw_create_node(&context, node_name, node_namespace);
ASSERT_NE(nullptr, node) << rmw_get_error_string().str;
EXPECT_EQ(RMW_RET_OK, rmw_destroy_node(node)) << rmw_get_error_string().str;
}

TEST_F(
CLASSNAME(TestNodeConstructionDestruction, RMW_IMPLEMENTATION),
create_with_internal_errors) {
TEST_F(TestNodeConstructionDestruction, create_with_internal_errors) {
RCUTILS_FAULT_INJECTION_TEST(
{
constexpr char node_name[] = "my_node";
Expand All @@ -198,9 +184,7 @@ TEST_F(
});
}

TEST_F(
CLASSNAME(TestNodeConstructionDestruction, RMW_IMPLEMENTATION),
destroy_with_internal_errors) {
TEST_F(TestNodeConstructionDestruction, destroy_with_internal_errors) {
RCUTILS_FAULT_INJECTION_TEST(
{
constexpr char node_name[] = "my_node";
Expand Down
11 changes: 2 additions & 9 deletions test_rmw_implementation/test/test_duration_infinite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@
#include "./config.hpp"
#include "./testing_macros.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 (TestDurationInfinite, RMW_IMPLEMENTATION) : public ::testing::Test
class TestDurationInfinite : public ::testing::Test
{
protected:
void SetUp() override
Expand Down Expand Up @@ -67,7 +60,7 @@ class CLASSNAME (TestDurationInfinite, RMW_IMPLEMENTATION) : public ::testing::T
rmw_node_t * node;
};

TEST_F(CLASSNAME(TestDurationInfinite, RMW_IMPLEMENTATION), create_publisher)
TEST_F(TestDurationInfinite, create_publisher)
{
rmw_ret_t ret = RMW_RET_ERROR;
size_t match_count = 0;
Expand Down
17 changes: 5 additions & 12 deletions test_rmw_implementation/test/test_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@

#include "test_msgs/msg/basic_types.h"

#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 (TestEvent, RMW_IMPLEMENTATION) : public ::testing::Test
class TestEvent : public ::testing::Test
{
protected:
void SetUp() override
Expand Down Expand Up @@ -116,7 +109,7 @@ void event_callback(const void * user_data, size_t number_of_events)
}
}

TEST_F(CLASSNAME(TestEvent, RMW_IMPLEMENTATION), basic_publisher_matched_event) {
TEST_F(TestEvent, basic_publisher_matched_event) {
// Notice: Not support connextdds since it doesn't support rmw_event_set_callback() interface
if (std::string(rmw_get_implementation_identifier()).find("rmw_connextdds") == 0) {
GTEST_SKIP();
Expand Down Expand Up @@ -204,7 +197,7 @@ TEST_F(CLASSNAME(TestEvent, RMW_IMPLEMENTATION), basic_publisher_matched_event)
EXPECT_EQ(-2, matched_status.current_count_change);
}

TEST_F(CLASSNAME(TestEvent, RMW_IMPLEMENTATION), basic_subscription_matched_event) {
TEST_F(TestEvent, basic_subscription_matched_event) {
// Notice: Not support connextdds since it doesn't support rmw_event_set_callback() interface
if (std::string(rmw_get_implementation_identifier()).find("rmw_connextdds") == 0) {
GTEST_SKIP();
Expand Down Expand Up @@ -295,7 +288,7 @@ TEST_F(CLASSNAME(TestEvent, RMW_IMPLEMENTATION), basic_subscription_matched_even
EXPECT_EQ(-2, matched_status.current_count_change);
}

TEST_F(CLASSNAME(TestEvent, RMW_IMPLEMENTATION), one_pub_multi_sub_connect_disconnect) {
TEST_F(TestEvent, one_pub_multi_sub_connect_disconnect) {
rmw_publisher_t * pub =
rmw_create_publisher(node, ts, topic_name, &rmw_qos_profile_default, &pub_options);
ASSERT_NE(nullptr, pub) << rmw_get_error_string().str;
Expand Down Expand Up @@ -354,7 +347,7 @@ TEST_F(CLASSNAME(TestEvent, RMW_IMPLEMENTATION), one_pub_multi_sub_connect_disco
EXPECT_EQ(-1, matched_status.current_count_change);
}

TEST_F(CLASSNAME(TestEvent, RMW_IMPLEMENTATION), one_sub_multi_pub_matched_unmatched_event) {
TEST_F(TestEvent, one_sub_multi_pub_matched_unmatched_event) {
rmw_subscription_t * sub =
rmw_create_subscription(node, ts, topic_name, &rmw_qos_profile_default, &sub_options);
ASSERT_NE(nullptr, sub) << rmw_get_error_string().str;
Expand Down
Loading

0 comments on commit 513f670

Please sign in to comment.