| 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 | |
| 5 | import unittest2 |
| 6 | import lldb |
| 7 | import lldbutil |
| 8 | from lldbtest import * |
| 9 | |
| 10 | class ExprCommandWithTimeoutsTestCase(TestBase): |
| 11 | |
| Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 12 | mydir = TestBase.compute_mydir(__file__) |
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 13 | |
| 14 | def setUp(self): |
| 15 | # Call super's setUp(). |
| 16 | TestBase.setUp(self) |
| 17 | |
| Zachary Turner | c782652 | 2014-08-13 17:44:53 +0000 | [diff] [blame] | 18 | self.main_source = "wait-a-while.cpp" |
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 19 | self.main_source_spec = lldb.SBFileSpec (self.main_source) |
| 20 | |
| 21 | |
| Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame] | 22 | @skipUnlessDarwin |
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 23 | @dsym_test |
| Vince Harron | a0c9552 | 2015-05-17 15:32:14 +0000 | [diff] [blame] | 24 | @expectedFailureDarwin # failed 1/134 runs, line 83, value.IsValid() |
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 25 | def test_with_dsym(self): |
| 26 | """Test calling std::String member function.""" |
| 27 | self.buildDsym() |
| 28 | self.call_function() |
| 29 | |
| Ed Maste | 5c46618 | 2014-04-29 17:00:45 +0000 | [diff] [blame] | 30 | @expectedFailureFreeBSD("llvm.org/pr19605") # fails on buildbot |
| Vince Harron | 7ac3ea4 | 2015-06-26 15:13:21 +0000 | [diff] [blame] | 31 | @expectedFlakeyLinux("llvm.org/pr20275") |
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 32 | @dwarf_test |
| 33 | def test_with_dwarf(self): |
| 34 | """Test calling std::String member function.""" |
| Daniel Malea | d4214f0 | 2012-11-12 22:43:13 +0000 | [diff] [blame] | 35 | self.buildDwarf() |
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 36 | self.call_function() |
| 37 | |
| 38 | def call_function(self): |
| 39 | """Test calling function with timeout.""" |
| 40 | exe_name = "a.out" |
| 41 | exe = os.path.join(os.getcwd(), exe_name) |
| 42 | |
| 43 | target = self.dbg.CreateTarget(exe) |
| 44 | self.assertTrue(target, VALID_TARGET) |
| 45 | |
| 46 | breakpoint = target.BreakpointCreateBySourceRegex('stop here in main.',self.main_source_spec) |
| 47 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
| 48 | self.runCmd("breakpoint list") |
| 49 | |
| 50 | # Launch the process, and do not stop at the entry point. |
| Greg Clayton | c694751 | 2013-12-13 19:18:59 +0000 | [diff] [blame] | 51 | process = target.LaunchSimple (None, None, self.get_process_working_directory()) |
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 52 | |
| 53 | self.assertTrue(process, PROCESS_IS_VALID) |
| 54 | |
| 55 | # Frame #0 should be on self.step_out_of_malloc. |
| 56 | threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) |
| 57 | |
| 58 | self.assertTrue(len(threads) == 1) |
| 59 | thread = threads[0] |
| 60 | |
| 61 | # First set the timeout too short, and make sure we fail. |
| 62 | options = lldb.SBExpressionOptions() |
| Jim Ingham | 9435b3c | 2015-07-25 00:52:38 +0000 | [diff] [blame^] | 63 | options.SetTimeoutInMicroSeconds(10) |
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 64 | options.SetUnwindOnError(True) |
| 65 | |
| 66 | frame = thread.GetFrameAtIndex(0) |
| 67 | |
| 68 | value = frame.EvaluateExpression ("wait_a_while (10000)", options) |
| 69 | self.assertTrue (value.IsValid()) |
| 70 | self.assertTrue (value.GetError().Success() == False) |
| 71 | |
| 72 | # Now do the same thing with the command line command, and make sure it works too. |
| 73 | interp = self.dbg.GetCommandInterpreter() |
| 74 | |
| 75 | result = lldb.SBCommandReturnObject() |
| 76 | return_value = interp.HandleCommand ("expr -t 100 -u true -- wait_a_while(10000)", result) |
| 77 | self.assertTrue (return_value == lldb.eReturnStatusFailed) |
| 78 | |
| 79 | # Okay, now do it again with long enough time outs: |
| 80 | |
| Greg Clayton | cced156 | 2012-10-16 22:58:25 +0000 | [diff] [blame] | 81 | options.SetTimeoutInMicroSeconds(1000000) |
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 82 | value = frame.EvaluateExpression ("wait_a_while (1000)", options) |
| 83 | self.assertTrue(value.IsValid()) |
| 84 | self.assertTrue (value.GetError().Success() == True) |
| 85 | |
| 86 | # Now do the same thingwith the command line command, and make sure it works too. |
| 87 | interp = self.dbg.GetCommandInterpreter() |
| 88 | |
| 89 | result = lldb.SBCommandReturnObject() |
| 90 | return_value = interp.HandleCommand ("expr -t 1000000 -u true -- wait_a_while(1000)", result) |
| 91 | self.assertTrue(return_value == lldb.eReturnStatusSuccessFinishResult) |
| 92 | |
| Jim Ingham | 914f4e7 | 2014-03-28 21:58:28 +0000 | [diff] [blame] | 93 | |
| 94 | # Finally set the one thread timeout and make sure that doesn't change things much: |
| 95 | |
| 96 | options.SetTimeoutInMicroSeconds(1000000) |
| 97 | options.SetOneThreadTimeoutInMicroSeconds(500000) |
| 98 | value = frame.EvaluateExpression ("wait_a_while (1000)", options) |
| 99 | self.assertTrue(value.IsValid()) |
| 100 | self.assertTrue (value.GetError().Success() == True) |
| 101 | |
| 102 | |
| Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 103 | if __name__ == '__main__': |
| 104 | import atexit |
| 105 | lldb.SBDebugger.Initialize() |
| 106 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 107 | unittest2.main() |