Skip to content

Commit

Permalink
only run overcommit dependent tests on Linux when overcommit is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
spoonincode committed Jan 31, 2024
1 parent 21f6da1 commit a3cf611
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
26 changes: 24 additions & 2 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,43 @@ 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<char>(ocmem_file)), std::istreambuf_iterator<char>());

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);
}

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()

0 comments on commit a3cf611

Please sign in to comment.