Skip to content

[lldb] Support ordered patterns in lldbtest.expect #131475

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

Merged
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
22 changes: 12 additions & 10 deletions lldb/packages/Python/lldbsuite/test/lldbtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2356,8 +2356,9 @@ def expect(
matches the patterns contained in 'patterns'.

When matching is true and ordered is true, which are both the default,
the strings in the substrs array have to appear in the command output
in the order in which they appear in the array.
the strings in the substrs array, and regex in the patterns array, have
to appear in the command output in the order in which they appear in
their respective array.

If the keyword argument error is set to True, it signifies that the API
client is expecting the command to fail. In this case, the error stream
Expand Down Expand Up @@ -2460,9 +2461,9 @@ def found_str(matched):
if substrs and matched == matching:
start = 0
for substr in substrs:
index = output[start:].find(substr)
start = start + index + len(substr) if ordered and matching else 0
index = output.find(substr, start)
matched = index != -1
start = index + len(substr) if ordered and matched else 0
log_lines.append(
'{} sub string: "{}" ({})'.format(
expecting_str, substr, found_str(matched)
Expand All @@ -2473,20 +2474,21 @@ def found_str(matched):
break

if patterns and matched == matching:
start = 0
for pattern in patterns:
matched = re.search(pattern, output)
pat = re.compile(pattern)
match = pat.search(output, start)
matched = bool(match)
start = match.end() if ordered and matched else 0

pattern_line = '{} regex pattern: "{}" ({}'.format(
expecting_str, pattern, found_str(matched)
)
if matched:
pattern_line += ', matched "{}"'.format(matched.group(0))
if match:
pattern_line += ', matched "{}"'.format(match.group(0))
pattern_line += ")"
log_lines.append(pattern_line)

# Convert to bool because match objects
# are True-ish but is not True itself
matched = bool(matched)
if matched != matching:
break

Expand Down
2 changes: 1 addition & 1 deletion lldb/test/API/functionalities/alias/TestBtAliasRepeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test(self):
lldbutil.run_to_source_breakpoint(self, "return", lldb.SBFileSpec("main.c"))

# Expect "frame #0" but not "frame #1".
self.expect("bt 1", inHistory=True, patterns=["frame #0", "^(?!.*frame #1)"])
self.expect("bt 1", inHistory=True, patterns=["frame #0", "(?!.*frame #1)"])

# Run an empty command to run the repeat command for `bt`.
# The repeat command for `bt N` lists the subsequent N frames.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def nscontainers_data_formatter_commands(self):

self.expect(
"frame variable -d run-target *nscfDictionary",
ordered=False,
patterns=[
r"\(__NSCFDictionary\) \*nscfDictionary =",
'key = 0x.* @"foo"',
Expand All @@ -67,6 +68,7 @@ def nscontainers_data_formatter_commands(self):

self.expect(
"frame variable -d run-target *cfDictionaryRef",
ordered=False,
patterns=[
r"\(const __CFDictionary\) \*cfDictionaryRef =",
'key = 0x.* @"foo"',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ def cleanup():
)

def look_for_content_and_continue(self, var_name, patterns):
self.expect(("frame variable %s" % var_name), patterns=patterns)
self.expect(("frame variable %s" % var_name), patterns=patterns)
self.expect(("frame variable %s" % var_name), ordered=False, patterns=patterns)
self.expect(("frame variable %s" % var_name), ordered=False, patterns=patterns)
self.runCmd("continue")

@add_test_categories(["libstdcxx"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ def test_ref_and_ptr(self):

# The pointer should just show the right number of elements:

self.expect("frame variable ptr", patterns=["ptr = 0x.*", " size=5"])
self.expect("frame variable ptr", patterns=["ptr = 0x[0-9a-f]+ size=5"])
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def test(self):
"v summary_and_children_ref", substrs=["some summary", "child = 30"]
)
self.expect(
"v summary_only_ref", patterns=["some summary", "(?s)^(?!.*child = )"]
"v summary_only_ref", patterns=["some summary", "(?s)(?!.*child = )"]
)
self.expect(
"v children_only_ref", patterns=["(?s)^(?!.*some summary)", "child = 30"]
"v children_only_ref", patterns=["(?s)(?!.*some summary)", "child = 30"]
)
2 changes: 1 addition & 1 deletion lldb/test/API/lang/cpp/signed_types/TestSignedTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def test(self):
"frame variable --show-types --no-args",
VARIABLES_DISPLAYED_CORRECTLY,
patterns=[
r"\((short int|short)\) the_signed_short = 99",
r"\((signed char|char)\) the_signed_char = 'c'",
r"\((short int|short)\) the_signed_short = 99",
],
substrs=[
"(int) the_signed_int = 99",
Expand Down
2 changes: 1 addition & 1 deletion lldb/test/API/lang/objc/foundation/TestObjCMethods.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_data_type_and_expr(self):
"frame variable --show-types --scope",
VARIABLES_DISPLAYED_CORRECTLY,
substrs=["ARG: (MyString *) self"],
patterns=[r"ARG: \(.*\) _cmd", "(objc_selector *)|(SEL)"],
patterns=[r"ARG: \(SEL|objc_selector \*\) _cmd"],
)

# rdar://problem/8651752
Expand Down
1 change: 1 addition & 0 deletions lldb/test/API/source-manager/TestSourceManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def do_display_source_python_api(
stream.GetData(),
"Source code displayed correctly:\n" + stream.GetData(),
exe=False,
ordered=False,
patterns=["=>", "%d.*Hello world" % self.line, needle_regex],
)

Expand Down