v31.1-roots.1 · Commit 7: [PATCH 07/17] feat(rpc): preserve Roots operator interfaces on v31
src/test/fs_tests.cpp
Before: src/test/fs_tests.cpp · After: src/test/fs_tests.cpp
File metadata
index 988ab18d08dfd72c1e91717ff072c9578e38cb9b..79773b0acd3e595525dffb3d6c23e195c8340a16 100644
Download original patch · Release notes
Diff rows 1–60 of 60. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
src/test/fs_tests.cpp
CHANGED
|
@@ -8,11 +8,17 @@
|
|
| 8 |
|
| 9 |
#include <boost/test/unit_test.hpp>
|
| 10 |
|
|
|
|
| 11 |
#include <fstream>
|
| 12 |
#include <ios>
|
|
|
|
|
|
|
| 13 |
#include <string>
|
|
|
|
|
|
|
| 14 |
|
| 15 |
#ifndef WIN32
|
|
|
|
| 16 |
#include <unistd.h>
|
| 17 |
#endif
|
| 18 |
|
|
@@ -160,4 +166,43 @@ BOOST_AUTO_TEST_CASE(rename)
|
|
| 160 |
fs::remove(path2);
|
| 161 |
}
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
BOOST_AUTO_TEST_SUITE_END()
|
|
|
|
| 8 |
|
| 9 |
#include <boost/test/unit_test.hpp>
|
| 10 |
|
| 11 |
+
#include <cstdio>
|
| 12 |
#include <fstream>
|
| 13 |
#include <ios>
|
| 14 |
+
#include <limits>
|
| 15 |
+
#include <memory>
|
| 16 |
#include <string>
|
| 17 |
+
#include <utility>
|
| 18 |
+
#include <vector>
|
| 19 |
|
| 20 |
#ifndef WIN32
|
| 21 |
+
#include <sys/resource.h>
|
| 22 |
#include <unistd.h>
|
| 23 |
#endif
|
| 24 |
|
|
|
|
| 166 |
fs::remove(path2);
|
| 167 |
}
|
| 168 |
|
| 169 |
+
#ifndef WIN32
|
| 170 |
+
BOOST_AUTO_TEST_CASE(file_descriptor_limit_bounds)
|
| 171 |
+
{
|
| 172 |
+
struct rlimit limit{};
|
| 173 |
+
BOOST_REQUIRE_EQUAL(getrlimit(RLIMIT_NOFILE, &limit), 0);
|
| 174 |
+
const int expected{limit.rlim_cur == RLIM_INFINITY || std::cmp_greater_equal(limit.rlim_cur, std::numeric_limits<int>::max())
|
| 175 |
+
? std::numeric_limits<int>::max() : static_cast<int>(limit.rlim_cur)};
|
| 176 |
+
// A zero request must retain the current soft limit, saturating the int result.
|
| 177 |
+
BOOST_CHECK_EQUAL(RaiseFileDescriptorLimit(0), expected);
|
| 178 |
+
struct rlimit after{};
|
| 179 |
+
BOOST_REQUIRE_EQUAL(getrlimit(RLIMIT_NOFILE, &after), 0);
|
| 180 |
+
BOOST_CHECK_EQUAL(after.rlim_cur, limit.rlim_cur);
|
| 181 |
+
BOOST_CHECK_EQUAL(after.rlim_max, limit.rlim_max);
|
| 182 |
+
}
|
| 183 |
+
#endif
|
| 184 |
+
|
| 185 |
+
BOOST_AUTO_TEST_CASE(allocate_file_range_preserves_data)
|
| 186 |
+
{
|
| 187 |
+
const auto path{m_args.GetDataDirBase() / "allocate-range.dat"};
|
| 188 |
+
const auto close_file{[](FILE* file) { std::fclose(file); }};
|
| 189 |
+
std::unique_ptr<FILE, decltype(close_file)> file{fsbridge::fopen(path, "w+b"), close_file};
|
| 190 |
+
BOOST_REQUIRE(file);
|
| 191 |
+
std::vector<unsigned char> contents(3 * 65536);
|
| 192 |
+
for (size_t i{0}; i < contents.size(); ++i) contents[i] = static_cast<unsigned char>(i / 65536 + 1);
|
| 193 |
+
BOOST_REQUIRE_EQUAL(std::fwrite(contents.data(), 1, contents.size(), file.get()), contents.size());
|
| 194 |
+
BOOST_REQUIRE_EQUAL(std::fflush(file.get()), 0);
|
| 195 |
+
|
| 196 |
+
AllocateFileRange(file.get(), 65536, static_cast<unsigned int>(contents.size() - 65536 + 256));
|
| 197 |
+
BOOST_REQUIRE_EQUAL(std::fseek(file.get(), 0, SEEK_SET), 0);
|
| 198 |
+
std::vector<unsigned char> actual(contents.size());
|
| 199 |
+
BOOST_REQUIRE_EQUAL(std::fread(actual.data(), 1, actual.size(), file.get()), actual.size());
|
| 200 |
+
BOOST_CHECK(actual == contents);
|
| 201 |
+
|
| 202 |
+
// Allocation entirely inside a live file must never shorten it.
|
| 203 |
+
AllocateFileRange(file.get(), 65536, 128);
|
| 204 |
+
BOOST_REQUIRE_EQUAL(std::fseek(file.get(), 0, SEEK_END), 0);
|
| 205 |
+
BOOST_CHECK_EQUAL(std::ftell(file.get()), contents.size() + 256);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
BOOST_AUTO_TEST_SUITE_END()
|