[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 04:24:31 PDT 2025


https://github.com/Michael137 created https://github.com/llvm/llvm-project/pull/147141

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

>From 09c96620f3912679ea3c0444fc0315d18f9d0b31 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}         | 25 +++++----
 .../{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, 12 insertions(+), 102 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} (89%)
 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 89%
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..3f73f157b3a0e 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")
         )
@@ -56,16 +53,8 @@ def test_shared_ptr_variables(self):
         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"')],
         )
         self.assertRegex(valobj.summary, r'^"hello"( strong=1)? weak=0$')
@@ -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