hate-no-d/tests/cases/11_strings.lua
pedro-bento 449be4c4b7
Some checks failed
release / linux/x86_64 (pull_request) Failing after 1m54s
release / freebsd/x86_64 (pull_request) Successful in 5m1s
release / linux/aarch64 (pull_request) Failing after 1m54s
release / linux/armv7 (pull_request) Failing after 2m12s
release / linux/i686 (pull_request) Failing after 1m59s
release / android (pull_request) Successful in 2m54s
release / windows/i686 (pull_request) Successful in 2m3s
release / windows/x86_64 (pull_request) Successful in 2m15s
probe
2026-10-24 22:20:01 +01:00

47 lines
1.4 KiB
Lua

-- 11: string-returning wrappers copy and free inside the wrapper. This is a
-- regression test for TextInsertAlloc / TextReplaceAlloc / TextReplaceBetweenAlloc
-- and friends: no reference is kept, so RSS must not grow. Valgrind is the
-- authoritative leak check.
local M = dofile("tests/helpers.lua")
local ffi = require("ffi")
local R = M.load()
M.reset()
local b = M.snapshot()
local path = M.tmpfile("hate-no-d string regression\n")
local cps = ffi.new("int[3]", 97, 98, 99)
local out_size = M.out_int()
local failures = {}
local function check(label, v)
if v == nil then failures[#failures + 1] = label end
end
M.gc(2)
local rss0 = M.rss_kb()
for _ = 1, 2000 do
check("LoadFileText", R.LoadFileText(path))
check("LoadUTF8", R.LoadUTF8(cps, 3))
check("EncodeDataBase64", R.EncodeDataBase64("hello", 5, out_size))
check("TextInsertAlloc", R.TextInsertAlloc("abcd", "X", 2))
check("TextReplaceAlloc", R.TextReplaceAlloc("aaaa", "a", "b"))
check("TextReplaceBetweenAlloc",
R.TextReplaceBetweenAlloc("abcdef", "b", "e", "X"))
end
M.gc(3)
local rss1 = M.rss_kb()
os.remove(path)
M.eq(#failures, 0, "wrappers returned nil: " .. table.concat(failures, ", "))
M.eq(M.delta(b, "errors"), 0, "no finalizer errors")
if rss0 > 0 and not M.under_valgrind() then
local growth_kb = rss1 - rss0
M.ok(growth_kb < 20 * 1024, string.format(
"rss grew %d kB across 2000 string iterations (%d -> %d kB)",
growth_kb, rss0, rss1))
end
print("ok 11_strings")