DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] devtools: add cppcheck wrapper
@ 2021-02-11 17:27 Ferruh Yigit
  2021-05-20  7:48 ` Thomas Monjalon
  2023-06-12 23:55 ` Stephen Hemminger
  0 siblings, 2 replies; 3+ messages in thread
From: Ferruh Yigit @ 2021-02-11 17:27 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit

Adding wrapper script for cppcheck code analysis tool.

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

Without any argument current folder scanned with all sub folders, if
'path' argument provided, that 'path' is scanned with all its
subfolders, like:
"./devtools/cppcheck.sh lib/librte_ethdev/"

The output log is saved to 'cppcheck_error.txt' in current folder.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 devtools/cppcheck.sh | 67 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100755 devtools/cppcheck.sh

diff --git a/devtools/cppcheck.sh b/devtools/cppcheck.sh
new file mode 100755
index 000000000000..935eb5d9d625
--- /dev/null
+++ b/devtools/cppcheck.sh
@@ -0,0 +1,67 @@
+#! /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
+out=cppcheck_error.txt
+
+which ${CPPCHECK_BIN} > /dev/null 2> /dev/null
+if [ $? -ne 0 ]; then
+	echo "${CPPCHECK_BIN} is missing!"
+	exit 1
+fi
+
+print_usage () {
+	cat <<- END_OF_HELP
+	usage: $(basename $0) [-h] [path]
+
+	Wrapper on checkpatch tool. Output goes to ${out} file.
+
+	Without parameter current folder with all subfolders scanned. It is possible
+	to provide a sub-folder to recude the scan to that folder.
+	END_OF_HELP
+}
+
+if [ "$1" = "-h" ]; then
+	print_usage
+	exit 1;
+fi
+
+dir=${1:-$(dirname $(readlink -f $0))/..}
+if [ ! -e ${dir} ]; then
+	echo "\"${dir}\" is not valid folder/file to check"
+	exit 1
+fi
+
+
+suppress_args="
+	--suppress=invalidPrintfArgType_sint \
+	--suppress=invalidPrintfArgType_uint \
+	--suppress=duplicateAssignExpression \
+	--suppress=nullPointerRedundantCheck \
+	--suppress=identicalConditionAfterEarlyExit \
+	--suppress=objectIndex
+	"
+
+# all, warning, performance, portability,
+# information, unusedFunction, missingInclude
+additional_checks=warning
+
+${CPPCHECK_BIN} \
+	-j64 \
+	--language=c \
+	--enable=${additional_checks} \
+	--force \
+	${suppress_args} \
+	${dir} \
+	2> ${out}
+
+if [ $? -eq 0 ]; then
+	echo -e "\nOutput saved to ${out}"
+else
+	exit $?
+fi
-- 
2.29.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH] devtools: add cppcheck wrapper
  2021-02-11 17:27 [dpdk-dev] [PATCH] devtools: add cppcheck wrapper Ferruh Yigit
@ 2021-05-20  7:48 ` Thomas Monjalon
  2023-06-12 23:55 ` Stephen Hemminger
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2021-05-20  7:48 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev

11/02/2021 18:27, Ferruh Yigit:
> +CPPCHECK_BIN=cppcheck
> +out=cppcheck_error.txt

In general we generate files in $(mktemp -t dpdk.cppcheck.XXXXXX)
The path is printed at the end anyway.

> +
> +which ${CPPCHECK_BIN} > /dev/null 2> /dev/null
> +if [ $? -ne 0 ]; then
> +	echo "${CPPCHECK_BIN} is missing!"

Curly braces are not needed.

> +	exit 1
> +fi
> +
> +print_usage () {
> +	cat <<- END_OF_HELP
> +	usage: $(basename $0) [-h] [path]
> +
> +	Wrapper on checkpatch tool. Output goes to ${out} file.

s/checkpatch/cppcheck/

> +
> +	Without parameter current folder with all subfolders scanned. It is possible
> +	to provide a sub-folder to recude the scan to that folder.

A bit hard to read :)

> +	END_OF_HELP
> +}
> +
> +if [ "$1" = "-h" ]; then
> +	print_usage
> +	exit 1;
> +fi
> +
> +dir=${1:-$(dirname $(readlink -f $0))/..}
> +if [ ! -e ${dir} ]; then
> +	echo "\"${dir}\" is not valid folder/file to check"
> +	exit 1
> +fi
> +
> +
> +suppress_args="
> +	--suppress=invalidPrintfArgType_sint \
> +	--suppress=invalidPrintfArgType_uint \
> +	--suppress=duplicateAssignExpression \
> +	--suppress=nullPointerRedundantCheck \
> +	--suppress=identicalConditionAfterEarlyExit \
> +	--suppress=objectIndex
> +	"
> +
> +# all, warning, performance, portability,
> +# information, unusedFunction, missingInclude
> +additional_checks=warning
> +
> +${CPPCHECK_BIN} \
> +	-j64 \
> +	--language=c \
> +	--enable=${additional_checks} \
> +	--force \
> +	${suppress_args} \
> +	${dir} \
> +	2> ${out}

Is it possible to have only errors by default in the output,
and add all lines about what is being checked in a verbose mode?

> +
> +if [ $? -eq 0 ]; then
> +	echo -e "\nOutput saved to ${out}"

Please prefer printf.

> +else
> +	exit $?
> +fi

The report has 2000 lines of defects,
and it seems to have lots of false positive.
Is it possible to reduce them?



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] devtools: add cppcheck wrapper
  2021-02-11 17:27 [dpdk-dev] [PATCH] devtools: add cppcheck wrapper Ferruh Yigit
  2021-05-20  7:48 ` Thomas Monjalon
@ 2023-06-12 23:55 ` Stephen Hemminger
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2023-06-12 23:55 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: dev, Ferruh Yigit, Stephen Hemminger

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

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} $@
-- 
2.39.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-12 23:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-11 17:27 [dpdk-dev] [PATCH] devtools: add cppcheck wrapper Ferruh Yigit
2021-05-20  7:48 ` Thomas Monjalon
2023-06-12 23:55 ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).