diff --git a/.travis.yml b/.travis.yml index 0e26302a..84c52393 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,10 +46,11 @@ before_install: - sudo apt-get update -qq # - sudo apt-get install -t trusty-backports cppcheck - sudo apt-get build-dep -qq cppcheck - - wget https://github.com/danmar/cppcheck/archive/1.79.zip - - unzip 1.79.zip - - cd cppcheck-1.79 -# - make SRCDIR=build CFGDIR=/usr/share/cppcheck/ HAVE_RULES=yes +# - wget https://github.com/danmar/cppcheck/archive/1.79.zip +# - unzip 1.79.zip +# - cd cppcheck-1.79 + - git clone --depth=10 https://github.com/noisymime/cppcheck.git + - cd cppcheck - sudo make install CFGDIR=/usr/share/cppcheck/ HAVE_RULES=yes # Requirements for doxygen - sudo apt-get install doxygen graphviz @@ -59,10 +60,9 @@ install: script: - cd /home/travis/build - - git clone --depth=20 https://github.com/noisymime/cppcheck.git noisymime/cppcheck + - git clone --depth=10 https://github.com/noisymime/cppcheck.git noisymime/cppcheck_github - cd noisymime/speeduino - platformio update -# - platformio run -e megaatmega2560 -e teensy35 -e bluepill_f103c8 -e genericSTM32F103RB # Run the builds - platformio run -e megaatmega2560 -e teensy35 # Upload ini and hex files to speeduino.com server @@ -70,8 +70,8 @@ script: - curl -v --user "speeduino_firmware@speeduino.com:$WEB_PWD" --basic -T "./reference/speeduino.ini" "https://speeduino.com:2078/master.ini" # Begin MISRA scan - cd .. - - chmod +x speeduino/misra/check_misra.sh - - speeduino/misra/check_misra.sh + - chmod +x speeduino/misra/check_misra_github.sh + - speeduino/misra/check_misra_github.sh # Do doxygen run and upload to gh-pages server. - cd speeduino - doxygen diff --git a/misra/check_misra_github.sh b/misra/check_misra_github.sh new file mode 100755 index 00000000..b02035bb --- /dev/null +++ b/misra/check_misra_github.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +cppcheck_path=cppcheck_github/ +cppcheck_bin="${cppcheck_path}cppcheck" +cppcheck_misra="${cppcheck_path}addons/misra.py" + +if [ -f ./results.txt ]; then + rm results.txt +fi + +for i in speeduino/speeduino/*.ino; do + $cppcheck_bin --dump --max-configs=1 --suppressions-list=speeduino/misra/suppressions.txt --suppress=syntaxError:speeduino/speeduino/src/PID_v1/PID_v1.h --include=${i%.*}.h -DCORE_AVR=1 -D__AVR_ATmega2560__=1 $i > /dev/null +done + +mv speeduino/speeduino/*.dump ./ +rm ./utils.*.dump + +python $cppcheck_misra --rule-texts=speeduino/misra/misra_2012_text.txt *.dump 2> results.txt +#rm *.dump + +cat results.txt +# wc -l results.txt + +errors=`wc -l < results.txt | tr -d ' '` +echo $errors MISRA violations + +if [ $errors -gt 0 ]; then + exit 1 +else + exit 0 +fi diff --git a/misra/check_misra_v1.86.sh b/misra/check_misra_v1.86.sh deleted file mode 100755 index 540c838f..00000000 --- a/misra/check_misra_v1.86.sh +++ /dev/null @@ -1,26 +0,0 @@ -if [ -f ./results.txt ]; then - rm results.txt -fi - -cd speeduino/speeduino -#cppcheck --dump --inline-suppr --suppress=syntaxError:src/PID_v1/PID_v1.h --suppressions-list=../misra/suppressions.txt --include=./*.h -DCORE_AVR=1 -D__AVR_ATmega2560__ -U__STM32F1__ -USTM32F4 ./*.ino > /dev/null -cppcheck --dump --inline-suppr --suppress=syntaxError:src/PID_v1/PID_v1.h --suppressions-list=../misra/suppressions.txt --include=./*.h -DCORE_AVR=1 -D__AVR_ATmega2560__ -U__STM32F1__ -USTM32F4 -UCORE_STM32 -UCORE_TEENSY ./storage.ino > /dev/null -cd ../.. -mv speeduino/speeduino/*.dump ./ -rm ./utils.*.dump - -python cppcheck/addons/misra.py --rule-texts=speeduino/misra/misra_2012_text.txt *.dump 2> results.txt -#python cppcheck/addons/misra.py --rule-texts=speeduino/misra/misra_2012_text.txt board_avr2560.ino.dump 2> results.txt -#rm *.dump - -cat results.txt -# wc -l results.txt - -errors=`wc -l < results.txt | tr -d ' '` -echo $errors MISRA violations - -if [ $errors -gt 0 ]; then - exit 1 -else - exit 0 -fi diff --git a/misra/misra_2012_text.txt b/misra/misra_2012_text.txt index fb58afd3..91784479 100644 --- a/misra/misra_2012_text.txt +++ b/misra/misra_2012_text.txt @@ -100,7 +100,7 @@ No text specified Rule 10.3 No text specified Rule 10.4 -No text specified +The target of an operation must be of an appropriate type Rule 10.5 No text specified Rule 10.6 @@ -232,7 +232,7 @@ Advisory - Use of #undef is not permitted Rule 20.6 No text specified Rule 20.7 -No text specified +Macro expressions must be enclosed in parentheses Rule 20.8 No text specified Rule 20.9 diff --git a/misra/suppression_notes.txt b/misra/suppression_notes.txt new file mode 100644 index 00000000..074e4c99 --- /dev/null +++ b/misra/suppression_notes.txt @@ -0,0 +1,2 @@ +5.4 - cppcheck currently doesn't appear to handle the scope of #defines within header files and so is counting all instances as duplicates. +10.4 - Currently suppressing this as the work required to go through and add I, U, UL, L etc to all the contstants is not worth it. diff --git a/misra/suppressions.txt b/misra/suppressions.txt index e78929fe..89f97547 100644 --- a/misra/suppressions.txt +++ b/misra/suppressions.txt @@ -1,7 +1,6 @@ -misra_12.1:board_avr2560.ino:7 -misra_14_4 -misra.5.2 +misra_10.4 +misra_5.4 MISRA_16_4:misra-suppressions1-test.c MISRA.16.6:misra-suppressions1-test.c MISRA_4_1:misra-suppressions2-test.c -MISRA.19_2:misra-suppressions2-test.c \ No newline at end of file +MISRA.19_2:misra-suppressions2-test.c