Skip to content

Commit ff27b81

Browse files
morlov-apexaimergify[bot]
authored andcommitted
Use tmpfs in rosbag2 temporary_directory_fixture (#1901)
* 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
1 parent 69009cf commit ff27b81

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

Diff for: rosbag2_test_common/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ endif()
2424
find_package(ament_cmake REQUIRED)
2525
find_package(rclcpp REQUIRED)
2626
find_package(rcutils REQUIRED)
27+
find_package(rcpputils REQUIRED)
2728
find_package(test_msgs REQUIRED)
2829

2930
add_library(${PROJECT_NAME} INTERFACE)

Diff for: rosbag2_test_common/include/rosbag2_test_common/temporary_directory_fixture.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include <gmock/gmock.h>
1919

20+
#include <filesystem>
21+
#include <iostream>
2022
#include <string>
2123

2224
#include "rcpputils/filesystem_helper.hpp"
@@ -31,7 +33,18 @@ class TemporaryDirectoryFixture : public Test
3133
public:
3234
TemporaryDirectoryFixture()
3335
{
36+
<<<<<<< HEAD
3437
temporary_dir_path_ = rcpputils::fs::create_temp_directory("tmp_test_dir_").string();
38+
=======
39+
std::filesystem::path parent_path = std::filesystem::path("/tmpfs");
40+
if (!std::filesystem::exists(parent_path)) {
41+
std::cerr << "The '/tmpfs' doesn't exist, falling back to the default temp directory \n";
42+
parent_path = std::filesystem::temp_directory_path();
43+
}
44+
45+
temporary_dir_path_ =
46+
rcpputils::fs::create_temporary_directory("tmp_test_dir_", parent_path).string();
47+
>>>>>>> 1d60d7b (Use tmpfs in rosbag2 temporary_directory_fixture (#1901))
3548
}
3649

3750
~TemporaryDirectoryFixture() override

Diff for: rosbag2_test_common/package.xml

+2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
<buildtool_depend>python_cmake_module</buildtool_depend>
1717

1818
<build_depend>rclcpp</build_depend>
19+
<build_depend>rcpputils</build_depend>
1920
<build_depend>rcutils</build_depend>
2021
<build_depend>test_msgs</build_depend>
2122

2223
<exec_depend>rclcpp</exec_depend>
24+
<exec_depend>rcpputils</exec_depend>
2325
<exec_depend>rcutils</exec_depend>
2426
<exec_depend>test_msgs</exec_depend>
2527

Diff for: rosbag2_transport/test/rosbag2_transport/test_rewrite.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
#include <vector>
2020
#include <utility>
2121

22+
#include "rosbag2_test_common/temporary_directory_fixture.hpp"
2223
#include "rosbag2_test_common/tested_storage_ids.hpp"
2324
#include "rosbag2_transport/bag_rewrite.hpp"
2425
#include "rosbag2_transport/reader_writer_factory.hpp"
2526

2627
using namespace ::testing; // NOLINT
28+
using namespace rosbag2_test_common; // NOLINT
2729

2830
namespace fs = std::filesystem;
2931

@@ -48,13 +50,17 @@ Builtin knowledge about the bags under test:
4850
- 50 messages
4951
- 1 offered QoS Profile
5052
*/
51-
class TestRewrite : public Test, public WithParamInterface<std::string>
53+
class TestRewrite : public ParametrizedTemporaryDirectoryFixture
5254
{
5355
public:
5456
TestRewrite()
5557
{
58+
<<<<<<< HEAD
5659
auto tmp_dir = rcpputils::fs::create_temp_directory("test_bag_rewrite");
5760
output_dir_ = fs::path(tmp_dir.string());
61+
=======
62+
output_dir_ = fs::path(temporary_dir_path_);
63+
>>>>>>> 1d60d7b (Use tmpfs in rosbag2 temporary_directory_fixture (#1901))
5864
storage_id_ = GetParam();
5965
bags_path_ = fs::path(_SRC_RESOURCES_DIR_PATH) / storage_id_;
6066
}
@@ -75,10 +81,7 @@ class TestRewrite : public Test, public WithParamInterface<std::string>
7581
input_bags_.push_back(storage);
7682
}
7783

78-
~TestRewrite()
79-
{
80-
fs::remove_all(output_dir_);
81-
}
84+
~TestRewrite() override = default;
8285

8386
fs::path output_dir_;
8487
fs::path bags_path_{_SRC_RESOURCES_DIR_PATH};

0 commit comments

Comments
 (0)