1#!/bin/sh 2 3#--------------------------------------------------------------------------# 4 5die () { 6 echo "${HIDE}test/api/run.sh:${NORMAL} ${BAD}error:${NORMAL} $*" 7 exit 1 8} 9 10msg () { 11 echo "${HIDE}test/api/run.sh:${NORMAL} $*" 12} 13 14for dir in . .. ../.. 15do 16 [ -f $dir/scripts/colors.sh ] || continue 17 . $dir/scripts/colors.sh || exit 1 18 break 19done 20 21#--------------------------------------------------------------------------# 22 23[ -d ../test -a -d ../test/api ] || \ 24die "needs to be called from a top-level sub-directory of CaDiCaL" 25 26[ x"$CADICALBUILD" = x ] && CADICALBUILD="../build" 27 28[ -f "$CADICALBUILD/makefile" ] || \ 29 die "can not find '$CADICALBUILD/makefile' (run 'configure' first)" 30 31[ -f "$CADICALBUILD/libcadical.a" ] || \ 32 die "can not find '$CADICALBUILD/libcadical.a' (run 'make' first)" 33 34echo -n "$HILITE" 35echo "---------------------------------------------------------" 36echo "API testing in '$CADICALBUILD'" 37echo "---------------------------------------------------------" 38echo -n "$NORMAL" 39 40make -C $CADICALBUILD 41res=$? 42[ $res = 0 ] || exit $res 43 44#--------------------------------------------------------------------------# 45 46makefile=$CADICALBUILD/makefile 47 48CXX=`grep '^CXX=' "$makefile"|sed -e 's,CXX=,,'` 49CXXFLAGS=`grep '^CXXFLAGS=' "$makefile"|sed -e 's,CXXFLAGS=,,'` 50 51msg "using CXX=$CXX" 52msg "using CXXFLAGS=$CXXFLAGS" 53 54tests=../test/api 55 56export CADICALBUILD 57 58#--------------------------------------------------------------------------# 59 60ok=0 61failed=0 62 63cmd () { 64 test $status = 1 && return 65 echo $* 66 $* >> $name.log 67 status=$? 68} 69 70run () { 71 msg "running API test ${HILITE}'$1'${NORMAL}" 72 if [ -f $tests/$1.c ] 73 then 74 src=$tests/$1.c 75 language=" -x c" 76 COMPILE="$CXX `echo $CXXFLAGS|sed -e 's,-std=c++0x,-std=c99,'`" 77 elif [ -f $tests/$1.cpp ] 78 then 79 src=$tests/$1.cpp 80 language="" 81 COMPILE="$CXX $CXXFLAGS" 82 else 83 die "can not find '$tests.c' nor '$tests.cpp'" 84 fi 85 name=$CADICALBUILD/test-api-$1 86 rm -f $name.log $name.o $name 87 status=0 88 cmd $COMPILE$language -o $name.o -c $src 89 cmd $COMPILE -o $name $name.o -L$CADICALBUILD -lcadical 90 cmd $name 91 if test $status = 0 92 then 93 echo "# 0 ... ${GOOD}ok${NORMAL} (zero exit code)" 94 ok=`expr $ok + 1` 95 else 96 echo "# 0 ... ${BAD}failed${NORMAL} (non-zero exit code)" 97 failed=`expr $failed + 1` 98 fi 99} 100 101#--------------------------------------------------------------------------# 102 103run newdelete 104run unit 105run morenmore 106run ctest 107run example 108run terminate 109run cfreeze 110run traverse 111run apitrace 112 113#--------------------------------------------------------------------------# 114 115[ $ok -gt 0 ] && OK="$GOOD" 116[ $failed -gt 0 ] && FAILED="$BAD" 117 118msg "${HILITE}API testing results:${NORMAL} ${OK}$ok ok${NORMAL}, ${FAILED}$failed failed${NORMAL}" 119 120exit $failed 121