Skip to content

Commit d9b208b

Browse files
authored
[lldb][test] Combine libstdc++ and libc++ std::variant tests into generic test (llvm#147253)
This combines the libc++ and libstdc++ test cases. The libstdc++ test had an additional test-case for "reference to typedef". So I added those to the generic test. The rest of the tests was the same as libc++. I also moved the test-case for checking invalid variant indexes into a separate libstdcpp test because it relied on the layout of the libstdc++ type. We should probably rewrite it in the "simulator" style. But for now I just moved it. This also removes some redundant checks for libc++ versions and existence of the `variant` header, which at this point should be available anywhere these tests are run. Split out from llvm#146740
1 parent e4d0068 commit d9b208b

File tree

8 files changed

+78
-232
lines changed

8 files changed

+78
-232
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
CXX_SOURCES := main.cpp
2-
3-
USE_LIBCPP := 1
4-
52
CXXFLAGS_EXTRAS := -std=c++17
3+
64
include Makefile.rules
Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Test lldb data formatter for LibStdC++ std::variant.
2+
Test lldb data formatter subsystem.
33
"""
44

55
import lldb
@@ -8,18 +8,23 @@
88
from lldbsuite.test import lldbutil
99

1010

11-
class LibStdcxxVariantDataFormatterTestCase(TestBase):
12-
@add_test_categories(["libstdcxx"])
13-
def test_with_run_command(self):
14-
"""Test LibStdC++ std::variant data formatter works correctly."""
15-
self.build()
11+
class StdVariantDataFormatterTestCase(TestBase):
12+
def do_test(self):
13+
"""Test that that file and class static variables display correctly."""
14+
15+
def cleanup():
16+
self.runCmd("type format clear", check=False)
17+
self.runCmd("type summary clear", check=False)
18+
self.runCmd("type filter clear", check=False)
19+
self.runCmd("type synth clear", check=False)
20+
21+
# Execute the cleanup function during test case tear down.
22+
self.addTearDownHook(cleanup)
1623

1724
(self.target, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint(
1825
self, "// break here", lldb.SBFileSpec("main.cpp", False)
1926
)
2027

21-
lldbutil.continue_to_breakpoint(self.process, bkpt)
22-
2328
for name in ["v1", "v1_typedef"]:
2429
self.expect(
2530
"frame variable " + name,
@@ -65,32 +70,16 @@ def test_with_run_command(self):
6570
self.expect("frame variable v_valueless", substrs=["v_valueless = No Value"])
6671

6772
self.expect(
68-
"frame variable v_many_types_valueless",
69-
substrs=["v_many_types_valueless = No Value"],
70-
)
71-
72-
@add_test_categories(["libstdcxx"])
73-
def test_invalid_variant_index(self):
74-
"""Test LibStdC++ data formatter for std::variant with invalid index."""
75-
self.build()
76-
77-
(self.target, self.process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
78-
self, "// break here", lldb.SBFileSpec("main.cpp", False)
79-
)
80-
81-
lldbutil.continue_to_breakpoint(self.process, bkpt)
82-
83-
self.expect(
84-
"frame variable v1",
85-
substrs=["v1 = Active Type = int {", "Value = 12", "}"],
73+
"frame variable v_300_types_valueless",
74+
substrs=["v_300_types_valueless = No Value"],
8675
)
8776

88-
var_v1 = thread.frames[0].FindVariable("v1")
89-
var_v1_raw_obj = var_v1.GetNonSyntheticValue()
90-
index_obj = var_v1_raw_obj.GetChildMemberWithName("_M_index")
91-
self.assertTrue(index_obj and index_obj.IsValid())
77+
@add_test_categories(["libc++"])
78+
def test_libcxx(self):
79+
self.build(dictionary={"USE_LIBCPP": 1})
80+
self.do_test()
9281

93-
INVALID_INDEX = "100"
94-
index_obj.SetValueFromCString(INVALID_INDEX)
95-
96-
self.expect("frame variable v1", substrs=["v1 = <Invalid>"])
82+
@add_test_categories(["libstdcxx"])
83+
def test_libstdcxx(self):
84+
self.build(dictionary={"USE_LIBSTDCPP": 1})
85+
self.do_test()

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/variant/main.cpp renamed to lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/variant/main.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ struct S {
1010
};
1111

1212
int main() {
13-
bool has_variant = true;
14-
15-
printf("%d\n", has_variant); // break here
16-
1713
std::variant<int, double, char> v1;
1814
std::variant<int, double, char> &v1_ref = v1;
15+
1916
using V1_typedef = std::variant<int, double, char>;
2017
V1_typedef v1_typedef;
2118
V1_typedef &v1_typedef_ref = v1_typedef;
@@ -24,7 +21,7 @@ int main() {
2421
std::variant<int, double, char> v3;
2522
std::variant<std::variant<int, double, char>> v_v1;
2623
std::variant<int, char, S> v_valueless = 5;
27-
// The next variant has many types, meaning the type index does not fit in
24+
// The next variant has 300 types, meaning the type index does not fit in
2825
// a byte and must be `unsigned short` instead of `unsigned char` when
2926
// using the unstable libc++ ABI. With stable libc++ ABI, the type index
3027
// is always just `unsigned int`.
@@ -45,11 +42,15 @@ int main() {
4542
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
4643
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
4744
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
48-
int, int, int, int, int, int, int, int, int, int, int, int, S>
49-
v_many_types_valueless;
45+
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
46+
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
47+
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
48+
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
49+
S>
50+
v_300_types_valueless;
5051

5152
v_valueless = 5;
52-
v_many_types_valueless.emplace<0>(10);
53+
v_300_types_valueless.emplace<0>(10);
5354

5455
v1 = 12; // v contains int
5556
v1_typedef = v1;
@@ -83,11 +84,11 @@ int main() {
8384
try {
8485
// Exception in move-assignment is guaranteed to put std::variant into a
8586
// valueless state.
86-
v_many_types_valueless = S();
87+
v_300_types_valueless = S();
8788
} catch (...) {
8889
}
8990

90-
printf("%d\n", v_many_types_valueless.valueless_by_exception());
91+
printf("%d\n", v_300_types_valueless.valueless_by_exception());
9192

9293
return 0; // break here
9394
}

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py

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

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

Lines changed: 0 additions & 95 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CXX_SOURCES := main.cpp
2-
3-
USE_LIBSTDCPP := 1
42
CXXFLAGS_EXTRAS := -std=c++17
3+
USE_LIBSTDCPP := 1
4+
55
include Makefile.rules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
from lldbsuite.test.lldbtest import *
4+
from lldbsuite.test import lldbutil
5+
6+
7+
class InvalidStdVariantDataFormatterTestCase(TestBase):
8+
@add_test_categories(["libstdcxx"])
9+
def test(self):
10+
"""Test STL data formatters for std::variant with invalid index."""
11+
self.build()
12+
13+
(_, _, thread, _) = lldbutil.run_to_source_breakpoint(
14+
self, "// break here", lldb.SBFileSpec("main.cpp", False)
15+
)
16+
17+
self.expect(
18+
"frame variable v1",
19+
substrs=["v1 = Active Type = char {", "Value = 'x'", "}"],
20+
)
21+
22+
var_v1 = thread.frames[0].FindVariable("v1")
23+
var_v1_raw_obj = var_v1.GetNonSyntheticValue()
24+
index_obj = var_v1_raw_obj.GetChildMemberWithName("_M_index")
25+
self.assertTrue(index_obj and index_obj.IsValid())
26+
27+
INVALID_INDEX = "100"
28+
index_obj.SetValueFromCString(INVALID_INDEX)
29+
30+
self.expect("frame variable v1", substrs=["v1 = <Invalid>"])
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <cstdio>
2+
#include <variant>
3+
4+
int main() {
5+
std::variant<int, double, char> v1;
6+
v1 = 'x';
7+
8+
std::puts("// break here");
9+
10+
return 0;
11+
}

0 commit comments

Comments
 (0)