blob: 6e3e8879073980b8116a05375141c29dd9dfb378 [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
Zachary Turner35d017f2015-10-23 17:04:29 +00005from __future__ import print_function
6
Zachary Turner0a0490b2015-10-27 20:12:05 +00007import use_lldb_suite
Zachary Turner77db4a82015-10-22 20:06:20 +00008
Jim Ingham35e1bda2012-10-16 21:41:58 +00009import lldb
10import lldbutil
11from lldbtest import *
12
13class ExprCommandWithTimeoutsTestCase(TestBase):
14
Greg Clayton4570d3e2013-12-10 23:19:29 +000015 mydir = TestBase.compute_mydir(__file__)
Jim Ingham35e1bda2012-10-16 21:41:58 +000016
17 def setUp(self):
18 # Call super's setUp().
19 TestBase.setUp(self)
20
Zachary Turnerc7826522014-08-13 17:44:53 +000021 self.main_source = "wait-a-while.cpp"
Jim Ingham35e1bda2012-10-16 21:41:58 +000022 self.main_source_spec = lldb.SBFileSpec (self.main_source)
23
24
Ed Maste1a6ddd52015-09-16 18:00:09 +000025 @expectedFlakeyFreeBSD("llvm.org/pr19605")
Vince Harron7ac3ea42015-06-26 15:13:21 +000026 @expectedFlakeyLinux("llvm.org/pr20275")
Zachary Turner608cb822015-09-11 20:00:00 +000027 @expectedFailureWindows("llvm.org/pr21765")
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000028 def test(self):
Jim Ingham35e1bda2012-10-16 21:41:58 +000029 """Test calling std::String member function."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000030 self.build()
Jim Ingham35e1bda2012-10-16 21:41:58 +000031
Jim Ingham35e1bda2012-10-16 21:41:58 +000032 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 Claytonc6947512013-12-13 19:18:59 +000043 process = target.LaunchSimple (None, None, self.get_process_working_directory())
Jim Ingham35e1bda2012-10-16 21:41:58 +000044
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 Ingham9435b3c2015-07-25 00:52:38 +000055 options.SetTimeoutInMicroSeconds(10)
Jim Ingham35e1bda2012-10-16 21:41:58 +000056 options.SetUnwindOnError(True)
57
58 frame = thread.GetFrameAtIndex(0)
59
Pavel Labathc6a144b2015-08-20 12:12:09 +000060 value = frame.EvaluateExpression ("wait_a_while (50000)", options)
Jim Ingham35e1bda2012-10-16 21:41:58 +000061 self.assertTrue (value.IsValid())
Pavel Labathc6a144b2015-08-20 12:12:09 +000062 self.assertFalse (value.GetError().Success())
Jim Ingham35e1bda2012-10-16 21:41:58 +000063
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 Labathc6a144b2015-08-20 12:12:09 +000068 return_value = interp.HandleCommand ("expr -t 100 -u true -- wait_a_while(50000)", result)
Jim Ingham35e1bda2012-10-16 21:41:58 +000069 self.assertTrue (return_value == lldb.eReturnStatusFailed)
70
71 # Okay, now do it again with long enough time outs:
72
Greg Claytoncced1562012-10-16 22:58:25 +000073 options.SetTimeoutInMicroSeconds(1000000)
Jim Ingham35e1bda2012-10-16 21:41:58 +000074 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 Ingham914f4e72014-03-28 21:58:28 +000085
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)