Skip to content

[jazzy] Use tmpfs in rosbag2 temporary_directory_fixture (backport #1901) #1904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,12 +33,19 @@ class TemporaryDirectoryFixture : public Test
public:
TemporaryDirectoryFixture()
{
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_temp_directory(
"tmp_test_dir_", rcpputils::fs::path(parent_path.generic_string())).string();
}

~TemporaryDirectoryFixture() override
{
rcpputils::fs::remove_all(rcpputils::fs::path(temporary_dir_path_));
std::filesystem::remove_all(std::filesystem::path(temporary_dir_path_));
}

std::string temporary_dir_path_;
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
12 changes: 5 additions & 7 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,12 @@ 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()
{
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_);
storage_id_ = GetParam();
bags_path_ = fs::path(_SRC_RESOURCES_DIR_PATH) / storage_id_;
}
Expand All @@ -75,10 +76,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
Loading