[mlir][PDLL] Allow (and ignore) `-D` tablegen macros. (#124166)
[llvm-project.git] / lldb / test / API / lang / cpp / nsimport / TestCppNsImport.py
blobc61bdc9cb4ac394bf3fe5169b9e54d7252b2fdee
1 """
2 Tests imported namespaces in C++.
3 """
4 import lldb
5 from lldbsuite.test.decorators import *
6 from lldbsuite.test.lldbtest import *
7 from lldbsuite.test import lldbutil
10 class TestCppNsImport(TestBase):
11 def test_with_run_command(self):
12 """Tests imported namespaces in C++."""
13 self.build()
15 # Get main source file
16 src_file = os.path.join(self.getSourceDir(), "main.cpp")
17 src_file_spec = lldb.SBFileSpec(src_file)
18 self.assertTrue(src_file_spec.IsValid(), "Main source file")
20 # Get the path of the executable
21 exe_path = self.getBuildArtifact("a.out")
23 # Load the executable
24 target = self.dbg.CreateTarget(exe_path)
25 self.assertTrue(target.IsValid(), VALID_TARGET)
27 # Break on main function
28 break_0 = target.BreakpointCreateBySourceRegex("// break 0", src_file_spec)
29 self.assertTrue(
30 break_0.IsValid() and break_0.GetNumLocations() >= 1, VALID_BREAKPOINT
32 break_1 = target.BreakpointCreateBySourceRegex("// break 1", src_file_spec)
33 self.assertTrue(
34 break_1.IsValid() and break_1.GetNumLocations() >= 1, VALID_BREAKPOINT
37 # Launch the process
38 args = None
39 env = None
40 process = target.LaunchSimple(args, env, self.get_process_working_directory())
41 self.assertTrue(process.IsValid(), PROCESS_IS_VALID)
43 # Get the thread of the process
44 self.assertEqual(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED)
45 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
47 # Get current fream of the thread at the breakpoint
48 frame = thread.GetSelectedFrame()
50 # Test imported namespaces
51 test_result = frame.EvaluateExpression("n")
52 self.assertTrue(
53 test_result.IsValid() and test_result.GetValueAsSigned() == 1, "n = 1"
56 test_result = frame.EvaluateExpression("N::n")
57 self.assertTrue(
58 test_result.IsValid() and test_result.GetValueAsSigned() == 1, "N::n = 1"
61 test_result = frame.EvaluateExpression("nested")
62 self.assertTrue(
63 test_result.IsValid() and test_result.GetValueAsSigned() == 3, "nested = 3"
66 test_result = frame.EvaluateExpression("anon")
67 self.assertTrue(
68 test_result.IsValid() and test_result.GetValueAsSigned() == 2, "anon = 2"
71 test_result = frame.EvaluateExpression("global")
72 self.assertTrue(
73 test_result.IsValid() and test_result.GetValueAsSigned() == 4, "global = 4"
76 test_result = frame.EvaluateExpression("fun_var")
77 self.assertTrue(
78 test_result.IsValid() and test_result.GetValueAsSigned() == 9, "fun_var = 9"
81 test_result = frame.EvaluateExpression("Fun::fun_var")
82 self.assertTrue(
83 test_result.IsValid() and test_result.GetValueAsSigned() == 0,
84 "Fun::fun_var = 0",
87 test_result = frame.EvaluateExpression("not_imported")
88 self.assertTrue(
89 test_result.IsValid() and test_result.GetValueAsSigned() == 35,
90 "not_imported = 35",
93 # Currently there is no way to distinguish between "::imported" and "imported" in ClangExpressionDeclMap so this fails
94 # test_result = frame.EvaluateExpression("::imported")
95 # self.assertTrue(test_result.IsValid() and test_result.GetValueAsSigned() == 89, "::imported = 89")
97 test_result = frame.EvaluateExpression("Imported::imported")
98 self.assertTrue(
99 test_result.IsValid() and test_result.GetValueAsSigned() == 99,
100 "Imported::imported = 99",
103 test_result = frame.EvaluateExpression("imported")
104 self.assertTrue(
105 test_result.IsValid() and test_result.GetValueAsSigned() == 99,
106 "imported = 99",
109 test_result = frame.EvaluateExpression("single")
110 self.assertTrue(
111 test_result.IsValid() and test_result.GetValueAsSigned() == 3, "single = 3"
114 # Continue to second breakpoint
115 process.Continue()
117 # Get the thread of the process
118 self.assertEqual(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED)
119 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
121 # Get current fream of the thread at the breakpoint
122 frame = thread.GetSelectedFrame()
124 # Test function inside namespace
125 test_result = frame.EvaluateExpression("fun_var")
126 self.assertTrue(
127 test_result.IsValid() and test_result.GetValueAsSigned() == 5, "fun_var = 5"