blob: 96c8364d6546bec0d66d5204c0a7e63aba20cda9 [file] [log] [blame]
Jim Ingham35e1bda2012-10-16 21:41:58 +00001"""
2Test calling a function that waits a while, and make sure the timeout option to expr works.
3"""
4
5import unittest2
6import lldb
7import lldbutil
8from lldbtest import *
9
10class ExprCommandWithTimeoutsTestCase(TestBase):
11
Greg Clayton4570d3e2013-12-10 23:19:29 +000012 mydir = TestBase.compute_mydir(__file__)
Jim Ingham35e1bda2012-10-16 21:41:58 +000013
14 def setUp(self):
15 # Call super's setUp().
16 TestBase.setUp(self)
17
18 self.main_source = "wait-a-while.c"
19 self.main_source_spec = lldb.SBFileSpec (self.main_source)
20
21
22 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
23 @dsym_test
24 def test_with_dsym(self):
25 """Test calling std::String member function."""
26 self.buildDsym()
27 self.call_function()
28
Ed Maste5c466182014-04-29 17:00:45 +000029 @expectedFailureFreeBSD("llvm.org/pr19605") # fails on buildbot
Jim Ingham35e1bda2012-10-16 21:41:58 +000030 @dwarf_test
31 def test_with_dwarf(self):
32 """Test calling std::String member function."""
Daniel Malead4214f02012-11-12 22:43:13 +000033 self.buildDwarf()
Jim Ingham35e1bda2012-10-16 21:41:58 +000034 self.call_function()
35
36 def call_function(self):
37 """Test calling function with timeout."""
38 exe_name = "a.out"
39 exe = os.path.join(os.getcwd(), exe_name)
40
41 target = self.dbg.CreateTarget(exe)
42 self.assertTrue(target, VALID_TARGET)
43
44 breakpoint = target.BreakpointCreateBySourceRegex('stop here in main.',self.main_source_spec)
45 self.assertTrue(breakpoint, VALID_BREAKPOINT)
46 self.runCmd("breakpoint list")
47
48 # Launch the process, and do not stop at the entry point.
Greg Claytonc6947512013-12-13 19:18:59 +000049 process = target.LaunchSimple (None, None, self.get_process_working_directory())
Jim Ingham35e1bda2012-10-16 21:41:58 +000050
51 self.assertTrue(process, PROCESS_IS_VALID)
52
53 # Frame #0 should be on self.step_out_of_malloc.
54 threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
55
56 self.assertTrue(len(threads) == 1)
57 thread = threads[0]
58
59 # First set the timeout too short, and make sure we fail.
60 options = lldb.SBExpressionOptions()
Greg Claytoncced1562012-10-16 22:58:25 +000061 options.SetTimeoutInMicroSeconds(100)
Jim Ingham35e1bda2012-10-16 21:41:58 +000062 options.SetUnwindOnError(True)
63
64 frame = thread.GetFrameAtIndex(0)
65
66 value = frame.EvaluateExpression ("wait_a_while (10000)", options)
67 self.assertTrue (value.IsValid())
68 self.assertTrue (value.GetError().Success() == False)
69
70 # Now do the same thing with the command line command, and make sure it works too.
71 interp = self.dbg.GetCommandInterpreter()
72
73 result = lldb.SBCommandReturnObject()
74 return_value = interp.HandleCommand ("expr -t 100 -u true -- wait_a_while(10000)", result)
75 self.assertTrue (return_value == lldb.eReturnStatusFailed)
76
77 # Okay, now do it again with long enough time outs:
78
Greg Claytoncced1562012-10-16 22:58:25 +000079 options.SetTimeoutInMicroSeconds(1000000)
Jim Ingham35e1bda2012-10-16 21:41:58 +000080 value = frame.EvaluateExpression ("wait_a_while (1000)", options)
81 self.assertTrue(value.IsValid())
82 self.assertTrue (value.GetError().Success() == True)
83
84 # Now do the same thingwith the command line command, and make sure it works too.
85 interp = self.dbg.GetCommandInterpreter()
86
87 result = lldb.SBCommandReturnObject()
88 return_value = interp.HandleCommand ("expr -t 1000000 -u true -- wait_a_while(1000)", result)
89 self.assertTrue(return_value == lldb.eReturnStatusSuccessFinishResult)
90
Jim Ingham914f4e72014-03-28 21:58:28 +000091
92 # Finally set the one thread timeout and make sure that doesn't change things much:
93
94 options.SetTimeoutInMicroSeconds(1000000)
95 options.SetOneThreadTimeoutInMicroSeconds(500000)
96 value = frame.EvaluateExpression ("wait_a_while (1000)", options)
97 self.assertTrue(value.IsValid())
98 self.assertTrue (value.GetError().Success() == True)
99
100
Jim Ingham35e1bda2012-10-16 21:41:58 +0000101if __name__ == '__main__':
102 import atexit
103 lldb.SBDebugger.Initialize()
104 atexit.register(lambda: lldb.SBDebugger.Terminate())
105 unittest2.main()