llvm-project
99 строк · 3.2 Кб
1_T = require('lua_lldb_test').create_test('TestComprehensive')
2
3function _T:Test0_CreateTarget()
4self.target = self:create_target()
5assertTrue(self.target:IsValid())
6end
7
8function _T:Test1_Breakpoint()
9self.main_bp = self.target:BreakpointCreateByName('main', 'a.out')
10self.loop_bp = self.target:BreakpointCreateByLocation('main.c', 28)
11assertTrue(self.main_bp:IsValid() and self.main_bp:GetNumLocations() == 1)
12assertTrue(self.loop_bp:IsValid() and self.loop_bp:GetNumLocations() == 1)
13end
14
15function _T:Test2_Launch()
16local error = lldb.SBError()
17self.args = { 'arg' }
18self.process = self.target:Launch(
19self.debugger:GetListener(),
20self.args,
21nil,
22nil,
23self.output,
24nil,
25nil,
260,
27false,
28error
29)
30assertTrue(error:Success())
31assertTrue(self.process:IsValid())
32end
33
34function _T:Test3_BreakpointFindVariables()
35-- checking "argc" value
36local thread = get_stopped_thread(self.process, lldb.eStopReasonBreakpoint)
37assertNotNil(thread)
38assertTrue(thread:IsValid())
39local frame = thread:GetFrameAtIndex(0)
40assertTrue(frame:IsValid())
41local error = lldb.SBError()
42local var_argc = frame:FindVariable('argc')
43assertTrue(var_argc:IsValid())
44local var_argc_value = var_argc:GetValueAsSigned(error, 0)
45assertTrue(error:Success())
46assertEqual(var_argc_value, 2)
47
48-- checking "inited" value
49local continue = self.process:Continue()
50assertTrue(continue:Success())
51thread = get_stopped_thread(self.process, lldb.eStopReasonBreakpoint)
52assertNotNil(thread)
53assertTrue(thread:IsValid())
54frame = thread:GetFrameAtIndex(0)
55assertTrue(frame:IsValid())
56error = lldb.SBError()
57local var_inited = frame:FindVariable('inited')
58assertTrue(var_inited:IsValid())
59self.var_inited = var_inited
60local var_inited_value = var_inited:GetValueAsUnsigned(error, 0)
61assertTrue(error:Success())
62assertEqual(var_inited_value, 0xDEADBEEF)
63end
64
65function _T:Test3_RawData()
66local error = lldb.SBError()
67local address = self.var_inited:GetAddress()
68assertTrue(address:IsValid())
69local size = self.var_inited:GetByteSize()
70local raw_data = self.process:ReadMemory(address:GetOffset(), size, error)
71assertTrue(error:Success())
72local data_le = lldb.SBData.CreateDataFromUInt32Array(lldb.eByteOrderLittle, 1, {0xDEADBEEF})
73local data_be = lldb.SBData.CreateDataFromUInt32Array(lldb.eByteOrderBig, 1, {0xDEADBEEF})
74assertTrue(data_le:GetUnsignedInt32(error, 0) == 0xDEADBEEF or data_be:GetUnsignedInt32(error, 0) == 0xDEADBEEF)
75assertTrue(raw_data == "\xEF\xBE\xAD\xDE" or raw_data == "\xDE\xAD\xBE\xEF")
76end
77
78function _T:Test4_ProcessExit()
79self.loop_bp:SetAutoContinue(true)
80local continue = self.process:Continue()
81assertTrue(continue:Success())
82assertTrue(self.process:GetExitStatus() == 0)
83end
84
85function _T:Test5_FileOutput()
86local f = io.open(self.output, 'r')
87assertEqual(
88read_file_non_empty_lines(f),
89{
90self.exe,
91table.unpack(self.args),
92'I am a function.',
93'sum = 5050'
94}
95)
96f:close()
97end
98
99os.exit(_T:run())
100