-
Notifications
You must be signed in to change notification settings - Fork 10
1120: Run cppcheck only and and report cppcheck for obmc image #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1120
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| #!/bin/bash | ||
| ############################################################################### | ||
| # | ||
| # This script is for running the cppcheck for obmc-phosphor-image | ||
| # | ||
| ############################################################################### | ||
| # | ||
| # Required Inputs: | ||
| # WORKSPACE: Directory which contains the extracted openbmc-build-scripts | ||
| # directory | ||
| # REPOLIST: List of repos to do the cppcheck. | ||
|
|
||
| usage() | ||
| { | ||
| echo "usage: run-obmc-cppcheck.sh <opt>" | ||
| echo "Example:" | ||
| echo 'WORKSPACE=$(pwd) openbmc-build-scripts/run-obmc-cppcheck.sh ' | ||
| echo "" | ||
| } | ||
|
|
||
| # Default variables | ||
| WORKSPACE=${WORKSPACE:-$(pwd)} | ||
| REPOLIST=${REPOLIST:-""} | ||
| OBMC_BUILD_SCRIPTS="openbmc-build-scripts" | ||
|
|
||
| # | ||
| REPOLIST=$(echo $REPOLIST) | ||
| # | ||
|
|
||
| # Check workspace, build scripts, and package to be unit tested exists | ||
| if [ ! -d "${WORKSPACE}" ]; then | ||
| echo "Workspace(${WORKSPACE}) doesn't exist, exiting..." | ||
| exit 1 | ||
| fi | ||
| if [ ! -d "${WORKSPACE}/${OBMC_BUILD_SCRIPTS}" ]; then | ||
| echo "Package(${OBMC_BUILD_SCRIPTS}) not found in ${WORKSPACE}, exiting..." | ||
| exit 1 | ||
| fi | ||
|
|
||
| ## | ||
|
|
||
| # run cppcheck | ||
| function run_cppcheck() | ||
| { | ||
| cd ${WORKSPACE} | ||
| for REPONAME in ${REPOLIST} | ||
| do | ||
| UNIT_TEST_PKG=$REPONAME CPPCHECK_ONLY=1 ./openbmc-build-scripts/run-unit-test-docker.sh | ||
| done | ||
| } | ||
|
|
||
|
|
||
| ### MAIN #### | ||
|
|
||
|
|
||
| # MACHINE | ||
| MACHINE=${MACHINE:-p10bmc} | ||
| export MACHINE | ||
|
|
||
| # environment variables | ||
| # | ||
| # List of Repos to scan. | ||
| REPOLIST=${REPOLIST:-""} | ||
|
|
||
| # Check the repolist config file | ||
| REPOLIST_FILE=${WORKSPACE}/obmc-cppcheck-repolist.txt | ||
| [[ -z "${REPOLIST}" && -f "${REPOLIST_FILE}" ]] && REPOLIST=$(cat ${REPOLIST_FILE}) | ||
|
|
||
| # Use default repos if not passed | ||
| if [ -z "${REPOLIST}" ] | ||
| then | ||
| REPOLIST=" | ||
| bmcweb \ | ||
| dbus-sensors \ | ||
| entity-manager \ | ||
| ibm-acf \ | ||
| ipl \ | ||
| libpldm \ | ||
| obmc-console \ | ||
| openpower-debug-collector \ | ||
| openpower-hw-diags \ | ||
| openpower-hw-isolation \ | ||
| openpower-occ-control \ | ||
| openpower-vpd-parser \ | ||
| panel \ | ||
| phosphor-bmc-code-mgmt \ | ||
| phosphor-certificate-manager \ | ||
| phosphor-dbus-interfaces \ | ||
| phosphor-debug-collector \ | ||
| phosphor-host-ipmid \ | ||
| phosphor-inventory-manager \ | ||
| phosphor-led-manager \ | ||
| phosphor-logging \ | ||
| phosphor-power \ | ||
| phosphor-state-manager \ | ||
| phosphor-user-manager \ | ||
| pldm \ | ||
| powervm-handler \ | ||
| service-config-manager \ | ||
| telemetry \ | ||
| " | ||
| fi | ||
|
|
||
| echo "usage: run-obmc-cppcheck.sh" | ||
|
|
||
|
|
||
| # | ||
| cd ${WORKSPACE}/openbmc | ||
| . setup ${MACHINE} | ||
|
|
||
| cd ${WORKSPACE} | ||
| run_cppcheck | ||
|
|
||
| exit 0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The commit message has a lot of the what and how but not a lot of why. Could you add some details on why we need this? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #!/bin/bash | ||
| # | ||
| # Test for cppcheck filter | ||
| # Required Inputs: | ||
| # WORKSPACE: Directory which contains the extracted openbmc-build-scripts | ||
| # directory | ||
| # REPONAME: repo to run cppcheck. If not, use UNIT_TEST_PKG | ||
| # LOGDIR: Optional, log output dir. If not, WORKSPACE/logs/ | ||
| # REPORTDIR: Optional, report output dir, If not, use WORKSPACE/reports/ | ||
|
|
||
| set -uo pipefail | ||
|
|
||
| args=$* | ||
|
|
||
| [ -z "${UNIT_TEST_PKG}" ] && ( echo "UNIT_TEST_PKG is not set"; exit 1) | ||
|
|
||
| WORKSPACE=${WORKSPACE:-$(pwd)} | ||
| REPONAME=${REPONAME:-${UNIT_TEST_PKG}} | ||
| LOGDIR=${LOGDIR:-${WORKSPACE}/logs} | ||
| REPORTDIR=${REPORTDIR:-${WORKSPACE}/reports} | ||
| mkdir -p ${LOGDIR} | ||
| mkdir -p ${REPORTDIR} | ||
|
|
||
| ## Note: Additional necessary opts | ||
| CPPCHECK_ADD_OPTS=-D"__cppcheck__=1" | ||
|
|
||
| CPPCHECK_STDOUT=${LOGDIR}/cppchk.${REPONAME}.stdout | ||
| CPPCHECK_STDERR=${LOGDIR}/cppchk.${REPONAME}.stderr | ||
| cppcheck ${CPPCHECK_ADD_OPTS} --template="{file}:{line}:{column}: {id}: {severity}: {message}" $args 2> ${CPPCHECK_STDERR} | tee ${CPPCHECK_STDOUT} | ||
|
|
||
| CPPCHECK_ERR_LOG=${REPORTDIR}/cppchk.${REPONAME}.error.log | ||
|
|
||
| FAILED=0 | ||
|
|
||
| rm -f ${CPPCHECK_ERR_LOG} | ||
| while read -r filelinecol id severity remaining; do | ||
| if [[ "$filelinecol" == "/"* || "$filelinecol" == "subprojects/"* ]] | ||
| then | ||
| # ignore the absolute-full-file paths like /usr/include/*, or under subprojects | ||
| continue | ||
| fi | ||
| if [[ "$severity" == "warning:" || "$severity" == "error:" ]] | ||
| then | ||
| echo "Filename:Line:Column: $filelinecol" >> ${CPPCHECK_ERR_LOG} | ||
| echo "id:severity: $id $severity" >> ${CPPCHECK_ERR_LOG} | ||
| echo "remaining: $remaining" >> ${CPPCHECK_ERR_LOG} | ||
| echo "---" >> ${CPPCHECK_ERR_LOG} | ||
| FAILED=1 | ||
| fi | ||
| done < ${CPPCHECK_STDERR} | ||
|
|
||
| if [[ $FAILED -ne 0 ]] | ||
| then | ||
| echo "cppcheck ($UNIT_TEST_PKG) failed, CPPCHECK_ERR_LOG=$CPPCHECK_ERR_LOG" | ||
| cat ${CPPCHECK_ERR_LOG} | ||
| exit 1 | ||
| fi |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the general concept of providing a way to only run cppcheck and failing on it is upstreamable so lets send that portion upstream. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard coding the same defaults in 2 places is always dangerous. Can we just combine the 2 scripts, run-obmc-cppcheck.sh and setup-obmc-cppchck.sh?
Also, we tend to not put the ".sh" on files now as it allows to change to something like python later without impacting the things calling the script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@geissonator
Thanks for the review.
I'll try to incorporate your suggestions later.