test: split out `system_ram_tests` to signal when total ram cannot be determined
What changed, and why it matters
This commit only reorganizes a test. It moves a memory-size sanity check from one test file into its own separate test file and makes the test skip gracefully when the system cannot determine total RAM. There is no change to Bitcoin Core's actual runtime code, no bug fix, and no security issue.
No security action needed. This is a test-only refactoring; routine review/merge is sufficient.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff splits the total_ram Boost.Test case out of system_tests.cpp into a new system_ram_tests.cpp. It wraps GetTotalRAM() so that if it returns std::nullopt, the test warns and returns instead of failing. CMake is updated to register the new test source and add ‘skipping total_ram’ to the skip-regular-expression list. The production code in common/system.h/GetTotalRAM is not modified.
Changed components
src/test/system_tests.cppsrc/test/system_ram_tests.cppsrc/test/CMakeLists.txtInspect captured patch +37 / −14
diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt
index c963afff..aacefb3f 100644
--- a/src/test/CMakeLists.txt
+++ b/src/test/CMakeLists.txt
@@ -102,6 +102,7 @@ add_executable(test_bitcoin
span_tests.cpp
streams_tests.cpp
sync_tests.cpp
+ system_ram_tests.cpp
system_tests.cpp
testnet4_miner_tests.cpp
timeoffsets_tests.cpp
@@ -197,7 +198,10 @@ function(add_boost_test source_file)
COMMAND test_bitcoin --run_test=${test_suite_name} --catch_system_error=no --log_level=test_suite -- DEBUG_LOG_OUT
)
set_property(TEST ${test_suite_name} PROPERTY
- SKIP_REGULAR_EXPRESSION "no test cases matching filter" "skipping script_assets_test"
+ SKIP_REGULAR_EXPRESSION
+ "no test cases matching filter"
+ "skipping script_assets_test"
+ "skipping total_ram"
)
endforeach()
endfunction()
diff --git a/src/test/system_ram_tests.cpp b/src/test/system_ram_tests.cpp
new file mode 100644
index 00000000..8ad62264
--- /dev/null
+++ b/src/test/system_ram_tests.cpp
@@ -0,0 +1,32 @@
+// Copyright (c) 2025-present The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or https://opensource.org/license/mit/.
+
+#include <common/system.h>
+#include <test/util/setup_common.h>
+
+#include <boost/test/unit_test.hpp>
+
+#include <cstdint>
+#include <optional>
+
+BOOST_AUTO_TEST_SUITE(system_ram_tests)
+
+BOOST_AUTO_TEST_CASE(total_ram)
+{
+ const auto total{GetTotalRAM()};
+ if (!total) {
+ BOOST_WARN_MESSAGE(false, "skipping total_ram: total RAM unknown");
+ return;
+ }
+
+ BOOST_CHECK_GE(*total, 1000_MiB);
+
+ if constexpr (SIZE_MAX == UINT64_MAX) {
+ // Upper bound check only on 64-bit: 32-bit systems can reasonably have max memory,
+ // but extremely large values on 64-bit likely indicate detection errors
+ BOOST_CHECK_LT(*total, 10'000'000_MiB); // >10 TiB memory is unlikely
+ }
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/test/system_tests.cpp b/src/test/system_tests.cpp
index 53db3200..dec4d418 100644
--- a/src/test/system_tests.cpp
+++ b/src/test/system_tests.cpp
@@ -8,8 +8,6 @@
#include <common/run_command.h>
#include <univalue.h>
-#include <common/system.h>
-
#ifdef ENABLE_EXTERNAL_SIGNER
#include <util/subprocess.h>
#endif // ENABLE_EXTERNAL_SIGNER
@@ -18,17 +16,6 @@
BOOST_FIXTURE_TEST_SUITE(system_tests, BasicTestingSetup)
-BOOST_AUTO_TEST_CASE(total_ram)
-{
- BOOST_CHECK_GE(GetTotalRAM(), 1000_MiB);
-
- if constexpr (SIZE_MAX == UINT64_MAX) {
- // Upper bound check only on 64-bit: 32-bit systems can reasonably have max memory,
- // but extremely large values on 64-bit likely indicate detection errors
- BOOST_CHECK_LT(GetTotalRAM(), 10'000'000_MiB); // >10 TiB memory is unlikely
- }
-}
-
#ifdef ENABLE_EXTERNAL_SIGNER
BOOST_AUTO_TEST_CASE(run_command)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.