[dpdk-dev,v9,10/10] devtools: prevent new instances of rte_panic and rte_exit
Checks
Commit Message
This patch adds a new function that is called
per every checked patch,
and alerts for new instances of rte_panic/rte_exit.
The check excludes comments, and alerts in the case
of a positive balance between additions and removals.
Signed-off-by: Arnon Warshavsky <arnon@qwilt.com>
---
devtools/checkpatches.sh | 95 +++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 94 insertions(+), 1 deletion(-)
Comments
I think the first line of the commit msg ^^^ should change as it no
longer prevents but just warns
On 04/26/2018 07:21 AM, Arnon Warshavsky wrote:
> This patch adds a new function that is called
> per every checked patch,
> and alerts for new instances of rte_panic/rte_exit.
> The check excludes comments, and alerts in the case
> of a positive balance between additions and removals.
>
Seems to drop the patch name if it finds a match
> Signed-off-by: Arnon Warshavsky <arnon@qwilt.com>
> ---
> devtools/checkpatches.sh | 95 +++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 94 insertions(+), 1 deletion(-)
>
> diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh
> index 7676a6b..48b2685 100755
> --- a/devtools/checkpatches.sh
> +++ b/devtools/checkpatches.sh
> @@ -61,6 +61,91 @@ print_usage () {
> END_OF_HELP
> }
>
> +check_forbidden_additions() { # <file>
> + # ---------------------------------
> + #This awk script receives a list of expressions to monitor
> + #and a list of folders to search these expressions in
> + # - No search is done inside comments
> + # - Both additions and removals of the expressions are checked
> + # A positive balance of additions fails the check
> + read -d '' awk_script << 'EOF'
> + BEGIN{
> + split(FOLDERS,deny_folders," ");
> + split(EXPRESSIONS,deny_expr," ");
> + in_file=0;
> + in_comment=0;
> + count=0;
> + comment_start="/*"
> + comment_end="*/"
> + }
> + # search for add/remove instances in current file
> + # state machine assumes the comments structure is enforced by
> + # checkpatches.pl
> + (in_file) {
> + # comment start
> + if (index($0,comment_start) > 0){
> + in_comment = 1
> + }
> + # non comment code
> + if (in_comment == 0) {
> + for (i in deny_expr) {
> + forbidden_added = "^\+.*" deny_expr[i];
> + forbidden_removed="^-.*" deny_expr[i];
> + current = expressions[deny_expr[i]]
> + if ($0 ~ forbidden_added) {
> + count = count + 1;
> + expressions[deny_expr[i]] = current + 1
> + }
> + if ($0 ~ forbidden_removed) {
> + count = count - 1;
> + expressions[deny_expr[i]] = current - 1
> + }
> + }
> + }
> +
> + # comment end
> + if (index($0,comment_end) > 0) {
> + in_comment = 0
> + }
> + }
> + # switch to next file , check if the balance of add/remove
> + # of previous filehad new additions
> + ($0 ~ "^\+\+\+ b/") {
> + in_file = 0;
> + if (count > 0){
> + exit;
> + }
> + for (i in deny_folders){
> + re = "^\+\+\+ b/" deny_folders[i];
> + if ($0 ~ deny_folders[i]) {
> + in_file = 1
> + last_file = $0
> + }
> + }
> + }
> + END{
> + if (count > 0){
> + print "Warning: in " substr(last_file,6) ":"
> + print "are you sure you want to add the following:"
> + for (key in expressions) {
> + if (expressions[key] > 0) {
> + print key
> + }
> + }
> + exit 1
> + }
> + }
> +EOF
> + # ---------------------------------
> +
> + # refrain from new additions of rte_panic() and rte_exit()
> + # under lib and net
> + # multiple folders and expressions are separated by spaces
> + awk -v FOLDERS="lib net" \
> + -v EXPRESSIONS="rte_panic\\\( rte_exit\\\(" \
> + "$awk_script" -
> +}
> +
> number=0
> quiet=false
> verbose=false
> @@ -89,11 +174,19 @@ check () { # <patch> <commit> <title>
> total=$(($total + 1))
> ! $verbose || printf '\n### %s\n\n' "$3"
> if [ -n "$1" ] ; then
> + cat "$1" | check_forbidden_additions
> + [ $? -eq 0 ] || return 0
> report=$($DPDK_CHECKPATCH_PATH $options "$1" 2>/dev/null)
> elif [ -n "$2" ] ; then
> - report=$(git format-patch --find-renames --no-stat --stdout -1 $commit |
> + params=$(echo "--find-renames --no-stat --stdout -1")
> + body=$(git format-patch $params $commit)
> + echo "$body" | check_forbidden_additions
> + [ $? -eq 0 ] || return 0
> + report=$(echo "$body" |
> $DPDK_CHECKPATCH_PATH $options - 2>/dev/null)
> else
> + check_forbidden_additions -
> + [ $? -eq 0 ] || return 0
> report=$($DPDK_CHECKPATCH_PATH $options - 2>/dev/null)
> fi
> [ $? -ne 0 ] || return 0
>
On Thu, Apr 26, 2018 at 7:08 PM, Kevin Traynor <ktraynor@redhat.com> wrote:
> I think the first line of the commit msg ^^^ should change as it no
> longer prevents but just warns
>
> Actually the return value did not change, only the warning text did.
I would rather keep the word 'prevents' as an intention declaration that
puts the fact that a panic is undesired first, and the technical ability of
a maintainer to allow it second.
This is just in terms of how one positions the usage of panic.
> >
>
> Seems to drop the patch name if it finds a match
Not sure I understand what you meant here. Can you please elaborate?
Thanks
/Arnon
On 04/26/2018 10:57 PM, Arnon Warshavsky wrote:
>
>
> On Thu, Apr 26, 2018 at 7:08 PM, Kevin Traynor <ktraynor@redhat.com
> <mailto:ktraynor@redhat.com>> wrote:
>
> I think the first line of the commit msg ^^^ should change as it no
> longer prevents but just warns
>
> Actually the return value did not change, only the warning text did.
So will it fail checkpatch in patchwork? I agree with Aaron and Anatoly
that patches with rte_panic/exit should flag some warning message, but
the maintainer should have final say. I don't think failing checkpatch
is the solution for that.
> I would rather keep the word 'prevents' as an intention declaration that
> puts the fact that a panic is undesired first, and the technical ability
> of a maintainer to allow it second.
It's only words, but to me 'prevents' does not indicate that it is
undesirable - it indicates it is not allowed.
> This is just in terms of how one positions the usage of panic.
>
>
>
> >
>
> Seems to drop the patch name if it finds a match
>
>
> Not sure I understand what you meant here. Can you please elaborate?
>
Sure, I made a patch with an rte_panic and ran checkpatch on a bunch of
patches. It gave me the name of all the patches except the one with the
rte_panic.
> Thanks
> /Arnon
>
So will it fail checkpatch in patchwork? I agree with Aaron and Anatoly
> that patches with rte_panic/exit should flag some warning message, but
> the maintainer should have final say. I don't think failing checkpatch
> is the solution for that.
>
Ok. will leave that to the maintainers and change that not to fail
> > I would rather keep the word 'prevents' as an intention declaration that
> > puts the fact that a panic is undesired first, and the technical ability
> > of a maintainer to allow it second.
>
> It's only words, but to me 'prevents' does not indicate that it is
> undesirable - it indicates it is not allowed.
>
They say words create reality, but since we agreed on reality, I'll reword
:)
>
> > Not sure I understand what you meant here. Can you please elaborate?
> >
>
> Sure, I made a patch with an rte_panic and ran checkpatch on a bunch of
> patches. It gave me the name of all the patches except the one with the
> rte_panic.
>
> Got it now. I wasn't using -v .Will fix
Thanks
/Arnon
--
@@ -61,6 +61,91 @@ print_usage () {
END_OF_HELP
}
+check_forbidden_additions() { # <file>
+ # ---------------------------------
+ #This awk script receives a list of expressions to monitor
+ #and a list of folders to search these expressions in
+ # - No search is done inside comments
+ # - Both additions and removals of the expressions are checked
+ # A positive balance of additions fails the check
+ read -d '' awk_script << 'EOF'
+ BEGIN{
+ split(FOLDERS,deny_folders," ");
+ split(EXPRESSIONS,deny_expr," ");
+ in_file=0;
+ in_comment=0;
+ count=0;
+ comment_start="/*"
+ comment_end="*/"
+ }
+ # search for add/remove instances in current file
+ # state machine assumes the comments structure is enforced by
+ # checkpatches.pl
+ (in_file) {
+ # comment start
+ if (index($0,comment_start) > 0){
+ in_comment = 1
+ }
+ # non comment code
+ if (in_comment == 0) {
+ for (i in deny_expr) {
+ forbidden_added = "^\+.*" deny_expr[i];
+ forbidden_removed="^-.*" deny_expr[i];
+ current = expressions[deny_expr[i]]
+ if ($0 ~ forbidden_added) {
+ count = count + 1;
+ expressions[deny_expr[i]] = current + 1
+ }
+ if ($0 ~ forbidden_removed) {
+ count = count - 1;
+ expressions[deny_expr[i]] = current - 1
+ }
+ }
+ }
+
+ # comment end
+ if (index($0,comment_end) > 0) {
+ in_comment = 0
+ }
+ }
+ # switch to next file , check if the balance of add/remove
+ # of previous filehad new additions
+ ($0 ~ "^\+\+\+ b/") {
+ in_file = 0;
+ if (count > 0){
+ exit;
+ }
+ for (i in deny_folders){
+ re = "^\+\+\+ b/" deny_folders[i];
+ if ($0 ~ deny_folders[i]) {
+ in_file = 1
+ last_file = $0
+ }
+ }
+ }
+ END{
+ if (count > 0){
+ print "Warning: in " substr(last_file,6) ":"
+ print "are you sure you want to add the following:"
+ for (key in expressions) {
+ if (expressions[key] > 0) {
+ print key
+ }
+ }
+ exit 1
+ }
+ }
+EOF
+ # ---------------------------------
+
+ # refrain from new additions of rte_panic() and rte_exit()
+ # under lib and net
+ # multiple folders and expressions are separated by spaces
+ awk -v FOLDERS="lib net" \
+ -v EXPRESSIONS="rte_panic\\\( rte_exit\\\(" \
+ "$awk_script" -
+}
+
number=0
quiet=false
verbose=false
@@ -89,11 +174,19 @@ check () { # <patch> <commit> <title>
total=$(($total + 1))
! $verbose || printf '\n### %s\n\n' "$3"
if [ -n "$1" ] ; then
+ cat "$1" | check_forbidden_additions
+ [ $? -eq 0 ] || return 0
report=$($DPDK_CHECKPATCH_PATH $options "$1" 2>/dev/null)
elif [ -n "$2" ] ; then
- report=$(git format-patch --find-renames --no-stat --stdout -1 $commit |
+ params=$(echo "--find-renames --no-stat --stdout -1")
+ body=$(git format-patch $params $commit)
+ echo "$body" | check_forbidden_additions
+ [ $? -eq 0 ] || return 0
+ report=$(echo "$body" |
$DPDK_CHECKPATCH_PATH $options - 2>/dev/null)
else
+ check_forbidden_additions -
+ [ $? -eq 0 ] || return 0
report=$($DPDK_CHECKPATCH_PATH $options - 2>/dev/null)
fi
[ $? -ne 0 ] || return 0