1"""
2Test lldb data formatter subsystem.
3"""
4
5
6import lldb
7from lldbsuite.test.decorators import *
8from lldbsuite.test.lldbtest import *
9from lldbsuite.test import lldbutil
10
11
12class LibcxxChronoDataFormatterTestCase(TestBase):
13    @add_test_categories(["libc++"])
14    def test_with_run_command(self):
15        """Test that that file and class static variables display correctly."""
16        self.build()
17        (self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
18            self, "break here", lldb.SBFileSpec("main.cpp", False)
19        )
20
21        #
22        # std::valarray
23        #
24
25        self.expect(
26            "frame variable va_int",
27            substrs=[
28                "va_int = size=4",
29                "[0] = 0",
30                "[1] = 0",
31                "[2] = 0",
32                "[3] = 0",
33                "}",
34            ],
35        )
36
37        lldbutil.continue_to_breakpoint(process, bkpt)
38        self.expect(
39            "frame variable va_int",
40            substrs=[
41                "va_int = size=4",
42                "[0] = 1",
43                "[1] = 12",
44                "[2] = 123",
45                "[3] = 1234",
46                "}",
47            ],
48        )
49
50        # check access-by-index
51        self.expect("frame variable va_int[0]", substrs=["1"])
52        self.expect("frame variable va_int[1]", substrs=["12"])
53        self.expect("frame variable va_int[2]", substrs=["123"])
54        self.expect("frame variable va_int[3]", substrs=["1234"])
55        self.expect(
56            "frame variable va_int[4]",
57            error=True,
58            substrs=['array index 4 is not valid for "(valarray<int>) va_int"'],
59        )
60
61        self.expect(
62            "frame variable va_double",
63            substrs=[
64                "va_double = size=4",
65                "[0] = 1",
66                "[1] = 0.5",
67                "[2] = 0.25",
68                "[3] = 0.125",
69                "}",
70            ],
71        )
72
73        # check access-by-index
74        self.expect("frame variable va_double[0]", substrs=["1"])
75        self.expect("frame variable va_double[1]", substrs=["0.5"])
76        self.expect("frame variable va_double[2]", substrs=["0.25"])
77        self.expect("frame variable va_double[3]", substrs=["0.125"])
78        self.expect(
79            "frame variable va_double[4]",
80            error=True,
81            substrs=['array index 4 is not valid for "(valarray<double>) va_double"'],
82        )
83
84        #
85        # std::slice_array
86        #
87
88        self.expect(
89            "frame variable sa",
90            substrs=[
91                "sa = stride=2 size=4",
92                "[0] = 11",
93                "[1] = 13",
94                "[2] = 15",
95                "[3] = 17",
96                "}",
97            ],
98        )
99
100        # check access-by-index
101        self.expect("frame variable sa[0]", substrs=["11"])
102        self.expect("frame variable sa[1]", substrs=["13"])
103        self.expect("frame variable sa[2]", substrs=["15"])
104        self.expect("frame variable sa[3]", substrs=["17"])
105        self.expect(
106            "frame variable sa[4]",
107            error=True,
108            substrs=['array index 4 is not valid for "(slice_array<int>) sa"'],
109        )
110
111        #
112        # std::gslice_array
113        #
114
115        self.expect(
116            "frame variable ga",
117            substrs=[
118                "ga = size=3",
119                "[0] -> [3] = 13",
120                "[1] -> [4] = 14",
121                "[2] -> [5] = 15",
122                "}",
123            ],
124        )
125
126        # check access-by-index
127        self.expect("frame variable ga[0]", substrs=["13"])
128        self.expect("frame variable ga[1]", substrs=["14"])
129        self.expect("frame variable ga[2]", substrs=["15"])
130        self.expect(
131            "frame variable ga[3]",
132            error=True,
133            substrs=['array index 3 is not valid for "(gslice_array<int>) ga"'],
134        )
135        #
136        # std::mask_array
137        #
138
139        self.expect(
140            "frame variable ma",
141            substrs=[
142                "ma = size=2",
143                "[0] -> [1] = 11",
144                "[1] -> [2] = 12",
145                "}",
146            ],
147        )
148
149        # check access-by-index
150        self.expect("frame variable ma[0]", substrs=["11"])
151        self.expect("frame variable ma[1]", substrs=["12"])
152        self.expect(
153            "frame variable ma[2]",
154            error=True,
155            substrs=['array index 2 is not valid for "(mask_array<int>) ma"'],
156        )
157
158        #
159        # std::indirect_array
160        #
161
162        self.expect(
163            "frame variable ia",
164            substrs=[
165                "ia = size=3",
166                "[0] -> [3] = 13",
167                "[1] -> [6] = 16",
168                "[2] -> [9] = 19",
169                "}",
170            ],
171        )
172
173        # check access-by-index
174        self.expect("frame variable ia[0]", substrs=["13"])
175        self.expect("frame variable ia[1]", substrs=["16"])
176        self.expect("frame variable ia[2]", substrs=["19"])
177        self.expect(
178            "frame variable ia[3]",
179            error=True,
180            substrs=['array index 3 is not valid for "(indirect_array<int>) ia"'],
181        )
182