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