Skip to content

Commit 71de735

Browse files
jacob-kellerkuba-moo
authored andcommitted
tests: kdoc: handle buggy "line number only" warnings
Some versions of kernel-doc currently report certain warnings with only their line number. This breaks the logic of the kdoc test, as such lines do not pass the expected format defined by the KdocWarning class. Such warnings appear to indicate duplicate section headers in a kernel doc entry, but the text of the warning is not properly displayed. As a result, the kdoc test produces false positive failures for patches which touch files that have such warnings. The line contents are compared without ignoring the line numbers. This produces output failures: Warnings before: 7 after: 7 (add: 2 del: 2) Warnings removed: Warning: 174 Warning: 184 Per-file breakdown: 2 None New warnings added: Warning: 180 Warning: 196 Per-file breakdown: 2 None Since the warnings are compared directly, the changing line numbers are detected as differences. This is a bug in the kernel-doc script, and a proper fix requires updating the script to stop producing such warnings. In the mean time, the NIPA tests continue to fail. To fix that, use a separate regular expression to identify lines of the form 'Warning: <number>'. Set the content of such warnings to None. This will make all such warnings compare as identical in the existing algorithm, and thus the changing line numbers will no longer cause such a false positive. To avoid introducing further regressions, extend the check to count the total number of unparsed warnings. If it increases, then also fail the kdoc test. This way, we will correctly fail when we see more empty warnings after applying the current patch. This also should help catch issues for other types of unrecognized warnings in the future. Note that all warnings still get compared in the usual way, where fully unrecognized warnings will be compare the lines as-is without eliding the line number comparison. This just adds an additional safety guard in addition to handling the empty warning case. Signed-off-by: Jacob Keller <[email protected]>
1 parent 07b2101 commit 71de735

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

tests/patch/kdoc/test.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class KdocWarning:
3030
# Note: *not* part of comparison, or hash!
3131
line : Optional[int] = dataclasses.field(repr=True, compare=False)
3232
# The content of the warning (excluding kind, file, line)
33-
content : str = dataclasses.field(repr=True, compare=True)
33+
content : Optional[str] = dataclasses.field(repr=True, compare=True)
3434
parsed : bool = dataclasses.field(repr=True, compare=True)
3535

3636
@classmethod
@@ -65,6 +65,29 @@ def from_text(self, line, extra=None):
6565
return KdocWarning(message, kind=kind, file=file, line=line,
6666
content=content, parsed=True)
6767

68+
# Check for line-number only warnings produced by certain buggy
69+
# versions of kernel-doc. These will get treated as unparsed but
70+
# all such warnings will compare identically to each other.
71+
line_only_parser = re.compile(
72+
r"""
73+
^ # Start of string
74+
(?P<kind>warning|error): # Severity
75+
\s+ # Spacing
76+
(?P<line>[0-9]+) # Line number
77+
$ # End of string
78+
""",
79+
re.VERBOSE | re.IGNORECASE)
80+
81+
m = line_only_parser.match(line)
82+
if m:
83+
kind = m['kind']
84+
line = m['line']
85+
86+
return KdocWarning(message, kind=kind, file=None, line=line,
87+
content=None, parsed=False)
88+
89+
# The warning text didn't match a known format. Such warnings will be
90+
# counted to ensure that we don't increase this count over time.
6891
return KdocWarning(message, kind='Unknown', file=None, line=None,
6992
content=line, parsed=False)
7093

@@ -188,6 +211,10 @@ def kdoc(tree, patch, _result_dir) -> Tuple[int, str, str]:
188211
new_count = len(new_warnings)
189212
rm_count = len(rm_warnings)
190213

214+
# Count the number of warnings which we failed to parse
215+
current_unparsed = len([x for x in current_warnings if not x.parsed])
216+
incumbent_unparsed = len([x for x in incumbent_warnings if not x.parsed])
217+
191218
desc = f'Warnings before: {incumbent_count} after: {current_count}'
192219
brac = []
193220
if new_count:
@@ -220,4 +247,8 @@ def kdoc(tree, patch, _result_dir) -> Tuple[int, str, str]:
220247
for f, count in file_breakdown.items():
221248
log += [f'{count:6} {f}']
222249

250+
if current_unparsed > incumbent_unparsed:
251+
ret = 1
252+
log += ["", f'Number of parse failures increased from {incumbent_unparsed} to {current_unparsed}.']
253+
223254
return ret, desc, "\n".join(log)

0 commit comments

Comments
 (0)