checkpatch: detect missing changes to trace-events
RFC v2 1/1 checkpatch: detect missing changes to trace-events
--- scripts/checkpatch.pl | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-)
v1 -> v2 :
* track the "from" file in addition to the "to" file,
and grep into both (if they exist), looking for trace.h, trace-root.h
If files are reachable and readable, emit a warning if there is no update to trace-events.
scripts/checkpatch.pl +30 -7
@@ -1300,6 +1300,7 @@ sub process { my $in_header_lines = $file ? 0 : 1; my $in_commit_log = 0; #Scanning lines before patch my $reported_maintainer_file = 0; + my $reported_trace_events_file = 0; my $non_utf8_charset = 0; our @report = ();
@@ -1309,6 +1310,7 @@ sub process { our $cnt_chk = 0; # Trace the real file/line as we go. + my $fromfile = ''; my $realfile = ''; my $realline = 0; my $realcnt = 0;
@@ -1454,10 +1456,15 @@ sub process { $here = "#$realline: " if ($file); # extract the filename as it passes - if ($line =~ /^diff --git.*?(\S+)$/) { - $realfile = $1; - $realfile =~ s@^([^/]*)/@@ if (!$file); + if ($line =~ /^diff --git.*?(\S+).*?(\S+)$/) { + $fromfile = $1; + $realfile = $2; + if (!$file) { + $fromfile =~ s@^([^/]*)/@@ ; + $realfile =~ s@^([^/]*)/@@ ; + } checkfilename($realfile, \$acpi_testexpected, \$acpi_nontestexpected); + } elsif ($line =~ /^\+\+\+\s+(\S+)/) { $realfile = $1; $realfile =~ s@^([^/]*)/@@ if (!$file);
@@ -1470,6 +1477,11 @@ sub process { } next; + + } elsif ($line =~ /^---\s+(\S+)/) { + $fromfile = $1; + $fromfile =~ s@^([^/]*)/@@ if (!$file); + next; } $here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
@@ -1524,15 +1536,26 @@ sub process { if ($line =~ /^\s*MAINTAINERS\s*\|/) { $reported_maintainer_file = 1; } - +# similar check for trace-events + if ($line =~ /^\s*trace-events\s*\|/) { + $reported_trace_events_file = 1; + } # Check for added, moved or deleted files - if (!$reported_maintainer_file && !$in_commit_log && + if (!$in_commit_log && ($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ || $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ || ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ && (defined($1) || defined($2))))) { - $reported_maintainer_file = 1; - WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr); + if (!$reported_maintainer_file) { + $reported_maintainer_file = 1; + WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr); + } + if (!$reported_trace_events_file) { + if (`grep -F -s -e trace.h -e trace-root.h ${fromfile} ${realfile}` ne '') { + $reported_trace_events_file = 1; + WARN("added, moved or deleted file(s), does trace-events need updating?\n" . $herecurr); + } + } } # Check for wrappage within a valid hunk of the file
Signature · 1 line
2.16.4
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series failed the docker-quick@centos7 build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1 === TEST SCRIPT END ===
The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Quoted 5 lines · Claudio Fontana
# Check for added, moved or deleted files
scripts/checkpatch.pl +1
-1- if (!$reported_maintainer_file && !$in_commit_log && + if (!$in_commit_log && ($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ || $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ ||
scripts/checkpatch.pl sub process { · line 1554
Quoted 10 lines
scripts/checkpatch.pl +6
-2($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ && (defined($1) || defined($2))))) { - $reported_maintainer_file = 1; - WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr); + if (!$reported_maintainer_file) { + $reported_maintainer_file = 1; + WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr); + } + if (!$reported_trace_events_file) { + if (`grep -F -s -e trace.h -e trace-root.h ${fromfile} ${realfile}` ne '') {
Are there false positives on non-C files (e.g. Makefiles)?
The search expressions can be tightened to avoid false positives (at the cost of possible false negatives): -e '#include "trace.h"' -e '#include "trace-root.h"'. This way a C file containing "strace.handler" will not cause a false positive.
I wonder if there is a native Perl way to do this search instead of forking grep :). Nevermind though.
Quoted 19 lines · Stefan Hajnoczi
Quoted 5 lines · Claudio Fontana
# Check for added, moved or deleted files
scripts/checkpatch.pl +1
-1- if (!$reported_maintainer_file && !$in_commit_log && + if (!$in_commit_log && ($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ || $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ ||scripts/checkpatch.pl sub process { · line 1554
Quoted 10 lines
scripts/checkpatch.pl +6
-2($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ && (defined($1) || defined($2))))) { - $reported_maintainer_file = 1; - WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr); + if (!$reported_maintainer_file) { + $reported_maintainer_file = 1; + WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr); + } + if (!$reported_trace_events_file) { + if (`grep -F -s -e trace.h -e trace-root.h ${fromfile} ${realfile}` ne '') {Are there false positives on non-C files (e.g. Makefiles)?
Quoted 5 lines
The search expressions can be tightened to avoid false positives (at the cost of possible false negatives): -e '#include "
trace.h"' -e '#include "trace-root.h"'. This way a C file containing "strace.handler" will not cause a false positive.
Yep good point.
Quoted 3 lines
I wonder if there is a native Perl way to do this search instead of forking grep :). Nevermind though.
If only all the speedups from GNU grep would be available as a libgrep..
I had to post an RFC v3 of this one, because there is an issue in the order in_commit_log is set and checked (in my understanding).
https://lists.gnu.org/archive/html/qemu-devel/2020-08/msg01953.html
This is actually potentially an issue in upstream (kernel) checkpatch.pl as well, but it does not bite until you try to use realfile variable (or in this case fromfile also).
Ciao,
Claudio
Quoted 39 lines · Claudio Fontana
Signed-off-by Claudio Fontana <[email protected]>--- scripts/checkpatch.pl | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-)v1 -> v2 :
* track the "from" file in addition to the "to" file,
and grep into both (if they exist), looking fortrace.h,trace-root.hIf files are reachable and readable, emit a warning if there is no update to trace-events.
scripts/checkpatch.pl +2
-2@@ -1300,6 +1300,7 @@ sub process { my $in_header_lines = $file ? 0 : 1; my $in_commit_log = 0; #Scanning lines before patch my $reported_maintainer_file = 0; + my $reported_trace_events_file = 0; my $non_utf8_charset = 0; our @report = ();@@ -1309,6 +1310,7 @@ sub process { our $cnt_chk = 0; # Trace the real file/line as we go. + my $fromfile = ''; my $realfile = ''; my $realline = 0; my $realcnt = 0;@@ -1454,10 +1456,15 @@ sub process { $here = "#$realline: " if ($file); # extract the filename as it passes - if ($line =~ /^diff --git.*?(\S+)$/) { - $realfile = $1;
scripts/checkpatch.pl sub process { · line 1467
Quoted 10 lines
scripts/checkpatch.pl +8
-1- $realfile =~ s@^([^/]*)/@@ if (!$file); + if ($line =~ /^diff --git.*?(\S+).*?(\S+)$/) { + $fromfile = $1; + $realfile = $2; + if (!$file) { + $fromfile =~ s@^([^/]*)/@@ ; + $realfile =~ s@^([^/]*)/@@ ; + } checkfilename($realfile, \$acpi_testexpected, \$acpi_nontestexpected); +
Drop this blank line.
scripts/checkpatch.pl sub process { · line 1480
Quoted 8 lines
scripts/checkpatch.pl +1
-0} elsif ($line =~ /^\+\+\+\s+(\S+)/) { $realfile = $1; $realfile =~ s@^([^/]*)/@@ if (!$file);@@ -1470,6 +1477,11 @@ sub process { } next; +
And this one.
scripts/checkpatch.pl sub process { · line 1487
Quoted 7 lines
scripts/checkpatch.pl +4
-0+ } elsif ($line =~ /^---\s+(\S+)/) { + $fromfile = $1; + $fromfile =~ s@^([^/]*)/@@ if (!$file); + next; } $here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
Aside: I don't understand why we need to match both the diff line and the --- line (and now the +++ line, too).
scripts/checkpatch.pl sub process { · line 1542
Quoted 9 lines
scripts/checkpatch.pl +4
-1@@ -1524,15 +1536,26 @@ sub process { if ($line =~ /^\s*MAINTAINERS\s*\|/) { $reported_maintainer_file = 1; } - +# similar check for trace-events + if ($line =~ /^\s*trace-events\s*\|/) { + $reported_trace_events_file = 1; + }
These are meant to match in the diffstat (took me a stare to figure that out).
The existing one matches MAINTAINERS in the source root. Good; that's where it is.
The new one matches trace-events in the source root. Not so good; We use one trace-events per directory.
If I update trace-events in the source root, I won't be warned about other trace-events in need of updating (false negative), will I?
If I don't update trace-events in the source root, I will be warned regardless of what other trace-events I update (false positive), won't I?
Quoted 12 lines
scripts/checkpatch.pl +4
-3# Check for added, moved or deleted files - if (!$reported_maintainer_file && !$in_commit_log && + if (!$in_commit_log && ($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ || $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ || ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ && (defined($1) || defined($2))))) { - $reported_maintainer_file = 1; - WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr); + if (!$reported_maintainer_file) { + $reported_maintainer_file = 1; + WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr);
scripts/checkpatch.pl sub process { · line 1561
Quoted 10 lines
scripts/checkpatch.pl +7
-0+ } + if (!$reported_trace_events_file) { + if (`grep -F -s -e trace.h -e trace-root.h ${fromfile} ${realfile}` ne '') { + $reported_trace_events_file = 1; + WARN("added, moved or deleted file(s), does trace-events need updating?\n" . $herecurr); + } + } } # Check for wrappage within a valid hunk of the file
Regarding Stefan's observations:
* Yes, the grep patterns need tightening.
* Yes, forking grep could be replaced by a simple function that slurps in the file and searches it. Could doesn't imply should, let alome must.
As discussed in review of v1, I'm not sure checkpatch.pl is the best home for this kind of check. I'm not going to reject a working patch because of that.
Quoted 129 lines · Markus Armbruster
Quoted 39 lines · Claudio Fontana
Signed-off-by Claudio Fontana <[email protected]>--- scripts/checkpatch.pl | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-)v1 -> v2 :
* track the "from" file in addition to the "to" file,
and grep into both (if they exist), looking fortrace.h,trace-root.hIf files are reachable and readable, emit a warning if there is no update to trace-events.
scripts/checkpatch.pl +2
-2@@ -1300,6 +1300,7 @@ sub process { my $in_header_lines = $file ? 0 : 1; my $in_commit_log = 0; #Scanning lines before patch my $reported_maintainer_file = 0; + my $reported_trace_events_file = 0; my $non_utf8_charset = 0; our @report = ();@@ -1309,6 +1310,7 @@ sub process { our $cnt_chk = 0; # Trace the real file/line as we go. + my $fromfile = ''; my $realfile = ''; my $realline = 0; my $realcnt = 0;@@ -1454,10 +1456,15 @@ sub process { $here = "#$realline: " if ($file); # extract the filename as it passes - if ($line =~ /^diff --git.*?(\S+)$/) { - $realfile = $1;scripts/checkpatch.pl sub process { · line 1467
Quoted 10 lines
scripts/checkpatch.pl +8
-1- $realfile =~ s@^([^/]*)/@@ if (!$file); + if ($line =~ /^diff --git.*?(\S+).*?(\S+)$/) { + $fromfile = $1; + $realfile = $2; + if (!$file) { + $fromfile =~ s@^([^/]*)/@@ ; + $realfile =~ s@^([^/]*)/@@ ; + } checkfilename($realfile, \$acpi_testexpected, \$acpi_nontestexpected); +Drop this blank line.
scripts/checkpatch.pl sub process { · line 1480
Quoted 8 lines
scripts/checkpatch.pl +1
-0} elsif ($line =~ /^\+\+\+\s+(\S+)/) { $realfile = $1; $realfile =~ s@^([^/]*)/@@ if (!$file);@@ -1470,6 +1477,11 @@ sub process { } next; +And this one.
scripts/checkpatch.pl sub process { · line 1487
Quoted 7 lines
scripts/checkpatch.pl +4
-0+ } elsif ($line =~ /^---\s+(\S+)/) { + $fromfile = $1; + $fromfile =~ s@^([^/]*)/@@ if (!$file); + next; } $here .= "FILE: $realfile:$realline:" if ($realcnt != 0);Aside: I don't understand why we need to match both the diff line and the --- line (and now the +++ line, too).
scripts/checkpatch.pl sub process { · line 1542
Quoted 9 lines
scripts/checkpatch.pl +4
-1@@ -1524,15 +1536,26 @@ sub process { if ($line =~ /^\s*MAINTAINERS\s*\|/) { $reported_maintainer_file = 1; } - +# similar check for trace-events + if ($line =~ /^\s*trace-events\s*\|/) { + $reported_trace_events_file = 1; + }These are meant to match in the diffstat (took me a stare to figure that out).
The existing one matches
MAINTAINERSin the source root. Good; that's where it is.The new one matches trace-events in the source root. Not so good; We use one trace-events per directory.
If I update trace-events in the source root, I won't be warned about other trace-events in need of updating (false negative), will I?
If I don't update trace-events in the source root, I will be warned regardless of what other trace-events I update (false positive), won't I?
Quoted 12 lines
scripts/checkpatch.pl +4
-3# Check for added, moved or deleted files - if (!$reported_maintainer_file && !$in_commit_log && + if (!$in_commit_log && ($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ || $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ || ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ && (defined($1) || defined($2))))) { - $reported_maintainer_file = 1; - WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr); + if (!$reported_maintainer_file) { + $reported_maintainer_file = 1; + WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr);scripts/checkpatch.pl sub process { · line 1561
Quoted 10 lines
scripts/checkpatch.pl +7
-0+ } + if (!$reported_trace_events_file) { + if (`grep -F -s -e trace.h -e trace-root.h ${fromfile} ${realfile}` ne '') { + $reported_trace_events_file = 1; + WARN("added, moved or deleted file(s), does trace-events need updating?\n" . $herecurr); + } + } } # Check for wrappage within a valid hunk of the fileRegarding Stefan's observations:
* Yes, the grep patterns need tightening.
Quoted 8 lines
* Yes, forking grep could be replaced by a simple function that slurps in the file and searches it. Could doesn't imply should, let alome must.
As discussed in review of v1, I'm not sure checkpatch.pl is the best home for this kind of check. I'm not going to reject a working patch because of that.
Hi Marcus,
I will rethink this in the future, thanks for the useful feedback, but I think this needs to be rethought, reworked and tested more.
Thanks!
Claudio