From patchwork Thu Aug 16 15:56:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bala Sankaran X-Patchwork-Id: 958452 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41rrYd6yj2z9s3Z for ; Fri, 17 Aug 2018 01:56:53 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id AF841C37; Thu, 16 Aug 2018 15:56:50 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 0E51CC21 for ; Thu, 16 Aug 2018 15:56:49 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 6432C796 for ; Thu, 16 Aug 2018 15:56:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7235640201C6 for ; Thu, 16 Aug 2018 15:56:47 +0000 (UTC) Received: from bsankara.bos.com (unknown [10.18.25.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B93810FFE7A for ; Thu, 16 Aug 2018 15:56:47 +0000 (UTC) From: Bala Sankaran To: dev@openvswitch.org Date: Thu, 16 Aug 2018 11:56:46 -0400 Message-Id: <1534435006-4482-1-git-send-email-bsankara@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 16 Aug 2018 15:56:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 16 Aug 2018 15:56:47 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'bsankara@redhat.com' RCPT:'' X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] checkpatch: support macro continuation X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org 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 --- tests/checkpatch.at | 223 ++++++++++++++++++++++++++++++++++++++++++++++++ utilities/checkpatch.py | 6 +- 2 files changed, 228 insertions(+), 1 deletion(-) mode change 100644 => 100755 tests/checkpatch.at 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