blob: 768b9b6c63258e6462142a7d4e896c6b040860af [file] [log] [blame]
Jim Inghame81fc8e2011-12-13 04:04:44 +00001"""
2Test that expr will time out and allow other threads to run if it blocks.
3"""
4
5import os, time
6import re
7import unittest2
8import lldb, lldbutil
9from lldbtest import *
10
11class ExprDoesntDeadlockTestCase(TestBase):
12
13 mydir = os.path.join("functionalities", "expr-doesnt-deadlock")
14
15 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
16 def test_with_dsym_and_run_command(self):
17 """Test that expr will time out and allow other threads to run if it blocks - with dsym."""
18 self.buildDsym()
19 self.expr_doesnt_deadlock()
20
21 def test_with_dwarf_and_run_command(self):
22 """Test that expr will time out and allow other threads to run if it blocks."""
23 self.buildDwarf()
24 self.expr_doesnt_deadlock()
25
26 def setUp(self):
27 # Call super's setUp().
28 TestBase.setUp(self)
29
30 def expr_doesnt_deadlock (self):
31 """Test that expr will time out and allow other threads to run if it blocks."""
32 exe = os.path.join(os.getcwd(), "a.out")
33
34 # Create a target by the debugger.
35 target = self.dbg.CreateTarget(exe)
36 self.assertTrue(target, VALID_TARGET)
37
38 # Now create a breakpoint at source line before call_me_to_get_lock gets called.
39
40 main_file_spec = lldb.SBFileSpec ("locking.c")
41 breakpoint = target.BreakpointCreateBySourceRegex('Break here', main_file_spec)
42 print "breakpoint:", breakpoint
43 self.assertTrue(breakpoint and
44 breakpoint.GetNumLocations() == 1,
45 VALID_BREAKPOINT)
46
47 # Now launch the process, and do not stop at entry point.
48 process = target.LaunchSimple(None, None, os.getcwd())
49 self.assertTrue(process, PROCESS_IS_VALID)
50
51 # Frame #0 should be on self.line1 and the break condition should hold.
52 from lldbutil import get_stopped_thread
53 thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
54 self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint condition")
55
56 frame0 = thread.GetFrameAtIndex(0)
57
58 var = frame0.EvaluateExpression ("call_me_to_get_lock()")
59 self.assertTrue (var.IsValid())
60 self.assertTrue (var.GetValueAsSigned (0) == 567)
61
62if __name__ == '__main__':
63 import atexit
64 lldb.SBDebugger.Initialize()
65 atexit.register(lambda: lldb.SBDebugger.Terminate())
66 unittest2.main()