/
ihtiandr9
/
gc_learn
Обзор
Документация
Войти
/
ihtiandr9
/
gc_learn
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
test_oom.lua
64 строки
2 KB
user@krolik-note
replace malloc with local-heap allocator; port tests to Lua; add third_party/lua
10 июн 2026, 15:50
10 июн 2026, 15:50
9638131
Код
Авторство
О чём код?
#!/usr/bin/env lua --[[ Test: fill heap until OOM, verify GC recovers. ]] local BASE = arg[0]:match("^(.+)/") or "." local BUILD = BASE .. "/build" local BINARY = BUILD .. "/gc_basic" local function run_test(n, slen) local val = string.rep("X", slen) local cmds = {} for _ = 1, n do cmds[#cmds + 1] = string.format('LET A$ = "%s"', val) end cmds[#cmds + 1] = "STATUS" cmds[#cmds + 1] = "GC" cmds[#cmds + 1] = "STATUS" cmds[#cmds + 1] = "QUIT" local tmp = os.tmpname() local f = io.open(tmp, "w") f:write(table.concat(cmds, "\n")) f:close() local p = io.popen(BINARY .. " < " .. tmp .. " 2>&1", "r") local out = p:read("*a") p:close() os.remove(tmp) return out end local function main() print("=== Building ===") os.execute("cmake -S " .. BASE .. " -B " .. BUILD .. " >/dev/null 2>&1") os.execute("cmake --build " .. BUILD .. " -j 2>&1") print("Build OK\n") print("=== Test: flood heap with garbage strings ===") local output = run_test(700, 50) for line in output:gmatch("([^\n]+)") do for _, kw in ipairs({"Out of memory", "Heap usage", "After GC", "All variables", "FATAL"}) do if line:find(kw, 1, true) then print(line) break end end end print() if output:find("Out of memory", 1, true) then print("PASS: OOM was triggered, GC recovered") elseif output:find("FATAL", 1, true) then print("FAIL: OOM after GC was fatal") else print("SKIP: OOM was not triggered (heap large enough)") end end main()