| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 1 | """ | 
|  | 2 | Test calling a function that waits a while, and make sure the timeout option to expr works. | 
|  | 3 | """ | 
|  | 4 |  | 
| Zachary Turner | 77db4a8 | 2015-10-22 20:06:20 +0000 | [diff] [blame] | 5 | import lldb_shared | 
|  | 6 |  | 
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 7 | import lldb | 
|  | 8 | import lldbutil | 
|  | 9 | from lldbtest import * | 
|  | 10 |  | 
|  | 11 | class ExprCommandWithTimeoutsTestCase(TestBase): | 
|  | 12 |  | 
| Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 13 | mydir = TestBase.compute_mydir(__file__) | 
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 14 |  | 
|  | 15 | def setUp(self): | 
|  | 16 | # Call super's setUp(). | 
|  | 17 | TestBase.setUp(self) | 
|  | 18 |  | 
| Zachary Turner | c782652 | 2014-08-13 17:44:53 +0000 | [diff] [blame] | 19 | self.main_source = "wait-a-while.cpp" | 
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 20 | self.main_source_spec = lldb.SBFileSpec (self.main_source) | 
|  | 21 |  | 
|  | 22 |  | 
| Ed Maste | 1a6ddd5 | 2015-09-16 18:00:09 +0000 | [diff] [blame] | 23 | @expectedFlakeyFreeBSD("llvm.org/pr19605") | 
| Vince Harron | 7ac3ea4 | 2015-06-26 15:13:21 +0000 | [diff] [blame] | 24 | @expectedFlakeyLinux("llvm.org/pr20275") | 
| Zachary Turner | 608cb82 | 2015-09-11 20:00:00 +0000 | [diff] [blame] | 25 | @expectedFailureWindows("llvm.org/pr21765") | 
| Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 26 | def test(self): | 
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 27 | """Test calling std::String member function.""" | 
| Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 28 | self.build() | 
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 29 |  | 
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 30 | exe_name = "a.out" | 
|  | 31 | exe = os.path.join(os.getcwd(), exe_name) | 
|  | 32 |  | 
|  | 33 | target = self.dbg.CreateTarget(exe) | 
|  | 34 | self.assertTrue(target, VALID_TARGET) | 
|  | 35 |  | 
|  | 36 | breakpoint = target.BreakpointCreateBySourceRegex('stop here in main.',self.main_source_spec) | 
|  | 37 | self.assertTrue(breakpoint, VALID_BREAKPOINT) | 
|  | 38 | self.runCmd("breakpoint list") | 
|  | 39 |  | 
|  | 40 | # Launch the process, and do not stop at the entry point. | 
| Greg Clayton | c694751 | 2013-12-13 19:18:59 +0000 | [diff] [blame] | 41 | process = target.LaunchSimple (None, None, self.get_process_working_directory()) | 
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 42 |  | 
|  | 43 | self.assertTrue(process, PROCESS_IS_VALID) | 
|  | 44 |  | 
|  | 45 | # Frame #0 should be on self.step_out_of_malloc. | 
|  | 46 | threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) | 
|  | 47 |  | 
|  | 48 | self.assertTrue(len(threads) == 1) | 
|  | 49 | thread = threads[0] | 
|  | 50 |  | 
|  | 51 | # First set the timeout too short, and make sure we fail. | 
|  | 52 | options = lldb.SBExpressionOptions() | 
| Jim Ingham | 9435b3c | 2015-07-25 00:52:38 +0000 | [diff] [blame] | 53 | options.SetTimeoutInMicroSeconds(10) | 
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 54 | options.SetUnwindOnError(True) | 
|  | 55 |  | 
|  | 56 | frame = thread.GetFrameAtIndex(0) | 
|  | 57 |  | 
| Pavel Labath | c6a144b | 2015-08-20 12:12:09 +0000 | [diff] [blame] | 58 | value = frame.EvaluateExpression ("wait_a_while (50000)", options) | 
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 59 | self.assertTrue (value.IsValid()) | 
| Pavel Labath | c6a144b | 2015-08-20 12:12:09 +0000 | [diff] [blame] | 60 | self.assertFalse (value.GetError().Success()) | 
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 61 |  | 
|  | 62 | # Now do the same thing with the command line command, and make sure it works too. | 
|  | 63 | interp = self.dbg.GetCommandInterpreter() | 
|  | 64 |  | 
|  | 65 | result = lldb.SBCommandReturnObject() | 
| Pavel Labath | c6a144b | 2015-08-20 12:12:09 +0000 | [diff] [blame] | 66 | return_value = interp.HandleCommand ("expr -t 100 -u true -- wait_a_while(50000)", result) | 
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 67 | self.assertTrue (return_value == lldb.eReturnStatusFailed) | 
|  | 68 |  | 
|  | 69 | # Okay, now do it again with long enough time outs: | 
|  | 70 |  | 
| Greg Clayton | cced156 | 2012-10-16 22:58:25 +0000 | [diff] [blame] | 71 | options.SetTimeoutInMicroSeconds(1000000) | 
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 72 | value = frame.EvaluateExpression ("wait_a_while (1000)", options) | 
|  | 73 | self.assertTrue(value.IsValid()) | 
|  | 74 | self.assertTrue (value.GetError().Success() == True) | 
|  | 75 |  | 
|  | 76 | # Now do the same thingwith the command line command, and make sure it works too. | 
|  | 77 | interp = self.dbg.GetCommandInterpreter() | 
|  | 78 |  | 
|  | 79 | result = lldb.SBCommandReturnObject() | 
|  | 80 | return_value = interp.HandleCommand ("expr -t 1000000 -u true -- wait_a_while(1000)", result) | 
|  | 81 | self.assertTrue(return_value == lldb.eReturnStatusSuccessFinishResult) | 
|  | 82 |  | 
| Jim Ingham | 914f4e7 | 2014-03-28 21:58:28 +0000 | [diff] [blame] | 83 |  | 
|  | 84 | # Finally set the one thread timeout and make sure that doesn't change things much: | 
|  | 85 |  | 
|  | 86 | options.SetTimeoutInMicroSeconds(1000000) | 
|  | 87 | options.SetOneThreadTimeoutInMicroSeconds(500000) | 
|  | 88 | value = frame.EvaluateExpression ("wait_a_while (1000)", options) | 
|  | 89 | self.assertTrue(value.IsValid()) | 
|  | 90 | self.assertTrue (value.GetError().Success() == True) |