]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/data-formatter/parray/TestPrintArray.py
Vendor import of lldb trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / data-formatter / parray / TestPrintArray.py
1 """
2 Test lldb data formatter subsystem.
3 """
4
5 from __future__ import print_function
6
7
8 import datetime
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 PrintArrayTestCase(TestBase):
18
19     mydir = TestBase.compute_mydir(__file__)
20
21     def test_print_array(self):
22         """Test that expr -Z works"""
23         self.build()
24         self.printarray_data_formatter_commands()
25
26     def setUp(self):
27         # Call super's setUp().
28         TestBase.setUp(self)
29         # Find the line number to break at.
30         self.line = line_number('main.cpp', 'break here')
31
32     def printarray_data_formatter_commands(self):
33         """Test that expr -Z works"""
34         self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
35
36         lldbutil.run_break_set_by_file_and_line(
37             self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
38
39         self.runCmd("run", RUN_SUCCEEDED)
40
41         # The stop reason of the thread should be breakpoint.
42         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
43                     substrs=['stopped',
44                              'stop reason = breakpoint'])
45
46         # This is the function to remove the custom formats in order to have a
47         # clean slate for the next test case.
48         def cleanup():
49             self.runCmd('type format clear', check=False)
50             self.runCmd('type summary clear', check=False)
51             self.runCmd('type synth clear', check=False)
52
53         # Execute the cleanup function during test case tear down.
54         self.addTearDownHook(cleanup)
55
56         self.expect(
57             'expr --element-count 3 -- data',
58             substrs=[
59                 '[0] = 1',
60                 '[1] = 3',
61                 '[2] = 5'])
62         self.expect('expr data', substrs=['int *', '$', '0x'])
63         self.expect(
64             'expr -f binary --element-count 0 -- data',
65             substrs=[
66                 'int *',
67                 '$',
68                 '0b'])
69         self.expect(
70             'expr -f hex --element-count 3 -- data',
71             substrs=[
72                 '[0] = 0x',
73                 '1',
74                 '[1] = 0x',
75                 '3',
76                 '[2] = 0x',
77                 '5'])
78         self.expect(
79             'expr -f binary --element-count 2 -- data',
80             substrs=[
81                 'int *',
82                 '$',
83                 '0x',
84                 '[0] = 0b',
85                 '1',
86                 '[1] = 0b',
87                 '11'])
88         self.expect('parray 3 data', substrs=['[0] = 1', '[1] = 3', '[2] = 5'])
89         self.expect(
90             'parray `1 + 1 + 1` data',
91             substrs=[
92                 '[0] = 1',
93                 '[1] = 3',
94                 '[2] = 5'])
95         self.expect(
96             'parray `data[1]` data',
97             substrs=[
98                 '[0] = 1',
99                 '[1] = 3',
100                 '[2] = 5'])
101         self.expect(
102             'parray/x 3 data',
103             substrs=[
104                 '[0] = 0x',
105                 '1',
106                 '[1] = 0x',
107                 '3',
108                 '[2] = 0x',
109                 '5'])
110         self.expect(
111             'parray/x `data[1]` data',
112             substrs=[
113                 '[0] = 0x',
114                 '1',
115                 '[1] = 0x',
116                 '3',
117                 '[2] = 0x',
118                 '5'])
119
120         # check error conditions
121         self.expect(
122             'expr --element-count 10 -- 123',
123             error=True,
124             substrs=['expression cannot be used with --element-count as it does not refer to a pointer'])
125         self.expect(
126             'expr --element-count 10 -- (void*)123',
127             error=True,
128             substrs=['expression cannot be used with --element-count as it refers to a pointer to void'])
129         self.expect('parray data', error=True, substrs=[
130                     "invalid element count 'data'"])
131         self.expect(
132             'parray data data',
133             error=True,
134             substrs=["invalid element count 'data'"])
135         self.expect('parray', error=True, substrs=[
136                     'Not enough arguments provided'])