2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-22 09:58:01 +00:00

69 Commits

Author SHA1 Message Date
Ilya Maximets
b48aa1437d checkpatch: Check for C99 style comments.
Coding-style document asks not to use C99 ( '//' ) comments.

Acked-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2019-01-18 09:21:25 -08:00
Ilya Maximets
862b9cce15 checkpatch: Check style of FOREACH loops.
Current checkpatch rules matches only OVS 'FOR_EACH' loops.
This change will apply same style checks for DPDK iterators
like 'RTE_ETH_FOREACH_MATCHING_DEV () {}'.

Acked-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2019-01-15 09:18:06 -08:00
Ben Pfaff
145a7e88bb python: Fix invalid escape sequences.
It appears that Python silently treats invalid escape sequences in
strings as literals, e.g. "\." is the same as "\\.".  Newer versions of
checkpatch complain, and it does seem reasonable to me to fix these.

Acked-by: Numan Siddique <nusiddiq@redhat.com>
Tested-by: Numan Siddique <nusiddiq@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2019-01-11 08:45:04 -08:00
Bala Sankaran
64b90b3022 checkpatch: fix typographical error
A typographical error in a prompt for missing python enchant library is
identified and fixed.

Signed-off-by: Bala Sankaran <bsankara@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2018-11-05 11:44:15 -08:00
Ben Pfaff
0fb02e8e50 checkpatch: Speed up checking when spell checking not enabled.
On my machine it takes almost a second for enchant to read its dictionary.
This time is wasted when spell checking is not enabled.  This commit makes
checkpatch read the dictionary only when it will be used.

Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2018-11-02 13:40:54 -07:00
Ben Pfaff
3bd2e465a1 checkpatch: Add explicit test for mailing list as author.
Somehow some such patches snuck through.  checkpatch caught them (and the
committer missed that) but this makes it even more explicit.

Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2018-11-02 13:40:51 -07:00
Bala Sankaran
16770c6d91 checkpatch: support macro continuation
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>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2018-08-16 10:11:25 -07:00
Ben Pfaff
3267343a84 checkpatch: Improve accuracy and specificity of sign-off checking.
This also makes a start at a testsuite for checkpatch.

CC: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Aaron Conole <aconole@bytheb.org>
2018-08-13 14:52:42 -07:00
Bala Sankaran
a9e5ac0f97 checkpatch: warn on possible bare return
void functions do not need to have a return statement, because
such statements are redundant. Warn the user of such instances.

An interim line check is added to allow gathering additional
context for each line that is being processed.

Signed-off-by: Bala Sankaran <bsankara@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2018-08-06 16:56:51 -07:00
Aaron Conole
128b46a077 checkpatch: fix patch separator line regex
The separator line always starts with three dashes on a line, optionally
followed by either white-space, OR a single space and a filename.  The
regex would previously match on any three dashes in a row.  This means
that a patch (such as [1]) would trigger the parser state machine to
advance beyond the signed-off checks.

Now, bound the check only to use what git-mailinfo would use as a
separator.
   --- <filename>
   ---<sp>

1: https://mail.openvswitch.org/pipermail/ovs-dev/2018-June/348625.html

Fixes: c599d5ccf316 ("checkpatch.py: A simple script for finding patch issues")
Signed-off-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2018-07-03 11:41:49 -07:00
Aaron Conole
3ccb889989 checkpatch: Only consider certain signoffs
Formatted patches can contain a heirarchy of sign-offs.  This is true when
merging patches from different projects (eg. backports to the datapath
directory from the linux net project).

This means that a submitted backport will contain multiple signed-off
tags, and not all should be considered.

This commit updates checkpatch to only consider those signoff lines which
start at the beginning of a line.  So the following:

  Signed-off-by: Foo Bar <foo@bar.com>

should not trigger.

Signed-off-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2018-06-25 15:24:38 -07:00
Aaron Conole
de8fa82a48 checkpatch: add quiet option
This allows scripts which only want to process error messages to silence
the normal 'warm and fuzzy' status messages from checkpatch.

Signed-off-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2018-06-25 15:24:37 -07:00
Ben Pfaff
860ffe70fe checkpatch: Be more specific about line length, misspelling warnings.
Until now checkpatch warnings have not said how long a too-long line is
or what word might be misspelled.  This commit makes the messages more
explicit.

To do this the 'print' functions needed to know the line that was in error.
One way to do that was to also pass the line in question to the 'print'
function.  I decided instead to just allow the 'print' function to be
missing and to instead issue these warnings from the 'check' function.  I
don't know whether this design raises any red flags with anyone.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Aaron Conole <aconole@redhat.com>
2018-05-16 15:42:08 -07:00
Ben Pfaff
09b94206e5 checkpatch: Fix filename matching.
The .match() method only matches at the beginning of a string but the
blacklists here need to match anywhere in a string.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Aaron Conole <aconole@redhat.com>
Acked-by: Numan Siddique <nusiddiq@redhat.com>
2018-05-10 16:28:46 -07:00
Ben Pfaff
9aef43f085 checkpatch: Don't do line length or whitespace checks on debian/rules.
debian/rules is a Makefile with a funny name.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Reviewed-by: Aaron Conole <aconole@redhat.com>
2018-04-25 08:56:34 -07:00
Flavio Leitner
8503a516bf checkpatch: add checks for new rst docs
When a new rst document is added under Documentation, check if the
new file is added to the proper index.rst and to the automake.mk.

Signed-off-by: Flavio Leitner <fbl@sysclose.org>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2018-04-17 14:55:10 -07:00
Ben Pfaff
0056086d75 checkpatch: Fix mis-flagging of division operators as lacking whitespace.
The regular expression here would flag any slash that wasn't adjacent to
an asterisk as missing whitespace.  This fixes the problem.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Tested-by: Aaron Conole <aconole@redhat.com>
2018-04-03 14:13:28 -07:00
Aaron Conole
999c7773a6 checkpatch: add a comment spell-checker
Grow a new opt-in feature to check comments for possible spelling
mistakes.  Uses the 'enchant' library to provide a default link to
aspell/ispell as the backend.

Additionally, a custom set of kewords is included inline to match what
would be possibly encountered in 'the wild'.  The list is fairly
comprehensive at this point.

Signed-off-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2018-04-01 09:35:43 -07:00
Aaron Conole
8361e64739 checkpatch: filter comment contents
For the infix operator whitespace checks, some of these operators are
used within comments.  In those cases, it probably doesn't make sense
to warn about whitespacing.

There may be other checks that could use this kind of filter, but
that can wait for a future commit (and someone ambitious enough to
test each case).

Signed-off-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2018-04-01 09:35:41 -07:00
Aaron Conole
6ed8068624 checkpatch: introduce constants for the parse states
It's just easier to read.  Should be no functional change.

Signed-off-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2018-04-01 09:35:39 -07:00
Ben Pfaff
bbb2cb209a checkpatch: Avoid warnings for /* or */.
checkpatch would sometimes confuse comment markers for operators.  This
fixes the problem.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Aaron Conole <aconole@redhat.com>
2018-03-31 12:36:22 -07:00
Ben Pfaff
8df9a0c410 checkpatch.py: Fix Python style.
Fixes the following warnings:

../utilities/checkpatch.py:219:1: E302 expected 2 blank lines, found 1
../utilities/checkpatch.py:224:1: E302 expected 2 blank lines, found 1
../utilities/checkpatch.py:228:1: E302 expected 2 blank lines, found 1

CC: Justin Pettit <jpettit@ovn.org>
Fixes: 4e99b70dfae0 ("checkpatch.py: Add check for "xxx" in comments.")
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Justin Pettit <jpettit@ovn.org>
2018-01-26 12:51:18 -08:00
Justin Pettit
4e99b70dfa checkpatch.py: Add check for "xxx" in comments.
"xxx" is often used to indicate items that the developer wanted to look
at again before committing.  Flag those as a warning.

Signed-off-by: Justin Pettit <jpettit@ovn.org>
Acked-by: Aaron Conole <aconole@redhat.com>
2018-01-25 12:56:49 -08:00
Ilya Maximets
f61d40dec9 checkpatch: Reset line counter.
Lines should be counted for each file separately.

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Aaron Conole <aconole@redhat.com>
2017-10-10 07:55:24 -07:00
Joe Stringer
3f9e248f6e checkpatch: Enforce bracing around conditionals.
The coding style states that BSD-style brace placement should be used,
and even single statements should be enclosed. Add checks to checkpatch
for this, particularly for 'else' statements.

Signed-off-by: Joe Stringer <joe@ovn.org>
Acked-by: Aaron Conole <aconole@redhat.com>
2017-08-21 11:41:53 -07:00
Joe Stringer
12f62e9df6 checkpatch: Check for trailing operators.
The style guide states that lines should not end with '?' or ':'. Check
for this and report an error.

Signed-off-by: Joe Stringer <joe@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-08-09 16:56:38 -07:00
Joe Stringer
bcd93351fc checkpatch: Fix matching on C filenames.
Most of the prerequisite checks so far matched on filenames that ended
in some character followed by 'c' or 'h', rather than a filename that
ends in '.c' or '.h'. Fix this.

Signed-off-by: Joe Stringer <joe@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-08-09 16:56:38 -07:00
Joe Stringer
0d7b16daea checkpatch: Check for infix operator whitespace.
The 'Expressions' section of the coding style specifies that one space
should be on either side of infix binary and ternary operators. This
adds a check to checkpatch.py for most of these.

The regex won't match if there are speech marks on the line, because
the style should not apply to the contents of strings.

This check is left at warning level because there isn't a good way to
determine whether a line is within a multiline comment or string, so it
will occasionally flag such lines which contain hyphenated words.

Signed-off-by: Joe Stringer <joe@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-08-09 16:56:38 -07:00
Ilya Maximets
d962bad25a checkpatch: Print commit hashes and names.
It's better to see real commits instead of 'HEAD~n'.

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Acked-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Russell Bryant <russell@ovn.org>
2017-07-26 16:43:41 -04:00
Ilya Maximets
b90cfa86a2 checkpatch: Allow checking more than one file.
Currently to check more than one patch or file it's required
to invoke script for each file separately.
Fix that by iterating over all the passed filenames.

Note: If '-f' option passed, all the files treated as usual files.
      Without '-f' all the files treated as patch files.

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Acked-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Russell Bryant <russell@ovn.org>
2017-07-26 16:42:11 -04:00
Ilya Maximets
81c2316f71 checkpatch: Print results while checking HEAD and stdin.
Currently, result status printed only for patch files.
It'll be nice to have results for other checking types.

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Acked-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Russell Bryant <russell@ovn.org>
2017-07-26 16:42:09 -04:00
Ilya Maximets
bc03d850d6 checkpatch: Don't allow Gerrit Change-Ids.
Local Gerrit Change-Ids are not welcome in common repository.
Inspired by checkpatch.pl from Linux Kernel.

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Acked-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Russell Bryant <russell@ovn.org>
2017-07-26 16:41:58 -04:00
Bhanuprakash Bodireddy
d9d849fec5 checkpatch: Suggest ovs_assert() to author.
Suggest the author to use the OVS wrapper of the assert function.

Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Aaron Conole <aconole@redhat.com>
2017-07-12 09:29:40 -07:00
Joe Stringer
822a3d8831 checkpatch: Use default encoding from email library.
There are three paths for running the core checkpatch path: From a file,
from stdin, or reading from git output. Currently, the file version of
this calls the "email" library's decode routine which translates the
stream into a bytes array, which we later call decode() to turn it back
into a regular string. This works on python2 and python3, but the other
paths don't work in python3 due to the following error:

$ utilities/checkpatch.py -1
== Checking HEAD~0 ==
Traceback (most recent call last):
  File "utilities/checkpatch.py", line 491, in <module>
    if ovs_checkpatch_parse(patch, revision):
  File "utilities/checkpatch.py", line 324, in ovs_checkpatch_parse
    for line in text.decode().split('\n'):
AttributeError: 'str' object has no attribute 'decode'

Rather than performing this extra encode/decode, strip these out from
this path so that the stdin and git variants of checkpatch can work in
python3.

Signed-off-by: Joe Stringer <joe@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-07-06 05:45:34 -07:00
Ilya Maximets
057653abfb checkpatch: Fix skipping of the most recent commit.
'range(n_patches, 0, -1)' generates list starting from 'n_patches'
and not including zero. This leads to checking of N most recent
commits starting from the second one.

New version will generate right list starting from 'n_patches - 1'
and including zero. So, the most recent commit (HEAD~0) will be
checked and desired behavior will be achieved.

Also, 'reversed' looks better than 'range(n_patches - 1, -1, -1)'

Fixes: a1fccabce2cb ("checkpatch: Support checking recent commits in the current repo.")
Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-06-15 21:46:35 -07:00
Ben Pfaff
a1fccabce2 checkpatch: Support checking recent commits in the current repo.
Requested-by: Miguel Angel Ajo <majopela@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-06-14 13:42:54 -07:00
Ben Pfaff
ae9c09850a checkpatch: Also allow .at files to have leading tabs.
Autotest .at files often have lines with samples of expected output from
various programs, which fairly often includes leading tabs, so this warning
causes false positives there.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Reviewed-by: Aaron Conole <aconole@redhat.com>
2017-06-08 09:22:17 -07:00
Ben Pfaff
fedf830195 checkpatch: Also exempt Makefile.am from leading whitespace checks.
Signed-off-by: Ben Pfaff <blp@ovn.org>
Reviewed-by: Greg Rose <gvrose8192@gmail.com>
2017-06-01 15:28:52 -07:00
Ben Pfaff
f651d4ac4b checkpatch: Fix typo for use as filter.
ovs_checkpatch_parse() takes 2 arguments, not sys.exit().  Oops.

Fixes: 95bd35d3db19 ("checkpatch: Implement -f option more usefully.")
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Aaron Conole <aconole@redhat.com>
2017-06-01 14:20:55 -07:00
Ben Pfaff
d6ec6c108a checkpatch: Omit some checks on comment lines.
Comments are more freeform than code, so this patch tries to ignore many
checks on comment lines.  It assumes that any line that begins with "/*"
or "* " is a comment line.  (Without a following space, "*" might be
something like "*x = 1;".)

Suggested-by: Joe Stringer <joe@ovn.org>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Aaron Conole <aconole@redhat.com>
2017-06-01 07:29:46 -07:00
Ben Pfaff
95bd35d3db checkpatch: Implement -f option more usefully.
A lot of checkpatch warnings are only enabled for particular kinds of
files, e.g. C warnings only apply to C source and header files.  The -f
option didn't pass the file name to the code that determines what kinds
of warnings to report, so only generic warnings were actually reported.
This fixes that problem.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Aaron Conole <aconole@redhat.com>
2017-05-31 08:56:49 -07:00
Ben Pfaff
b537de13ec checkpatch: Also check switch, HMAP_FOR_EACH, etc.
The switch statement and our FOR_EACH macro iteration constructs have the
same rules as if, for, and while.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Aaron Conole <aconole@redhat.com>
2017-05-31 08:55:13 -07:00
Joe Stringer
4f74db48af checkpatch: Skip checking Linux headers.
Headers introduced from Linux do not need the style checking applied.

Signed-off-by: Joe Stringer <joe@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-05-30 18:43:31 -07:00
Ben Pfaff
6ecf961e7c checkpatch: Be more careful about checking function names.
This code would complain about the use of ovs_strerror because it
matches [^x]strerror, and the same was true in many other similar cases.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Joe Stringer <joe@ovn.org>
2017-05-30 10:33:10 -07:00
Joe Stringer
b95d82bf93 checkpatch: Check for stdlib usage.
Many standard library functions are wrapped in OVS, so check for usage
of the original versions and suggest that authors replace them with the
OVS versions.

Signed-off-by: Joe Stringer <joe@ovn.org>
Acked-by: Aaron Conole <aconole@redhat.com>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-05-25 13:32:16 -07:00
Ben Pfaff
2797ff0015 checkpatch: Fix inconsistencies skipping datapath files.
The code in checkpatch inconsistently stripped "a/" or "b/" from the
beginning of a file name, and the check for "datapath" only worked when
the prefix was not stripped.  This fixes the problem.

Acked-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-05-08 16:06:57 -04:00
Aaron Conole
d56ec3bc08 checkpatch: fix pointer declaration
A common way of expressing 'raise to the power of' when authoring
comments uses **.  This is currently getting caught by the pointer
spacing warning.  So, catch it here.

Reported-by: Lance Richardson <lrichard@redhat.com>
Signed-off-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-05-01 13:26:58 -07:00
Aaron Conole
bbbe2fa2e6 checkpatch: filename from hunks fix
Filenames that come from the hunks match include the git-ified 'b/'
prefix, which makes jumping to the error file that much harder.  This
patch corrects that by simply skipping those bytes.

Signed-off-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-05-01 13:26:48 -07:00
Aaron Conole
ebba2af618 checkpatch: print conformance
Other utilities (notoriously the linux kernel's checkpatch.pl) have a more
standardized form for printing file and lines.  With this change, the
template used to print gains two enhancements:
1. Color
2. Conformance with the kernel's version of checkpatch.pl

Signed-off-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-05-01 13:26:35 -07:00
Aaron Conole
0b93d978cf checkpatch: correct a parsing issue
Occasionally, characters will be sent which violate the
ascii decoder's sense of propriety.  In fact, in-tree there are
a few such files (ex: tests/atlocal.in), and they cause an
exception to be raised when they are encountered.

Set the policy to ignore these cases.  This means these bytes are
omitted from the text stream during processing.

Signed-off-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-05-01 13:25:35 -07:00