Skip to content

Commit

Permalink
[lldb][Test] Fix import-std-module and data-formatter tests on older …
Browse files Browse the repository at this point in the history
…compilers

Fixes API tests for older compilers.
Since https://reviews.llvm.org/D141828 defaulted
arguments will be omitted, but older Clang's won't.

Differential Revision: https://reviews.llvm.org/D143022
  • Loading branch information
Michael137 committed Feb 2, 2023
1 parent d2375f3 commit 3c66729
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def test(self):

self.runCmd("settings set target.import-std-module true")

deque_type = "std::deque<int>"
if self.expectedCompilerVersion(['>', '16.0']):
deque_type = "std::deque<int>"
else:
deque_type = "std::deque<int, std::allocator<int> >"

size_type = "size_type"
value_type = "value_type"
iterator = "iterator"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def test(self):

self.runCmd("settings set target.import-std-module true")

deque_type = "std::deque<Foo>"
if self.expectedCompilerVersion(['>', '16.0']):
deque_type = "std::deque<Foo>"
else:
deque_type = "std::deque<Foo, std::allocator<Foo> >"

size_type = "size_type"
value_type = "value_type"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def test(self):

self.runCmd("settings set target.import-std-module true")

list_type = "std::forward_list<Foo>"
if self.expectedCompilerVersion(['>', '16.0']):
list_type = "std::forward_list<Foo>"
else:
list_type = "std::forward_list<Foo, std::allocator<Foo> >"

value_type = "value_type"

# FIXME: This has three elements in it but the formatter seems to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def test(self):

self.runCmd("settings set target.import-std-module true")

list_type = "std::forward_list<int>"
if self.expectedCompilerVersion(['>', '16.0']):
list_type = "std::forward_list<int>"
else:
list_type = "std::forward_list<int, std::allocator<int> >"

value_type = "value_type"

# FIXME: This has three elements in it but the formatter seems to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def test(self):

self.runCmd("settings set target.import-std-module true")

list_type = "std::list<Foo>"
if self.expectedCompilerVersion(['>', '16.0']):
list_type = "std::list<Foo>"
else:
list_type = "std::list<Foo, std::allocator<Foo> >"

size_type = "size_type"
value_type = "value_type"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def test(self):

self.runCmd("settings set target.import-std-module true")

list_type = "std::list<int>"
if self.expectedCompilerVersion(['>', '16.0']):
list_type = "std::list<int>"
else:
list_type = "std::list<int, std::allocator<int> >"

size_type = "size_type"
value_type = "value_type"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ def test(self):
ValueCheck(value="2"),
]

vector_type = "std::vector<int>"
if self.expectedCompilerVersion(['>', '16.0']):
vector_type = "std::vector<int>"
dbg_vec_type = "std::vector<DbgInfoClass>"
module_vector_type = "std::vector<int>"
else:
vector_type = "std::vector<int, std::allocator<int> >"
dbg_vec_type = "std::vector<DbgInfoClass, std::allocator<DbgInfoClass> >"
module_vector_type = "std::vector<int>"

# First muddy the scratch AST with non-C++ module types.
self.expect_expr("a", result_type=vector_type,
result_children=children)
self.expect_expr("dbg_info_vec",
result_type="std::vector<DbgInfoClass>",
result_type=dbg_vec_type,
result_children=[
ValueCheck(type="DbgInfoClass", children=[
ValueCheck(name="ints", type=vector_type, children=[
Expand All @@ -48,15 +55,15 @@ def test(self):

# Enable the C++ module import and get the module vector type.
self.runCmd("settings set target.import-std-module true")
self.expect_expr("a", result_type=vector_type,
self.expect_expr("a", result_type=module_vector_type,
result_children=children)

# Test mixed debug info/module types
self.expect_expr("dbg_info_vec",
result_type="std::vector<DbgInfoClass>",
result_type=dbg_vec_type,
result_children=[
ValueCheck(type="DbgInfoClass", children=[
ValueCheck(name="ints", type=vector_type, children=[
ValueCheck(name="ints", type=module_vector_type, children=[
ValueCheck(value="1")
])
])
Expand All @@ -70,7 +77,7 @@ def test(self):

# Test the types that were previoiusly mixed debug info/module types.
self.expect_expr("dbg_info_vec",
result_type="std::vector<DbgInfoClass>",
result_type=dbg_vec_type,
result_children=[
ValueCheck(type="DbgInfoClass", children=[
ValueCheck(name="ints", type=vector_type, children=[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def test(self):

self.runCmd("settings set target.import-std-module true")

queue_type = "std::queue<C>"
if self.expectedCompilerVersion(['>', '16.0']):
queue_type = "std::queue<C>"
else:
queue_type = "std::queue<C, std::deque<C, std::allocator<C> > >"

size_type = "size_type"
value_type = "value_type"

Expand Down Expand Up @@ -52,7 +56,11 @@ def test(self):
result_value="5")

# Test std::queue functionality with a std::list.
queue_type = "std::queue<C, std::list<C> >"
if self.expectedCompilerVersion(['>', '16.0']):
queue_type = "std::queue<C, std::list<C> >"
else:
queue_type = "std::queue<C, std::list<C, std::allocator<C> > >"

self.expect_expr(
"q_list",
result_type=queue_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ def test(self):
"// Set break point at this line.",
lldb.SBFileSpec("main.cpp"))

if self.expectedCompilerVersion(['>', '16.0']):
vec_type = "std::vector<int>"
else:
vec_type = "std::vector<int, std::allocator<int> >"

# Test printing the vector before enabling any C++ module setting.
self.expect_expr("a", result_type="std::vector<int>")
self.expect_expr("a", result_type=vec_type)

# Set loading the import-std-module to 'fallback' which loads the module
# and retries when an expression fails to parse.
self.runCmd("settings set target.import-std-module fallback")

# Printing the vector still works. This should return the same type
# as before as this shouldn't use a C++ module type.
self.expect_expr("a", result_type="std::vector<int>")
self.expect_expr("a", result_type=vec_type)

# This expression can only parse with a C++ module. LLDB should
# automatically fall back to import the C++ module to get this working.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ def test(self):

self.runCmd("settings set target.import-std-module true")

if self.expectedCompilerVersion(['>', '16.0']):
ptr_type = "std::unique_ptr<Foo>"
else:
ptr_type = "std::unique_ptr<Foo, std::default_delete<Foo> >"

self.expect_expr(
"s",
result_type="std::unique_ptr<Foo>",
result_type=ptr_type,
result_children=[ValueCheck(children=[ValueCheck(value="3")])])
self.expect_expr("s->a", result_type="int", result_value="3")
self.expect_expr("s->a = 5", result_type="int", result_value="5")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ def test(self):

self.runCmd("settings set target.import-std-module true")

if self.expectedCompilerVersion(['>', '16.0']):
ptr_type = "std::unique_ptr<int>"
else:
ptr_type = "std::unique_ptr<int, std::default_delete<int> >"

self.expect_expr(
"s",
result_type="std::unique_ptr<int>",
result_type=ptr_type,
result_summary="3",
result_children=[ValueCheck(name="__value_")])
self.expect_expr("*s", result_type="int", result_value="3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def test(self):

self.runCmd("settings set target.import-std-module true")

vector_type = "std::vector<Foo>"
if self.expectedCompilerVersion(['>', '16.0']):
vector_type = "std::vector<Foo>"
else:
vector_type = "std::vector<Foo, std::allocator<Foo> >"

size_type = "size_type"
value_type = "value_type"
iterator = "iterator"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ def test(self):
"// Set break point at this line.",
lldb.SBFileSpec("main.cpp"))

vector_type = "std::vector<int>"
vector_of_vector_type = "std::vector<" + vector_type + " >"
if self.expectedCompilerVersion(['>', '16.0']):
vector_type = "std::vector<int>"
vector_of_vector_type = "std::vector<std::vector<int> >"
else:
vector_type = "std::vector<int>"
vector_of_vector_type = "std::vector<std::vector<int>, std::allocator<std::vector<int> > >"

size_type = "size_type"
value_type = "value_type"

Expand All @@ -29,13 +34,13 @@ def test(self):
"a",
result_type=vector_of_vector_type,
result_children=[
ValueCheck(type="std::vector<int>",
ValueCheck(type=vector_type,
children=[
ValueCheck(value='1'),
ValueCheck(value='2'),
ValueCheck(value='3'),
]),
ValueCheck(type="std::vector<int>",
ValueCheck(type=vector_type,
children=[
ValueCheck(value='3'),
ValueCheck(value='2'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ def test_shared_ptr_variables(self):
self.assertRegex(valobj.summary, r"^10( strong=1)? weak=1$")
self.assertNotEqual(valobj.child[0].unsigned, 0)

if self.expectedCompilerVersion(['>', '16.0']):
string_type = "std::basic_string<char>"
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<std::basic_string<char> >",
type="std::shared_ptr<" + string_type + " >",
children=[ValueCheck(name="__ptr_", summary='"hello"')],
)
self.assertRegex(valobj.summary, r'^"hello"( strong=1)? weak=1$')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ def cleanup():
self.addTearDownHook(cleanup)

ns = self.namespace

if self.expectedCompilerVersion(['>', '16.0']):
expected_basic_string = '%s::basic_string<unsigned char>'%ns
else:
expected_basic_string = '%s::basic_string<unsigned char, %s::char_traits<unsigned char>, ' \
'%s::allocator<unsigned char> >'%(ns,ns,ns)

self.expect(
"frame variable",
substrs=[
Expand All @@ -70,7 +77,7 @@ def cleanup():
'(%s::u32string) u32_string = U"🍄🍅🍆🍌"'%ns,
# FIXME: This should have a 'U' prefix.
'(%s::u32string) u32_empty = ""'%ns,
'(%s::basic_string<unsigned char>) uchar = "aaaaa"'%(ns),
'(%s) uchar = "aaaaa"'%expected_basic_string,
'(%s::string *) null_str = nullptr'%ns,
])

Expand Down Expand Up @@ -107,7 +114,7 @@ def cleanup():
'(%s::u16string) u16_string = u"ß水氶"'%ns,
'(%s::u32string) u32_string = U"🍄🍅🍆🍌"'%ns,
'(%s::u32string) u32_empty = ""'%ns,
'(%s::basic_string<unsigned char>) uchar = "aaaaa"'%(ns),
'(%s) uchar = "aaaaa"'%expected_basic_string,
'(%s::string *) null_str = nullptr'%ns,
])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ def cleanup():
# Execute the cleanup function during test case tear down.
self.addTearDownHook(cleanup)

if self.expectedCompilerVersion(['>', '16.0']):
expected_basic_string = 'std::basic_string<unsigned char>'
expected_basic_string_view = 'std::basic_string_view<unsigned char>'
else:
expected_basic_string = 'std::basic_string<unsigned char, std::char_traits<unsigned char>, std::allocator<unsigned char> >'
expected_basic_string_view = 'std::basic_string_view<unsigned char, std::char_traits<unsigned char> >'

self.expect_var_path('wempty',
type='std::wstring_view',
summary='L""')
Expand Down Expand Up @@ -96,10 +103,10 @@ def cleanup():
type='std::u32string_view',
summary='""')
self.expect_var_path('uchar_source',
type='std::basic_string<unsigned char>',
type=expected_basic_string,
summary='"aaaaaaaaaa"')
self.expect_var_path('uchar',
type='std::basic_string_view<unsigned char>',
type=expected_basic_string_view,
summary='"aaaaa"')
self.expect_var_path('oops',
type='std::string_view',
Expand Down Expand Up @@ -172,10 +179,10 @@ def cleanup():
type='std::u32string_view',
summary='""')
self.expect_var_path('uchar_source',
type='std::basic_string<unsigned char>',
type=expected_basic_string,
summary='"aaaaaaaaaa"')
self.expect_var_path('uchar',
type='std::basic_string_view<unsigned char>',
type=expected_basic_string_view,
summary='"aaaaa"')

self.runCmd('cont')
Expand Down
Loading

0 comments on commit 3c66729

Please sign in to comment.