From patchwork Tue Apr 19 12:04:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 612078 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3qq3b532fgz9t8r; Tue, 19 Apr 2016 22:04:16 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1asUO2-0003fq-HX; Tue, 19 Apr 2016 12:04:10 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1asUNx-0003fX-NP for fwts-devel@lists.ubuntu.com; Tue, 19 Apr 2016 12:04:05 +0000 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1asUNx-0004TS-Cg; Tue, 19 Apr 2016 12:04:05 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH] Add cppcheck static analysis checking script Date: Tue, 19 Apr 2016 13:04:04 +0100 Message-Id: <1461067444-19787-1-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 2.7.4 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King Automated cppcheck build + run script for static analysis on fwts source. Signed-off-by: Colin Ian King Acked-by: Alex Hung Acked-by: Ivan Hu --- cppcheck.sh | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100755 cppcheck.sh diff --git a/cppcheck.sh b/cppcheck.sh new file mode 100755 index 0000000..3cc5c9b --- /dev/null +++ b/cppcheck.sh @@ -0,0 +1,117 @@ +#!/bin/bash +# +# Copyright (C) 2016 Canonical +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +CPPCHECK_DIR=/tmp/cppcheck +CPPCHECK=${CPPCHECK_DIR}/cppcheck +CPPCHECK_REPO=git://github.com/danmar/cppcheck +CPPCHECK_LOG=cppcheck.log +DEPENDENCIES="git build-essential" +JOBS=$(nproc) +HERE=$(pwd) + +# +# Install any packages we depend on to build cppcheck +# +cppcheck_install_dependencies() +{ + install="" + + echo "Checking for dependencies for cppcheck.." + + for d in ${DEPENDENCIES} + do + if [ "$(dpkg -l | grep $d)" == "" ]; then + install="$install $d" + fi + done + if [ "$install" != "" ]; then + echo "Need to install:$install" + sudo apt-get install $install + if [ $? -ne 0 ]; then + echo "Installation of packages failed" + exit 1 + fi + fi +} + +# +# Get an up to date version of cppcheck +# +cppcheck_get() +{ + if [ -d ${CPPCHECK_DIR} ]; then + echo "Getting latest version of cppcheck.." + mkdir -p ${CPPCHECK_DIR} + cd ${CPPCHECK_DIR} + git checkout -f master >& /dev/null + git fetch origin >& /dev/null + git fetch origin master >& /dev/null + git reset --hard FETCH_HEAD >& /dev/null + cd ${HERE} + else + echo "Getting cppcheck.." + git clone ${CPPCHECK_REPO} ${CPPCHECK_DIR} + fi +} + +# +# Build cppcheck +# +cppcheck_build() +{ + cd ${CPPCHECK_DIR} + echo "cppcheck: make clean.." + make clean >& /dev/null + echo "cppcheck: make.." + nice make -j $JOBS > /dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "Build of cppcheck succeeded" + else + echo "Build of cppcheckfailed" + exit 1 + fi + cd ${HERE} +} + +# +# Build fwts using cppcheck +# +cppcheck_fwts() +{ + echo "cppchecking fwts.." + rm -f ${CPPCHECK_LOG} + nice ${CPPCHECK} --force -j $JOBS --enable=all . 2>&1 | tee ${CPPCHECK_LOG} +} + +# +# Check for errors +# +cppcheck_errors() +{ + errors=$(grep "(error" ${CPPCHECK_LOG} | wc -l) + warnings=$(grep "(warning" ${CPPCHECK_LOG} | wc -l) + echo " " + echo "cppcheck found $errors errors and $warnings warnings, see ${CPPCHECK_LOG} for more details." +} + +cppcheck_install_dependencies +cppcheck_get +cppcheck_build +cppcheck_fwts +cppcheck_errors