Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / python_api / run_locker / TestRunLocker.py
blob7604754fff57636c18adeecb38e4d147f6478587
1 """
2 Test that the run locker really does work to keep
3 us from running SB API that should only be run
4 while stopped. This test is mostly concerned with
5 what happens between launch and first stop.
6 """
8 import lldb
9 import lldbsuite.test.lldbutil as lldbutil
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
14 class TestRunLocker(TestBase):
15 NO_DEBUG_INFO_TESTCASE = True
17 @expectedFailureAll(oslist=["windows"])
18 def test_run_locker(self):
19 """Test that the run locker is set correctly when we launch"""
20 self.build()
21 self.runlocker_test(False)
23 @expectedFailureAll(oslist=["windows"])
24 def test_run_locker_stop_at_entry(self):
25 """Test that the run locker is set correctly when we launch"""
26 self.build()
27 self.runlocker_test(False)
29 def setUp(self):
30 # Call super's setUp().
31 TestBase.setUp(self)
32 self.main_source_file = lldb.SBFileSpec("main.c")
34 def runlocker_test(self, stop_at_entry):
35 """The code to stop at entry handles events slightly differently, so
36 we test both versions of process launch."""
38 target = lldbutil.run_to_breakpoint_make_target(self)
40 launch_info = target.GetLaunchInfo()
41 if stop_at_entry:
42 flags = launch_info.GetFlags()
43 launch_info.SetFlags(flags | lldb.eLaunchFlagStopAtEntry)
45 error = lldb.SBError()
46 # We are trying to do things when the process is running, so
47 # we have to run the debugger asynchronously.
48 self.dbg.SetAsync(True)
50 listener = lldb.SBListener("test-run-lock-listener")
51 launch_info.SetListener(listener)
52 process = target.Launch(launch_info, error)
53 self.assertSuccess(error, "Launched the process")
55 event = lldb.SBEvent()
57 event_result = listener.WaitForEvent(10, event)
58 self.assertTrue(event_result, "timed out waiting for launch")
59 state_type = lldb.SBProcess.GetStateFromEvent(event)
60 # We don't always see a launching...
61 if state_type == lldb.eStateLaunching:
62 event_result = listener.WaitForEvent(10, event)
63 self.assertTrue(
64 event_result, "Timed out waiting for running after launching"
66 state_type = lldb.SBProcess.GetStateFromEvent(event)
68 self.assertState(state_type, lldb.eStateRunning, "Didn't get a running event")
70 # We aren't checking the entry state, but just making sure
71 # the running state is set properly if we continue in this state.
73 if stop_at_entry:
74 event_result = listener.WaitForEvent(10, event)
75 self.assertTrue(event_result, "Timed out waiting for stop at entry stop")
76 state_type = lldb.SBProcess.GetStateFromEvent(event)
77 self.assertState(state_type, eStateStopped, "Stop at entry stopped")
78 process.Continue()
80 # Okay, now the process is running, make sure we can't do things
81 # you aren't supposed to do while running, and that we get some
82 # actual error:
83 val = target.EvaluateExpression("SomethingToCall()")
84 error = val.GetError()
85 self.assertTrue(error.Fail(), "Failed to run expression")
86 self.assertIn(
87 "can't evaluate expressions when the process is running",
88 error.GetCString(),
89 "Stopped by stop locker",
92 # This should also fail if we try to use the script interpreter directly:
93 interp = self.dbg.GetCommandInterpreter()
94 result = lldb.SBCommandReturnObject()
95 ret = interp.HandleCommand(
96 "script var = lldb.frame.EvaluateExpression('SomethingToCall()'); var.GetError().GetCString()",
97 result,
99 self.assertIn(
100 "can't evaluate expressions when the process is running", result.GetOutput()