Jim Ingham | e81fc8e | 2011-12-13 04:04:44 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test that expr will time out and allow other threads to run if it blocks. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import re |
| 7 | import unittest2 |
| 8 | import lldb, lldbutil |
| 9 | from lldbtest import * |
| 10 | |
| 11 | class ExprDoesntDeadlockTestCase(TestBase): |
| 12 | |
| 13 | mydir = os.path.join("functionalities", "expr-doesnt-deadlock") |
| 14 | |
| 15 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
Johnny Chen | f1548d4 | 2012-04-06 00:56:05 +0000 | [diff] [blame] | 16 | @dsym_test |
Jim Ingham | e81fc8e | 2011-12-13 04:04:44 +0000 | [diff] [blame] | 17 | 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 Chen | f1548d4 | 2012-04-06 00:56:05 +0000 | [diff] [blame] | 22 | @dwarf_test |
Daniel Malea | 34f21d1 | 2012-12-19 17:19:28 +0000 | [diff] [blame] | 23 | @expectedFailureLinux # due to bugzilla 14437 |
Jim Ingham | e81fc8e | 2011-12-13 04:04:44 +0000 | [diff] [blame] | 24 | 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 Chen | 798b0c8 | 2011-12-14 01:36:04 +0000 | [diff] [blame] | 45 | if self.TraceOn(): |
| 46 | print "breakpoint:", breakpoint |
Jim Ingham | e81fc8e | 2011-12-13 04:04:44 +0000 | [diff] [blame] | 47 | 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 | |
| 66 | if __name__ == '__main__': |
| 67 | import atexit |
| 68 | lldb.SBDebugger.Initialize() |
| 69 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 70 | unittest2.main() |