Skip to content

Commit e324392

Browse files
authored
[lldb][test] Consolidate generic and libcxx std::deque formatter tests (#146697)
The plan is to move all STL formatter API tests into a single directory. The `std::deque` test is currently the only test that is duplicated between the `libcxx` and `generic` directories. This patch moves the libcxx deque tests into `generic` (moving over any functionality that wasn't tested in the `generic` tests, mainly formatting pointers/references to `std::deque`).
1 parent 3cb28e9 commit e324392

File tree

5 files changed

+97
-123
lines changed

5 files changed

+97
-123
lines changed

lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/deque/TestDataFormatterGenericDeque.py

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,44 @@ def check_size(self, var_name, size):
2121
var = self.findVariable(var_name)
2222
self.assertEqual(var.GetNumChildren(), size)
2323

24+
def check_numbers(self, var_name, show_ptr=False):
25+
patterns = []
26+
substrs = [
27+
"[0] = 1",
28+
"[1] = 12",
29+
"[2] = 123",
30+
"[3] = 1234",
31+
"[4] = 12345",
32+
"[5] = 123456",
33+
"[6] = 1234567",
34+
"}",
35+
]
36+
if show_ptr:
37+
patterns = [var_name + " = 0x.* size=7"]
38+
else:
39+
substrs.insert(0, var_name + " = size=7")
40+
self.expect(
41+
"frame variable " + var_name,
42+
patterns=patterns,
43+
substrs=substrs,
44+
)
45+
self.expect_expr(
46+
var_name,
47+
result_summary="size=7",
48+
result_children=[
49+
ValueCheck(value="1"),
50+
ValueCheck(value="12"),
51+
ValueCheck(value="123"),
52+
ValueCheck(value="1234"),
53+
ValueCheck(value="12345"),
54+
ValueCheck(value="123456"),
55+
ValueCheck(value="1234567"),
56+
],
57+
)
58+
2459
def do_test(self, stdlib_type):
2560
self.build(dictionary={stdlib_type: "1"})
26-
lldbutil.run_to_source_breakpoint(
61+
(_, process, _, bkpt) = lldbutil.run_to_source_breakpoint(
2762
self, "break here", lldb.SBFileSpec("main.cpp")
2863
)
2964

@@ -83,10 +118,47 @@ def do_test(self, stdlib_type):
83118
],
84119
)
85120

121+
lldbutil.continue_to_breakpoint(process, bkpt)
122+
123+
# first value added
124+
self.expect("frame variable empty", substrs=["empty = size=1", "[0] = 1", "}"])
125+
126+
# add remaining values
127+
lldbutil.continue_to_breakpoint(process, bkpt)
128+
129+
self.check_numbers("empty")
130+
131+
# clear out the deque
132+
lldbutil.continue_to_breakpoint(process, bkpt)
133+
134+
self.expect_expr("empty", result_children=[])
135+
86136
@add_test_categories(["libstdcxx"])
87137
def test_libstdcpp(self):
88138
self.do_test(USE_LIBSTDCPP)
89139

90140
@add_test_categories(["libc++"])
91141
def test_libcpp(self):
92142
self.do_test(USE_LIBCPP)
143+
144+
def do_test_ref_and_ptr(self, stdlib_type: str):
145+
"""Test formatting of std::deque& and std::deque*"""
146+
self.build(dictionary={stdlib_type: "1"})
147+
(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
148+
self, "stop here", lldb.SBFileSpec("main.cpp", False)
149+
)
150+
151+
# The reference should display the same was as the value did
152+
self.check_numbers("ref", True)
153+
154+
# The pointer should just show the right number of elements:
155+
self.expect("frame variable ptr", substrs=["ptr =", " size=7"])
156+
self.expect("expression ptr", substrs=["$", "size=7"])
157+
158+
@add_test_categories(["libstdcxx"])
159+
def test_libstdcpp_ref_and_ptr(self):
160+
self.do_test_ref_and_ptr(USE_LIBSTDCPP)
161+
162+
@add_test_categories(["libc++"])
163+
def test_libcpp_ref_and_ptr(self):
164+
self.do_test_ref_and_ptr(USE_LIBCPP)

lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/deque/main.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ template <typename T> T fill(T deque) {
2626
return deque;
2727
}
2828

29+
void by_ref_and_ptr(std::deque<int> &ref, std::deque<int> *ptr) {
30+
puts("stop here");
31+
return;
32+
}
33+
2934
int main() {
3035
std::deque<int> empty;
3136
std::deque<int> deque_1 = {1};
@@ -37,5 +42,23 @@ int main() {
3742
std::deque<Foo_large> deque_200_large;
3843
deque_200_large = fill<std::deque<Foo_large>>(deque_200_large);
3944

40-
return empty.size() + deque_1.front() + deque_3.front(); // break here
45+
puts("break here");
46+
47+
empty.push_back(1);
48+
puts("break here");
49+
50+
(empty.push_back(12));
51+
(empty.push_back(123));
52+
(empty.push_back(1234));
53+
(empty.push_back(12345));
54+
(empty.push_back(123456));
55+
(empty.push_back(1234567));
56+
puts("break here");
57+
58+
by_ref_and_ptr(empty, &empty);
59+
60+
empty.clear();
61+
puts("break here");
62+
63+
return empty.size() + deque_1.front() + deque_3.front();
4164
}

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/Makefile

Lines changed: 0 additions & 4 deletions
This file was deleted.

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/TestDataFormatterLibcxxDeque.py

Lines changed: 0 additions & 87 deletions
This file was deleted.

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/deque/main.cpp

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)