Skip to content

Commit b7d53eb

Browse files
tests: dt_binding_check: new test
We currently "rely" on Rob Herring's mail bot to provide sanity checking on patches that touch device tree bindings: https://lore.kernel.org/netdev/[email protected] and that is sufficient in "public" settings (patches sent to [email protected] and [email protected] also copied). But in "private" settings (i.e. individual developers encouraged to do sanity checking on their own, for example by running ingest_mdir), we quickly find that Rob's mail bot is apparently closed source, and it has happened more than once (at least to me) for me to miss newly introduced dt_binding_check errors even if I did the due dilligence of running that test locally. So an automated check would be good to have. The justification for including it in NIPA is that while device tree maintainers review binding patches, they get applied to the subsystem tree (in this case netdev). Furthermore, I don't see the overlap with Rob Herring's mail bot as being a strong reason against such checks in NIPA, similar to how the existence of Intel's kbuild test robot does not preclude NIPA from having build tests. In terms of implementation, "make dt_binding_check" does not always nicely print "error" or "warning" on the lines with issues. Furthermore, the errors are multi-line. So instead of filtering for error lines, here we filter out the "normal" lines, which contain things such as "make", "SCHEMA", "CHKDT", "LINT", "DTEX", "DTC" at the beginning. Signed-off-by: Vladimir Oltean <[email protected]>
1 parent b4025ac commit b7d53eb

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
# Copyright 2025 NXP
4+
5+
HEAD=$(git rev-parse HEAD)
6+
ncpu=$(grep -c processor /proc/cpuinfo)
7+
rc=0
8+
9+
pr() {
10+
echo " ====== $* ======" | tee -a /dev/stderr
11+
}
12+
13+
build() {
14+
make -j $ncpu DT_CHECKER_FLAGS=-m dt_binding_check 2>&1
15+
}
16+
17+
# Only run this check if the patch touches DT binding files.
18+
if ! git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | \
19+
grep -q -E "^Documentation/devicetree/bindings/"
20+
then
21+
echo "No DT binding files touched, skip" >&"$DESC_FD"
22+
exit 0
23+
fi
24+
25+
# Create temporary files for logs
26+
tmpfile_o_raw=$(mktemp)
27+
tmpfile_n_raw=$(mktemp)
28+
tmpfile_o_filtered=$(mktemp)
29+
tmpfile_n_filtered=$(mktemp)
30+
tmp_new_issues=$(mktemp)
31+
32+
echo "Tree base:"
33+
git log -1 --pretty='%h ("%s")' HEAD~
34+
echo "Now at:"
35+
git log -1 --pretty='%h ("%s")' HEAD
36+
37+
# Define the filter pattern to exclude build noise from the make output.
38+
# We only want to see the actual error/warning lines.
39+
FILTER_PATTERN="^(make\[| CHKDT| DTC| DTEX| HOSTCC| HOSTLD| LEX| LINT| SCHEMA| YACC|$)"
40+
41+
pr "Checking before the patch"
42+
git checkout -q HEAD~
43+
44+
# Run the check on the parent commit
45+
(build | tee -a "$tmpfile_o_raw") || true
46+
47+
# Filter and sort the output to get only relevant issue lines
48+
grep -v -E "$FILTER_PATTERN" "$tmpfile_o_raw" | sort > "$tmpfile_o_filtered"
49+
incumbent_total=$(wc -l < "$tmpfile_o_filtered")
50+
51+
pr "Checking the tree with the patch"
52+
git checkout -q "$HEAD"
53+
54+
# Run the check on the new commit
55+
(build | tee -a "$tmpfile_n_raw") || true
56+
57+
# Filter and sort the output
58+
grep -v -E "$FILTER_PATTERN" "$tmpfile_n_raw" | sort > "$tmpfile_n_filtered"
59+
current_total=$(wc -l < "$tmpfile_n_filtered")
60+
61+
# Compare the filtered lists to find new and fixed issues
62+
# Use comm to find fixed issues (lines only in the old log, column 1).
63+
fixed_issues_count=$(comm -23 "$tmpfile_o_filtered" "$tmpfile_n_filtered" | wc -l)
64+
65+
# Use comm to find new issues (lines only in the new log, column 2)
66+
# and save them for later display.
67+
comm -13 "$tmpfile_o_filtered" "$tmpfile_n_filtered" > "$tmp_new_issues"
68+
new_issues_count=$(wc -l < "$tmp_new_issues")
69+
70+
echo "Issues before: $incumbent_total, after: $current_total" \
71+
"(Fixed: $fixed_issues_count, New: $new_issues_count)" >&"$DESC_FD"
72+
73+
if [ "$new_issues_count" -gt 0 ]; then
74+
echo "New issues added:" 1>&2
75+
# Print the new issues we saved
76+
cat "$tmp_new_issues" 1>&2
77+
rc=1
78+
elif [ "$fixed_issues_count" -gt 0 ]; then
79+
echo "Patch fixed $fixed_issues_count issue(s)." >&2
80+
# No new issues, and some were fixed. This is a success.
81+
fi
82+
83+
rm "$tmpfile_o_raw" "$tmpfile_n_raw" "$tmpfile_o_filtered" "$tmpfile_n_filtered" \
84+
"$tmp_new_issues"
85+
86+
exit $rc
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"run": ["dt_binding_check.sh"]
3+
}

0 commit comments

Comments
 (0)