]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/cpp/scope/TestCppScope.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / cpp / scope / TestCppScope.py
1 """
2 Test scopes in C++.
3 """
4 import lldb
5 from lldbsuite.test.decorators import *
6 from lldbsuite.test.lldbtest import *
7 from lldbsuite.test import lldbutil
8
9
10 class TestCppScopes(TestBase):
11
12     mydir = TestBase.compute_mydir(__file__)
13
14     @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24764")
15     def test_all_but_c(self):
16         self.do_test(False)
17
18     # There's a global symbol in libsystem on Darwin that messes up
19     # the lookup of class C.  Breaking that test out from the others
20     # since that is a odd failure, and I don't want it to mask the
21     # real purpose of this test.
22     @expectedFailureDarwin(bugnumber="<rdar://problem/28623427>")
23     @expectedFailureAll(oslist=["windows"])
24     def test_c(self):
25         self.do_test(True)
26     
27     def do_test(self, test_c):
28         self.build()
29
30         # Get main source file
31         src_file = "main.cpp"
32         src_file_spec = lldb.SBFileSpec(src_file)
33         self.assertTrue(src_file_spec.IsValid(), "Main source file")
34
35         # Get the path of the executable
36         cwd = os.getcwd()
37         exe_file = "a.out"
38         exe_path = os.path.join(cwd, exe_file)
39
40         # Load the executable
41         target = self.dbg.CreateTarget(exe_path)
42         self.assertTrue(target.IsValid(), VALID_TARGET)
43
44         # Break on main function
45         main_breakpoint = target.BreakpointCreateBySourceRegex(
46             "// break here", src_file_spec)
47         self.assertTrue(
48             main_breakpoint.IsValid() and main_breakpoint.GetNumLocations() >= 1,
49             VALID_BREAKPOINT)
50
51         # Launch the process
52         args = None
53         env = None
54         process = target.LaunchSimple(
55             args, env, self.get_process_working_directory())
56         self.assertTrue(process.IsValid(), PROCESS_IS_VALID)
57
58         # Get the thread of the process
59         self.assertTrue(
60             process.GetState() == lldb.eStateStopped,
61             PROCESS_STOPPED)
62         thread = lldbutil.get_stopped_thread(
63             process, lldb.eStopReasonBreakpoint)
64
65         # Get current fream of the thread at the breakpoint
66         frame = thread.GetSelectedFrame()
67
68         # Test result for scopes of variables
69
70         global_variables = frame.GetVariables(True, True, True, False)
71         global_variables_assert = {
72             'A::a': 1111,
73             'B::a': 2222,
74             'C::a': 3333,
75             '::a': 4444,
76             'a': 4444
77         }
78
79         self.assertTrue(
80             global_variables.GetSize() == 4,
81             "target variable returns all variables")
82         for variable in global_variables:
83             name = variable.GetName()
84             self.assertTrue(
85                 name in global_variables_assert,
86                 "target variable returns wrong variable " + name)
87
88         for name in global_variables_assert:
89             if name is "C::a" and not test_c:
90                 continue
91             if name is not "C::a" and test_c:
92                 continue
93
94             value = frame.EvaluateExpression(name)
95             assert_value = global_variables_assert[name]
96             self.assertTrue(
97                 value.IsValid() and value.GetValueAsSigned() == assert_value,
98                 name + " = " + str(assert_value))