Skip to content

Commit 1e6dd8c

Browse files
authored
[lldb][test] Merge MSVC STL std::(u8)string tests into generic directory (#147525)
Now that most STL formatter tests have been moved to `generic`. Do the same for the MSVC tests (which are currently just for `std::string`). The `std::string` test was mostly the same (MSVC just had 1 additional check, which I moved over). We also only tested `u8string` with MSVC. So i moved those into `generic` as-is. I kept it separate from the existing std::string tests since it requires c++20. The tests are currently failing for libc++ and libstdc++ because MSVC had a test case which checked that: ``` std::string overwritten_zero("abc"); const_cast<char *>(overwritten_zero.data())[3] = 'd'; ``` prints as `"abc"`. But libc++ and libstdc++ print it as `"abcd"` (which seems like the more correct thing to do?)
1 parent 8ff6363 commit 1e6dd8c

File tree

8 files changed

+106
-182
lines changed

8 files changed

+106
-182
lines changed

lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/TestDataFormatterStdString.py

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ def test_libstdcxx(self):
124124
self.build(dictionary={"USE_LIBSTDCPP": 1})
125125
self.do_test()
126126

127+
@add_test_categories(["msvcstl"])
128+
def test_msvc(self):
129+
self.build()
130+
self.do_test()
131+
127132
def do_test_multibyte(self):
128133
lldbutil.run_to_source_breakpoint(
129134
self, "Set break point at this line.", self.main_spec
@@ -134,9 +139,6 @@ def do_test_multibyte(self):
134139
self.expect(
135140
"frame variable",
136141
substrs=[
137-
'(%s::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"' % ns,
138-
'(%s::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"'
139-
% ns,
140142
'(%s::u16string) u16_string = u"ß水氶"' % ns,
141143
'(%s::u16string) u16_empty = u""' % ns,
142144
'(%s::u32string) u32_string = U"🍄🍅🍆🍌"' % ns,
@@ -157,6 +159,11 @@ def test_multibyte_libstdcxx(self):
157159
self.build(dictionary={"USE_LIBSTDCPP": 1})
158160
self.do_test_multibyte()
159161

162+
@add_test_categories(["msvcstl"])
163+
def test_multibyte_msvc(self):
164+
self.build()
165+
self.do_test_multibyte()
166+
160167
def do_test_uncapped_summary(self):
161168
(_, _, thread, _) = lldbutil.run_to_source_breakpoint(
162169
self, "Set break point at this line.", self.main_spec
@@ -187,6 +194,11 @@ def test_uncapped_libstdcxx(self):
187194
self.build(dictionary={"USE_LIBSTDCPP": 1})
188195
self.do_test_uncapped_summary()
189196

197+
@add_test_categories(["msvcstl"])
198+
def test_uncapped_msvc(self):
199+
self.build()
200+
self.do_test_uncapped_summary()
201+
190202
def do_test_summary_unavailable(self):
191203
"""
192204
Make sure that if the string is not readable, we give an error.
@@ -212,3 +224,67 @@ def test_unavailable_summary_libcxx(self):
212224
def test_unavailable_summary_libstdcxx(self):
213225
self.build(dictionary={"USE_LIBSTDCPP": 1})
214226
self.do_test_summary_unavailable()
227+
228+
@add_test_categories(["msvcstl"])
229+
def test_unavailable_summary_msvc(self):
230+
self.build()
231+
self.do_test_summary_unavailable()
232+
233+
def do_test_overwritten(self):
234+
lldbutil.run_to_source_breakpoint(
235+
self, "Set break point at this line.", self.main_spec
236+
)
237+
238+
self.expect_var_path("overwritten_zero", summary='"abc"')
239+
240+
@add_test_categories(["libc++"])
241+
def test_overwritten_libcxx(self):
242+
self.build(dictionary={"USE_LIBCPP": 1})
243+
self.do_test_overwritten()
244+
245+
@expectedFailureAll(
246+
bugnumber="libstdc++ format for non-null terminated std::string currently diverges from MSVC and libc++ formatter."
247+
)
248+
@add_test_categories(["libstdcxx"])
249+
def test_overwritten_libstdcxx(self):
250+
self.build(dictionary={"USE_LIBSTDCPP": 1})
251+
self.do_test_overwritten()
252+
253+
@add_test_categories(["msvcstl"])
254+
def test_overwritten_msvc(self):
255+
self.build()
256+
self.do_test_overwritten()
257+
258+
def do_test_embedded_null(self):
259+
lldbutil.run_to_source_breakpoint(
260+
self, "Set break point at this line.", self.main_spec
261+
)
262+
263+
ns = self.namespace
264+
265+
self.expect(
266+
"frame variable",
267+
substrs=[
268+
'(%s::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"' % ns,
269+
'(%s::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"'
270+
% ns,
271+
],
272+
)
273+
274+
@add_test_categories(["libc++"])
275+
def test_embedded_null_libcxx(self):
276+
self.build(dictionary={"USE_LIBCPP": 1})
277+
self.do_test_embedded_null()
278+
279+
@expectedFailureAll(
280+
bugnumber="libstdc++ formatters incorrectly format std::string with embedded '\0' characters."
281+
)
282+
@add_test_categories(["libstdcxx"])
283+
def test_embedded_null_libstdcxx(self):
284+
self.build(dictionary={"USE_LIBSTDCPP": 1})
285+
self.do_test_embedded_null()
286+
287+
@add_test_categories(["msvcstl"])
288+
def test_embedded_null_msvc(self):
289+
self.build()
290+
self.do_test_embedded_null()

lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/string/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ int main() {
1313
std::string empty("");
1414
std::string q("hello world");
1515
std::string Q("quite a long std::strin with lots of info inside it");
16+
std::string overwritten_zero("abc");
17+
const_cast<char *>(overwritten_zero.data())[3] = 'd';
1618
std::string TheVeryLongOne(
1719
"123456789012345678901234567890123456789012345678901234567890123456789012"
1820
"345678901234567890123456789012345678901234567890123456789012345678901234"
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
CXX_SOURCES := main.cpp
2+
CXXFLAGS_EXTRAS := -std=c++20
23

34
include Makefile.rules
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# coding=utf8
22
"""
3-
Test std::u8string summary with MSVC's STL.
3+
Test std::u8string summary.
44
"""
55

66

@@ -10,14 +10,8 @@
1010
from lldbsuite.test import lldbutil
1111

1212

13-
class MsvcStlU8StringDataFormatterTestCase(TestBase):
14-
NO_DEBUG_INFO_TESTCASE = True
15-
16-
@add_test_categories(["msvcstl"])
17-
def test_with_run_command(self):
18-
"""Test that that file and class static variables display correctly."""
19-
self.build()
20-
13+
class StdU8StringDataFormatterTestCase(TestBase):
14+
def do_test(self):
2115
lldbutil.run_to_source_breakpoint(
2216
self, "Set break point at this line.", lldb.SBFileSpec("main.cpp")
2317
)
@@ -31,3 +25,20 @@ def test_with_run_command(self):
3125
'(std::u8string) u8_text = u8"ABC"',
3226
],
3327
)
28+
29+
@expectedFailureAll(bugnumber="No libc++ formatters for std::u8string yet.")
30+
@add_test_categories(["libc++"])
31+
def test_libcxx(self):
32+
self.build(dictionary={"USE_LIBCPP": 1})
33+
self.do_test()
34+
35+
@expectedFailureAll(bugnumber="No libstdc++ formatters for std::u8string yet.")
36+
@add_test_categories(["libstdcxx"])
37+
def test_libstdcxx(self):
38+
self.build(dictionary={"USE_LIBSTDCPP": 1})
39+
self.do_test()
40+
41+
@add_test_categories(["msvcstl"])
42+
def test_msvc(self):
43+
self.build()
44+
self.do_test()
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1+
#include <cstdio>
12
#include <string>
23

3-
#ifndef _MSVC_STL_VERSION
4-
// this is more of a sanity check that the categories work as expected
5-
#error Not using MSVC STL
6-
#endif
7-
84
int main() {
95
std::u8string u8_string_small(u8"🍄");
106
std::u8string u8_string(u8"❤️👍📄📁😃🧑‍🌾");
117
std::u8string u8_empty(u8"");
128
std::u8string u8_text(u8"ABC");
13-
u8_text.assign(u8"ABCd"); // Set break point at this line.
9+
u8_text.assign(u8"ABCd");
10+
11+
std::puts("// Set break point at this line.");
1412
}

lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/string/TestDataFormatterMsvcStlString.py

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

lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/string/main.cpp

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

lldb/test/API/functionalities/data-formatter/data-formatter-stl/msvcstl/u8string/Makefile

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

0 commit comments

Comments
 (0)