blob: e63cebede5236781732dca522aff78ca7d934e9b [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 Turner77db4a82015-10-22 20:06:20 +00005import lldb_shared
6
Jim Ingham35e1bda2012-10-16 21:41:58 +00007import lldb
8import lldbutil
9from lldbtest import *
10
11class ExprCommandWithTimeoutsTestCase(TestBase):
12
Greg Clayton4570d3e2013-12-10 23:19:29 +000013 mydir = TestBase.compute_mydir(__file__)
Jim Ingham35e1bda2012-10-16 21:41:58 +000014
15 def setUp(self):
16 # Call super's setUp().
17 TestBase.setUp(self)
18
Zachary Turnerc7826522014-08-13 17:44:53 +000019 self.main_source = "wait-a-while.cpp"
Jim Ingham35e1bda2012-10-16 21:41:58 +000020 self.main_source_spec = lldb.SBFileSpec (self.main_source)
21
22
Ed Maste1a6ddd52015-09-16 18:00:09 +000023 @expectedFlakeyFreeBSD("llvm.org/pr19605")
Vince Harron7ac3ea42015-06-26 15:13:21 +000024 @expectedFlakeyLinux("llvm.org/pr20275")
Zachary Turner608cb822015-09-11 20:00:00 +000025 @expectedFailureWindows("llvm.org/pr21765")
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000026 def test(self):
Jim Ingham35e1bda2012-10-16 21:41:58 +000027 """Test calling std::String member function."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000028 self.build()
Jim Ingham35e1bda2012-10-16 21:41:58 +000029
Jim Ingham35e1bda2012-10-16 21:41:58 +000030 exe_name = "a.out"
31 exe = os.path.join(os.getcwd(), exe_name)
32
33 target = self.dbg.CreateTarget(exe)
34 self.assertTrue(target, VALID_TARGET)
35
36 breakpoint = target.BreakpointCreateBySourceRegex('stop here in main.',self.main_source_spec)
37 self.assertTrue(breakpoint, VALID_BREAKPOINT)
38 self.runCmd("breakpoint list")
39
40 # Launch the process, and do not stop at the entry point.
Greg Claytonc6947512013-12-13 19:18:59 +000041 process = target.LaunchSimple (None, None, self.get_process_working_directory())
Jim Ingham35e1bda2012-10-16 21:41:58 +000042
43 self.assertTrue(process, PROCESS_IS_VALID)
44
45 # Frame #0 should be on self.step_out_of_malloc.
46 threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint)
47
48 self.assertTrue(len(threads) == 1)
49 thread = threads[0]
50
51 # First set the timeout too short, and make sure we fail.
52 options = lldb.SBExpressionOptions()
Jim Ingham9435b3c2015-07-25 00:52:38 +000053 options.SetTimeoutInMicroSeconds(10)
Jim Ingham35e1bda2012-10-16 21:41:58 +000054 options.SetUnwindOnError(True)
55
56 frame = thread.GetFrameAtIndex(0)
57
Pavel Labathc6a144b2015-08-20 12:12:09 +000058 value = frame.EvaluateExpression ("wait_a_while (50000)", options)
Jim Ingham35e1bda2012-10-16 21:41:58 +000059 self.assertTrue (value.IsValid())
Pavel Labathc6a144b2015-08-20 12:12:09 +000060 self.assertFalse (value.GetError().Success())
Jim Ingham35e1bda2012-10-16 21:41:58 +000061
62 # Now do the same thing with the command line command, and make sure it works too.
63 interp = self.dbg.GetCommandInterpreter()
64
65 result = lldb.SBCommandReturnObject()
Pavel Labathc6a144b2015-08-20 12:12:09 +000066 return_value = interp.HandleCommand ("expr -t 100 -u true -- wait_a_while(50000)", result)
Jim Ingham35e1bda2012-10-16 21:41:58 +000067 self.assertTrue (return_value == lldb.eReturnStatusFailed)
68
69 # Okay, now do it again with long enough time outs:
70
Greg Claytoncced1562012-10-16 22:58:25 +000071 options.SetTimeoutInMicroSeconds(1000000)
Jim Ingham35e1bda2012-10-16 21:41:58 +000072 value = frame.EvaluateExpression ("wait_a_while (1000)", options)
73 self.assertTrue(value.IsValid())
74 self.assertTrue (value.GetError().Success() == True)
75
76 # Now do the same thingwith the command line command, and make sure it works too.
77 interp = self.dbg.GetCommandInterpreter()
78
79 result = lldb.SBCommandReturnObject()
80 return_value = interp.HandleCommand ("expr -t 1000000 -u true -- wait_a_while(1000)", result)
81 self.assertTrue(return_value == lldb.eReturnStatusSuccessFinishResult)
82
Jim Ingham914f4e72014-03-28 21:58:28 +000083
84 # Finally set the one thread timeout and make sure that doesn't change things much:
85
86 options.SetTimeoutInMicroSeconds(1000000)
87 options.SetOneThreadTimeoutInMicroSeconds(500000)
88 value = frame.EvaluateExpression ("wait_a_while (1000)", options)
89 self.assertTrue(value.IsValid())
90 self.assertTrue (value.GetError().Success() == True)