|
| 1 | +return { |
| 2 | + groupName = "HolyLib manages to properly Get HolyLib Referenced UserData to Lua", |
| 3 | + cases = { |
| 4 | + { |
| 5 | + name = "Is _HOLYLIB_CORE.GetReferencedTestUserData function existent", |
| 6 | + func = function() |
| 7 | + expect( _HOLYLIB_CORE.GetReferencedTestUserData ).to.beA( "function" ) |
| 8 | + end |
| 9 | + }, |
| 10 | + { |
| 11 | + name = "Properly got the valid pointer to our userdata", |
| 12 | + func = function() |
| 13 | + local userdata = _HOLYLIB_CORE.PushReferencedTestUserData() |
| 14 | + expect( userdata ).to.beA( "_HOLYLIB_CORE_TEST_REFERENCED" ) |
| 15 | + |
| 16 | + -- If we got a garbage pointer, this will return false or crash. |
| 17 | + expect( _HOLYLIB_CORE.GetReferencedTestUserData(userdata) ).to.beTrue() |
| 18 | + end |
| 19 | + }, |
| 20 | + { |
| 21 | + name = "__newindex and __index functions properly work on userdata", |
| 22 | + func = function() |
| 23 | + local userdata = _HOLYLIB_CORE.PushReferencedTestUserData() |
| 24 | + expect( userdata ).to.beA( "_HOLYLIB_CORE_TEST_REFERENCED" ) |
| 25 | + |
| 26 | + userdata.example = "Hello World" |
| 27 | + |
| 28 | + expect( userdata.example ).to.equal( "Hello World" ) |
| 29 | + end |
| 30 | + }, |
| 31 | + { |
| 32 | + name = "Performance", |
| 33 | + func = function() |
| 34 | + local userdata = _HOLYLIB_CORE.PushReferencedTestUserData() |
| 35 | + HolyLib_RunPerformanceTest("_HOLYLIB_CORE.GetReferencedTestUserData", _HOLYLIB_CORE.RawReferencedGetTestUserData, userdata) |
| 36 | + |
| 37 | + HolyLib_RunPerformanceTest("_HOLYLIB_CORE.__newindex", function(userdata) userdata.example = "Hello World" end, userdata) |
| 38 | + HolyLib_RunPerformanceTest("_HOLYLIB_CORE.__index", function(userdata) return userdata.example end, userdata) |
| 39 | + end |
| 40 | + }, |
| 41 | + { |
| 42 | + name = "LuaJIT traces do not create a crash", |
| 43 | + async = true, |
| 44 | + timeout = 5, |
| 45 | + func = function() |
| 46 | + --[[ |
| 47 | + Very specific crash caused by LuaJIT generating a GCtrace which then for very magical reasons can lead to memory corruption of userdata |
| 48 | + ]] |
| 49 | + |
| 50 | + function generate_trace() |
| 51 | + jit.opt.start("hotloop=1", "hotexit=1") |
| 52 | + jit.flush() |
| 53 | + |
| 54 | + --[[jit.attach(function(what, traceno, func, pc, exitno) |
| 55 | + if exitno ~= nil then what = "abort" end |
| 56 | +
|
| 57 | + local src = "<unknown>" |
| 58 | + if type(func) == "function" or type(func) == "proto" then |
| 59 | + local info = jit.util.funcinfo(func) |
| 60 | + if info then |
| 61 | + src = string.format("%s:%d", info.source or "C", info.linedefined or 0) |
| 62 | + end |
| 63 | + elseif func ~= nil then |
| 64 | + src = tostring(func) |
| 65 | + end |
| 66 | +
|
| 67 | + print(string.format("[TRACE] %-6s %s %-35s pc=%s exit=%s", |
| 68 | + tostring(what), |
| 69 | + tostring(traceno or "?"), |
| 70 | + tostring(src), |
| 71 | + tostring(pc or "-"), |
| 72 | + tostring(exitno or "-") |
| 73 | + )) |
| 74 | + end, "trace")]] |
| 75 | + |
| 76 | + local function trace_userdata(u) |
| 77 | + return u.test |
| 78 | + end |
| 79 | + |
| 80 | + local userData = _HOLYLIB_CORE.PushReferencedTestUserData() |
| 81 | + for n = 1, 1e4 do -- Generate those sweet GCtrace |
| 82 | + trace_userdata(userData) |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | + generate_trace() |
| 87 | + |
| 88 | + timer.Simple(1, function() |
| 89 | + collectgarbage("collect") |
| 90 | + |
| 91 | + timer.Simple(1, function() |
| 92 | + generate_trace() -- If this crashes, we got a problem... |
| 93 | + |
| 94 | + done() |
| 95 | + end) |
| 96 | + end) |
| 97 | + end |
| 98 | + }, |
| 99 | + } |
| 100 | +} |
0 commit comments