summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBen Pfaff <blp@ovn.org>2018-08-10 13:15:41 -0700
committerBen Pfaff <blp@ovn.org>2018-08-13 14:52:42 -0700
commit3267343a84872dca7731a76d91357044f51fae35 (patch)
tree0dd69d04ff0e436264237ec7492b6259d476397b /tests
parent2360464d629de3acacabd960ffc02fbb5081028d (diff)
downloadopenvswitch-3267343a84872dca7731a76d91357044f51fae35.tar.gz
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/automake.mk1
-rw-r--r--tests/checkpatch.at158
-rw-r--r--tests/testsuite.at1
3 files changed, 160 insertions, 0 deletions
diff --git a/tests/automake.mk b/tests/automake.mk
index 8224e5a4a..01f5077cd 100644
--- a/tests/automake.mk
+++ b/tests/automake.mk
@@ -24,6 +24,7 @@ COMMON_MACROS_AT = \
TESTSUITE_AT = \
tests/testsuite.at \
tests/completion.at \
+ tests/checkpatch.at \
tests/library.at \
tests/heap.at \
tests/bundle.at \
diff --git a/tests/checkpatch.at b/tests/checkpatch.at
new file mode 100644
index 000000000..bcfb75378
--- /dev/null
+++ b/tests/checkpatch.at
@@ -0,0 +1,158 @@
+AT_BANNER([checkpatch])
+
+OVS_START_SHELL_HELPERS
+# try_checkpatch PATCH [ERRORS]
+#
+# Runs checkpatch under Python 2 and Python 3, if installed, on the given
+# PATCH, expecting the specified set of ERRORS (and warnings).
+try_checkpatch() {
+ AT_SKIP_IF([test $HAVE_PYTHON2 = no && test $HAVE_PYTHON3 = no])
+ # Take the patch to test from $1. Remove an initial four-space indent
+ # from it and, if it is just headers with no body, add a null body.
+ echo "$1" | sed 's/^ //' > test.patch
+ if grep '---' expout >/dev/null 2>&1; then :
+ else
+ printf '\n---\n' >> test.patch
+ fi
+
+ # Take expected output from $2.
+ if test -n "$2"; then
+ echo "$2" | sed 's/^ //' > expout
+ else
+ : > expout
+ fi
+
+ try_checkpatch__ "$HAVE_PYTHON2" "$PYTHON2"
+ try_checkpatch__ "$HAVE_PYTHON3" "$PYTHON3"
+}
+try_checkpatch__() {
+ if test $1 = no; then
+ :
+ elif test -s expout; then
+ AT_CHECK([$2 $top_srcdir/utilities/checkpatch.py -q test.patch],
+ [255], [stdout])
+ AT_CHECK([sed '/^Lines checked:/,$d' stdout], [0], [expout])
+ else
+ AT_CHECK([$2 $top_srcdir/utilities/checkpatch.py -q test.patch])
+ fi
+}
+OVS_END_SHELL_HELPERS
+
+AT_SETUP([checkpatch - sign-offs])
+
+# Sign-off for single author who is also the committer.
+try_checkpatch \
+ "Author: A
+ Commit: A
+
+ Signed-off-by: A"
+try_checkpatch \
+ "Author: A
+ Commit: A" \
+ "ERROR: Author A needs to sign off."
+
+# Sign-off for single author and different committer.
+try_checkpatch \
+ "Author: A
+ Commit: B
+
+ Signed-off-by: A
+ Signed-off-by: B"
+try_checkpatch \
+ "Author: A
+ Commit: B" \
+ "ERROR: Author A needs to sign off.
+ ERROR: Committer B needs to sign off."
+
+# Sign-off for multiple authors with one author also the committer.
+try_checkpatch \
+ "Author: A
+ Commit: A
+
+ Signed-off-by: A
+ Co-authored-by: B
+ Signed-off-by: B"
+try_checkpatch \
+ "Author: A
+ Commit: A
+
+ Co-authored-by: B
+ Signed-off-by: B" \
+ "ERROR: Author A needs to sign off."
+try_checkpatch \
+ "Author: A
+ Commit: A
+
+ Signed-off-by: A
+ Co-authored-by: B" \
+ "ERROR: Co-author B needs to sign off."
+try_checkpatch \
+ "Author: A
+ Commit: A
+
+ Co-authored-by: B" \
+ "ERROR: Author A needs to sign off.
+ ERROR: Co-author B needs to sign off."
+
+# Sign-off for multiple authors and separate committer.
+try_checkpatch \
+ "Author: A
+ Commit: C
+
+ Signed-off-by: A
+ Co-authored-by: B
+ Signed-off-by: B
+ Signed-off-by: C"
+try_checkpatch \
+ "Author: A
+ Commit: C
+
+ Signed-off-by: A
+ Co-authored-by: B
+ Signed-off-by: B" \
+ "ERROR: Committer C needs to sign off."
+
+# Extra sign-offs:
+#
+# - If we know the committer, one extra sign-off raises a warning.
+#
+# - If we do not know the committer, two extra sign-offs raise a warning.
+try_checkpatch \
+ "Author: A
+ Commit: C
+
+ Signed-off-by: A
+ Co-authored-by: B
+ Signed-off-by: B
+ Signed-off-by: C
+ Signed-off-by: D" \
+ "WARNING: Unexpected sign-offs from developers who are not authors or co-authors or committers: D"
+try_checkpatch \
+ "Author: A
+
+ Signed-off-by: A
+ Co-authored-by: B
+ Signed-off-by: B
+ Signed-off-by: C"
+try_checkpatch \
+ "Author: A
+
+ Signed-off-by: A
+ Co-authored-by: B
+ Signed-off-by: B
+ Signed-off-by: C
+ Signed-off-by: D" \
+ "WARNING: Unexpected sign-offs from developers who are not authors or co-authors or committers: C, D"
+
+# Missing committer is OK, missing author is an error.
+try_checkpatch \
+ "Author: A
+
+ Signed-off-by: A"
+try_checkpatch \
+ "Commit: A
+
+ Signed-off-by: A" \
+ "ERROR: Patch lacks author."
+
+AT_CLEANUP
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 15c385e2c..690904e30 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -21,6 +21,7 @@ m4_include([tests/ovsdb-macros.at])
m4_include([tests/ofproto-macros.at])
m4_include([tests/completion.at])
+m4_include([tests/checkpatch.at])
m4_include([tests/bfd.at])
m4_include([tests/cfm.at])
m4_include([tests/lacp.at])