Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / lang / objc / objc-checker / TestObjCCheckers.py
blob8b0965d23b431cadcb4e320ec27cae10e774654b
1 """
2 Use lldb Python API to make sure the dynamic checkers are doing their jobs.
3 """
6 import lldb
7 from lldbsuite.test.decorators import *
8 from lldbsuite.test.lldbtest import *
9 from lldbsuite.test import lldbutil
12 class ObjCCheckerTestCase(TestBase):
13 NO_DEBUG_INFO_TESTCASE = True
15 def setUp(self):
16 # Call super's setUp().
17 TestBase.setUp(self)
19 # Find the line number to break for main.c.
20 self.source_name = "main.m"
22 @add_test_categories(["pyapi"])
23 def test_objc_checker(self):
24 """Test that checkers catch unrecognized selectors"""
25 if self.getArchitecture() == "i386":
26 self.skipTest("requires Objective-C 2.0 runtime")
28 self.build()
29 exe = self.getBuildArtifact("a.out")
31 # Create a target from the debugger.
33 target = self.dbg.CreateTarget(exe)
34 self.assertTrue(target, VALID_TARGET)
36 # Set up our breakpoints:
38 main_bkpt = target.BreakpointCreateBySourceRegex(
39 "Set a breakpoint here.", lldb.SBFileSpec(self.source_name)
41 self.assertTrue(
42 main_bkpt and main_bkpt.GetNumLocations() == 1, VALID_BREAKPOINT
45 # Now launch the process, and do not stop at the entry point.
46 process = target.LaunchSimple(None, None, self.get_process_working_directory())
48 self.assertState(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED)
50 threads = lldbutil.get_threads_stopped_at_breakpoint(process, main_bkpt)
51 self.assertEqual(len(threads), 1)
52 thread = threads[0]
55 # The class Simple doesn't have a count method. Make sure that we don't
56 # actually try to send count but catch it as an unrecognized selector.
58 frame = thread.GetFrameAtIndex(0)
59 expr_value = frame.EvaluateExpression("(int) [my_simple count]", False)
60 expr_error = expr_value.GetError()
62 self.assertTrue(expr_error.Fail())
64 # Make sure the call produced no NSLog stdout.
65 stdout = process.GetSTDOUT(100)
66 self.assertTrue(stdout is None or (len(stdout) == 0))
68 # Make sure the error is helpful:
69 err_string = expr_error.GetCString()
70 self.assertIn("selector", err_string)
73 # Check that we correctly insert the checker for an
74 # ObjC method with the struct return convention.
75 # Getting this wrong would cause us to call the checker
76 # with the wrong arguments, and the checker would crash
77 # So I'm just checking "expression runs successfully" here:
79 expr_value = frame.EvaluateExpression("[my_simple getBigStruct]", False)
80 expr_error = expr_value.GetError()
82 self.assertSuccess(expr_error)