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 def getCategories(self): 14 return ['basic_process'] 15 16 mydir = os.path.join("functionalities", "expr-doesnt-deadlock") 17 18 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 19 @dsym_test 20 def test_with_dsym_and_run_command(self): 21 """Test that expr will time out and allow other threads to run if it blocks - with dsym.""" 22 self.buildDsym() 23 self.expr_doesnt_deadlock() 24 25 @dwarf_test 26 @skipIfLinux # llvm.org/pr15258: disabled due to assertion failure in ProcessMonitor::GetCrashReasonForSIGSEGV: 27 def test_with_dwarf_and_run_command(self): 28 """Test that expr will time out and allow other threads to run if it blocks.""" 29 self.buildDwarf() 30 self.expr_doesnt_deadlock() 31 32 def setUp(self): 33 # Call super's setUp(). 34 TestBase.setUp(self) 35 36 def expr_doesnt_deadlock (self): 37 """Test that expr will time out and allow other threads to run if it blocks.""" 38 exe = os.path.join(os.getcwd(), "a.out") 39 40 # Create a target by the debugger. 41 target = self.dbg.CreateTarget(exe) 42 self.assertTrue(target, VALID_TARGET) 43 44 # Now create a breakpoint at source line before call_me_to_get_lock gets called. 45 46 main_file_spec = lldb.SBFileSpec ("locking.c") 47 breakpoint = target.BreakpointCreateBySourceRegex('Break here', main_file_spec) 48 if self.TraceOn(): 49 print "breakpoint:", breakpoint 50 self.assertTrue(breakpoint and 51 breakpoint.GetNumLocations() == 1, 52 VALID_BREAKPOINT) 53 54 # Now launch the process, and do not stop at entry point. 55 process = target.LaunchSimple(None, None, os.getcwd()) 56 self.assertTrue(process, PROCESS_IS_VALID) 57 58 # Frame #0 should be on self.line1 and the break condition should hold. 59 from lldbutil import get_stopped_thread 60 thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) 61 self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint condition") 62 63 frame0 = thread.GetFrameAtIndex(0) 64 65 var = frame0.EvaluateExpression ("call_me_to_get_lock()") 66 self.assertTrue (var.IsValid()) 67 self.assertTrue (var.GetValueAsSigned (0) == 567) 68 69 if __name__ == '__main__': 70 import atexit 71 lldb.SBDebugger.Initialize() 72 atexit.register(lambda: lldb.SBDebugger.Terminate()) 73 unittest2.main() 74