2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-23 02:17:42 +00:00

92 Commits

Author SHA1 Message Date
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
Aaron Conole
907848bdd9 checkpatch: move the checks to the framework
All of the checks are now part of the new 'check' framework.

Signed-off-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-05-01 13:24:53 -07:00
Aaron Conole
a84a1edb33 checkpatch: common print_line
With the new framework, print_line can be moved out to the checks
framework.

Signed-off-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-05-01 13:24:21 -07:00
Aaron Conole
517f04ad26 checkpatch: introduce a flexible framework
Developers wishing to add checks to checkpatch sift through an adhoc mess,
currently.  The process goes something like:
1. Figure out what to test in the patch
2. Write some code, quickly, that checks for that condition
3. Look through the statemachine to find where the check should go
4. ignore parts of the above and just throw something together

That worked fine for the initial development, but as interesting new tests
are developed, it is important to have a more flexible framework that lets
a developer just plug in a new test, easily.

This commit brings in a new framework that allows plugging in checks very
quickly.  Hook up the line-length test as an initial demonstration.

Signed-off-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-05-01 13:23:59 -07:00
Eric Garver
973496b9be checkpatch.py: Fix false positive on if/when/for
We need to use == instead of the is operator. If you're unlucky it may
fail because they're not exactly the same object, but hold the same
value.

Example false positive:

E(120): Inappropriate bracing around statement

+            if (0 != nl_attr_get_u8(vxlan[IFLA_VXLAN_LEARNING])

Fixes: 30c7ffd5ac46 ("utilities/checkpatch.py: Check for appropriate bracing")
Signed-off-by: Eric Garver <e@erig.me>
Signed-off-by: Russell Bryant <russell@ovn.org>
2017-03-16 10:37:31 -04:00
Joe Stringer
bddbdd4325 checkpatch: Fix running under python3.
Signed-off-by: Joe Stringer <joe@ovn.org>
Acked-by: Russell Bryant <russell@ovn.org>
2017-03-09 12:34:54 -08:00
Joe Stringer
6fc2799e9e checkpatch: Check for pointer whitespace.
Signed-off-by: Joe Stringer <joe@ovn.org>
Acked-by: Russell Bryant <russell@ovn.org>
2017-03-09 12:34:44 -08:00
Daniele Di Proietto
884e0dfe8f python: Add double newline after fuction or class (E305).
pycodestyle >= 2.1.0 reports E305 otherwise, and the flake8-check step
fails.

Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com>
Acked-by: Ben Pfaff <blp@ovn.org>
2016-12-02 11:03:36 -08:00
Aaron Conole
fb9410d844 checkpatch: Add file-parsing mode
This adds a new argument and feature, 'check-file', which will allow
checkpatch to run against files instead of only against patches.

Signed-off-by: Aaron Conole <aconole@bytheb.org>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-11-28 17:05:13 -08:00
Aaron Conole
a1193b4def checkpatch: fix the if and whitespace checks
The regex for the if/for/while bracket tests fails to distinguish
non-space text.  This means text such as do_something_if() would match
incorrectly.

Additionally, the ends-with-bracket test doesn't allow for the common
coding paradigm:

    if (condition) { /* Text about conditional. */
    }

So fix that as well.

Signed-off-by: Aaron Conole <aconole@bytheb.org>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-11-28 17:04:54 -08:00
Aaron Conole
83f76d4ef1 checkpatch: Fix signoff error
When no 'Signed-off-by' tags are found, the output will look like:

    E: No signatures found.
    E: Too many signoffs; are you missing Co-authored-by lines?
    Warnings: 0, Errors: 2

However, there should really only be one error reported in this case.

Signed-off-by: Aaron Conole <aconole@bytheb.org>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-11-28 17:04:35 -08:00
Aaron Conole
4d7f5e5136 checkpatch: Print file line numbers
The line numbers being printed were the line numbers for the patchfile.
This is sometimes okay to fix simple things (trailing or leading
whitespace, missing signoffs, etc).  But more complicated fixes, or
those fixes which require a bit more care, aren't helped by this.  So,
we use the implied file line number.

This can be useful with future work to 'mock' apply and build a real
contextual scanner for checking multi-line changes.

Signed-off-by: Aaron Conole <aconole@bytheb.org>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-11-28 17:04:18 -08:00
Aaron Conole
e3ecc9d35c checkpatch: convert some of the warnings
These coding issues are not just things that shouldn't be done.  They are
styles which should never be submitted.

Signed-off-by: Aaron Conole <aconole@bytheb.org>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-11-28 17:04:00 -08:00
Aaron Conole
7d6b834fe5 checkpatch: Print the line in question distinctly
This makes it easier to distinguish between the line, and
the warning/error message.

Signed-off-by: Aaron Conole <aconole@bytheb.org>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-11-28 17:03:24 -08:00
Aaron Conole
3239c7937c checkpatch: Announce the file where errors occur
This makes finding the warning and error marks much easier.

Signed-off-by: Aaron Conole <aconole@bytheb.org>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-11-28 17:01:05 -08:00
Aaron Conole
30c7ffd5ac utilities/checkpatch.py: Check for appropriate bracing
Teach checkpatch.py to understand that if/for/while blocks should always
end with braces on the same line (if possible). This does not address
multi-line if/for/while blocks, but provides a point where such blocks
could be added.

Signed-off-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-05-20 10:07:50 -07:00
Daniele Di Proietto
c61e93d602 checkpatch: Accept form feeds.
CodingStyle.md says:

"Use form feeds (control+L) to divide long source files into logical
pieces.  A form feed should appear as the only character on a line."

checkpatch.py currently complains about form feed. For example, on
commit 2c06d9a927c5("ovstest: Add test-netlink-conntrack command."),
checkpatch.py returns:

    W(140): Line has non-spaces leading whitespace
    W(140): Line has trailing whitespace
    +

    W(177): Line has non-spaces leading whitespace
    W(177): Line has trailing whitespace
    +

    W(199): Line has non-spaces leading whitespace
    W(199): Line has trailing whitespace
    +

This commit suppresses the two warnings for lines with form feeds as the
only character.

Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com>
Acked-by: Ben Pfaff <blp@ovn.org>
2016-04-18 14:36:20 -07:00
Joe Stringer
6982ee960e checkpatch: Don't enforce char limit on tests.
Although tests ideally also stick to shorter line lengths, it is very
common for fixed text blocks like flows or large packets to be specified
within tests. Checkpatch shouldn't complain about cases like these.

Signed-off-by: Joe Stringer <joe@ovn.org>
Acked-by: Russell Bryant <russell@ovn.org>
Tested-by: Aaron Conole <aconole@redhat.com>
2016-04-08 18:31:17 -07:00
Ben Pfaff
a5e9c53ce4 checkpatch: Fix Python style violation.
I introduced this when updating the script before commit.  My fault, sorry.

Fixes: c599d5ccf31 (checkpatch.py: A simple script for finding patch issues)
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-03-31 08:46:09 -07:00
Aaron Conole
c599d5ccf3 checkpatch.py: A simple script for finding patch issues
Most projects have a checkpatch facility, which can be used as a pre-commit
sanity check. This introduces such a mechanism to the Open vSwitch project
to catch some of the more silly formatting mistakes which can occur. It is
not meant to replace good code review practices, but it can help eliminate
the silly code review issues which get added.

Suggested-by: Mauricio Vásquez <mauricio.vasquezbernal@studenti.polito.it>
Signed-off-by: Aaron Conole <aconole@redhat.com>
[blp@ovn.org adjusted long line threshold and treatment of terminal]
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-03-31 08:29:14 -07:00