diff --git a/rosbag2_test_common/CMakeLists.txt b/rosbag2_test_common/CMakeLists.txt index a3a4f59ba..0d09759fc 100644 --- a/rosbag2_test_common/CMakeLists.txt +++ b/rosbag2_test_common/CMakeLists.txt @@ -24,6 +24,7 @@ endif() find_package(ament_cmake REQUIRED) find_package(rclcpp REQUIRED) find_package(rcutils REQUIRED) +find_package(rcpputils REQUIRED) find_package(test_msgs REQUIRED) add_library(${PROJECT_NAME} INTERFACE) diff --git a/rosbag2_test_common/include/rosbag2_test_common/temporary_directory_fixture.hpp b/rosbag2_test_common/include/rosbag2_test_common/temporary_directory_fixture.hpp index 7098e9286..68e97b11b 100644 --- a/rosbag2_test_common/include/rosbag2_test_common/temporary_directory_fixture.hpp +++ b/rosbag2_test_common/include/rosbag2_test_common/temporary_directory_fixture.hpp @@ -17,6 +17,8 @@ #include +#include +#include #include #include "rcpputils/filesystem_helper.hpp" @@ -31,7 +33,14 @@ class TemporaryDirectoryFixture : public Test public: TemporaryDirectoryFixture() { - temporary_dir_path_ = rcpputils::fs::create_temporary_directory("tmp_test_dir_").string(); + std::filesystem::path parent_path = std::filesystem::path("/tmpfs"); + if (!std::filesystem::exists(parent_path)) { + std::cerr << "The '/tmpfs' doesn't exist, falling back to the default temp directory \n"; + parent_path = std::filesystem::temp_directory_path(); + } + + temporary_dir_path_ = + rcpputils::fs::create_temporary_directory("tmp_test_dir_", parent_path).string(); } ~TemporaryDirectoryFixture() override diff --git a/rosbag2_test_common/package.xml b/rosbag2_test_common/package.xml index bbc998b19..0b9bd80d4 100644 --- a/rosbag2_test_common/package.xml +++ b/rosbag2_test_common/package.xml @@ -15,10 +15,12 @@ ament_cmake_python rclcpp + rcpputils rcutils test_msgs rclcpp + rcpputils rcutils test_msgs diff --git a/rosbag2_transport/test/rosbag2_transport/test_rewrite.cpp b/rosbag2_transport/test/rosbag2_transport/test_rewrite.cpp index 36ed868d9..c85016945 100644 --- a/rosbag2_transport/test/rosbag2_transport/test_rewrite.cpp +++ b/rosbag2_transport/test/rosbag2_transport/test_rewrite.cpp @@ -19,11 +19,13 @@ #include #include +#include "rosbag2_test_common/temporary_directory_fixture.hpp" #include "rosbag2_test_common/tested_storage_ids.hpp" #include "rosbag2_transport/bag_rewrite.hpp" #include "rosbag2_transport/reader_writer_factory.hpp" using namespace ::testing; // NOLINT +using namespace rosbag2_test_common; // NOLINT namespace fs = std::filesystem; @@ -48,13 +50,12 @@ Builtin knowledge about the bags under test: - 50 messages - 1 offered QoS Profile */ -class TestRewrite : public Test, public WithParamInterface +class TestRewrite : public ParametrizedTemporaryDirectoryFixture { public: TestRewrite() { - auto tmp_dir = rcpputils::fs::create_temporary_directory("test_bag_rewrite"); - output_dir_ = fs::path(tmp_dir.string()); + output_dir_ = fs::path(temporary_dir_path_); storage_id_ = GetParam(); bags_path_ = fs::path(_SRC_RESOURCES_DIR_PATH) / storage_id_; } @@ -75,10 +76,7 @@ class TestRewrite : public Test, public WithParamInterface input_bags_.push_back(storage); } - ~TestRewrite() - { - fs::remove_all(output_dir_); - } + ~TestRewrite() override = default; fs::path output_dir_; fs::path bags_path_{_SRC_RESOURCES_DIR_PATH};