From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mta.qwilt.com (mta.qwilt.com [52.9.191.255]) by dpdk.org (Postfix) with ESMTP id 3BB61255 for ; Mon, 16 Jul 2018 14:44:12 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mta.qwilt.com (Postfix) with ESMTP id 841678069CC; Mon, 16 Jul 2018 12:44:11 +0000 (UTC) X-Virus-Scanned: amavisd-new at qwilt.com Received: from mta.qwilt.com ([127.0.0.1]) by localhost (mta.qwilt.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id knF1jt5I90KU; Mon, 16 Jul 2018 12:44:10 +0000 (UTC) Received: from rd01.it.qwilt.com.qwilt.com (80.179.204.39.cable.012.net.il [80.179.204.39]) by mta.qwilt.com (Postfix) with ESMTPSA id 3ED3C8069C9; Mon, 16 Jul 2018 12:44:08 +0000 (UTC) From: Arnon Warshavsky To: thomas@monjalon.net, anatoly.burakov@intel.com, wenzhuo.lu@intel.com, declan.doherty@intel.com, jerin.jacob@caviumnetworks.com, bruce.richardson@intel.com, ferruh.yigit@intel.com Cc: dev@dpdk.org, arnon@qwilt.com Date: Mon, 16 Jul 2018 15:44:04 +0300 Message-Id: <1531745044-19185-1-git-send-email-arnon@qwilt.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1531741077-5513-1-git-send-email-arnon@qwilt.com> References: <1531741077-5513-1-git-send-email-arnon@qwilt.com> Subject: [dpdk-dev] [PATCH v12] devtools: alert on new instances of rte_panic and rte_exit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Jul 2018 12:44:12 -0000 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 Reviewed-by: Stephen Hemminger Tested-by: Kevin Traynor --- v11 - Use Neils tmpfile infrastructure to consume the patches - Allow different calls to the awk script decide if they want to fail the check or just warn v12 - Restored Tested message devtools/checkpatches.sh | 95 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index 1439bce..22832ef 100755 --- a/devtools/checkpatches.sh +++ b/devtools/checkpatches.sh @@ -43,6 +43,94 @@ print_usage () { END_OF_HELP } + +check_forbidden_additions() { # + # --------------------------------- + #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){ + warnText = "\\033[1;31m" "Warning:" "\\033[0m" + print warnText " 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 RET_ON_FAIL + } + } +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\\\(" \ + -v RET_ON_FAIL=0 \ + "$awk_script" - +} + number=0 quiet=false verbose=false @@ -97,6 +185,13 @@ check () { # ret=1 fi + ! $verbose || printf '\nChecking forbidden tokens additions/removals:\n' + report=$(cat $tmpinput | check_forbidden_additions) + if [ $? -ne 0 ] ; then + ret=1 + fi + printf '%s\n' "$report" + clean_tmp_files [ $ret -eq 0 ] && return 0 -- 1.8.3.1