[Lldb-commits] [lldb] [lldb][test] Combine libstdc++ and libc++ std::shared_ptr tests into generic test (PR #147141)
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Sat Jul 5 15:36:18 PDT 2025
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/147141
>From c5380d0632ad29e6aedcbf07dfb74b9264ffc5c9 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Sat, 5 Jul 2025 12:22:01 +0100
Subject: [PATCH] [lldb][test] Combine libstdc++ and libc++ std::shared_ptr
tests into generic test
This combines the libc++ and libstdc++ test cases.
The libstdcpp tests were a subset of the libc++ test, so this patch
moves the libcxx test into `generic` and removes the libstdcpp test
entirely.
Split out from https://github.com/llvm/llvm-project/pull/146740
---
.../smart_ptr => generic/shared_ptr}/Makefile | 3 --
.../TestDataFormatterStdSharedPtr.py} | 39 +++++++-------
.../{libcxx => generic}/shared_ptr/main.cpp | 0
.../libcxx/shared_ptr/Makefile | 8 ---
.../smart_ptr/TestDataFormatterStdSmartPtr.py | 52 -------------------
.../libstdcpp/smart_ptr/main.cpp | 26 ----------
6 files changed, 19 insertions(+), 109 deletions(-)
rename lldb/test/API/functionalities/data-formatter/data-formatter-stl/{libstdcpp/smart_ptr => generic/shared_ptr}/Makefile (57%)
rename lldb/test/API/functionalities/data-formatter/data-formatter-stl/{libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py => generic/shared_ptr/TestDataFormatterStdSharedPtr.py} (78%)
rename lldb/test/API/functionalities/data-formatter/data-formatter-stl/{libcxx => generic}/shared_ptr/main.cpp (100%)
delete mode 100644 lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
delete mode 100644 lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/TestDataFormatterStdSmartPtr.py
delete mode 100644 lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/main.cpp
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/Makefile b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/shared_ptr/Makefile
similarity index 57%
rename from lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/Makefile
rename to lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/shared_ptr/Makefile
index 654e4b15bd568..99998b20bcb05 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/Makefile
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/shared_ptr/Makefile
@@ -1,6 +1,3 @@
CXX_SOURCES := main.cpp
-CXXFLAGS := -O0
-USE_LIBSTDCPP := 1
-
include Makefile.rules
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/shared_ptr/TestDataFormatterStdSharedPtr.py
similarity index 78%
rename from lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
rename to lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/shared_ptr/TestDataFormatterStdSharedPtr.py
index 25f616ff61046..8b641c9643958 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/shared_ptr/TestDataFormatterStdSharedPtr.py
@@ -1,5 +1,5 @@
"""
-Test lldb data formatter for libc++ std::shared_ptr.
+Test lldb data formatter for std::shared_ptr.
"""
import lldb
@@ -9,11 +9,8 @@
class TestCase(TestBase):
- @add_test_categories(["libc++"])
- def test_shared_ptr_variables(self):
+ def do_test(self):
"""Test `frame variable` output for `std::shared_ptr` types."""
- self.build()
-
(_, process, _, bkpt) = lldbutil.run_to_source_breakpoint(
self, "// break here", lldb.SBFileSpec("main.cpp")
)
@@ -22,7 +19,7 @@ def test_shared_ptr_variables(self):
"sp_empty",
type="std::shared_ptr<int>",
summary="nullptr",
- children=[ValueCheck(name="__ptr_")],
+ children=[ValueCheck(name="pointer")],
)
self.assertEqual(
valobj.child[0].GetValueAsUnsigned(lldb.LLDB_INVALID_ADDRESS), 0
@@ -35,7 +32,7 @@ def test_shared_ptr_variables(self):
valobj = self.expect_var_path(
"sp_int",
type="std::shared_ptr<int>",
- children=[ValueCheck(name="__ptr_")],
+ children=[ValueCheck(name="pointer")],
)
self.assertRegex(valobj.summary, r"^10( strong=1)? weak=0$")
self.assertNotEqual(valobj.child[0].unsigned, 0)
@@ -43,7 +40,7 @@ def test_shared_ptr_variables(self):
valobj = self.expect_var_path(
"sp_int_ref",
type="std::shared_ptr<int> &",
- children=[ValueCheck(name="__ptr_")],
+ children=[ValueCheck(name="pointer")],
)
self.assertRegex(valobj.summary, r"^10( strong=1)? weak=0$")
self.assertNotEqual(valobj.child[0].unsigned, 0)
@@ -51,29 +48,21 @@ def test_shared_ptr_variables(self):
valobj = self.expect_var_path(
"sp_int_ref_ref",
type="std::shared_ptr<int> &&",
- children=[ValueCheck(name="__ptr_")],
+ children=[ValueCheck(name="pointer")],
)
self.assertRegex(valobj.summary, r"^10( strong=1)? weak=0$")
self.assertNotEqual(valobj.child[0].unsigned, 0)
- if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(
- [">", "16.0"]
- ):
- string_type = "std::string"
- else:
- string_type = "std::basic_string<char, std::char_traits<char>, std::allocator<char> > "
-
valobj = self.expect_var_path(
"sp_str",
- type="std::shared_ptr<" + string_type + ">",
- children=[ValueCheck(name="__ptr_", summary='"hello"')],
+ children=[ValueCheck(name="pointer", summary='"hello"')],
)
self.assertRegex(valobj.summary, r'^"hello"( strong=1)? weak=0$')
valobj = self.expect_var_path("sp_user", type="std::shared_ptr<User>")
self.assertRegex(
valobj.summary,
- "^std(::__[^:]*)?::shared_ptr<User>::element_type @ 0x0*[1-9a-f][0-9a-f]+( strong=1)? weak=0",
+ "element_type @ 0x0*[1-9a-f][0-9a-f]+( strong=1)? weak=0",
)
self.assertNotEqual(valobj.child[0].unsigned, 0)
@@ -85,7 +74,7 @@ def test_shared_ptr_variables(self):
ValueCheck(name="name", summary='"steph"'),
],
)
- self.assertEqual(str(valobj), '(User) *__ptr_ = (id = 30, name = "steph")')
+ self.assertEqual(str(valobj), '(User) *pointer = (id = 30, name = "steph")')
self.expect_var_path("sp_user->id", type="int", value="30")
self.expect_var_path("sp_user->name", type="std::string", summary='"steph"')
@@ -115,3 +104,13 @@ def test_shared_ptr_variables(self):
self.expect_var_path("ptr_node->next->value", value="2")
self.expect_var_path("(*ptr_node).value", value="1")
self.expect_var_path("(*(*ptr_node).next).value", value="2")
+
+ @add_test_categories(["libc++"])
+ def test_libcxx(self):
+ self.build(dictionary={"USE_LIBCPP": 1})
+ self.do_test()
+
+ @add_test_categories(["libstdcxx"])
+ def test_libstdcxx(self):
+ self.build(dictionary={"USE_LIBSTDCPP": 1})
+ self.do_test()
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/shared_ptr/main.cpp
similarity index 100%
rename from lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/main.cpp
rename to lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/shared_ptr/main.cpp
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
deleted file mode 100644
index c1c8b4a2a0a53..0000000000000
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
-CXX_SOURCES := main.cpp
-
-USE_LIBCPP := 1
-
-# We need debug info tuning for lldb in order to emit the preferred name for
-# std::string. See https://reviews.llvm.org/D145803.
-CXXFLAGS_EXTRAS := -std=c++14 -glldb
-include Makefile.rules
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/TestDataFormatterStdSmartPtr.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/TestDataFormatterStdSmartPtr.py
deleted file mode 100644
index a6856177858a3..0000000000000
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/TestDataFormatterStdSmartPtr.py
+++ /dev/null
@@ -1,52 +0,0 @@
-"""
-Test lldb data formatter subsystem.
-"""
-
-
-import lldb
-from lldbsuite.test.decorators import *
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test import lldbutil
-
-
-class StdSmartPtrDataFormatterTestCase(TestBase):
- @add_test_categories(["libstdcxx"])
- @expectedFailureAll(bugnumber="llvm.org/pr50861", compiler="gcc")
- def test_with_run_command(self):
- self.build()
- self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
-
- lldbutil.run_break_set_by_source_regexp(self, "Set break point at this line.")
- self.runCmd("run", RUN_SUCCEEDED)
-
- # The stop reason of the thread should be breakpoint.
- self.expect(
- "thread list",
- STOPPED_DUE_TO_BREAKPOINT,
- substrs=["stopped", "stop reason = breakpoint"],
- )
-
- self.expect("frame variable nsp", substrs=["nsp = nullptr"])
- self.expect("frame variable isp", substrs=["isp = 123"])
- self.expect("frame variable ssp", substrs=['ssp = "foobar"'])
-
- self.expect("frame variable nwp", substrs=["nwp = nullptr"])
- self.expect("frame variable iwp", substrs=["iwp = 123"])
- self.expect("frame variable swp", substrs=['swp = "foobar"'])
-
- self.expect("frame variable *nsp", substrs=["*nsp = <parent is NULL>"])
- self.expect("frame variable *isp", substrs=["*isp = 123"])
- self.expect("frame variable *ssp", substrs=['*ssp = "foobar"'])
- self.expect("frame variable *fsp", substrs=["*fsp = (mem = 5)"])
-
- self.expect("frame variable fsp->mem", substrs=["(int) fsp->mem = 5"])
-
- self.runCmd("continue")
-
- self.expect("frame variable nsp", substrs=["nsp = nullptr"])
- self.expect("frame variable isp", substrs=["isp = nullptr"])
- self.expect("frame variable ssp", substrs=["ssp = nullptr"])
-
- self.expect("frame variable nwp", substrs=["nwp = nullptr"])
- self.expect("frame variable iwp", substrs=["iwp = nullptr"])
- self.expect("frame variable swp", substrs=["swp = nullptr"])
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/main.cpp
deleted file mode 100644
index 6e4b869e1c8e0..0000000000000
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/smart_ptr/main.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include <memory>
-#include <string>
-
-struct Foo {
- int mem = 5;
-};
-
-int
-main()
-{
- std::shared_ptr<char> nsp;
- std::shared_ptr<int> isp(new int{123});
- std::shared_ptr<std::string> ssp = std::make_shared<std::string>("foobar");
- std::shared_ptr<Foo> fsp = std::make_shared<Foo>();
-
- std::weak_ptr<char> nwp;
- std::weak_ptr<int> iwp = isp;
- std::weak_ptr<std::string> swp = ssp;
-
- nsp.reset(); // Set break point at this line.
- isp.reset();
- ssp.reset();
- fsp.reset();
-
- return 0; // Set break point at this line.
-}
More information about the lldb-commits
mailing list