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