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="../.." 10if test ! -x "`which clang 2>&1`"; then 11 echo "No clang in path" 12 exit 0 13fi 14#echo "have clang" 15# test if assertions are enabled 16if grep "^#define UNBOUND_DEBUG" $PRE/config.h >/dev/null; then 17 : 18else 19 echo "UNBOUND_DEBUG is not enabled, skip test" 20 # no unbound debug means no assertions, and clang analyzer uses 21 # the assertions to make inferences. 22 exit 0 23fi 24 25# read value from Makefile 26# $1: result variable name 27# $2: string on Makefile 28# $3: Makefile location 29read_value () { 30 x=`grep "$2" $3 | sed -e "s/$2//"` 31 eval $1="'""$x""'" 32 # print what we just read 33 #echo $1"="'"'"`eval echo '$'$1`"'"' 34} 35 36# read some values from the Makefile 37read_value srcdir '^srcdir=' $PRE/Makefile 38read_value CPPFLAGS '^CPPFLAGS=' $PRE/Makefile 39read_value LIBOBJS '^LIBOBJS= *' $PRE/Makefile 40read_value DNSCRYPT_SRC '^DNSCRYPT_SRC= *' $PRE/Makefile 41read_value DNSTAP_SRC '^DNSTAP_SRC= *' $PRE/Makefile 42read_value WITH_PYTHONMODULE '^WITH_PYTHONMODULE= *' $PRE/Makefile 43read_value WINAPPS '^WINAPPS= *' $PRE/Makefile 44 45#echo dir is $dir 46# turn libobjs into C files 47compatfiles=`echo "$LIBOBJS" | sed -e 's?..LIBOBJDIR.?compat/?g' -e 's/.U.o/.c/g'` 48#echo compatfiles are $compatfiles 49#echo 50if test "$WITH_PYTHONMODULE" = "yes"; then PYTHONMOD_SRC="pythonmod/*.c"; fi 51if test ! -z "$WINAPPS"; then WIN_SRC="winrc/*.c"; fi 52 53cd $PRE; 54odir=`pwd` 55cd $srcdir 56# check the files in the srcdir 57fail="no" 58for 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 59 if test "$x" = "util/configlexer.c"; then continue; fi 60 if test "$x" = "util/configparser.c"; then continue; fi 61 if test "$x" = "testcode/signit.c"; then continue; fi 62 if test "$x" = "compat/reallocarray.c"; then continue; fi 63 echo clang --analyze $CPPFLAGS $x 64 plist=`basename $x .c`.plist 65 rm -rf $plist 66 #echo "(cd $odir; clang --analyze $CPPFLAGS $srcdir/$x 2>&1 ) | tee tmp.$$" 67 (cd "$odir"; clang --analyze $CPPFLAGS $srcdir/$x 2>&1 ) | tee tmp.$$ 68 if grep -e warning -e error tmp.$$ >/dev/null; then 69 fail="yes" 70 fails="$fails $x" 71 fi 72 rm -rf $plist tmp.$$ 73done 74 75echo 76if test "$fail" = "yes"; then 77 echo "Failures" 78 echo "create reports in file.plist dir with clang --analyze --analyzer-output html $CPPFLAGS""$fails" 79 exit 1 80fi 81echo "OK" 82exit 0 83