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