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