Skip to content

Commit

Permalink
Use tmpfs in rosbag2 temporary_directory_fixture (#1901)
Browse files Browse the repository at this point in the history
* Use tmpfs for rosbag2 temporary_directory_fixture

- Added missing `rcpputils` dependency in rosbag2_test_common package
- Use ParametrizedTemporaryDirectoryFixture in the
"rosbag2_transport/test_rewrite.cpp"

Signed-off-by: Michael Orlov <[email protected]>

* Nitpick from code review. Reuse already created `parent_path`

Signed-off-by: Michael Orlov <[email protected]>

---------

Signed-off-by: Michael Orlov <[email protected]>
(cherry picked from commit 1d60d7b)

# Conflicts:
#	rosbag2_test_common/include/rosbag2_test_common/temporary_directory_fixture.hpp
#	rosbag2_transport/test/rosbag2_transport/test_rewrite.cpp
  • Loading branch information
MichaelOrlov authored and mergify[bot] committed Jan 28, 2025
1 parent 69009cf commit ff27b81
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions rosbag2_test_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include <gmock/gmock.h>

#include <filesystem>
#include <iostream>
#include <string>

#include "rcpputils/filesystem_helper.hpp"
Expand All @@ -31,7 +33,18 @@ class TemporaryDirectoryFixture : public Test
public:
TemporaryDirectoryFixture()
{
<<<<<<< HEAD
temporary_dir_path_ = rcpputils::fs::create_temp_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();
>>>>>>> 1d60d7b (Use tmpfs in rosbag2 temporary_directory_fixture (#1901))
}

~TemporaryDirectoryFixture() override
Expand Down
2 changes: 2 additions & 0 deletions rosbag2_test_common/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
<buildtool_depend>python_cmake_module</buildtool_depend>

<build_depend>rclcpp</build_depend>
<build_depend>rcpputils</build_depend>
<build_depend>rcutils</build_depend>
<build_depend>test_msgs</build_depend>

<exec_depend>rclcpp</exec_depend>
<exec_depend>rcpputils</exec_depend>
<exec_depend>rcutils</exec_depend>
<exec_depend>test_msgs</exec_depend>

Expand Down
13 changes: 8 additions & 5 deletions rosbag2_transport/test/rosbag2_transport/test_rewrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
#include <vector>
#include <utility>

#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;

Expand All @@ -48,13 +50,17 @@ Builtin knowledge about the bags under test:
- 50 messages
- 1 offered QoS Profile
*/
class TestRewrite : public Test, public WithParamInterface<std::string>
class TestRewrite : public ParametrizedTemporaryDirectoryFixture
{
public:
TestRewrite()
{
<<<<<<< HEAD
auto tmp_dir = rcpputils::fs::create_temp_directory("test_bag_rewrite");
output_dir_ = fs::path(tmp_dir.string());
=======
output_dir_ = fs::path(temporary_dir_path_);
>>>>>>> 1d60d7b (Use tmpfs in rosbag2 temporary_directory_fixture (#1901))
storage_id_ = GetParam();
bags_path_ = fs::path(_SRC_RESOURCES_DIR_PATH) / storage_id_;
}
Expand All @@ -75,10 +81,7 @@ class TestRewrite : public Test, public WithParamInterface<std::string>
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};
Expand Down

0 comments on commit ff27b81

Please sign in to comment.