From 3267343a84872dca7731a76d91357044f51fae35 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 10 Aug 2018 13:15:41 -0700 Subject: checkpatch: Improve accuracy and specificity of sign-off checking. This also makes a start at a testsuite for checkpatch. CC: Aaron Conole Signed-off-by: Ben Pfaff Acked-by: Aaron Conole --- tests/automake.mk | 1 + tests/checkpatch.at | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/testsuite.at | 1 + 3 files changed, 160 insertions(+) create mode 100644 tests/checkpatch.at (limited to 'tests') 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]) -- cgit v1.2.1