1"""
2Test that expr will time out and allow other threads to run if it blocks.
3"""
4
5from __future__ import print_function
6
7
8import lldb
9from lldbsuite.test.decorators import *
10from lldbsuite.test.lldbtest import *
11from lldbsuite.test import lldbutil
12
13
14class ExprDoesntDeadlockTestCase(TestBase):
15
16    mydir = TestBase.compute_mydir(__file__)
17
18    @add_test_categories(["basic_process"])
19    def test_with_run_command(self):
20        """Test that expr will time out and allow other threads to run if it blocks."""
21        self.build()
22        target = self.createTestTarget()
23
24        # Now create a breakpoint at source line before call_me_to_get_lock
25        # gets called.
26
27        main_file_spec = lldb.SBFileSpec("locking.cpp")
28        breakpoint = target.BreakpointCreateBySourceRegex(
29            'Break here', main_file_spec)
30        if self.TraceOn():
31            print("breakpoint:", breakpoint)
32        self.assertTrue(breakpoint and
33                        breakpoint.GetNumLocations() == 1,
34                        VALID_BREAKPOINT)
35
36        # Now launch the process, and do not stop at entry point.
37        process = target.LaunchSimple(
38            None, None, self.get_process_working_directory())
39        self.assertTrue(process, PROCESS_IS_VALID)
40
41        # Frame #0 should be on self.line1 and the break condition should hold.
42        from lldbsuite.test.lldbutil import get_stopped_thread
43        thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
44        self.assertTrue(
45            thread.IsValid(),
46            "There should be a thread stopped due to breakpoint condition")
47
48        frame0 = thread.GetFrameAtIndex(0)
49
50        var = frame0.EvaluateExpression("call_me_to_get_lock(get_int())")
51        self.assertTrue(var.IsValid())
52        self.assertEqual(var.GetValueAsSigned(0), 567)
53