Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/llfio.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNiall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com>2016-08-22 23:15:28 +0300
committerNiall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com>2016-08-22 23:15:28 +0300
commite28cf39e4d5de24cbbaaf01820ef2d4993ed7f3f (patch)
tree84b43d7d7b2d6ea26d3b5120341ea8fee9eaba24 /test
parentf375d45d699be1f6899fe58faf6f5c12e9090353 (diff)
Made map_handle unit testing much more complete, and thus found and fixed a raft more bugs.
Diffstat (limited to 'test')
-rw-r--r--test/tests/map_handle_create_close/integration.cpp4
-rw-r--r--test/tests/map_handle_create_close/runner.cpp71
2 files changed, 62 insertions, 13 deletions
diff --git a/test/tests/map_handle_create_close/integration.cpp b/test/tests/map_handle_create_close/integration.cpp
index ef01fe0c..e877a299 100644
--- a/test/tests/map_handle_create_close/integration.cpp
+++ b/test/tests/map_handle_create_close/integration.cpp
@@ -5,4 +5,6 @@ File Created: Aug 2016
#include "../kerneltest/include/boost/kerneltest.hpp"
-BOOST_KERNELTEST_TEST_KERNEL(integration, afio, map_handle_nocommit_and_commit, map_handle, "Tests that afio::map_handle's nocommit and commit work as expected", [] {})
+BOOST_KERNELTEST_TEST_KERNEL(integration, afio, map_handle_nocommit_and_commit, map_handle, "Tests that afio::map_handle's nocommit and commit work as expected", [] {
+ //! \todo TODO test map_handle::commit, decommit, zero, prefetch, do_not_store
+})
diff --git a/test/tests/map_handle_create_close/runner.cpp b/test/tests/map_handle_create_close/runner.cpp
index 31e84c5b..42e26ca2 100644
--- a/test/tests/map_handle_create_close/runner.cpp
+++ b/test/tests/map_handle_create_close/runner.cpp
@@ -49,33 +49,80 @@ template <class U> inline void map_handle_create_close_(U &&f)
[&](auto &permuter, auto &testreturn, size_t idx, int use_file_backing) {
if (use_file_backing)
{
+ // Create a temporary backing file
temph = file_handle::file("tempfile", file_handle::mode::write, file_handle::creation::if_needed).get();
temph.write(0, "I am some file data", 19).get();
}
else
+ // Use the page file
temph = file_handle();
return std::make_tuple(std::ref(permuter), std::ref(testreturn), idx, use_file_backing);
},
[&](auto tuplestate) {
- //auto &permuter = std::get<0>(tuplestate);
+ auto &permuter = std::get<0>(tuplestate);
auto &testreturn = std::get<1>(tuplestate);
- //size_t idx = std::get<2>(tuplestate);
+ size_t idx = std::get<2>(tuplestate);
int use_file_backing = std::get<3>(tuplestate);
+ map_handle maph;
+ if (testreturn)
+ maph = std::move(testreturn.get());
+ // Need to close the map and any backing file as otherwise filesystem_setup won't be able to clear up the working dir on Windows
+ auto onexit = BOOST_AFIO_V2_NAMESPACE::detail::Undoer([&]{
+ maph.close();
+ temph.close();
+ });
if (testreturn)
{
- map_handle &h = testreturn.get();
- char *addr = h.address();
- BOOST_KERNELTEST_CHECK(testreturn, h.length() > 0);
+ char *addr = maph.address();
+ section_handle::flag flags = std::get<1>(std::get<1>(permuter[idx]));
+ BOOST_KERNELTEST_CHECK(testreturn, maph.length() > 0);
BOOST_KERNELTEST_CHECK(testreturn, addr != nullptr);
- if (use_file_backing)
+ if (!(flags & section_handle::flag::nocommit))
{
- BOOST_KERNELTEST_CHECK(testreturn, !memcmp(addr, "I am some file data", 19));
+ char buffer[64];
+ // Make sure the backing file is appearing in the map
+ if (use_file_backing && maph.is_readable())
+ {
+ BOOST_KERNELTEST_CHECK(testreturn, !memcmp(addr, "I am some file data", 19));
+ }
+ // Make sure maph's read() does what it is supposed to
+ {
+ auto b = maph.read(0, nullptr, 20).get();
+ BOOST_KERNELTEST_CHECK(testreturn, b.first == addr);
+ BOOST_KERNELTEST_CHECK(testreturn, b.second == 20);
+ }
+ {
+ auto b = maph.read(5, nullptr, 5000).get();
+ BOOST_KERNELTEST_CHECK(testreturn, b.first == addr+5);
+ BOOST_KERNELTEST_CHECK(testreturn, b.second == 4091);
+ }
+ // If we are writable, write straight into the map
+ if (maph.is_writable())
+ {
+ memcpy(addr, "NIALL was here", 14);
+ // Make sure maph's write() works
+ maph.write(1, "iall", 4);
+ // Make sure data written to the map turns up in the file
+ if (use_file_backing)
+ {
+ temph.read(0, buffer, 64);
+ if (flags & section_handle::flag::cow)
+ {
+ BOOST_KERNELTEST_CHECK(testreturn, !memcmp(buffer, "I am some file data", 19));
+ }
+ else
+ {
+ BOOST_KERNELTEST_CHECK(testreturn, !memcmp(buffer, "Niall was here data", 19));
+ }
+ }
+ }
+ // If we did not commit, the OS should not auto expand storage to 4Kb
+ if (use_file_backing && (flags & section_handle::flag::nocommit))
+ {
+ BOOST_KERNELTEST_CHECK(testreturn, temph.length().get() == 19);
+ }
}
}
- // Need to close the map and any backing file as otherwise filesystem_setup won't be able to clear up the working dir on Windows
- if(testreturn)
- testreturn.get().close();
- temph.close();
},
"check mmap")
));
@@ -85,4 +132,4 @@ template <class U> inline void map_handle_create_close_(U &&f)
check_results_with_boost_test(permuter, results);
}
-BOOST_KERNELTEST_TEST_KERNEL(integration, afio, map_handle_create_close, map_handle, "Tests that afio::map_handle's creation parameters work as expected", map_handle_create_close_(map_handle_create_close::test_kernel_map_handle))
+BOOST_KERNELTEST_TEST_KERNEL(unit, afio, map_handle_create_close, map_handle, "Tests that afio::map_handle's creation parameters work as expected", map_handle_create_close_(map_handle_create_close::test_kernel_map_handle))