Skip to content

[lldb][test] Turn (most) libcxx data-formatters tests into generic tests #146740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
CXX_SOURCES := main.cpp
CXXFLAGS_EXTRAS := -std=c++11
USE_LIBCPP := 1

include Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@
from lldbsuite.test import lldbutil


class LibCxxAtomicTestCase(TestBase):
class StdAtomicTestCase(TestBase):
def get_variable(self, name):
var = self.frame().FindVariable(name)
var.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)
var.SetPreferSyntheticValue(True)
return var

@skipIf(compiler=["gcc"])
@add_test_categories(["libc++"])
def test(self):
"""Test that std::atomic as defined by libc++ is correctly printed by LLDB"""
self.build()
def do_test(self):
"""Test that std::atomic is correctly printed by LLDB"""
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)

bkpt = self.target().FindBreakpointByID(
Expand Down Expand Up @@ -66,3 +63,15 @@ def test(self):
self.expect(
"frame var p.child.parent", substrs=["p.child.parent = {\n Value = 0x"]
)

@skipIf(compiler=["gcc"])
@add_test_categories(["libc++"])
def test_libcxx(self):
self.build(dictionary={"USE_LIBCPP": 1})
self.do_test()

@skipIf(compiler=["gcc"])
@add_test_categories(["libstdcxx"])
def test_libstdcxx(self):
self.build(dictionary={"USE_LIBSTDCPP": 1})
self.do_test()
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,26 @@ struct Child {
// This should point to the parent which in turn owns this
// child instance. This cycle should not cause LLDB to infinite loop
// during printing.
std::atomic<Parent*> parent{nullptr};
std::atomic<Parent *> parent{nullptr};
};
struct Parent {
Child child;
};

struct S {
int x = 1;
int y = 2;
int x = 1;
int y = 2;
};

int main ()
{
std::atomic<S> s;
s.store(S());
std::atomic<int> i;
i.store(5);
int main() {
std::atomic<S> s;
s.store(S());
std::atomic<int> i;
i.store(5);

Parent p;
// Let the child node know what its parent is.
p.child.parent = &p;
Parent p;
// Let the child node know what its parent is.
p.child.parent = &p;

return 0; // Set break point at this line.
return 0; // Set break point at this line.
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
CXX_SOURCES := main.cpp

USE_LIBCPP := 1

CXXFLAGS_EXTRAS := -std=c++20
include Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@
Test lldb data formatter subsystem.
"""


import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class LibcxxChronoDataFormatterTestCase(TestBase):
@add_test_categories(["libc++"])
@skipIf(compiler="clang", compiler_version=["<", "17.0"])
def test_with_run_command(self):
class StdChronoDataFormatterTestCase(TestBase):
def do_test(self):
"""Test that that file and class static variables display correctly."""
isNotWindowsHost = lldbplatformutil.getHostPlatform() != "windows"
self.build()
(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.cpp", False)
)
Expand Down Expand Up @@ -433,3 +429,15 @@ def test_with_run_command(self):
"ymwdl_2024_last_tuesday_january = year=2024 month=January weekday=Tuesday index=last"
],
)

@skipIf(compiler="clang", compiler_version=["<", "17.0"])
@add_test_categories(["libc++"])
def test_libcxx(self):
self.build(dictionary={"USE_LIBCPP": 1})
self.do_test()

@skipIf(compiler="clang", compiler_version=["<", "17.0"])
@add_test_categories(["libstdcxx"])
def test_libstdcxx(self):
self.build(dictionary={"USE_LIBSTDCPP": 1})
self.do_test()
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
CXX_SOURCES := main.cpp
CXXFLAGS_EXTRAS := -std=c++11
USE_LIBCPP := 1

include Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
Test lldb data formatter subsystem.
"""


import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class LibCxxFunctionTestCase(TestBase):
class StdFunctionTestCase(TestBase):
# Run frame var for a variable twice. Verify we do not hit the cache
# the first time but do the second time.
def run_frame_var_check_cache_use(
Expand All @@ -34,10 +33,8 @@ def run_frame_var_check_cache_use(
substrs=["lldb_private::CompileUnit::FindFunction"],
)

@add_test_categories(["libc++"])
def test(self):
"""Test that std::function as defined by libc++ is correctly printed by LLDB"""
self.build()
def do_test(self):
"""Test that std::function is correctly printed by LLDB"""
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)

bkpt = self.target().FindBreakpointByID(
Expand Down Expand Up @@ -82,3 +79,13 @@ def test(self):
self.expect(
"frame variable f5", substrs=["f5 = Function = Bar::add_num(int) const"]
)

@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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <functional>

int foo(int x, int y) { return x + y - 1; }

struct Bar {
int operator()() { return 66; }
int add_num(int i) const { return i + 3; }
int add_num2(int i) {
std::function<int(int)> add_num2_f = [](int x) { return x + 1; };

return add_num2_f(i); // Set break point at this line.
}
};

int foo2() {
auto f = [](int x) { return x + 1; };

std::function<int(int)> foo2_f = f;

return foo2_f(10); // Set break point at this line.
}

int main(int argc, char *argv[]) {
int acc = 42;
std::function<int(int, int)> f1 = foo;
std::function<int(int)> f2 = [acc, f1](int x) -> int {
return x + f1(acc, x);
};

auto f = [](int x, int y) { return x + y; };
auto g = [](int x, int y) { return x * y; };
std::function<int(int, int)> f3 = argc % 2 ? f : g;

Bar bar1;
std::function<int()> f4(bar1);
std::function<int(const Bar &, int)> f5 = &Bar::add_num;

int foo2_result = foo2();
int bar_add_num2_result = bar1.add_num2(10);

return f1(acc, acc) + f2(acc) + f3(acc + 1, acc + 2) + f4() +
f5(bar1, 10); // Set break point at this line.
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
CXX_SOURCES := main.cpp

USE_LIBCPP := 1
include Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
Test lldb data formatter subsystem.
"""


import re
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class InitializerListTestCase(TestBase):
@add_test_categories(["libc++"])
def test(self):
class StdInitializerListTestCase(TestBase):
def do_test(self):
"""Test that that file and class static variables display correctly."""
self.build()
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)

bkpt = self.target().FindBreakpointByID(
Expand All @@ -39,3 +36,13 @@ def test(self):
"frame variable ils",
substrs=['[4] = "surprise it is a long string!! yay!!"'],
)

@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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <initializer_list>
#include <string>
#include <vector>

int main() {
std::initializer_list<int> ili{1, 2, 3, 4, 5};
std::initializer_list<std::string> ils{
"1", "2", "3", "4", "surprise it is a long string!! yay!!"};

return 0; // Set break point at this line.
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
CXX_SOURCES := main.cpp

USE_LIBCPP := 1

CXXFLAGS_EXTRAS := -O0
include Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,22 @@
Test lldb data formatter subsystem.
"""


import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class LibcxxIteratorDataFormatterTestCase(TestBase):
class StdIteratorDataFormatterTestCase(TestBase):
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to break at.
self.line = line_number("main.cpp", "// Set break point at this line.")
self.namespace = "std"

@add_test_categories(["libc++"])
def test_with_run_command(self):
"""Test that libc++ iterators format properly."""
self.build()
def do_test(self):
"""Test that STL iterators format properly."""
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)

lldbutil.run_break_set_by_file_and_line(
Expand Down Expand Up @@ -84,3 +81,13 @@ def cleanup():
self.expect("frame variable siumI.first", substrs=["second"], matching=False)
self.expect("frame variable siumI.second", substrs=["second = 137"])
self.expect("frame variable siumI.second", substrs=["first"], matching=False)

@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()
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
CXX_SOURCES := main.cpp

USE_LIBCPP := 1
include Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
Test lldb data formatter subsystem.
"""


import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class LibcxxMapDataFormatterTestCase(TestBase):
class StdMapDataFormatterTestCase(TestBase):
def setUp(self):
TestBase.setUp(self)
ns = "ndk" if lldbplatformutil.target_is_android() else ""
Expand All @@ -22,10 +21,8 @@ def check_pair(self, first_value, second_value):
]
return ValueCheck(children=pair_children)

@add_test_categories(["libc++"])
def test_with_run_command(self):
def do_test(self):
"""Test that that file and class static variables display correctly."""
self.build()
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)

bkpt = self.target().FindBreakpointByID(
Expand Down Expand Up @@ -326,3 +323,13 @@ def cleanup():
lldbutil.continue_to_breakpoint(self.process(), bkpt)

self.expect("frame variable ss", substrs=["%s::map" % ns, "size=0", "{}"])

@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()
Loading
Loading