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