1# #-- clang-analysis.test --# 2# source the master var file when it's there 3[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master 4# use .tpkg.var.test for in test variable passing 5[ -f .tpkg.var.test ] && source .tpkg.var.test 6# common functions 7. ../common.sh 8 9PRE="../.." 10 11# read value from Makefile 12# $1: result variable name 13# $2: string on Makefile 14# $3: Makefile location 15read_value () { 16 x=`grep "$2" $3 | sed -e "s/$2//"` 17 eval $1="'""$x""'" 18 # print what we just read 19 #echo $1"="'"'"`eval echo '$'$1`"'"' 20} 21 22# read some values from the Makefile 23read_value srcdir '^srcdir=' $PRE/Makefile 24read_value CPPFLAGS '^CPPFLAGS=' $PRE/Makefile 25read_value LIBOBJS '^LIBOBJS= *' $PRE/Makefile 26read_value DNSCRYPT_SRC '^DNSCRYPT_SRC= *' $PRE/Makefile 27read_value DNSTAP_SRC '^DNSTAP_SRC= *' $PRE/Makefile 28read_value WITH_PYTHONMODULE '^WITH_PYTHONMODULE= *' $PRE/Makefile 29read_value WINAPPS '^WINAPPS= *' $PRE/Makefile 30 31#echo dir is $dir 32# turn libobjs into C files 33compatfiles=`echo "$LIBOBJS" | sed -e 's?..LIBOBJDIR.?compat/?g' -e 's/.U.o/.c/g'` 34#echo compatfiles are $compatfiles 35#echo 36if test "$WITH_PYTHONMODULE" = "yes"; then PYTHONMOD_SRC="pythonmod/*.c"; fi 37if test ! -z "$WINAPPS"; then WIN_SRC="winrc/*.c"; fi 38 39cd $PRE; 40odir=`pwd` 41cd $srcdir 42# check the files in the srcdir 43fail="no" 44for x in cachedb/*.c daemon/*.c dns64/*.c $DNSCRYPT_SRC $DNSTAP_SRC edns-subnet/*.c ipsecmod/*.c iterator/*.c libunbound/*.c $PYTHONMOD_SRC respip/*.c services/*.c services/*/*.c sldns/*.c smallapp/*.c util/*.c util/*/*.c validator/*.c $WIN_SRC $compatfiles testcode/*.c; do 45 if test "$x" = "util/configlexer.c"; then continue; fi 46 if test "$x" = "util/configparser.c"; then continue; fi 47 if test "$x" = "testcode/signit.c"; then continue; fi 48 if test "$x" = "compat/reallocarray.c"; then continue; fi 49 echo clang --analyze $CPPFLAGS $x 50 plist=`basename $x .c`.plist 51 rm -rf $plist 52 #echo "(cd $odir; clang --analyze $CPPFLAGS $srcdir/$x 2>&1 ) | tee tmp.$$" 53 (cd "$odir"; clang --analyze $CPPFLAGS $srcdir/$x 2>&1 ) | tee tmp.$$ 54 if grep -e warning -e error tmp.$$ >/dev/null; then 55 fail="yes" 56 fails="$fails $x" 57 fi 58 rm -rf $plist tmp.$$ 59done 60 61echo 62if test "$fail" = "yes"; then 63 echo "Failures" 64 echo "create reports in file.plist dir with clang --analyze --analyzer-output html $CPPFLAGS""$fails" 65 exit 1 66fi 67echo "OK" 68exit 0 69