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") |
| 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 Chen | 798b0c8 | 2011-12-14 01:36:04 +0000 | [diff] [blame^] | 42 | if self.TraceOn(): |
| 43 | print "breakpoint:", breakpoint |
Jim Ingham | e81fc8e | 2011-12-13 04:04:44 +0000 | [diff] [blame] | 44 | 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 | |
| 63 | if __name__ == '__main__': |
| 64 | import atexit |
| 65 | lldb.SBDebugger.Initialize() |
| 66 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 67 | unittest2.main() |