blob: 2ec84aee55a69a73ea240870a9c6f420dd78441d [file] [log] [blame]
Johnny Chen80fdd7c2011-10-05 00:42:59 +00001"""
2Test that lldb stop-hook works for multiple threads.
3"""
4
5import os, time
6import unittest2
7import lldb
8import pexpect
9from lldbtest import *
10
11class StopHookForMultipleThreadsTestCase(TestBase):
12
13 mydir = os.path.join("functionalities", "stop-hook", "multiple_threads")
14
15 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
Johnny Chenf1548d42012-04-06 00:56:05 +000016 @dsym_test
Johnny Chen80fdd7c2011-10-05 00:42:59 +000017 def test_stop_hook_multiple_threads_with_dsym(self):
18 """Test that lldb stop-hook works for multiple threads."""
19 self.buildDsym(dictionary=self.d)
20 self.setTearDownCleanup(dictionary=self.d)
21 self.stop_hook_multiple_threads()
22
Johnny Chenf1548d42012-04-06 00:56:05 +000023 @dwarf_test
Johnny Chen80fdd7c2011-10-05 00:42:59 +000024 def test_stop_hook_multiple_threads_with_dwarf(self):
25 """Test that lldb stop-hook works for multiple threads."""
26 self.buildDwarf(dictionary=self.d)
27 self.setTearDownCleanup(dictionary=self.d)
28 self.stop_hook_multiple_threads()
29
30 def setUp(self):
31 # Call super's setUp().
32 TestBase.setUp(self)
33 # Our simple source filename.
34 self.source = 'main.cpp'
35 # Find the line number to break inside main().
36 self.first_stop = line_number(self.source, '// Set break point at this line, and add a stop-hook.')
37 self.thread_function = line_number(self.source, '// Break here to test that the stop-hook mechanism works for multiple threads.')
38 # Build dictionary to have unique executable names for each test method.
39 self.exe_name = self.testMethodName
40 self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}
41
42 def stop_hook_multiple_threads(self):
43 """Test that lldb stop-hook works for multiple threads."""
44 exe = os.path.join(os.getcwd(), self.exe_name)
45 prompt = "(lldb) "
46
47 # So that the child gets torn down after the test.
Johnny Chenebe51722011-10-07 19:21:09 +000048 self.child = pexpect.spawn('%s %s %s' % (self.lldbHere, self.lldbOption, exe))
Johnny Chen80fdd7c2011-10-05 00:42:59 +000049 child = self.child
50 # Turn on logging for what the child sends back.
51 if self.TraceOn():
52 child.logfile_read = sys.stdout
53
54 # Set the breakpoint, followed by the target stop-hook commands.
55 child.expect_exact(prompt)
56 child.sendline('breakpoint set -f main.cpp -l %d' % self.first_stop)
57 child.expect_exact(prompt)
58 child.sendline('breakpoint set -f main.cpp -l %d' % self.thread_function)
59 child.expect_exact(prompt)
60
61 # Now run the program, expect to stop at the the first breakpoint which is within the stop-hook range.
62 child.sendline('run')
63 child.expect_exact(prompt)
64 child.sendline('target stop-hook add -o "frame variable -g g_val"')
65 child.expect_exact(prompt)
66
67 # Continue and expect to find the output emitted by the firing of our stop hook.
68 child.sendline('continue')
69 child.expect_exact('(uint32_t) g_val = ')
70
71
72if __name__ == '__main__':
73 import atexit
74 lldb.SBDebugger.Initialize()
75 atexit.register(lambda: lldb.SBDebugger.Terminate())
76 unittest2.main()