From b983cc8fe64438aa9ac40bb677455e8798571223 Mon Sep 17 00:00:00 2001 From: Riccardo Date: Tue, 9 Jul 2019 14:37:26 -0700 Subject: [PATCH] Re-wrote test_misra.sh --- tests/misra/test_misra.sh | 52 ++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/tests/misra/test_misra.sh b/tests/misra/test_misra.sh index 5b80b9c906d244..0ea7237ddb5914 100755 --- a/tests/misra/test_misra.sh +++ b/tests/misra/test_misra.sh @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/bin/bash git clone https://github.com/danmar/cppcheck.git || true cd cppcheck @@ -7,22 +7,50 @@ git checkout 862c4ef87b109ae86c2d5f12769b7c8d199f35c5 make -j4 cd ../../../ -# panda code -tests/misra/cppcheck/cppcheck -DPANDA -UPEDAL -DCAN3 -DUID_BASE --suppressions-list=tests/misra/suppressions.txt --dump --enable=all --inline-suppr --force board/main.c 2>/tmp/misra/cppcheck_output.txt || true -python tests/misra/cppcheck/addons/misra.py board/main.c.dump 2>/tmp/misra/misra_output.txt || true + +printf "\nPANDA CODE\n" +#tests/misra/cppcheck/cppcheck -DPANDA -UPEDAL -DCAN3 -DUID_BASE \ +# --suppressions-list=tests/misra/suppressions.txt \ +# --dump --enable=all --inline-suppr --force \ +# board/main.c 2>/tmp/misra/cppcheck_output.txt + +python tests/misra/cppcheck/addons/misra.py board/main.c.dump 2>/tmp/misra/misra_output.txt # violations in safety files -(cat /tmp/misra/misra_output.txt | grep safety) > /tmp/misra/misra_safety_output.txt || true -(cat /tmp/misra/cppcheck_output.txt | grep safety) > /tmp/misra/cppcheck_safety_output.txt || true +misra_output=$( cat /tmp/misra/misra_output.txt | grep safety); +cppcheck_output=$( cat /tmp/misra/cppcheck_output.txt | grep safety); +# TODO: remove safety only check when the whole panda code is MISRA compatible and replace with below +# strip (information) lines +#misra_output=$(cat /tmp/misra/misra_output.txt | grep -v "(information) " || true) +#cppcheck_output=$(cat /tmp/misra/cppcheck_output.txt | grep -v "(information) " || true) + + + +printf "\nPEDAL CODE\n" +tests/misra/cppcheck/cppcheck -UPANDA -DPEDAL -UCAN3 \ + --suppressions-list=tests/misra/suppressions.txt \ + -I board/ --dump --enable=all --inline-suppr --force \ + board/pedal/main.c 2>/tmp/misra/cppcheck_pedal_output.txt + +python tests/misra/cppcheck/addons/misra.py board/pedal/main.c.dump 2>/tmp/misra/misra_pedal_output.txt + +# strip (information) lines +misra_pedal_output=$( cat /tmp/misra/misra_pedal_output.txt | grep -v "(information) ") +cppcheck_pedal_output=$( cat /tmp/misra/cppcheck_pedal_output.txt | grep -v "(information) ") -if [[ -s "/tmp/misra/misra_safety_output.txt" ]] || [[ -s "/tmp/misra/cppcheck_safety_output.txt" ]] +if [[ -n "$misra_output" ]] || [[ -n "$cppcheck_output" ]] then echo "Found Misra violations in the safety code:" - cat /tmp/misra/misra_safety_output.txt - cat /tmp/misra/cppcheck_safety_output.txt + echo "$misra_output" + echo "$cppcheck_output" exit 1 fi -# pedal code -tests/misra/cppcheck/cppcheck -UPANDA -DPEDAL -UCAN3 --suppressions-list=tests/misra/suppressions.txt -I board/ --dump --enable=all --inline-suppr --force board/pedal/main.c 2>/tmp/misra/cppcheck_pedal_output.txt || true -python tests/misra/cppcheck/addons/misra.py board/pedal/main.c.dump 2>/tmp/misra/misra_pedal_output.txt || true +# TODO: enable pedal check when the whole pedal code is Misra compliant +#if [[ ! -z "$misra_pedal_output" ]] || [[ ! -z "$cppcheck_pedal_output" ]] +#then +# echo "Found Misra violations in the pedal code:" +# echo "$misra_pedal_output" +# echo "$cppcheck_pedal_output" +# exit 1 +#fi