misra test cleanup (#1764)

* misra test cleanup

* fix pedal

* cleanup

* debug

* fix

* undo debug

* add CAN3
This commit is contained in:
Adeeb Shihadeh 2023-12-09 01:28:50 -08:00 committed by GitHub
parent 7340ece196
commit 6e96d2e57a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 70 deletions

View File

@ -10,3 +10,6 @@ misra-c2012-19.2
misra-c2012-20.10
# Required: it's ok re-defining potentially reserved Macro names. Not likely to cause confusion
misra-c2012-21.1
# needed since not all of these suppressions are applicable to all builds
unmatchedSuppression

View File

@ -4,8 +4,14 @@ set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
PANDA_DIR=$DIR/../../
CPPCHECK_DIR=$DIR/cppcheck
CPPCHECK=$CPPCHECK_DIR/cppcheck
GREEN='\033[0;32m'
NC='\033[0m'
GCC_INC="$(arm-none-eabi-gcc -print-file-name=include)"
: "${CPPCHECK_DIR:=$DIR/cppcheck/}"
CPPCHECK="$CPPCHECK_DIR/cppcheck --dump --enable=all --force --inline-suppr -I $PANDA_DIR/board/ -I $GCC_INC \
--suppressions-list=$DIR/suppressions.txt --suppress=*:*inc/* \
--suppress=*:*include/* --error-exitcode=2"
RULES="$DIR/MISRA_C_2012.txt"
MISRA="python $CPPCHECK_DIR/addons/misra.py"
@ -13,82 +19,27 @@ if [ -f "$RULES" ]; then
MISRA="$MISRA --rule-texts $RULES"
fi
mkdir -p /tmp/misra
ERROR_CODE=0
# install cppcheck if missing
if [ ! -d cppcheck/ ]; then
if [ ! -d $CPPCHECK_DIR ]; then
$DIR/install.sh
fi
# generate coverage matrix
#python tests/misra/cppcheck/addons/misra.py -generate-table > tests/misra/coverage_table
printf "\nPANDA F4 CODE\n"
$CPPCHECK -DPANDA -DSTM32F4 -UPEDAL -DCAN3 -DUID_BASE \
--suppressions-list=$DIR/suppressions.txt --suppress=*:*inc/* \
-I $PANDA_DIR/board/ --dump --enable=all --inline-suppr --force \
$PANDA_DIR/board/main.c 2>/tmp/misra/cppcheck_f4_output.txt
cd $PANDA_DIR
scons -j8
$MISRA $PANDA_DIR/board/main.c.dump 2> /tmp/misra/misra_f4_output.txt || true
printf "\n${GREEN}** PANDA F4 CODE **${NC}\n"
$CPPCHECK -DCAN3 -DPANDA -DSTM32F4 -UPEDAL -DUID_BASE board/main.c
$MISRA board/main.c.dump
# strip (information) lines
cppcheck_f4_output=$( cat /tmp/misra/cppcheck_f4_output.txt | grep -v ": information: " ) || true
misra_f4_output=$( cat /tmp/misra/misra_f4_output.txt | grep -v ": information: " ) || true
printf "\n${GREEN}** PANDA H7 CODE **${NC}\n"
$CPPCHECK -DCAN3 -DPANDA -DSTM32H7 -UPEDAL -DUID_BASE board/main.c
$MISRA board/main.c.dump
printf "\n${GREEN}** PEDAL CODE **${NC}\n"
$CPPCHECK -UCAN3 -UPANDA -DSTM32F2 -DPEDAL -UUID_BASE board/pedal/main.c
$MISRA board/pedal/main.c.dump
printf "\nPANDA H7 CODE\n"
$CPPCHECK -DPANDA -DSTM32H7 -UPEDAL -DUID_BASE \
--suppressions-list=$DIR/suppressions.txt --suppress=*:*inc/* \
-I $PANDA_DIR/board/ --dump --enable=all --inline-suppr --force \
$PANDA_DIR/board/main.c 2>/tmp/misra/cppcheck_h7_output.txt
$MISRA $PANDA_DIR/board/main.c.dump 2> /tmp/misra/misra_h7_output.txt || true
# strip (information) lines
cppcheck_h7_output=$( cat /tmp/misra/cppcheck_h7_output.txt | grep -v ": information: " ) || true
misra_h7_output=$( cat /tmp/misra/misra_h7_output.txt | grep -v ": information: " ) || true
printf "\nPEDAL CODE\n"
$CPPCHECK -UPANDA -DSTM32F2 -DPEDAL -UCAN3 \
--suppressions-list=$DIR/suppressions.txt --suppress=*:*inc/* \
-I $PANDA_DIR/board/ --dump --enable=all --inline-suppr --force \
$PANDA_DIR/board/pedal/main.c 2>/tmp/misra/cppcheck_pedal_output.txt
$MISRA $PANDA_DIR/board/pedal/main.c.dump 2> /tmp/misra/misra_pedal_output.txt || true
# strip (information) lines
cppcheck_pedal_output=$( cat /tmp/misra/cppcheck_pedal_output.txt | grep -v ": information: " ) || true
misra_pedal_output=$( cat /tmp/misra/misra_pedal_output.txt | grep -v ": information: " ) || true
if [[ -n "$misra_f4_output" ]] || [[ -n "$cppcheck_f4_output" ]]
then
echo "Failed! found Misra violations in panda F4 code:"
echo "$misra_f4_output"
echo "$cppcheck_f4_output"
ERROR_CODE=1
fi
if [[ -n "$misra_h7_output" ]] || [[ -n "$cppcheck_h7_output" ]]
then
echo "Failed! found Misra violations in panda H7 code:"
echo "$misra_h7_output"
echo "$cppcheck_h7_output"
ERROR_CODE=1
fi
if [[ -n "$misra_pedal_output" ]] || [[ -n "$cppcheck_pedal_output" ]]
then
echo "Failed! found Misra violations in pedal code:"
echo "$misra_pedal_output"
echo "$cppcheck_pedal_output"
ERROR_CODE=1
fi
if [[ $ERROR_CODE > 0 ]]
then
exit 1
fi
echo "Success"
printf "\n${GREEN}Success!${NC} took $SECONDS seconds\n"