1"""
2Test calling a function that waits a while, and make sure the timeout option to expr works.
3"""
4
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class ExprCommandWithTimeoutsTestCase(TestBase):
14
15    mydir = TestBase.compute_mydir(__file__)
16
17    def setUp(self):
18        # Call super's setUp().
19        TestBase.setUp(self)
20
21        self.main_source = "wait-a-while.cpp"
22        self.main_source_spec = lldb.SBFileSpec(self.main_source)
23
24    @expectedFlakeyFreeBSD("llvm.org/pr19605")
25    @expectedFailureAll(
26        oslist=[
27            "windows"],
28        bugnumber="llvm.org/pr21765")
29    def test(self):
30        """Test calling std::String member function."""
31        self.build()
32
33        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
34            self, 'stop here in main.', self.main_source_spec)
35
36        # First set the timeout too short, and make sure we fail.
37        options = lldb.SBExpressionOptions()
38        options.SetTimeoutInMicroSeconds(10)
39        options.SetUnwindOnError(True)
40
41        frame = thread.GetFrameAtIndex(0)
42
43        value = frame.EvaluateExpression("wait_a_while(1000000)", options)
44        self.assertTrue(value.IsValid())
45        self.assertFalse(value.GetError().Success())
46
47        # Now do the same thing with the command line command, and make sure it
48        # works too.
49        interp = self.dbg.GetCommandInterpreter()
50
51        result = lldb.SBCommandReturnObject()
52        return_value = interp.HandleCommand(
53            "expr -t 100 -u true -- wait_a_while(1000000)", result)
54        self.assertEquals(return_value, lldb.eReturnStatusFailed)
55
56        # Okay, now do it again with long enough time outs:
57
58        options.SetTimeoutInMicroSeconds(1000000)
59        value = frame.EvaluateExpression("wait_a_while (1000)", options)
60        self.assertTrue(value.IsValid())
61        self.assertSuccess(value.GetError())
62
63        # Now do the same thingwith the command line command, and make sure it
64        # works too.
65        interp = self.dbg.GetCommandInterpreter()
66
67        result = lldb.SBCommandReturnObject()
68        return_value = interp.HandleCommand(
69            "expr -t 1000000 -u true -- wait_a_while(1000)", result)
70        self.assertEquals(return_value, lldb.eReturnStatusSuccessFinishResult)
71
72        # Finally set the one thread timeout and make sure that doesn't change
73        # things much:
74
75        options.SetTimeoutInMicroSeconds(1000000)
76        options.SetOneThreadTimeoutInMicroSeconds(500000)
77        value = frame.EvaluateExpression("wait_a_while (1000)", options)
78        self.assertTrue(value.IsValid())
79        self.assertSuccess(value.GetError())
80