Skip to content

Commit 0fc951b

Browse files
committed
memory limit WIP
1 parent f17faa1 commit 0fc951b

2 files changed

Lines changed: 53 additions & 2 deletions

File tree

cmake/modules/RootTestDriver.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,12 @@ endif()
132132
#---Execute pre-command-----------------------------------------------------------------------------
133133
if(PRE)
134134
execute_process(COMMAND ${_pre} ${_cwd} RESULT_VARIABLE _rc)
135-
if(_rc)
135+
if(_rc EQUAL 77)
136+
# Exit code 77 from a pre-command means "skip this test".
137+
# Re-exit with 77 so CTest's SKIP_RETURN_CODE property takes effect.
138+
message(STATUS "pre-command requested skip (exit 77) -- skipping test")
139+
cmake_language(EXIT 77)
140+
elseif(_rc)
136141
message(FATAL_ERROR "pre-command error code : ${_rc}")
137142
endif()
138143
endif()

io/io/test/CMakeLists.txt

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,55 @@ if(NOT _32BIT)
6666
ROOTTEST_COMPILE_MACRO(testLargeCollection.cxx
6767
FIXTURES_SETUP io-io-testcoll-fixture)
6868

69+
# Memory-check script: exits 0 when enough RAM+swap is available, 77 (skip) otherwise.
70+
# RootTestDriver.cmake propagates exit code 77 from PRECMD to the test's own exit code,
71+
# and SKIP_RETURN_CODE 77 on the main test turns that into a proper CTest "Skipped".
72+
set(_memcheck_script "${CMAKE_CURRENT_BINARY_DIR}/check_mem_for_large_coll.sh")
73+
file(WRITE ${_memcheck_script}
74+
"#!/bin/sh\n"
75+
"# Exit 77 (CTest SKIP via SKIP_RETURN_CODE) if free RAM+swap < 32 GB.\n"
76+
"THRESHOLD_KB=33554432\n"
77+
"if [ -r /proc/meminfo ]; then\n"
78+
" # Linux\n"
79+
" RAM_KB=\$(awk '/^MemAvailable:/{print \$2}' /proc/meminfo)\n"
80+
" SWAP_KB=\$(awk '/^SwapFree:/{print \$2}' /proc/meminfo)\n"
81+
" RAM_KB=\${RAM_KB:-0}\n"
82+
" SWAP_KB=\${SWAP_KB:-0}\n"
83+
" TOTAL_KB=\$(( RAM_KB + SWAP_KB ))\n"
84+
"elif [ \"\$(uname)\" = \"Darwin\" ]; then\n"
85+
" # macOS: free+speculative pages via vm_stat, free swap via sysctl vm.swapusage\n"
86+
" PAGE_SIZE=\$(pagesize)\n"
87+
" FREE_PAGES=\$(vm_stat | awk '/^Pages free:/{gsub(\"\\\\.\",\"\",\$3); print \$3}')\n"
88+
" SPEC_PAGES=\$(vm_stat | awk '/^Pages speculative:/{gsub(\"\\\\.\",\"\",\$3); print \$3}')\n"
89+
" FREE_PAGES=\${FREE_PAGES:-0}\n"
90+
" SPEC_PAGES=\${SPEC_PAGES:-0}\n"
91+
" RAM_KB=\$(( (FREE_PAGES + SPEC_PAGES) * PAGE_SIZE / 1024 ))\n"
92+
" # sysctl output: 'total = NNN.NNM used = NNN.NNM free = NNN.NNM (encrypted)'\n"
93+
" SWAP_FREE_MB=\$(sysctl -n vm.swapusage 2>/dev/null | sed 's/.*free = \\([0-9.]*\\)M.*/\\1/')\n"
94+
" if [ -n \"\$SWAP_FREE_MB\" ]; then\n"
95+
" SWAP_KB=\$(awk \"BEGIN{printf \\\"%d\\\", \$SWAP_FREE_MB * 1024}\")\n"
96+
" else\n"
97+
" SWAP_KB=0\n"
98+
" fi\n"
99+
" TOTAL_KB=\$(( RAM_KB + SWAP_KB ))\n"
100+
"else\n"
101+
" echo \"testLargeCollections memory check: unsupported OS, assuming enough memory\"\n"
102+
" exit 0\n"
103+
"fi\n"
104+
"echo \"testLargeCollections memory check: available \${TOTAL_KB} kB (RAM \${RAM_KB} + swap \${SWAP_KB}), need \${THRESHOLD_KB} kB\"\n"
105+
"if [ \"\$TOTAL_KB\" -lt \"\$THRESHOLD_KB\" ]; then\n"
106+
" echo \"Insufficient memory -- skipping testLargeCollections\"\n"
107+
" exit 77\n"
108+
"fi\n"
109+
"exit 0\n"
110+
)
111+
execute_process(COMMAND chmod +x ${_memcheck_script})
112+
69113
ROOTTEST_ADD_TEST(testLargeCollections
70114
TIMEOUT 1200
71115
MACRO testLargeCollection.cxx+
72116
OUTREF testLargeCollection.ref
73-
FIXTURES_REQUIRED io-io-testcoll-fixture)
117+
FIXTURES_REQUIRED io-io-testcoll-fixture
118+
PRECMD sh ${_memcheck_script}
119+
PROPERTIES "SKIP_RETURN_CODE;77")
74120
endif()

0 commit comments

Comments
 (0)