From c4170946ad922a1266d0f397c1edd15e4d9f0a90 Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Wed, 31 Jan 2024 16:34:10 -0500 Subject: [PATCH] only run overcommit dependent tests on Linux when configured appropriately --- .github/workflows/build.yaml | 6 +++++- test/test.cpp | 26 ++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index f21c7f5..8e64c96 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -39,4 +39,8 @@ jobs: - name: Build run: cmake -B build ${{matrix.cfg.cmake}} && cmake --build build -- -j - name: Test - run: cd build && ctest --output-on-failure \ No newline at end of file + run: cd build && ctest --output-on-failure + # some tests are ignored unless overcommit_memory is allowed + - name: Check Linux overcommit_memory settings + if: matrix.cfg.runson == 'ubuntu-latest' + run: grep -q 0 /proc/sys/vm/overcommit_memory \ No newline at end of file diff --git a/test/test.cpp b/test/test.cpp index f7f0885..26a15dd 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -127,11 +127,27 @@ BOOST_AUTO_TEST_CASE( open_and_create ) { BOOST_REQUIRE_EQUAL( new_book.b, copy_new_book.b ); } +// behavior of these tests are dependent on linux's overcommit behavior, they are also dependent on the system not having +// enough memory+swap to balk at 6TB request +#if defined(__linux__) + +static bool overcommit_protection_enabled() { + std::ifstream ocmem_file("/proc/sys/vm/overcommit_memory"); + BOOST_REQUIRE(ocmem_file.good()); + std::string ocmem_contents((std::istreambuf_iterator(ocmem_file)), std::istreambuf_iterator()); + + return ocmem_contents.at(0) == '0' || ocmem_contents.at(0) == '2'; +} + BOOST_AUTO_TEST_CASE( mapped_big_boy ) { temp_directory temp_dir; const auto& temp = temp_dir.path(); - BOOST_REQUIRE_THROW(chainbase::database(temp, database::read_write, 1024ull*1024*1024*1024*4, false, pinnable_mapped_file::map_mode::mapped_private), boost::interprocess::interprocess_exception); + //silently pass test if system not configured for overcommit protection + if(!overcommit_protection_enabled()) + return; + + BOOST_REQUIRE_THROW(chainbase::database(temp, database::read_write, 1024ull*1024*1024*1024*6, false, pinnable_mapped_file::map_mode::mapped_private), boost::interprocess::interprocess_exception); chainbase::database(temp, database::read_write, 0, false); } @@ -139,9 +155,15 @@ BOOST_AUTO_TEST_CASE( mapped_big_boy_extra ) { temp_directory temp_dir; const auto& temp = temp_dir.path(); - chainbase::database(temp, database::read_write, 1024ull*1024*1024*1024*4, false); + //silently pass test if system not configured for overcommit protection + if(!overcommit_protection_enabled()) + return; + + chainbase::database(temp, database::read_write, 1024ull*1024*1024*1024*6, false); BOOST_REQUIRE_THROW(chainbase::database(temp, database::read_write, 0, false, pinnable_mapped_file::map_mode::mapped_private), boost::interprocess::interprocess_exception); chainbase::database(temp, database::read_write, 0, false); } +#endif + // BOOST_AUTO_TEST_SUITE_END()