]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Test set makeover.
authorWouter Wijngaards <wouter@NLnetLabs.nl>
Fri, 11 Feb 2011 14:39:37 +0000 (14:39 +0000)
committerWouter Wijngaards <wouter@NLnetLabs.nl>
Fri, 11 Feb 2011 14:39:37 +0000 (14:39 +0000)
Makefile.in
test/05-nm.tpkg [deleted file]
test/13-unit-tests-base.tpkg [new file with mode: 0644]
test/14-drill-random.tpkg [deleted file]
test/14-unit-tests-base.tpkg [deleted file]
test/18-drill-tests1.tpkg
test/common.sh [new file with mode: 0644]
test/test_all.sh

index 0cb2bf4cf876de7ec28319a035fc40897f36d4ae..cf6d61fbba5c9796ecdbd2886bf6de9a916e96a3 100644 (file)
@@ -114,7 +114,7 @@ LINK_LIB    = $(LIBTOOL) --mode=link $(CC) $(strip $(CFLAGS) $(LDFLAGS) $(LIBS) -ve
 %.o:    $(srcdir)/%.c $(LIBDNS_HEADERS) ldns/net.h ldns/util.h ldns/config.h
        $(COMP_LIB) $(LIBSSL_CPPFLAGS) -c $<
 
-.PHONY:        clean realclean docclean manpages doc lint all lib pyldns
+.PHONY:        clean realclean docclean manpages doc lint all lib pyldns test
 .PHONY: install uninstall install-doc uninstall-doc uninstall-pyldns
 .PHONY: install-h uninstall-h install-lib uninstall-lib install-pyldns
 
@@ -353,6 +353,9 @@ allclean: test-clean clean
 test-clean:
        tpkg -b test clean
 
+test:
+       if test -x "`which bash`"; then bash test/test_all.sh; else sh test/test_all.sh; fi
+
 #-include $(ALL_SOURCES:.c=.d)
 
 # Recreate symbols file, only needed when API changes
diff --git a/test/05-nm.tpkg b/test/05-nm.tpkg
deleted file mode 100644 (file)
index 5c6bc99..0000000
Binary files a/test/05-nm.tpkg and /dev/null differ
diff --git a/test/13-unit-tests-base.tpkg b/test/13-unit-tests-base.tpkg
new file mode 100644 (file)
index 0000000..a753312
Binary files /dev/null and b/test/13-unit-tests-base.tpkg differ
diff --git a/test/14-drill-random.tpkg b/test/14-drill-random.tpkg
deleted file mode 100644 (file)
index bda4684..0000000
Binary files a/test/14-drill-random.tpkg and /dev/null differ
diff --git a/test/14-unit-tests-base.tpkg b/test/14-unit-tests-base.tpkg
deleted file mode 100644 (file)
index 93dc15e..0000000
Binary files a/test/14-unit-tests-base.tpkg and /dev/null differ
index 4dbbd8a373b5c93efca2d4c1569158c356edbc85..7634c6c14484296723d1a0658523ecd7cc1e4851 100644 (file)
Binary files a/test/18-drill-tests1.tpkg and b/test/18-drill-tests1.tpkg differ
diff --git a/test/common.sh b/test/common.sh
new file mode 100644 (file)
index 0000000..bec2901
--- /dev/null
@@ -0,0 +1,232 @@
+# common.sh - an include file for commonly used functions for test code.
+# BSD licensed (see LICENSE file).
+#
+# Version 1
+# 2011-02-11: first version.
+#
+# include this file from a tpkg script with
+#   . ../common.sh
+#
+# overview of functions available:
+# error x              : print error and exit
+# info x               : print info
+# test_tool_avail x    : see if program in path and complain, exit if not.
+# get_ldns_testns      : set LDNS_TESTNS to executable ldns-testns
+# get_make             : set MAKE to gmake or make tool.
+# get_gcc              : get cc or gcc in CC
+# set_doxygen_path     : set doxygen path
+# skip_if_in_list      : set SKIP=1 if name in list and tool not available.
+# get_random_port x    : get RND_PORT a sequence of free random port numbers.
+# wait_server_up       : wait on logfile to see when server comes up.
+# wait_ldns_testns_up   : wait for ldns-testns to come up.
+# wait_unbound_up      : wait for unbound to come up.
+# wait_petal_up                : wait for petal to come up.
+# wait_server_up_or_fail: wait for server to come up or print a failure string
+# kill_pid             : kill a server, make sure and wait for it to go down.
+
+
+# print error and exit
+# $0: name of program
+# $1: error to printout.
+error () {
+       echo "$0: error: $1" >&2
+       exit 1
+}
+
+# print info
+# $0: name of program
+# $1: to printout.
+info () {
+           echo "$0: info: $1"
+}
+
+# test if 'tool' is available in path and complain otherwise.
+# $1: tool
+test_tool_avail () {
+       if test ! -x "`which $1 2>&1`"; then
+               echo No "$1" in path
+               exit 1
+       fi
+}
+
+# get ldns-testns tool in LDNS_TESTNS variable.
+get_ldns_testns () {
+       if test -x "`which ldns-testns 2>&1`"; then
+               LDNS_TESTNS=ldns-testns
+       else
+               LDNS_TESTNS=/home/wouter/bin/ldns-testns
+       fi
+}
+
+# get make tool in MAKE variable, gmake is used if present.
+get_make () {
+       if test -x "`which gmake 2>&1`"; then
+               MAKE=gmake
+       else
+               MAKE=make
+       fi
+}
+
+# get cc tool in CC variable, gcc is used if present.
+get_gcc () {
+       if test -x "`which gcc 2>&1`"; then
+               CC=gcc
+       else
+               CC=cc
+       fi
+}
+
+# set SKIP=1 if the name is in list and tool is not available.
+# $1: name of package to check.
+# $2: list of packages that need the tool.
+# #3: name of the tool required.
+skip_if_in_list () {
+       if echo $2 | grep $1 >/dev/null; then
+               if test ! -x "`which $3 2>&1`"; then
+                       SKIP=1;
+               fi
+       fi
+}
+
+# function to get a number of random port numbers.
+# $1: number of random ports.
+# RND_PORT is returned as the starting port number
+get_random_port () {
+       local plist
+       local cont
+       local collisions
+       local i
+       local MAXCOLLISION=1000
+       cont=1
+       collisions=0
+       while test "$cont" = 1; do
+               #netstat -n -A ip -A ip6 -a | sed -e "s/^.*:\([0-9]*\) .*$/\1/"
+               RND_PORT=$(( $RANDOM + 5354 ))
+               # depending on uname try to check for collisions in port numbers
+               case "`uname`" in
+               linux|Linux)
+                       plist=`netstat -n -A ip -A ip6 -a | sed -e "s/^.*:\([0-9]*\) .*$/\1/"`
+               ;;
+               *)
+                       plist=""
+               ;;
+               esac
+               cont=0
+               for (( i=0 ; i < $1 ; i++ )); do
+                       if echo "$plist" | grep '^'`expr $i + $RND_PORT`'$' >/dev/null 2>&1; then
+                               cont=1;
+                               collisions=`expr $collisions + 1`
+                       fi
+               done
+               if test $collisions = $MAXCOLLISION; then
+                       error "too many collisions getting random port number"
+               fi
+       done
+}
+
+# wait for server to go up, pass <logfilename> <string to watch>
+# $1 : logfilename
+# $2 : string to watch for.
+# exits with failure if it does not come up
+wait_server_up () {
+       local MAX_UP_TRY=120
+       local WAIT_THRES=30
+       local try
+       for (( try=0 ; try <= $MAX_UP_TRY ; try++ )) ; do
+               if test -f $1 && fgrep "$2" $1 >/dev/null; then
+                       #echo "done on try $try"
+                       break;
+               fi
+               if test $try -eq $MAX_UP_TRY; then
+                       echo "Server in $1 did not go up!"
+                       cat $1
+                       exit 1;
+               fi
+               if test $try -ge $WAIT_THRES; then
+                       sleep 1
+               fi
+       done
+}
+
+# wait for ldns-testns to come up
+# $1 : logfilename that is watched.
+wait_ldns_testns_up () {
+       wait_server_up "$1" "Listening on port"
+}
+
+# wait for unbound to come up
+# string 'Start of service' in log.
+# $1 : logfilename that is watched.
+wait_unbound_up () {
+       wait_server_up "$1" "start of service"
+}
+
+# wait for petal to come up
+# string 'petal start' in log.
+# $1 : logfilename that is watched.
+wait_petal_up () {
+       wait_server_up "$1" "petal start"
+}
+
+# wait for server to go up, pass <logfilename> <string to watch> <badstr>
+# $1 : logfile
+# $2 : success string
+# $3 : failure string
+wait_server_up_or_fail () {
+       local MAX_UP_TRY=120
+       local WAIT_THRES=30
+       local try
+       for (( try=0 ; try <= $MAX_UP_TRY ; try++ )) ; do
+               if test -f $1 && fgrep "$2" $1 >/dev/null; then
+                       echo "done on try $try"
+                       break;
+               fi
+               if test -f $1 && fgrep "$3" $1 >/dev/null; then
+                       echo "failed on try $try"
+                       break;
+               fi
+               if test $try -eq $MAX_UP_TRY; then
+                       echo "Server in $1 did not go up!"
+                       cat $1
+                       exit 1;
+               fi
+               if test $try -ge $WAIT_THRES; then
+                       sleep 1
+               fi
+       done
+}
+
+# kill a pid, make sure and wait for it to go down.
+# $1 : pid to kill
+kill_pid () {
+       local MAX_DOWN_TRY=120
+       local WAIT_THRES=30
+       local try
+       kill $1
+       for (( try=0 ; try <= $MAX_DOWN_TRY ; try++ )) ; do
+               if kill -0 $1 >/dev/null 2>&1; then
+                       :
+               else
+                       #echo "done on try $try"
+                       break;
+               fi
+               if test $try -eq $MAX_DOWN_TRY; then
+                       echo "Server in $1 did not go down! Send SIGKILL"
+                       kill -9 $1 >/dev/null 2>&1
+               fi
+               if test $try -ge $WAIT_THRES; then
+                       sleep 1
+               fi
+               # re-send the signal
+               kill $1 >/dev/null 2>&1
+       done
+       return 0
+}
+
+# set doxygen path, so that make doc can find doxygen
+set_doxygen_path () {
+       if test -x '/home/wouter/bin/doxygen'; then
+               export PATH="/home/wouter/bin:$PATH"
+       fi
+}
+
index 5d0ad7b3d76ec41c4c375e5047336aba9e3e4c47..21f9d7cb68fc70f792669ed6666e81fc0dfc6f52 100755 (executable)
@@ -1,22 +1,35 @@
-TPKG=$1
-if [ -z "$TPKG" ]
-then
-  TPKG=$HOME/repos/tpkg/tpkg
+#!/bin/bash
+# do ldns tests
+cd test
+. common.sh
+
+# find tpkg
+if test -x "`which tpkg 2>&1`"; then
+       TPKG=tpkg
+else
+       TPKG=$1
+       if [ -z "$TPKG" ]
+       then
+       TPKG=$HOME/repos/tpkg/tpkg
+       fi
 fi
 
+test_tool_avail "dig"
+
+echo start the test at `date` in `pwd`
+$TPKG clean
+$TPKG -a ../.. fake 01-compile.tpkg
+$TPKG -a ../.. fake 07-compile-examples.tpkg
+$TPKG -a ../.. fake 16-compile-builddir.tpkg
+$TPKG -a ../.. fake 999-compile-nossl.tpkg
 
 for tests in *.tpkg
 do
        COMMAND="$TPKG -a ../.. exe `basename $tests`"
        echo $COMMAND
        $COMMAND
-       if [ $? = 1 ]; then
-               if [ $tests = "01-compile.tpkg" ]; then
-                       echo "Important base test failed, stopping."
-                       $TPKG report
-                       exit 1
-               fi
-       fi
 done 
+echo finished the test at `date` in `pwd`
 $TPKG report
+cd ..