blob: 856e1f7f2517f938ad365f81fec57e62a7f1727c [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
Zachary Turnerc7826522014-08-13 17:44:53 +000018 self.main_source = "wait-a-while.cpp"
Jim Ingham35e1bda2012-10-16 21:41:58 +000019 self.main_source_spec = lldb.SBFileSpec (self.main_source)
20
21
Robert Flack13c7ad92015-03-30 14:12:17 +000022 @skipUnlessDarwin
Jim Ingham35e1bda2012-10-16 21:41:58 +000023 @dsym_test
Vince Harrona0c95522015-05-17 15:32:14 +000024 @expectedFailureDarwin # failed 1/134 runs, line 83, value.IsValid()
Jim Ingham35e1bda2012-10-16 21:41:58 +000025 def test_with_dsym(self):
26 """Test calling std::String member function."""
27 self.buildDsym()
28 self.call_function()
29
Ed Maste5c466182014-04-29 17:00:45 +000030 @expectedFailureFreeBSD("llvm.org/pr19605") # fails on buildbot
Vince Harron7ac3ea42015-06-26 15:13:21 +000031 @expectedFlakeyLinux("llvm.org/pr20275")
Jim Ingham35e1bda2012-10-16 21:41:58 +000032 @dwarf_test
33 def test_with_dwarf(self):
34 """Test calling std::String member function."""
Daniel Malead4214f02012-11-12 22:43:13 +000035 self.buildDwarf()
Jim Ingham35e1bda2012-10-16 21:41:58 +000036 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 Claytonc6947512013-12-13 19:18:59 +000051 process = target.LaunchSimple (None, None, self.get_process_working_directory())
Jim Ingham35e1bda2012-10-16 21:41:58 +000052
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 Ingham9435b3c2015-07-25 00:52:38 +000063 options.SetTimeoutInMicroSeconds(10)
Jim Ingham35e1bda2012-10-16 21:41:58 +000064 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 Claytoncced1562012-10-16 22:58:25 +000081 options.SetTimeoutInMicroSeconds(1000000)
Jim Ingham35e1bda2012-10-16 21:41:58 +000082 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 Ingham914f4e72014-03-28 21:58:28 +000093
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 Ingham35e1bda2012-10-16 21:41:58 +0000103if __name__ == '__main__':
104 import atexit
105 lldb.SBDebugger.Initialize()
106 atexit.register(lambda: lldb.SBDebugger.Terminate())
107 unittest2.main()