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