Compare commits

...

1 Commits

Author SHA1 Message Date
Michael Carroll
a9d58f690e Test reproduction of 2664
Signed-off-by: Michael Carroll <mjcarroll@intrinsic.ai>
2024-11-08 15:28:14 +00:00
2 changed files with 90 additions and 0 deletions

View File

@@ -500,6 +500,15 @@ if(TARGET test_executors_callback_group_behavior)
target_link_libraries(test_executors_callback_group_behavior ${PROJECT_NAME})
endif()
ament_add_gtest(
test_executors_cbg_destroyed
executors/test_executors_cbg_destroyed.cpp
APPEND_LIBRARY_DIRS "${append_library_dirs}"
TIMEOUT 180)
if(TARGET test_executors_cbg_destroyed)
target_link_libraries(test_executors_cbg_destroyed ${PROJECT_NAME})
endif()
ament_add_gtest(
test_executors_intraprocess
executors/test_executors_intraprocess.cpp

View File

@@ -0,0 +1,81 @@
// Copyright 2024 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <gtest/gtest.h>
#include <chrono>
#include <cstddef>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>
#include "rclcpp/rclcpp.hpp"
#include "./executor_types.hpp"
using namespace std::chrono_literals;
template<typename T>
class TestExecutorsCbgDestroyed: public ::testing::Test
{
public:
void SetUp()
{
rclcpp::init(0, nullptr);
}
void TearDown()
{
rclcpp::shutdown();
}
};
TYPED_TEST_SUITE(TestExecutorsCbgDestroyed, ExecutorTypes, ExecutorTypeNames);
TYPED_TEST(TestExecutorsCbgDestroyed, doesnt_segfault)
{
auto node = rclcpp::Node::make_shared("test_node");
auto log = node->get_logger();
using ExecutorType = TypeParam;
ExecutorType executor;
auto spinThread = std::thread([&] {
RCLCPP_INFO(log, "add_node");
executor.add_node(node);
RCLCPP_INFO(log, "spin");
executor.spin();
RCLCPP_INFO(log, "remove_node");
executor.remove_node(node);
});
while (!executor.is_spinning()) {
std::this_thread::sleep_for(1ms);
}
{
RCLCPP_INFO(log, "BEGIN");
auto cg = node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
auto timer = node->create_timer(1s, [&log] { RCLCPP_INFO(log, "timer"); }, cg); // SIGSEGV
// auto timer = node->create_timer(1s, [&log] { RCLCPP_INFO(log, "timer"); }, std::move(cg)); // OK
std::this_thread::sleep_for(100ms); // wait a bit for the executor to catch up
RCLCPP_INFO(log, "END"); // timer and subscribers go out of scope here
}
executor.cancel();
if (spinThread.joinable()) {
spinThread.join();
}
}