blob: 8aadab735db70c584b5b2fad6a0ef98a824cb518 [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")
Johnny Chenf1548d42012-04-06 00:56:05 +000016 @dsym_test
Jim Inghame81fc8e2011-12-13 04:04:44 +000017 def test_with_dsym_and_run_command(self):
18 """Test that expr will time out and allow other threads to run if it blocks - with dsym."""
19 self.buildDsym()
20 self.expr_doesnt_deadlock()
21
Johnny Chenf1548d42012-04-06 00:56:05 +000022 @dwarf_test
Jim Inghame81fc8e2011-12-13 04:04:44 +000023 def test_with_dwarf_and_run_command(self):
24 """Test that expr will time out and allow other threads to run if it blocks."""
25 self.buildDwarf()
26 self.expr_doesnt_deadlock()
27
28 def setUp(self):
29 # Call super's setUp().
30 TestBase.setUp(self)
31
32 def expr_doesnt_deadlock (self):
33 """Test that expr will time out and allow other threads to run if it blocks."""
34 exe = os.path.join(os.getcwd(), "a.out")
35
36 # Create a target by the debugger.
37 target = self.dbg.CreateTarget(exe)
38 self.assertTrue(target, VALID_TARGET)
39
40 # Now create a breakpoint at source line before call_me_to_get_lock gets called.
41
42 main_file_spec = lldb.SBFileSpec ("locking.c")
43 breakpoint = target.BreakpointCreateBySourceRegex('Break here', main_file_spec)
Johnny Chen798b0c82011-12-14 01:36:04 +000044 if self.TraceOn():
45 print "breakpoint:", breakpoint
Jim Inghame81fc8e2011-12-13 04:04:44 +000046 self.assertTrue(breakpoint and
47 breakpoint.GetNumLocations() == 1,
48 VALID_BREAKPOINT)
49
50 # Now launch the process, and do not stop at entry point.
51 process = target.LaunchSimple(None, None, os.getcwd())
52 self.assertTrue(process, PROCESS_IS_VALID)
53
54 # Frame #0 should be on self.line1 and the break condition should hold.
55 from lldbutil import get_stopped_thread
56 thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
57 self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint condition")
58
59 frame0 = thread.GetFrameAtIndex(0)
60
61 var = frame0.EvaluateExpression ("call_me_to_get_lock()")
62 self.assertTrue (var.IsValid())
63 self.assertTrue (var.GetValueAsSigned (0) == 567)
64
65if __name__ == '__main__':
66 import atexit
67 lldb.SBDebugger.Initialize()
68 atexit.register(lambda: lldb.SBDebugger.Terminate())
69 unittest2.main()