Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / lang / cpp / global_operators / TestCppGlobalOperators.py
blob358ab5bb7e0ee8709d0cf14450b50d42f371cb55
1 """
2 Test that global operators are found and evaluated.
3 """
4 import lldb
5 from lldbsuite.test.decorators import *
6 from lldbsuite.test.lldbtest import *
7 from lldbsuite.test import lldbutil
10 class TestCppGlobalOperators(TestBase):
11 def prepare_executable_and_get_frame(self):
12 self.build()
14 # Get main source file
15 src_file = "main.cpp"
16 src_file_spec = lldb.SBFileSpec(src_file)
17 self.assertTrue(src_file_spec.IsValid(), "Main source file")
19 # Get the path of the executable
20 exe_path = self.getBuildArtifact("a.out")
22 # Load the executable
23 target = self.dbg.CreateTarget(exe_path)
24 self.assertTrue(target.IsValid(), VALID_TARGET)
26 # Break on main function
27 main_breakpoint = target.BreakpointCreateBySourceRegex(
28 "// break here", src_file_spec
30 self.assertTrue(
31 main_breakpoint.IsValid() and main_breakpoint.GetNumLocations() >= 1,
32 VALID_BREAKPOINT,
35 # Launch the process
36 args = None
37 env = None
38 process = target.LaunchSimple(args, env, self.get_process_working_directory())
39 self.assertTrue(process.IsValid(), PROCESS_IS_VALID)
41 # Get the thread of the process
42 self.assertEqual(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED)
43 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
45 return thread.GetSelectedFrame()
47 def test_equals_operator(self):
48 frame = self.prepare_executable_and_get_frame()
50 test_result = frame.EvaluateExpression("operator==(s1, s2)")
51 self.assertTrue(
52 test_result.IsValid() and test_result.GetValue() == "false",
53 "operator==(s1, s2) = false",
56 test_result = frame.EvaluateExpression("operator==(s1, s3)")
57 self.assertTrue(
58 test_result.IsValid() and test_result.GetValue() == "true",
59 "operator==(s1, s3) = true",
62 test_result = frame.EvaluateExpression("operator==(s2, s3)")
63 self.assertTrue(
64 test_result.IsValid() and test_result.GetValue() == "false",
65 "operator==(s2, s3) = false",
68 def do_new_test(self, frame, expr, expected_value_name):
69 """Evaluate a new expression, and check its result"""
71 expected_value = frame.FindValue(
72 expected_value_name, lldb.eValueTypeVariableGlobal
74 self.assertTrue(expected_value.IsValid())
76 expected_value_addr = expected_value.AddressOf()
77 self.assertTrue(expected_value_addr.IsValid())
79 got = frame.EvaluateExpression(expr)
80 self.assertTrue(got.IsValid())
81 self.assertEqual(
82 got.GetValueAsUnsigned(), expected_value_addr.GetValueAsUnsigned()
84 got_type = got.GetType()
85 self.assertTrue(got_type.IsPointerType())
86 self.assertEqual(got_type.GetPointeeType().GetName(), "Struct")
88 def test_operator_new(self):
89 frame = self.prepare_executable_and_get_frame()
91 self.do_new_test(frame, "new Struct()", "global_new_buf")
92 self.do_new_test(frame, "new(new_tag) Struct()", "tagged_new_buf")