Skip to content

Commit

Permalink
Revamp test_rclcpp to compile far few files. (#535)
Browse files Browse the repository at this point in the history
Instead of recompiling the tests multiple times for
each RMW, instead just compile it once and use the
RMW_IMPLEMENTATION environment variable to control
which RMW gets used.  On my machine, this sped up
compilation by about 2x, and should reduce the number
of times our coverage jobs fail because they run out
of memory.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
  • Loading branch information
clalancette committed Feb 15, 2024
1 parent 1da5e30 commit 2144c02
Show file tree
Hide file tree
Showing 24 changed files with 396 additions and 371 deletions.
379 changes: 253 additions & 126 deletions test_rclcpp/CMakeLists.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test_rclcpp/test/node_check_names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <chrono>
#include <string>

#include "rclcpp/rclcpp.hpp"
Expand Down
16 changes: 3 additions & 13 deletions test_rclcpp/test/test_avoid_ros_namespace_conventions_qos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,7 @@

#include "./pub_sub_fixtures.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 (test_avoid_ros_namespace_conventions_qos, RMW_IMPLEMENTATION)
: public ::testing::Test
class test_avoid_ros_namespace_conventions_qos : public ::testing::Test
{
public:
static void SetUpTestCase()
Expand All @@ -48,10 +40,8 @@ class CLASSNAME (test_avoid_ros_namespace_conventions_qos, RMW_IMPLEMENTATION)
};

// Test communciation works with the avoid_ros_namespace_conventions QoS enabled.
TEST_F(
CLASSNAME(test_avoid_ros_namespace_conventions_qos, RMW_IMPLEMENTATION),
pub_sub_works
) {
TEST_F(test_avoid_ros_namespace_conventions_qos, pub_sub_works)
{
// topic name
std::string topic_name = "test_avoid_ros_namespace_conventions_qos";
// code to create the callback and subscription
Expand Down
12 changes: 3 additions & 9 deletions test_rclcpp/test/test_client_scope_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,9 @@
#include "rclcpp/rclcpp.hpp"
#include "test_rclcpp/srv/add_two_ints.hpp"

#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 (service_client, RMW_IMPLEMENTATION) : public ::testing::Test
class service_client : public ::testing::Test
{
public:
static void SetUpTestCase()
Expand All @@ -44,7 +37,8 @@ class CLASSNAME (service_client, RMW_IMPLEMENTATION) : public ::testing::Test
}
};

TEST_F(CLASSNAME(service_client, RMW_IMPLEMENTATION), client_scope_regression_test) {
TEST_F(service_client, client_scope_regression_test)
{
auto node = rclcpp::Node::make_shared("client_scope_regression_test");

// Extra scope so the first client will be deleted afterwards
Expand Down
15 changes: 4 additions & 11 deletions test_rclcpp/test/test_client_scope_consistency_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <inttypes.h>

#include <chrono>
#include <cinttypes>
#include <iostream>
#include <memory>

Expand All @@ -23,16 +22,9 @@
#include "rclcpp/rclcpp.hpp"
#include "test_rclcpp/srv/add_two_ints.hpp"

#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 (service_client, RMW_IMPLEMENTATION) : public ::testing::Test
class service_client : public ::testing::Test
{
public:
static void SetUpTestCase()
Expand All @@ -48,7 +40,8 @@ class CLASSNAME (service_client, RMW_IMPLEMENTATION) : public ::testing::Test

// This test is concerned with the consistency of the two clients' behavior, not necessarily whether
// or not they are successful.
TEST_F(CLASSNAME(service_client, RMW_IMPLEMENTATION), client_scope_consistency_regression_test) {
TEST_F(service_client, client_scope_consistency_regression_test)
{
auto node = rclcpp::Node::make_shared("client_scope_consistency_regression_test");

// Replicate the settings that caused https://github.com/ros2/system_tests/issues/153
Expand Down
12 changes: 3 additions & 9 deletions test_rclcpp/test/test_client_wait_for_service_shutdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,9 @@
#include "rcpputils/scope_exit.hpp"
#include "test_rclcpp/srv/add_two_ints.hpp"

#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 (service_client, RMW_IMPLEMENTATION) : public ::testing::Test
class service_client : public ::testing::Test
{
public:
static void SetUpTestCase()
Expand All @@ -44,7 +37,8 @@ class CLASSNAME (service_client, RMW_IMPLEMENTATION) : public ::testing::Test
};

// rclcpp::shutdown() should wake up wait_for_service, even without spin.
TEST_F(CLASSNAME(service_client, RMW_IMPLEMENTATION), wait_for_service_shutdown) {
TEST_F(service_client, wait_for_service_shutdown)
{
auto node = rclcpp::Node::make_shared("wait_for_service_shutdown");

auto client = node->create_client<test_rclcpp::srv::AddTwoInts>("wait_for_service_shutdown");
Expand Down
24 changes: 11 additions & 13 deletions test_rclcpp/test/test_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,9 @@
#include "test_rclcpp/msg/u_int32.hpp"
#include "test_rclcpp/srv/add_two_ints.hpp"

#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 (test_executor, RMW_IMPLEMENTATION) : public ::testing::Test
class test_executor : public ::testing::Test
{
public:
static void SetUpTestCase()
Expand All @@ -54,7 +47,8 @@ class CLASSNAME (test_executor, RMW_IMPLEMENTATION) : public ::testing::Test
}
};

TEST_F(CLASSNAME(test_executor, RMW_IMPLEMENTATION), recursive_spin_call) {
TEST_F(test_executor, recursive_spin_call)
{
rclcpp::executors::SingleThreadedExecutor executor;
auto node = rclcpp::Node::make_shared("recursive_spin_call");
auto timer = node->create_wall_timer(
Expand All @@ -69,7 +63,8 @@ TEST_F(CLASSNAME(test_executor, RMW_IMPLEMENTATION), recursive_spin_call) {
executor.spin();
}

TEST_F(CLASSNAME(test_executor, RMW_IMPLEMENTATION), spin_some_max_duration) {
TEST_F(test_executor, spin_some_max_duration)
{
rclcpp::executors::SingleThreadedExecutor executor;
auto node = rclcpp::Node::make_shared("spin_some_max_duration");
auto lambda = []() {
Expand All @@ -92,7 +87,8 @@ TEST_F(CLASSNAME(test_executor, RMW_IMPLEMENTATION), spin_some_max_duration) {
ASSERT_GT(max_duration + 500ms, end - start);
}

TEST_F(CLASSNAME(test_executor, RMW_IMPLEMENTATION), multithreaded_spin_call) {
TEST_F(test_executor, multithreaded_spin_call)
{
rclcpp::executors::SingleThreadedExecutor executor;
auto node = rclcpp::Node::make_shared("multithreaded_spin_call");
std::mutex m;
Expand Down Expand Up @@ -124,7 +120,8 @@ TEST_F(CLASSNAME(test_executor, RMW_IMPLEMENTATION), multithreaded_spin_call) {
}

// Try spinning 2 single-threaded executors in two separate threads.
TEST_F(CLASSNAME(test_executor, RMW_IMPLEMENTATION), multiple_executors) {
TEST_F(test_executor, multiple_executors)
{
std::atomic_uint counter1;
counter1 = 0;
std::atomic_uint counter2;
Expand Down Expand Up @@ -184,7 +181,8 @@ TEST_F(CLASSNAME(test_executor, RMW_IMPLEMENTATION), multiple_executors) {

// Check that the executor is notified when a node adds a new timer, publisher, subscription,
// service or client.
TEST_F(CLASSNAME(test_executor, RMW_IMPLEMENTATION), notify) {
TEST_F(test_executor, notify)
{
rclcpp::executors::SingleThreadedExecutor executor;
auto executor_spin_lambda = [&executor]() {
executor.spin();
Expand Down
13 changes: 3 additions & 10 deletions test_rclcpp/test/test_intra_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,10 @@

#include "test_rclcpp/msg/u_int32.hpp"

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


static const std::chrono::milliseconds sleep_per_loop(10);
static const int max_loops = 200;

class CLASSNAME (test_intra_process_within_one_node, RMW_IMPLEMENTATION) : public ::testing::Test
class test_intra_process_within_one_node : public ::testing::Test
{
public:
static void SetUpTestCase()
Expand All @@ -47,7 +39,8 @@ class CLASSNAME (test_intra_process_within_one_node, RMW_IMPLEMENTATION) : publi
}
};

TEST_F(CLASSNAME(test_intra_process_within_one_node, RMW_IMPLEMENTATION), nominal_usage) {
TEST_F(test_intra_process_within_one_node, nominal_usage)
{
// use intra process = true
auto node = rclcpp::Node::make_shared(
"test_intra_process",
Expand Down
41 changes: 17 additions & 24 deletions test_rclcpp/test/test_local_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@

using namespace std::chrono_literals;

#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 (test_local_parameters, RMW_IMPLEMENTATION) : public ::testing::Test
class test_local_parameters : public ::testing::Test
{
public:
static void SetUpTestCase()
Expand All @@ -48,7 +41,8 @@ class CLASSNAME (test_local_parameters, RMW_IMPLEMENTATION) : public ::testing::
}
};

TEST_F(CLASSNAME(test_local_parameters, RMW_IMPLEMENTATION), to_string) {
TEST_F(test_local_parameters, to_string)
{
rclcpp::Parameter pv("foo", "bar");
rclcpp::Parameter pv2("foo2", "bar2");
std::string json_dict = std::to_string(pv);
Expand Down Expand Up @@ -79,7 +73,8 @@ TEST_F(CLASSNAME(test_local_parameters, RMW_IMPLEMENTATION), to_string) {
std::to_string(pv).c_str());
}

TEST_F(CLASSNAME(test_local_parameters, RMW_IMPLEMENTATION), local_synchronous) {
TEST_F(test_local_parameters, local_synchronous)
{
auto node = rclcpp::Node::make_shared("test_parameters_local_synchronous");
declare_test_parameters(node);
auto parameters_client = std::make_shared<rclcpp::SyncParametersClient>(node);
Expand All @@ -90,7 +85,8 @@ TEST_F(CLASSNAME(test_local_parameters, RMW_IMPLEMENTATION), local_synchronous)
test_get_parameters_sync(parameters_client);
}

TEST_F(CLASSNAME(test_local_parameters, RMW_IMPLEMENTATION), local_synchronous_repeated) {
TEST_F(test_local_parameters, local_synchronous_repeated)
{
auto node = rclcpp::Node::make_shared("test_parameters_local_synchronous_repeated");
declare_test_parameters(node);
auto parameters_client = std::make_shared<rclcpp::SyncParametersClient>(node);
Expand All @@ -104,7 +100,8 @@ TEST_F(CLASSNAME(test_local_parameters, RMW_IMPLEMENTATION), local_synchronous_r
}
}

TEST_F(CLASSNAME(test_local_parameters, RMW_IMPLEMENTATION), local_asynchronous) {
TEST_F(test_local_parameters, local_asynchronous)
{
auto node = rclcpp::Node::make_shared(std::string("test_parameters_local_asynchronous"));
declare_test_parameters(node);
auto parameters_client = std::make_shared<rclcpp::AsyncParametersClient>(node);
Expand Down Expand Up @@ -164,7 +161,8 @@ class ParametersAsyncNode : public rclcpp::Node

// Regression test for calling parameter client async services, but having the specified callback
// go out of scope before it gets called: see https://github.com/ros2/rclcpp/pull/414
TEST_F(CLASSNAME(test_local_parameters, RMW_IMPLEMENTATION), local_async_with_callback) {
TEST_F(test_local_parameters, local_async_with_callback)
{
auto node = std::make_shared<ParametersAsyncNode>();
if (!node->parameters_client_->wait_for_service(20s)) {
ASSERT_TRUE(false) << "service not available after waiting";
Expand All @@ -176,7 +174,8 @@ TEST_F(CLASSNAME(test_local_parameters, RMW_IMPLEMENTATION), local_async_with_ca
executor.spin();
}

TEST_F(CLASSNAME(test_local_parameters, RMW_IMPLEMENTATION), helpers) {
TEST_F(test_local_parameters, helpers)
{
auto node = rclcpp::Node::make_shared("test_parameters_local_helpers");
node->declare_parameter("foo", 0);
node->declare_parameter("bar", "");
Expand Down Expand Up @@ -299,7 +298,8 @@ TEST_F(CLASSNAME(test_local_parameters, RMW_IMPLEMENTATION), helpers) {
EXPECT_EQ(barfoo[2], 5);
}

TEST_F(CLASSNAME(test_local_parameters, RMW_IMPLEMENTATION), get_from_node_primitive_type) {
TEST_F(test_local_parameters, get_from_node_primitive_type)
{
auto node = rclcpp::Node::make_shared("test_parameters_local_helpers");
node->declare_parameter("foo", 0);
node->declare_parameter("bar", "");
Expand Down Expand Up @@ -372,7 +372,8 @@ TEST_F(CLASSNAME(test_local_parameters, RMW_IMPLEMENTATION), get_from_node_primi
EXPECT_EQ(barfoo[2], 5);
}

TEST_F(CLASSNAME(test_local_parameters, RMW_IMPLEMENTATION), get_from_node_variant_type) {
TEST_F(test_local_parameters, get_from_node_variant_type)
{
using rclcpp::Parameter;

auto node = rclcpp::Node::make_shared("test_parameters_local_helpers");
Expand Down Expand Up @@ -437,11 +438,3 @@ TEST_F(CLASSNAME(test_local_parameters, RMW_IMPLEMENTATION), get_from_node_varia
EXPECT_NO_THROW(got_param = node->get_parameter("barfoo", barfoo));
EXPECT_EQ(true, got_param);
}

int main(int argc, char ** argv)
{
setvbuf(stdout, NULL, _IONBF, BUFSIZ);
::testing::InitGoogleTest(&argc, argv);
int ret = RUN_ALL_TESTS();
return ret;
}
Loading

0 comments on commit 2144c02

Please sign in to comment.