Skip to content
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

misra test cleanup #1764

Merged
merged 7 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/misra/suppressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
91 changes: 21 additions & 70 deletions tests/misra/test_misra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,91 +4,42 @@ 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"
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

$MISRA $PANDA_DIR/board/main.c.dump 2> /tmp/misra/misra_f4_output.txt || true
cd $PANDA_DIR
scons -j8

# 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 F4 CODE **${NC}\n"
$CPPCHECK -DCAN3 -DPANDA -DSTM32F4 -UPEDAL -DUID_BASE board/main.c
$MISRA board/main.c.dump

printf "\n${GREEN}** PANDA H7 CODE **${NC}\n"
$CPPCHECK -DCAN3 -DPANDA -DSTM32H7 -UPEDAL -DUID_BASE board/main.c
$MISRA board/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
printf "\n${GREEN}** PEDAL CODE **${NC}\n"
$CPPCHECK -UCAN3 -UPANDA -DSTM32F2 -DPEDAL -UUID_BASE board/pedal/main.c
$MISRA board/pedal/main.c.dump

echo "Success"
printf "\n${GREEN}Success!${NC} took $SECONDS seconds\n"
Loading