mirror of https://github.com/rusefi/lua.git
New test module 'tracegc'
New module easies the inclusion of GC tracing in individual test files.
This commit is contained in:
parent
f9d857a81b
commit
5276973224
|
@ -154,18 +154,8 @@ end
|
||||||
|
|
||||||
dofile('main.lua')
|
dofile('main.lua')
|
||||||
|
|
||||||
do
|
-- trace GC cycles
|
||||||
local next, setmetatable, stderr = next, setmetatable, io.stderr
|
require"tracegc".start()
|
||||||
-- track collections
|
|
||||||
local mt = {}
|
|
||||||
-- each time a table is collected, remark it for finalization
|
|
||||||
-- on next cycle
|
|
||||||
mt.__gc = function (o)
|
|
||||||
stderr:write'.' -- mark progress
|
|
||||||
local n = setmetatable(o, mt) -- remark it
|
|
||||||
end
|
|
||||||
local n = setmetatable({}, mt) -- create object
|
|
||||||
end
|
|
||||||
|
|
||||||
report"gc.lua"
|
report"gc.lua"
|
||||||
local f = assert(loadfile('gc.lua'))
|
local f = assert(loadfile('gc.lua'))
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
-- See Copyright Notice in file all.lua
|
-- See Copyright Notice in file all.lua
|
||||||
|
|
||||||
|
|
||||||
|
local tracegc = require"tracegc"
|
||||||
|
|
||||||
print"testing stack overflow detection"
|
print"testing stack overflow detection"
|
||||||
|
|
||||||
-- Segmentation faults in these tests probably result from a C-stack
|
-- Segmentation faults in these tests probably result from a C-stack
|
||||||
|
@ -21,7 +23,9 @@ do print("testing stack overflow in message handling")
|
||||||
count = count + 1
|
count = count + 1
|
||||||
return 1 + loop(x, y, z)
|
return 1 + loop(x, y, z)
|
||||||
end
|
end
|
||||||
|
tracegc.stop() -- __gc should not be called with a full stack
|
||||||
local res, msg = xpcall(loop, loop)
|
local res, msg = xpcall(loop, loop)
|
||||||
|
tracegc.start()
|
||||||
assert(msg == "error in error handling")
|
assert(msg == "error in error handling")
|
||||||
print("final count: ", count)
|
print("final count: ", count)
|
||||||
end
|
end
|
||||||
|
@ -135,18 +139,18 @@ if T then
|
||||||
local topB, sizeB -- top and size Before overflow
|
local topB, sizeB -- top and size Before overflow
|
||||||
local topA, sizeA -- top and size After overflow
|
local topA, sizeA -- top and size After overflow
|
||||||
topB, sizeB = T.stacklevel()
|
topB, sizeB = T.stacklevel()
|
||||||
collectgarbage("stop") -- __gc should not be called with a full stack
|
tracegc.stop() -- __gc should not be called with a full stack
|
||||||
xpcall(f, err)
|
xpcall(f, err)
|
||||||
collectgarbage("restart")
|
tracegc.start()
|
||||||
topA, sizeA = T.stacklevel()
|
topA, sizeA = T.stacklevel()
|
||||||
-- sizes should be comparable
|
-- sizes should be comparable
|
||||||
assert(topA == topB and sizeA < sizeB * 2)
|
assert(topA == topB and sizeA < sizeB * 2)
|
||||||
print(string.format("maximum stack size: %d", stack1))
|
print(string.format("maximum stack size: %d", stack1))
|
||||||
LIM = N -- will stop recursion at maximum level
|
LIM = N -- will stop recursion at maximum level
|
||||||
N = 0 -- to count again
|
N = 0 -- to count again
|
||||||
collectgarbage("stop") -- __gc should not be called with a full stack
|
tracegc.stop() -- __gc should not be called with a full stack
|
||||||
f()
|
f()
|
||||||
collectgarbage("restart")
|
tracegc.start()
|
||||||
print"+"
|
print"+"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@ print('testing local variables and environments')
|
||||||
|
|
||||||
local debug = require"debug"
|
local debug = require"debug"
|
||||||
|
|
||||||
|
local tracegc = require"tracegc"
|
||||||
|
|
||||||
|
|
||||||
-- bug in 5.1:
|
-- bug in 5.1:
|
||||||
|
|
||||||
|
@ -554,9 +556,9 @@ do -- test for tbc variable high in the stack
|
||||||
obj[1] = 100
|
obj[1] = 100
|
||||||
flag = obj
|
flag = obj
|
||||||
end)
|
end)
|
||||||
collectgarbage("stop")
|
tracegc.stop()
|
||||||
st, obj = xpcall(overflow, errorh, 0)
|
st, obj = xpcall(overflow, errorh, 0)
|
||||||
collectgarbage("restart")
|
tracegc.start()
|
||||||
end)
|
end)
|
||||||
co()
|
co()
|
||||||
assert(not st and obj[1] == 10 and flag[1] == 100)
|
assert(not st and obj[1] == 10 and flag[1] == 100)
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
-- track collections
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
-- import list
|
||||||
|
local setmetatable, stderr, collectgarbage =
|
||||||
|
setmetatable, io.stderr, collectgarbage
|
||||||
|
|
||||||
|
_ENV = nil
|
||||||
|
|
||||||
|
local active = false
|
||||||
|
|
||||||
|
|
||||||
|
-- each time a table is collected, remark it for finalization on next
|
||||||
|
-- cycle
|
||||||
|
local mt = {}
|
||||||
|
function mt.__gc (o)
|
||||||
|
stderr:write'.' -- mark progress
|
||||||
|
if active then
|
||||||
|
setmetatable(o, mt) -- remark object for finalization
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function M.start ()
|
||||||
|
if not active then
|
||||||
|
active = true
|
||||||
|
setmetatable({}, mt) -- create initial object
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function M.stop ()
|
||||||
|
if active then
|
||||||
|
active = false
|
||||||
|
collectgarbage() -- call finalizer for the last time
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
Loading…
Reference in New Issue