Skip to content

Commit 0a1066f

Browse files
committed
tests: kdoc: fix handling file removal
Looks like the kdoc test struggles with file deletion as well as files which produce no warnings at all. Fix that. Add more logs for ease of troubleshooting. While at it shorten the outputs a little bit to make the summary fit on a line when running ingest_mdir Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent d390981 commit 0a1066f

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

tests/patch/kdoc/test.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def from_text(self, line, extra=None):
7272
def __str__(self):
7373
return self.message
7474

75-
def parse_warnings(lines) -> List[KdocWarning]:
75+
def parse_warnings(lines, logs) -> List[KdocWarning]:
7676
skip = False
7777
length = len(lines)
7878

@@ -87,16 +87,24 @@ def parse_warnings(lines) -> List[KdocWarning]:
8787
if line.endswith(':') and i + 1 < length:
8888
extra = lines[i + 1]
8989
skip = True
90+
elif not line.strip():
91+
continue
9092
else:
93+
logs += ["<parse fail>: " + line.strip()]
9194
extra = None
9295

9396
warnings.append(KdocWarning.from_text(line, extra))
9497

9598
return warnings
9699

97-
def run_kernel_doc(tree, commitish, files) -> List[KdocWarning]:
100+
def run_kernel_doc(tree, commitish, files, logs) -> List[KdocWarning]:
98101
""" Run ./scripts/kdoc on a given commit and capture its results. """
99102

103+
logs += ["files: " + str(files)]
104+
105+
if not files:
106+
return []
107+
100108
cmd = ["git", "checkout", "-q", commitish]
101109
subprocess.run(cmd, cwd=tree.path, capture_output=False, check=True)
102110

@@ -106,13 +114,13 @@ def run_kernel_doc(tree, commitish, files) -> List[KdocWarning]:
106114

107115
lines = result.stderr.strip().split('\n')
108116

109-
return parse_warnings(lines)
117+
return parse_warnings(lines, logs)
110118

111119
def extract_files(patch):
112120
"""Extract paths added or modified by the patch."""
113121

114-
all_files = set()
115-
mod_files = set()
122+
before_files = set()
123+
after_files = set()
116124
lines = patch.raw_patch.split("\n")
117125

118126
# Walk lines, skip last since it doesn't have next
@@ -124,19 +132,19 @@ def extract_files(patch):
124132

125133
file_path = next_line[6:]
126134

127-
all_files.add(file_path)
128-
129-
if line != "--- /dev/null":
130-
mod_files.add(file_path)
135+
if "/dev/null" not in line:
136+
before_files.add(file_path)
137+
if "/dev/null" not in next_line:
138+
after_files.add(file_path)
131139

132-
return list(mod_files), list(all_files)
140+
return list(before_files), list(after_files)
133141

134142
def kdoc(tree, patch, _result_dir) -> Tuple[int, str, str]:
135143
""" Main function / entry point """
136144

137-
mod_files, all_files = extract_files(patch)
145+
before_files, after_files = extract_files(patch)
138146

139-
if not mod_files or not all_files:
147+
if not before_files and not after_files:
140148
return 1, "Patch has no modified files?", ""
141149

142150
ret = 0
@@ -146,12 +154,12 @@ def kdoc(tree, patch, _result_dir) -> Tuple[int, str, str]:
146154
head_commit = get_git_head(tree)
147155

148156
try:
149-
incumbent_warnings = run_kernel_doc(tree, "HEAD~", mod_files)
150157
log += ["Warnings before patch:"]
158+
incumbent_warnings = run_kernel_doc(tree, "HEAD~", before_files, log)
151159
log.extend(map(str, incumbent_warnings))
152160

153-
current_warnings = run_kernel_doc(tree, head_commit, all_files)
154161
log += ["", "Current warnings:"]
162+
current_warnings = run_kernel_doc(tree, head_commit, after_files, log)
155163
log.extend(map(str, current_warnings))
156164
except subprocess.CalledProcessError as e:
157165
desc = f'{e.cmd} failed with exit code {e.returncode}'
@@ -173,11 +181,14 @@ def kdoc(tree, patch, _result_dir) -> Tuple[int, str, str]:
173181
new_count = len(new_warnings)
174182
rm_count = len(rm_warnings)
175183

176-
desc = f'Errors and warnings before: {incumbent_count} This patch: {current_count}'
184+
desc = f'Warnings before: {incumbent_count} after: {current_count}'
185+
brac = []
177186
if new_count:
178-
desc += f' New: {new_count}'
187+
brac += [f'add: {new_count}']
179188
if rm_count:
180-
desc += f' Removed: {rm_count}'
189+
brac += [f'del: {rm_count}']
190+
if brac:
191+
desc += f' ({" ".join(brac)})'
181192
log += ["", desc]
182193

183194
if rm_count:

0 commit comments

Comments
 (0)