[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`).
This commit is contained in:
Michael Buch
2025-07-02 16:05:09 +01:00
committed by GitHub
parent 3cb28e9dee
commit e32439249d
5 changed files with 97 additions and 123 deletions

View File

@@ -21,9 +21,44 @@ class GenericDequeDataFormatterTestCase(TestBase):
var = self.findVariable(var_name)
self.assertEqual(var.GetNumChildren(), size)
def check_numbers(self, var_name, show_ptr=False):
patterns = []
substrs = [
"[0] = 1",
"[1] = 12",
"[2] = 123",
"[3] = 1234",
"[4] = 12345",
"[5] = 123456",
"[6] = 1234567",
"}",
]
if show_ptr:
patterns = [var_name + " = 0x.* size=7"]
else:
substrs.insert(0, var_name + " = size=7")
self.expect(
"frame variable " + var_name,
patterns=patterns,
substrs=substrs,
)
self.expect_expr(
var_name,
result_summary="size=7",
result_children=[
ValueCheck(value="1"),
ValueCheck(value="12"),
ValueCheck(value="123"),
ValueCheck(value="1234"),
ValueCheck(value="12345"),
ValueCheck(value="123456"),
ValueCheck(value="1234567"),
],
)
def do_test(self, stdlib_type):
self.build(dictionary={stdlib_type: "1"})
lldbutil.run_to_source_breakpoint(
(_, process, _, bkpt) = lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.cpp")
)
@@ -83,6 +118,21 @@ class GenericDequeDataFormatterTestCase(TestBase):
],
)
lldbutil.continue_to_breakpoint(process, bkpt)
# first value added
self.expect("frame variable empty", substrs=["empty = size=1", "[0] = 1", "}"])
# add remaining values
lldbutil.continue_to_breakpoint(process, bkpt)
self.check_numbers("empty")
# clear out the deque
lldbutil.continue_to_breakpoint(process, bkpt)
self.expect_expr("empty", result_children=[])
@add_test_categories(["libstdcxx"])
def test_libstdcpp(self):
self.do_test(USE_LIBSTDCPP)
@@ -90,3 +140,25 @@ class GenericDequeDataFormatterTestCase(TestBase):
@add_test_categories(["libc++"])
def test_libcpp(self):
self.do_test(USE_LIBCPP)
def do_test_ref_and_ptr(self, stdlib_type: str):
"""Test formatting of std::deque& and std::deque*"""
self.build(dictionary={stdlib_type: "1"})
(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
self, "stop here", lldb.SBFileSpec("main.cpp", False)
)
# The reference should display the same was as the value did
self.check_numbers("ref", True)
# The pointer should just show the right number of elements:
self.expect("frame variable ptr", substrs=["ptr =", " size=7"])
self.expect("expression ptr", substrs=["$", "size=7"])
@add_test_categories(["libstdcxx"])
def test_libstdcpp_ref_and_ptr(self):
self.do_test_ref_and_ptr(USE_LIBSTDCPP)
@add_test_categories(["libc++"])
def test_libcpp_ref_and_ptr(self):
self.do_test_ref_and_ptr(USE_LIBCPP)

View File

@@ -26,6 +26,11 @@ template <typename T> T fill(T deque) {
return deque;
}
void by_ref_and_ptr(std::deque<int> &ref, std::deque<int> *ptr) {
puts("stop here");
return;
}
int main() {
std::deque<int> empty;
std::deque<int> deque_1 = {1};
@@ -37,5 +42,23 @@ int main() {
std::deque<Foo_large> deque_200_large;
deque_200_large = fill<std::deque<Foo_large>>(deque_200_large);
return empty.size() + deque_1.front() + deque_3.front(); // break here
puts("break here");
empty.push_back(1);
puts("break here");
(empty.push_back(12));
(empty.push_back(123));
(empty.push_back(1234));
(empty.push_back(12345));
(empty.push_back(123456));
(empty.push_back(1234567));
puts("break here");
by_ref_and_ptr(empty, &empty);
empty.clear();
puts("break here");
return empty.size() + deque_1.front() + deque_3.front();
}

View File

@@ -1,4 +0,0 @@
USE_LIBCPP := 1
CXX_SOURCES := main.cpp
include Makefile.rules

View File

@@ -1,87 +0,0 @@
"""
Test LLDB's data formatter for libcxx's std::deque.
"""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class LibcxxDequeDataFormatterTestCase(TestBase):
def check_numbers(self, var_name, show_ptr=False):
patterns = []
substrs = [
"[0] = 1",
"[1] = 12",
"[2] = 123",
"[3] = 1234",
"[4] = 12345",
"[5] = 123456",
"[6] = 1234567",
"}",
]
if show_ptr:
patterns = [var_name + " = 0x.* size=7"]
else:
substrs.insert(0, var_name + " = size=7")
self.expect(
"frame variable " + var_name,
patterns=patterns,
substrs=substrs,
)
self.expect_expr(
var_name,
result_summary="size=7",
result_children=[
ValueCheck(value="1"),
ValueCheck(value="12"),
ValueCheck(value="123"),
ValueCheck(value="1234"),
ValueCheck(value="12345"),
ValueCheck(value="123456"),
ValueCheck(value="1234567"),
],
)
@add_test_categories(["libc++"])
def test_with_run_command(self):
"""Test basic formatting of std::deque"""
self.build()
(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.cpp", False)
)
self.expect("frame variable numbers", substrs=["numbers = size=0"])
lldbutil.continue_to_breakpoint(process, bkpt)
# first value added
self.expect(
"frame variable numbers", substrs=["numbers = size=1", "[0] = 1", "}"]
)
# add remaining values
lldbutil.continue_to_breakpoint(process, bkpt)
self.check_numbers("numbers")
# clear out the deque
lldbutil.continue_to_breakpoint(process, bkpt)
self.expect("frame variable numbers", substrs=["numbers = size=0"])
@add_test_categories(["libc++"])
def test_ref_and_ptr(self):
"""Test formatting of std::deque& and std::deque*"""
self.build()
(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
self, "stop here", lldb.SBFileSpec("main.cpp", False)
)
# The reference should display the same was as the value did
self.check_numbers("ref", True)
# The pointer should just show the right number of elements:
self.expect("frame variable ptr", substrs=["ptr =", " size=7"])
self.expect("expression ptr", substrs=["$", "size=7"])

View File

@@ -1,30 +0,0 @@
#include <cstdio>
#include <deque>
typedef std::deque<int> int_deq;
void by_ref_and_ptr(std::deque<int> &ref, std::deque<int> *ptr) {
printf("stop here");
return;
}
int main() {
int_deq numbers;
printf("break here");
(numbers.push_back(1));
printf("break here");
(numbers.push_back(12));
(numbers.push_back(123));
(numbers.push_back(1234));
(numbers.push_back(12345));
(numbers.push_back(123456));
(numbers.push_back(1234567));
by_ref_and_ptr(numbers, &numbers);
printf("break here");
numbers.clear();
printf("break here");
return 0;
}