devtools: add cppcheck wrapper

Message ID 20230612235516.63546-1-stephen@networkplumber.org (mailing list archive)
State Rejected, archived
Delegated to: Thomas Monjalon
Headers
Series devtools: add cppcheck wrapper |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Functional success Functional PASS
ci/github-robot: build fail github build: failed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS

Commit Message

Stephen Hemminger June 12, 2023, 11:55 p.m. UTC
  From: Ferruh Yigit <ferruh.yigit@intel.com>

Adding wrapper script for cppcheck code analysis tool.

usage: cppcheck.sh [-h] [cppcheck options] [path]

Example:
 $ ./devtools/cppcheck.sh -q lib/ethdev/

The tool is useful but gets confused by macros in parts of DPDK.
It identified some bogus code in netvsc driver, and some possible
issues in pcapng.

Would also like to do another round of dead code squashing

Revised and simplified from original version by Ferruh Yigit.
Let the user redirect output as they want, and allow passing
options such as -q (quiet) and -v (verbose).

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 devtools/cppcheck.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100755 devtools/cppcheck.sh
  

Patch

diff --git a/devtools/cppcheck.sh b/devtools/cppcheck.sh
new file mode 100755
index 000000000000..df885df61423
--- /dev/null
+++ b/devtools/cppcheck.sh
@@ -0,0 +1,59 @@ 
+#! /bin/sh
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2021 Intel Corporation
+
+# wrapper script for cppcheck code analysis tool
+# Args:
+#   $1: path to scan (optional)
+
+CPPCHECK_BIN=cppcheck
+RTE_CONFIG=./build/rte_build_config.h
+
+which $CPPCHECK_BIN > /dev/null 2> /dev/null
+if [ $? -ne 0 ]; then
+	echo "$CPPCHECK_BIN is missing!" >&2
+	exit 1
+fi
+
+if [ ! -r $RTE_CONFIG ]; then
+	echo "Build not configured missing $RTE_CONFIG" >&2
+	exit 1
+fi
+
+print_usage () {
+	cat <<- END_OF_HELP
+	usage: $(basename $0) [-h] [cppcheck options] [file or path]
+
+	Run Linux cppcheck tool with DPDK options.
+
+	END_OF_HELP
+}
+
+if [ "$1" = "-h" ]; then
+	print_usage
+	exit 1;
+fi
+
+suppress_args="
+	--suppress=invalidPrintfArgType_sint \
+	--suppress=invalidPrintfArgType_uint \
+	--suppress=duplicateAssignExpression \
+	--suppress=nullPointerRedundantCheck \
+	--suppress=identicalConditionAfterEarlyExit \
+	--suppress=objectIndex \
+	--suppress=unknownMacro \
+	"
+
+includes="
+	--include=$RTE_CONFIG \
+	--includes-file=lib/eal/include \
+	--includes-file=lib/eal/linux/include \
+	"
+
+# all, warning, performance, portability,
+# information, unusedFunction, missingInclude
+additional_checks=warning
+
+${CPPCHECK_BIN}	--language=c ${includes} \
+		--enable=${additional_checks} \
+		--force ${suppress_args} $@