]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/expression_command/timeout/TestCallWithTimeout.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / expression_command / timeout / TestCallWithTimeout.py
1 """
2 Test calling a function that waits a while, and make sure the timeout option to expr works.
3 """
4
5 from __future__ import print_function
6
7
8 import lldb
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
12
13
14 class ExprCommandWithTimeoutsTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
18     def setUp(self):
19         # Call super's setUp().
20         TestBase.setUp(self)
21
22         self.main_source = "wait-a-while.cpp"
23         self.main_source_spec = lldb.SBFileSpec(self.main_source)
24
25     @expectedFlakeyFreeBSD("llvm.org/pr19605")
26     @expectedFailureAll(
27         oslist=[
28             "windows",
29             "macosx"],
30         bugnumber="llvm.org/pr21765")
31     def test(self):
32         """Test calling std::String member function."""
33         self.build()
34
35         exe_name = "a.out"
36         exe = os.path.join(os.getcwd(), exe_name)
37
38         target = self.dbg.CreateTarget(exe)
39         self.assertTrue(target, VALID_TARGET)
40
41         breakpoint = target.BreakpointCreateBySourceRegex(
42             'stop here in main.', self.main_source_spec)
43         self.assertTrue(breakpoint, VALID_BREAKPOINT)
44         self.runCmd("breakpoint list")
45
46         # Launch the process, and do not stop at the entry point.
47         process = target.LaunchSimple(
48             None, None, self.get_process_working_directory())
49
50         self.assertTrue(process, PROCESS_IS_VALID)
51
52         # Frame #0 should be on self.step_out_of_malloc.
53         threads = lldbutil.get_threads_stopped_at_breakpoint(
54             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()
61         options.SetTimeoutInMicroSeconds(10)
62         options.SetUnwindOnError(True)
63
64         frame = thread.GetFrameAtIndex(0)
65
66         value = frame.EvaluateExpression("wait_a_while(1000000)", options)
67         self.assertTrue(value.IsValid())
68         self.assertFalse(value.GetError().Success())
69
70         # Now do the same thing with the command line command, and make sure it
71         # works too.
72         interp = self.dbg.GetCommandInterpreter()
73
74         result = lldb.SBCommandReturnObject()
75         return_value = interp.HandleCommand(
76             "expr -t 100 -u true -- wait_a_while(1000000)", result)
77         self.assertTrue(return_value == lldb.eReturnStatusFailed)
78
79         # Okay, now do it again with long enough time outs:
80
81         options.SetTimeoutInMicroSeconds(1000000)
82         value = frame.EvaluateExpression("wait_a_while (1000)", options)
83         self.assertTrue(value.IsValid())
84         self.assertTrue(value.GetError().Success())
85
86         # Now do the same thingwith the command line command, and make sure it
87         # works too.
88         interp = self.dbg.GetCommandInterpreter()
89
90         result = lldb.SBCommandReturnObject()
91         return_value = interp.HandleCommand(
92             "expr -t 1000000 -u true -- wait_a_while(1000)", result)
93         self.assertTrue(return_value == lldb.eReturnStatusSuccessFinishResult)
94
95         # Finally set the one thread timeout and make sure that doesn't change
96         # things much:
97
98         options.SetTimeoutInMicroSeconds(1000000)
99         options.SetOneThreadTimeoutInMicroSeconds(500000)
100         value = frame.EvaluateExpression("wait_a_while (1000)", options)
101         self.assertTrue(value.IsValid())
102         self.assertTrue(value.GetError().Success())