1""" 2Test calling a function that waits a while, and make sure the timeout option to expr works. 3""" 4 5 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12 13class ExprCommandWithTimeoutsTestCase(TestBase): 14 15 def setUp(self): 16 # Call super's setUp(). 17 TestBase.setUp(self) 18 19 self.main_source = "wait-a-while.cpp" 20 self.main_source_spec = lldb.SBFileSpec(self.main_source) 21 22 @expectedFlakeyFreeBSD("llvm.org/pr19605") 23 @expectedFailureAll( 24 oslist=[ 25 "windows"], 26 bugnumber="llvm.org/pr21765") 27 def test(self): 28 """Test calling std::String member function.""" 29 self.build() 30 31 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( 32 self, 'stop here in main.', self.main_source_spec) 33 34 # First set the timeout too short, and make sure we fail. 35 options = lldb.SBExpressionOptions() 36 options.SetTimeoutInMicroSeconds(10) 37 options.SetUnwindOnError(True) 38 39 frame = thread.GetFrameAtIndex(0) 40 41 value = frame.EvaluateExpression("wait_a_while(1000000)", options) 42 self.assertTrue(value.IsValid()) 43 self.assertFalse(value.GetError().Success()) 44 45 # Now do the same thing with the command line command, and make sure it 46 # works too. 47 interp = self.dbg.GetCommandInterpreter() 48 49 result = lldb.SBCommandReturnObject() 50 return_value = interp.HandleCommand( 51 "expr -t 100 -u true -- wait_a_while(1000000)", result) 52 self.assertEquals(return_value, lldb.eReturnStatusFailed) 53 54 # Okay, now do it again with long enough time outs: 55 56 options.SetTimeoutInMicroSeconds(1000000) 57 value = frame.EvaluateExpression("wait_a_while (1000)", options) 58 self.assertTrue(value.IsValid()) 59 self.assertSuccess(value.GetError()) 60 61 # Now do the same thingwith the command line command, and make sure it 62 # works too. 63 interp = self.dbg.GetCommandInterpreter() 64 65 result = lldb.SBCommandReturnObject() 66 return_value = interp.HandleCommand( 67 "expr -t 1000000 -u true -- wait_a_while(1000)", result) 68 self.assertEquals(return_value, lldb.eReturnStatusSuccessFinishResult) 69 70 # Finally set the one thread timeout and make sure that doesn't change 71 # things much: 72 73 options.SetTimeoutInMicroSeconds(1000000) 74 options.SetOneThreadTimeoutInMicroSeconds(500000) 75 value = frame.EvaluateExpression("wait_a_while (1000)", options) 76 self.assertTrue(value.IsValid()) 77 self.assertSuccess(value.GetError()) 78