Skip to content

Commit 36ac2d9

Browse files
vladimirolteankuba-moo
authored andcommitted
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/176134124286.2841725.8990137232361008022.robh@kernel.org and that is sufficient in "public" settings (patches sent to netdev@vger.kernel.org and devicetree@vger.kernel.org also copied). But in "private" settings (i.e. individual developers encouraged to do sanity checking on their own, for example by running ingest_mdir), something that replicates Rob's mail bot is still required: https://gitlab.com/robherring/dt-review-ci/ https://gitlab.com/robherring/pw-utils 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). 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. The "normal" lines contain things such as "make", "SCHEMA", "CHKDT", "LINT", "DTEX", "DTC" at the beginning. Instead of detecting all 'normal' lines to filter them out, we just use 'make -s' which suppresses them, and leaves only the error messages. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
1 parent 788f069 commit 36ac2d9

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
# Copyright 2025-2026 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 -s -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+
tmp_new_issues=$(mktemp)
29+
30+
echo "Tree base:"
31+
git log -1 --pretty='%h ("%s")' HEAD~
32+
echo "Now at:"
33+
git log -1 --pretty='%h ("%s")' HEAD
34+
35+
pr "Checking before the patch"
36+
git checkout -q HEAD~
37+
38+
# Run the check on the parent commit
39+
(build | tee -a "$tmpfile_o_raw") || true
40+
41+
# Sort the output
42+
sort "$tmpfile_o_raw" > "${tmpfile_o_raw}.sorted"
43+
mv "${tmpfile_o_raw}.sorted" "$tmpfile_o_raw"
44+
incumbent_total=$(wc -l < "$tmpfile_o_raw")
45+
46+
pr "Checking the tree with the patch"
47+
git checkout -q "$HEAD"
48+
49+
# Run the check on the new commit
50+
(build | tee -a "$tmpfile_n_raw") || true
51+
52+
# Sort the output
53+
sort "$tmpfile_n_raw" > "${tmpfile_n_raw}.sorted"
54+
mv "${tmpfile_n_raw}.sorted" "$tmpfile_n_raw"
55+
current_total=$(wc -l < "$tmpfile_n_raw")
56+
57+
# Compare the lists to find new and fixed issues
58+
# Use comm to find fixed issues (lines only in the old log, column 1).
59+
fixed_issues_count=$(comm -23 "$tmpfile_o_raw" "$tmpfile_n_raw" | wc -l)
60+
61+
# Use comm to find new issues (lines only in the new log, column 2)
62+
# and save them for later display.
63+
comm -13 "$tmpfile_o_raw" "$tmpfile_n_raw" > "$tmp_new_issues"
64+
new_issues_count=$(wc -l < "$tmp_new_issues")
65+
66+
echo "Issues before: $incumbent_total, after: $current_total" \
67+
"(Fixed: $fixed_issues_count, New: $new_issues_count)" >&"$DESC_FD"
68+
69+
if [ "$new_issues_count" -gt 0 ]; then
70+
echo "New issues added:" 1>&2
71+
# Print the new issues we saved
72+
cat "$tmp_new_issues" 1>&2
73+
rc=1
74+
elif [ "$fixed_issues_count" -gt 0 ]; then
75+
echo "Patch fixed $fixed_issues_count issue(s)." >&2
76+
# No new issues, and some were fixed. This is a success.
77+
fi
78+
79+
rm "$tmpfile_o_raw" "$tmpfile_n_raw" "$tmp_new_issues"
80+
81+
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)