Skip to content

Commit b4025ac

Browse files
committed
tests: check_selftest: fix the Makefile, gitignore checks and result merging
Multiple issues here: - git grep does not have --exit-code - capture output, otherwise it goes to stdout - needle must be stripped from the full path - result merging logic is wrong - result merge doesn't override input, caller must capture ret Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent f93bc61 commit b4025ac

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

tests/patch/check_selftest/test.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212

1313
def ret_merge(ret, nret):
1414
""" merge results """
15-
if ret[0] == 0 or nret[0] == 0:
15+
if ret[0] == 0 and nret[0] == 0:
1616
val = 0
17+
elif ret[0] == 1 or nret[0] == 1:
18+
val = 1
1719
else:
18-
val = min(ret[0], nret[0])
20+
val = max(ret[0], nret[0])
1921

2022
desc = ""
2123
if ret[1] and nret[1]:
@@ -41,12 +43,14 @@ def check_new_files_makefile(tree, new_files, log):
4143
continue
4244

4345
makefile = os.path.dirname(path) + "/Makefile"
46+
needle = os.path.basename(path)
4447

45-
cmd = ["git", "grep", "--exit-code", needle, "---", makefile]
46-
result = subprocess.run(cmd, cwd=tree.path, check=False)
48+
cmd = ["git", "grep", needle, "--", makefile]
49+
result = subprocess.run(cmd, cwd=tree.path, capture_output=True,
50+
check=False)
4751
log.append(" ".join(cmd) + f":: {result.returncode}")
4852
if result.returncode:
49-
ret_merge(ret, (1, path + " not found in Makefile"))
53+
ret = ret_merge(ret, (1, path + " not found in Makefile"))
5054
cnt += 1
5155

5256
if not ret[0] and cnt:
@@ -69,12 +73,14 @@ def check_new_files_gitignore(tree, new_files, log):
6973
continue
7074

7175
target = os.path.dirname(path) + "/.gitignore"
76+
needle = os.path.basename(path)
7277

73-
cmd = ["git", "grep", "--exit-code", needle, "---", target]
74-
result = subprocess.run(cmd, cwd=tree.path, check=False)
78+
cmd = ["git", "grep", needle, "--", target]
79+
result = subprocess.run(cmd, cwd=tree.path, capture_output=True,
80+
check=False)
7581
log.append(" ".join(cmd) + f":: {result.returncode}")
7682
if result.returncode:
77-
ret_merge(ret, (1, needle + " not found in .gitignore"))
83+
ret = ret_merge(ret, (1, needle + " not found in .gitignore"))
7884
cnt += 1
7985

8086
if not ret[0] and cnt:

0 commit comments

Comments
 (0)