]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/cpp/stl/TestSTL.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / cpp / stl / TestSTL.py
1 """
2 Test some expressions involving STL data types.
3 """
4
5 from __future__ import print_function
6
7
8 import unittest2
9 import os
10 import time
11 import lldb
12 from lldbsuite.test.decorators import *
13 from lldbsuite.test.lldbtest import *
14 from lldbsuite.test import lldbutil
15
16
17 class STLTestCase(TestBase):
18
19     mydir = TestBase.compute_mydir(__file__)
20
21     def setUp(self):
22         # Call super's setUp().
23         TestBase.setUp(self)
24         # Find the line number to break inside main().
25         self.source = 'main.cpp'
26         self.line = line_number(
27             self.source, '// Set break point at this line.')
28
29     @expectedFailureAll(bugnumber="rdar://problem/10400981")
30     def test(self):
31         """Test some expressions involving STL data types."""
32         self.build()
33         exe = os.path.join(os.getcwd(), "a.out")
34
35         # The following two lines, if uncommented, will enable loggings.
36         #self.ci.HandleCommand("log enable -f /tmp/lldb.log lldb default", res)
37         # self.assertTrue(res.Succeeded())
38
39         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
40
41         # rdar://problem/8543077
42         # test/stl: clang built binaries results in the breakpoint locations = 3,
43         # is this a problem with clang generated debug info?
44         lldbutil.run_break_set_by_file_and_line(
45             self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
46
47         self.runCmd("run", RUN_SUCCEEDED)
48
49         # Stop at 'std::string hello_world ("Hello World!");'.
50         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
51                     substrs=['main.cpp:%d' % self.line,
52                              'stop reason = breakpoint'])
53
54         # The breakpoint should have a hit count of 1.
55         self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
56                     substrs=[' resolved, hit count = 1'])
57
58         # Now try some expressions....
59
60         self.runCmd(
61             'expr for (int i = 0; i < hello_world.length(); ++i) { (void)printf("%c\\n", hello_world[i]); }')
62
63         # rdar://problem/10373783
64         # rdar://problem/10400981
65         self.expect('expr associative_array.size()',
66                     substrs=[' = 3'])
67         self.expect('expr associative_array.count(hello_world)',
68                     substrs=[' = 1'])
69         self.expect('expr associative_array[hello_world]',
70                     substrs=[' = 1'])
71         self.expect('expr associative_array["hello"]',
72                     substrs=[' = 2'])
73
74     @expectedFailureAll(
75         compiler="icc",
76         bugnumber="ICC (13.1, 14-beta) do not emit DW_TAG_template_type_parameter.")
77     @add_test_categories(['pyapi'])
78     def test_SBType_template_aspects(self):
79         """Test APIs for getting template arguments from an SBType."""
80         self.build()
81         exe = os.path.join(os.getcwd(), 'a.out')
82
83         # Create a target by the debugger.
84         target = self.dbg.CreateTarget(exe)
85         self.assertTrue(target, VALID_TARGET)
86
87         # Create the breakpoint inside function 'main'.
88         breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
89         self.assertTrue(breakpoint, VALID_BREAKPOINT)
90
91         # Now launch the process, and do not stop at entry point.
92         process = target.LaunchSimple(
93             None, None, self.get_process_working_directory())
94         self.assertTrue(process, PROCESS_IS_VALID)
95
96         # Get Frame #0.
97         self.assertTrue(process.GetState() == lldb.eStateStopped)
98         thread = lldbutil.get_stopped_thread(
99             process, lldb.eStopReasonBreakpoint)
100         self.assertTrue(
101             thread.IsValid(),
102             "There should be a thread stopped due to breakpoint condition")
103         frame0 = thread.GetFrameAtIndex(0)
104
105         # Get the type for variable 'associative_array'.
106         associative_array = frame0.FindVariable('associative_array')
107         self.DebugSBValue(associative_array)
108         self.assertTrue(associative_array, VALID_VARIABLE)
109         map_type = associative_array.GetType()
110         self.DebugSBType(map_type)
111         self.assertTrue(map_type, VALID_TYPE)
112         num_template_args = map_type.GetNumberOfTemplateArguments()
113         self.assertTrue(num_template_args > 0)
114
115         # We expect the template arguments to contain at least 'string' and
116         # 'int'.
117         expected_types = {'string': False, 'int': False}
118         for i in range(num_template_args):
119             t = map_type.GetTemplateArgumentType(i)
120             self.DebugSBType(t)
121             self.assertTrue(t, VALID_TYPE)
122             name = t.GetName()
123             if 'string' in name:
124                 expected_types['string'] = True
125             elif 'int' == name:
126                 expected_types['int'] = True
127
128         # Check that both entries of the dictionary have 'True' as the value.
129         self.assertTrue(all(expected_types.values()))