blob: 3fe24e29ea44174eef62c9dcc2e8c8ada99b2a29 [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)
Johnny Chen798b0c82011-12-14 01:36:04 +000042 if self.TraceOn():
43 print "breakpoint:", breakpoint
Jim Inghame81fc8e2011-12-13 04:04:44 +000044 self.assertTrue(breakpoint and
45 breakpoint.GetNumLocations() == 1,
46 VALID_BREAKPOINT)
47
48 # Now launch the process, and do not stop at entry point.
49 process = target.LaunchSimple(None, None, os.getcwd())
50 self.assertTrue(process, PROCESS_IS_VALID)
51
52 # Frame #0 should be on self.line1 and the break condition should hold.
53 from lldbutil import get_stopped_thread
54 thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
55 self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint condition")
56
57 frame0 = thread.GetFrameAtIndex(0)
58
59 var = frame0.EvaluateExpression ("call_me_to_get_lock()")
60 self.assertTrue (var.IsValid())
61 self.assertTrue (var.GetValueAsSigned (0) == 567)
62
63if __name__ == '__main__':
64 import atexit
65 lldb.SBDebugger.Initialize()
66 atexit.register(lambda: lldb.SBDebugger.Terminate())
67 unittest2.main()