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 <[email protected]> --- 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 -- 1.8.3.1 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
