diff mbox series

[ovs-dev] checkpatch: support macro continuation

Message ID 1534435006-4482-1-git-send-email-bsankara@redhat.com
State Accepted
Headers show
Series [ovs-dev] checkpatch: support macro continuation | expand

Commit Message

Bala Sankaran Aug. 16, 2018, 3:56 p.m. UTC
Added a test to identify a macro and skip
printing errors if the condition or loop
is part of a macro.

Additional tests are added to checkpatch
testsuite that cover conditionals and
loop constructs.

Signed-off by: Bala Sankaran <bsankara@redhat.com>
---
 tests/checkpatch.at     | 223 ++++++++++++++++++++++++++++++++++++++++++++++++
 utilities/checkpatch.py |   6 +-
 2 files changed, 228 insertions(+), 1 deletion(-)
 mode change 100644 => 100755 tests/checkpatch.at

Comments

0-day Robot Aug. 16, 2018, 4:56 p.m. UTC | #1
Bleep bloop.  Greetings Bala Sankaran, I am a robot and I have tried out your patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


checkpatch:
ERROR: Author Bala Sankaran <bsankara@redhat.com> needs to sign off.
WARNING: Line has trailing whitespace
#37 FILE: tests/checkpatch.at:164:
    

Lines checked: 282, Warnings: 1, Errors: 1


Please check this out.  If you feel there has been an error, please email aconole@bytheb.org

Thanks,
0-day Robot
Ben Pfaff Aug. 16, 2018, 5:12 p.m. UTC | #2
On Thu, Aug 16, 2018 at 11:56:46AM -0400, Bala Sankaran wrote:
> Added a test to identify a macro and skip
> printing errors if the condition or loop
> is part of a macro.
> 
> Additional tests are added to checkpatch
> testsuite that cover conditionals and
> loop constructs.
> 
> Signed-off by: Bala Sankaran <bsankara@redhat.com>

Thanks, applied to master.
diff mbox series

Patch

diff --git a/tests/checkpatch.at b/tests/checkpatch.at
old mode 100644
new mode 100755
index bcfb753..8af3a8c
--- a/tests/checkpatch.at
+++ b/tests/checkpatch.at
@@ -156,3 +156,226 @@  try_checkpatch \
    "ERROR: Patch lacks author."
 
 AT_CLEANUP
+
+AT_SETUP([checkpatch - parenthesized constructs])
+for ctr in 'if' 'while' 'switch'; do
+try_checkpatch \
+   "Author: A
+    
+    Signed-off-by: A
+    ---
+    diff --git a/A.c b/A.c
+    index 0000000..1111111 100644
+    --- a/A.c
+    +++ b/A.c
+    @@ -1,1 +1,1 @@
+    +     $ctr (first_run) {
+    "
+
+try_checkpatch \
+   "Author: A
+
+    Signed-off-by: A
+    ---
+    diff --git a/A.c b/A.c
+    index 0000000..1111111 100644
+    --- a/A.c
+    +++ b/A.c
+    @@ -1,1 +1,1 @@
+    +     $ctr ( first_run) {
+    " \
+    "ERROR: Improper whitespace around control block
+    #8 FILE: A.c:1:
+         $ctr ( first_run) {
+"
+
+try_checkpatch \
+   "Author: A
+
+    Signed-off-by: A
+    ---
+    diff --git a/A.c b/A.c
+    index 0000000..1111111 100644
+    --- a/A.c
+    +++ b/A.c
+    @@ -1,1 +1,1 @@
+    +     $ctr (first_run ) {
+    " \
+    "ERROR: Inappropriate bracing around statement
+    #8 FILE: A.c:1:
+         $ctr (first_run ) {
+"
+
+try_checkpatch \
+   "Author: A
+
+    Signed-off-by: A
+    ---
+    diff --git a/A.c b/A.c
+    index 0000000..1111111 100644
+    --- a/A.c
+    +++ b/A.c
+    @@ -1,1 +1,1 @@
+    +     $ctr (first_run)
+    " \
+    "ERROR: Inappropriate bracing around statement
+    #8 FILE: A.c:1:
+         $ctr (first_run)
+"
+
+try_checkpatch \
+   "Author: A
+
+    Signed-off-by: A
+    ---
+    diff --git a/A.c b/A.c
+    index 0000000..1111111 100644
+    --- a/A.c
+    +++ b/A.c
+    @@ -1,1 +1,1 @@
+    +     $ctr(first_run)
+    " \
+    "ERROR: Improper whitespace around control block
+    #8 FILE: A.c:1:
+         $ctr(first_run)
+"
+
+try_checkpatch \
+   "Author: A
+
+    Signed-off-by: A
+    ---
+    diff --git a/A.c b/A.c
+    index 0000000..1111111 100644
+    --- a/A.c
+    +++ b/A.c
+    @@ -1,1 +1,1 @@
+    +     $ctr (first_run) { /* foo */
+    "
+
+try_checkpatch \
+   "Author: A
+
+    Signed-off-by: A
+    ---
+    diff --git a/A.c b/A.c
+    index 0000000..1111111 100644
+    --- a/A.c
+    +++ b/A.c
+    @@ -1,1 +1,1 @@
+    +     $ctr (first_run) { \\
+    "
+done
+AT_CLEANUP
+
+
+
+AT_SETUP([checkpatch - parenthesized constructs - for])
+try_checkpatch \
+   "Author: A
+
+    Signed-off-by: A
+    ---
+    diff --git a/A.c b/A.c
+    index 0000000..1111111 100644
+    --- a/A.c
+    +++ b/A.c
+    @@ -1,1 +1,1 @@
+    +     for (init; condition; increment) {
+    "
+
+try_checkpatch \
+   "Author: A
+
+    Signed-off-by: A
+    ---
+    diff --git a/A.c b/A.c
+    index 0000000..1111111 100644
+    --- a/A.c
+    +++ b/A.c
+    @@ -1,1 +1,1 @@
+    +     for ( init; condition; increment) {
+    " \
+    "ERROR: Improper whitespace around control block
+    #8 FILE: A.c:1:
+         for ( init; condition; increment) {
+"
+
+try_checkpatch \
+   "Author: A
+
+    Signed-off-by: A
+    ---
+    diff --git a/A.c b/A.c
+    index 0000000..1111111 100644
+    --- a/A.c
+    +++ b/A.c
+    @@ -1,1 +1,1 @@
+    +     for (init; condition; increment ) {
+    " \
+    "ERROR: Inappropriate bracing around statement
+    #8 FILE: A.c:1:
+         for (init; condition; increment ) {
+"
+
+try_checkpatch \
+   "Author: A
+
+    Signed-off-by: A
+    ---
+    diff --git a/A.c b/A.c
+    index 0000000..1111111 100644
+    --- a/A.c
+    +++ b/A.c
+    @@ -1,1 +1,1 @@
+    +     for (init; condition; increment)
+    " \
+    "ERROR: Inappropriate bracing around statement
+    #8 FILE: A.c:1:
+         for (init; condition; increment)
+"
+
+try_checkpatch \
+   "Author: A
+
+    Signed-off-by: A
+    ---
+    diff --git a/A.c b/A.c
+    index 0000000..1111111 100644
+    --- a/A.c
+    +++ b/A.c
+    @@ -1,1 +1,1 @@
+    +     for(init; condition; increment)
+    " \
+    "ERROR: Improper whitespace around control block
+    #8 FILE: A.c:1:
+         for(init; condition; increment)
+"
+
+try_checkpatch \
+   "Author: A
+
+    Signed-off-by: A
+    ---
+    diff --git a/A.c b/A.c
+    index 0000000..1111111 100644
+    --- a/A.c
+    +++ b/A.c
+    @@ -1,1 +1,1 @@
+    +     for (init; condition; increment) { /* foo */
+    "
+
+try_checkpatch \
+   "Author: A
+
+    Signed-off-by: A
+    ---
+    diff --git a/A.c b/A.c
+    index 0000000..1111111 100644
+    --- a/A.c
+    +++ b/A.c
+    @@ -1,1 +1,1 @@
+    +     for (init; condition; increment) { \\
+    "
+
+AT_CLEANUP
diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
index 48bd5eb..5f5dd83 100755
--- a/utilities/checkpatch.py
+++ b/utilities/checkpatch.py
@@ -163,6 +163,8 @@  __regex_has_xxx_mark = re.compile(r'.*xxx.*', re.IGNORECASE)
 __regex_added_doc_rst = re.compile(
                     r'\ndiff .*Documentation/.*rst\nnew file mode')
 __regex_empty_return = re.compile(r'\s*return;')
+__regex_if_macros = re.compile(r'^ +(%s) \([\S][\s\S]+[\S]\) { \\' %
+                               __parenthesized_constructs)
 
 skip_leading_whitespace_check = False
 skip_trailing_whitespace_check = False
@@ -252,7 +254,9 @@  def if_and_for_end_with_bracket_check(line):
     if __regex_is_for_if_single_line_bracket.search(line) is not None:
         if not balanced_parens(line):
             return True
-        if __regex_ends_with_bracket.search(line) is None:
+
+        if __regex_ends_with_bracket.search(line) is None and \
+           __regex_if_macros.match(line) is None:
             return False
     if __regex_conditional_else_bracing.match(line) is not None:
         return False