1 -- Make lldb available in global
4 -- Global assertion functions
6 if not x
then error('assertTrue failure') end
9 function assertFalse(x
)
10 if x
then error('assertNotNil failure') end
13 function assertNotNil(x
)
14 if x
== nil then error('assertNotNil failure') end
17 function assertEquals(x
, y
)
18 if type(x
) == 'table' and type(y
) == 'table' then
19 for k
, _
in pairs(x
) do
20 assertEquals(x
[k
], y
[k
])
22 elseif type(x
) ~= type(y
) then
23 error('assertEquals failure')
25 error('assertEquals failure')
29 function assertStrContains(x
, y
)
30 if not string.find(x
, y
, 1, true) then
31 error('assertStrContains failure')
35 -- Global helper functions
36 function read_file_non_empty_lines(f
)
39 local line
= f
:read('*l')
40 if not line
then break end
41 if line
~= '\n' then table.insert(lines
, line
) end
46 function split_lines(str
)
48 for line
in str
:gmatch("[^\r\n]+") do
49 table.insert(lines
, line
)
54 function get_stopped_threads(process
, reason
)
56 for i
= 0, process
:GetNumThreads() - 1 do
57 local t
= process
:GetThreadAtIndex(i
)
58 if t
:IsValid() and t
:GetStopReason() == reason
then
59 table.insert(threads
, t
)
65 function get_stopped_thread(process
, reason
)
66 local threads
= get_stopped_threads(process
, reason
)
67 if #threads
~= 0 then return threads
[1]
76 local _mt
= { __index
= _m
}
78 function _M
.create_test(name
, exe
, output
, input
)
79 print('[lldb/lua] Create test ' .. name
)
80 exe
= exe
or os
.getenv('TEST_EXE')
81 output
= output
or os
.getenv('TEST_OUTPUT')
82 input
= input
or os
.getenv('TEST_INPUT')
83 lldb
.SBDebugger
.Initialize()
84 local debugger
= lldb
.SBDebugger
.Create()
85 -- Ensure that debugger is created
86 assertNotNil(debugger
)
87 assertTrue(debugger
:IsValid())
89 debugger
:SetAsync(false)
91 local lua_language
= debugger
:GetScriptingLanguage('lua')
92 assertNotNil(lua_language
)
93 debugger
:SetScriptLanguage(lua_language
)
95 local test
= setmetatable({
106 function _m
:create_target(exe
)
108 if not exe
then exe
= self
.exe
end
109 target
= self
.debugger
:CreateTarget(exe
)
110 -- Ensure that target is created
112 assertTrue(target
:IsValid())
116 function _m
:handle_command(command
, collect
)
117 if collect
== nil then collect
= true end
119 local ret
= lldb
.SBCommandReturnObject()
120 local interpreter
= self
.debugger
:GetCommandInterpreter()
121 assertTrue(interpreter
:IsValid())
122 interpreter
:HandleCommand(command
, ret
)
123 self
.debugger
:GetOutputFile():Flush()
124 self
.debugger
:GetErrorFile():Flush()
125 assertTrue(ret
:Succeeded())
126 return ret
:GetOutput()
128 self
.debugger
:HandleCommand(command
)
129 self
.debugger
:GetOutputFile():Flush()
130 self
.debugger
:GetErrorFile():Flush()
136 for k
, v
in pairs(self
) do
137 if string.sub(k
, 1, 4) == 'Test' then
138 table.insert(tests
, k
)
142 for _
, t
in ipairs(tests
) do
143 print('[lldb/lua] Doing test ' .. self
.name
.. ' - ' .. t
)
144 local success
= xpcall(self
[t
], function(e
)
145 print(debug
.traceback())
148 print('[lldb/lua] Failure in test ' .. self
.name
.. ' - ' .. t
)