From dd6bdeae73c21576db46f1c3a41dc3f90c6eabe3 Mon Sep 17 00:00:00 2001
From: Grigoris Pavlakis <gregory.pavlakis@gmail.com>
Date: Mon, 18 Mar 2019 11:50:52 +0000
Subject: [PATCH] Add MISRA support to cppcheck - test #1

Attempt to fix the segfaults that showed up

Fix escape codes and a syntax error in the for-loops

Add a line feed to `do` so that Bash stops whining

Update ci/cppcheck.sh

Fix segfaults, attempt #2

Update cppcheck to version 1.86-1

Fix the for loops
---
 .gitlab-ci.yml |  4 ++--
 ci/cppcheck.sh | 22 +++++++++++++++++++++-
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 19ca1713..9623a648 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -38,9 +38,9 @@ before_script:
 cppcheck:
   stage: build
   before_script:
-    - apt-get update -qq && apt-get install -y -qq cppcheck
+    - echo deb http://deb.debian.org/debian sid main > /etc/apt/sources.list  
+    - apt-get update -qq && apt-get -t sid install -y -qq cppcheck
     - cppcheck --version
-    - cppcheck --doc
   script:
     - ci/cppcheck.sh
   tags:
diff --git a/ci/cppcheck.sh b/ci/cppcheck.sh
index dd6aa043..65f0f184 100755
--- a/ci/cppcheck.sh
+++ b/ci/cppcheck.sh
@@ -7,8 +7,28 @@
 # $ ci/cppcheck.sh
 #
 
-echo -e "\033[0;34mRunning cppcheck...\033[0m"
+echo -e "\033[0;34mStarting cppcheck...\033[0m"
+
+echo -e "\033[0;34mRunning cppcheck with default checklist...\033[0m"
 
 cd "$(dirname "$0")/.."
 cppcheck --enable=all --inline-suppr --suppress=unusedFunction --suppress=missingIncludeSystem \
     --suppress=noExplicitConstructor --error-exitcode=1 -I inc src test
+
+echo -e "\033[33mRunning cppcheck with MISRA rule compliance tests...\033[0m"
+
+# grab the MISRA addon and the cppcheck addon interface from github
+curl https://raw.githubusercontent.com/danmar/cppcheck/master/addons/misra.py > misra.py
+curl https://raw.githubusercontent.com/danmar/cppcheck/master/addons/cppcheckdata.py > cppcheckdata.py
+
+# generate dump files (XML representations of AST etc.) for all headers, source files etc.
+for file in $(find inc/ src/ -type f)
+do 
+    cppcheck --dump $file
+done
+
+# run the MISRA checks against the dumps
+for file in $(find inc/ src/ -type f -name "*.dump")
+do 
+    python misra.py $file
+done
\ No newline at end of file
-- 
GitLab