diff options
author | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2016-08-19 22:58:00 +0300 |
---|---|---|
committer | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2016-08-19 22:58:00 +0300 |
commit | 3d600796af15e29c01e6a36d775a175401a6b3fe (patch) | |
tree | 40abbb71483bbbef4174b28cd7f6390fc66cce10 /test | |
parent | 4bc8c759d75336b2f59b5a1f30f9dc6871fd731d (diff) |
Added a kerneltest for map_handle, and found and fixed many more bugs in map_handle as a result.
Diffstat (limited to 'test')
m--------- | test/kerneltest | 0 | ||||
-rw-r--r-- | test/tests/map_handle_create_close/kernel_map_handle.cpp.hpp | 16 | ||||
-rw-r--r-- | test/tests/map_handle_create_close/runner.cpp | 88 | ||||
-rw-r--r-- | test/tests/section_handle_create_close/runner.cpp | 2 |
4 files changed, 105 insertions, 1 deletions
diff --git a/test/kerneltest b/test/kerneltest -Subproject d07a2d2198edf35d2f16b9d9894166e19004ddd +Subproject 6d003a09e7f12adbb48fd6ee86fe6aa706901a0 diff --git a/test/tests/map_handle_create_close/kernel_map_handle.cpp.hpp b/test/tests/map_handle_create_close/kernel_map_handle.cpp.hpp new file mode 100644 index 00000000..e48c0209 --- /dev/null +++ b/test/tests/map_handle_create_close/kernel_map_handle.cpp.hpp @@ -0,0 +1,16 @@ +/* Test kernel for map_handle create and close +(C) 2016 Niall Douglas http://www.nedprod.com/ +File Created: August 2016 +*/ + +#include "../../test_kernel_decl.hpp" + +namespace map_handle_create_close +{ + BOOST_AFIO_TEST_KERNEL_DECL boost::outcome::result<boost::afio::map_handle> test_kernel_map_handle(boost::afio::file_handle &backing, boost::afio::map_handle::size_type bytes, boost::afio::section_handle::flag m) + { + auto sectionh = boost::afio::section_handle::section(backing, bytes, boost::afio::section_handle::flag::readwrite); + auto h = boost::afio::map_handle::map(sectionh.get(), bytes, 0, m); + return h; + } +} diff --git a/test/tests/map_handle_create_close/runner.cpp b/test/tests/map_handle_create_close/runner.cpp new file mode 100644 index 00000000..31e84c5b --- /dev/null +++ b/test/tests/map_handle_create_close/runner.cpp @@ -0,0 +1,88 @@ +/* Integration test kernel for map_handle create and close +(C) 2016 Niall Douglas http://www.nedprod.com/ +File Created: Aug 2016 +*/ + +#include "../kerneltest/include/boost/kerneltest.hpp" +#include "kernel_map_handle.cpp.hpp" + +template <class U> inline void map_handle_create_close_(U &&f) +{ + using namespace BOOST_KERNELTEST_V1_NAMESPACE; + using namespace BOOST_AFIO_V2_NAMESPACE; + + // Create a temporary file and put some text into it + file_handle temph; + auto boundf = [&](auto... pars) { return f(temph, pars...); }; + + // clang-format off + static const auto permuter(st_permute_parameters< + result<void>, + parameters< + typename map_handle::size_type, + typename section_handle::flag + >, + precondition::filesystem_setup_parameters, + postcondition::custom_parameters<bool> + >( + { + { make_ready_result<void>(),{ 1, section_handle::flag::none },{ "_" },{ false } }, + { make_ready_result<void>(),{ 1, section_handle::flag::read },{ "_" },{ false } }, + { make_ready_result<void>(),{ 1, section_handle::flag::write },{ "_" },{ false } }, + { make_ready_result<void>(),{ 1, section_handle::flag::cow },{ "_" },{ false } }, + //{ make_ready_result<void>(),{ 1, section_handle::flag::execute },{ "_" },{ false } }, + { make_ready_result<void>(),{ 1, section_handle::flag::write|section_handle::flag::nocommit },{ "_" },{ false } }, + { make_ready_result<void>(),{ 1, section_handle::flag::write|section_handle::flag::prefault },{ "_" },{ false } }, + //{ make_ready_result<void>(),{ 1, section_handle::flag::write|section_handle::flag::executable },{ "_" },{ false } }, + + { make_ready_result<void>(),{ 1, section_handle::flag::none },{ "_" },{ true } }, + { make_ready_result<void>(),{ 1, section_handle::flag::read },{ "_" },{ true } }, + { make_ready_result<void>(),{ 1, section_handle::flag::write },{ "_" },{ true } }, + { make_ready_result<void>(),{ 1, section_handle::flag::cow },{ "_" },{ true } }, + //{ make_ready_result<void>(),{ 1, section_handle::flag::execute },{ "_" },{ true } }, + { make_ready_result<void>(),{ 1, section_handle::flag::write | section_handle::flag::nocommit },{ "_" },{ true } }, + { make_ready_result<void>(),{ 1, section_handle::flag::write | section_handle::flag::prefault },{ "_" },{ true } }, + //{ make_ready_result<void>(),{ 1, section_handle::flag::write|section_handle::flag::executable },{ "_" },{ true } }, + }, + precondition::filesystem_setup(), + postcondition::custom( + [&](auto &permuter, auto &testreturn, size_t idx, int use_file_backing) { + if (use_file_backing) + { + 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 + 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 &testreturn = std::get<1>(tuplestate); + //size_t idx = std::get<2>(tuplestate); + int use_file_backing = std::get<3>(tuplestate); + if (testreturn) + { + map_handle &h = testreturn.get(); + char *addr = h.address(); + BOOST_KERNELTEST_CHECK(testreturn, h.length() > 0); + BOOST_KERNELTEST_CHECK(testreturn, addr != nullptr); + if (use_file_backing) + { + BOOST_KERNELTEST_CHECK(testreturn, !memcmp(addr, "I am some file data", 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") + )); + // clang-format on + + auto results = permuter(boundf); + 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)) diff --git a/test/tests/section_handle_create_close/runner.cpp b/test/tests/section_handle_create_close/runner.cpp index 94f047c6..ac491f1c 100644 --- a/test/tests/section_handle_create_close/runner.cpp +++ b/test/tests/section_handle_create_close/runner.cpp @@ -46,7 +46,7 @@ template <class U> inline void section_handle_create_close_(U &&f) }, precondition::filesystem_setup(), postcondition::custom( - [&](auto *, auto &testreturn, size_t, int use_file_backing) { + [&](auto &, auto &testreturn, size_t, int use_file_backing) { if (use_file_backing) { temph = file_handle::file("tempfile", file_handle::mode::write, file_handle::creation::if_needed).get(); |