Skip to content

Commit

Permalink
- Fix to sync the tests script file common.sh.
Browse files Browse the repository at this point in the history
  • Loading branch information
wcawijngaards committed Dec 6, 2023
1 parent d8bd984 commit 5997355
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 6 deletions.
3 changes: 3 additions & 0 deletions doc/Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
6 December 2023: Wouter
- Fix to sync the tests script file common.sh.

5 December 2023: Wouter
- Merge #971: fix 'WARNING: Message has 41 extra bytes at end'.
- Fix #969: [FR] distinguish Do53, DoT and DoH in the logs.
Expand Down
120 changes: 114 additions & 6 deletions testdata/common.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# common.sh - an include file for commonly used functions for test code.
# BSD licensed (see LICENSE file).
#
# Version 3
# Version 5
# 2023-12-06: get_ldns_notify, skip_test and teststep, and previous changes
# also included are wait_logfile, cpu_count, process_cpu_list, and
# kill_from_pidfile, and use HOME variable for HOME/bin.
# 2011-04-06: tpk wait_logfile to wait (with timeout) for a logfile line to appear
# 2011-02-23: get_pcat for PCAT, PCAT_DIFF and PCAT_PRINT defines.
# 2011-02-18: ports check on BSD,Solaris. wait_nsd_up.
# 2011-02-11: first version.
Expand All @@ -21,6 +25,7 @@
# 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_logfile : wait on logfile to see entry.
# 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.
Expand All @@ -29,6 +34,9 @@
# wait_server_up_or_fail: wait for server to come up or print a failure string
# skip_test x : print message and skip test (must be called in .pre)
# kill_pid : kill a server, make sure and wait for it to go down.
# cpu_count : get number of cpus in system
# process_cpu_list : get cpu affinity list for process
# kill_from_pidfile : kill the pid in the given pid file
# teststep : print the current test step in the output


Expand Down Expand Up @@ -61,7 +69,7 @@ get_ldns_testns () {
if test -x "`which ldns-testns 2>&1`"; then
LDNS_TESTNS=ldns-testns
else
LDNS_TESTNS=/home/wouter/bin/ldns-testns
LDNS_TESTNS=$HOME/bin/ldns-testns
fi
}

Expand All @@ -70,7 +78,7 @@ get_ldns_notify () {
if test -x "`which ldns-notify 2>&1`"; then
LDNS_NOTIFY=ldns-notify
else
LDNS_NOTIFY=/home/wouter/bin/ldns-notify
LDNS_NOTIFY=$HOME/bin/ldns-notify
fi
}

Expand Down Expand Up @@ -160,13 +168,39 @@ get_random_port () {
done
}

# wait for a logfile line to appear, with a timeout.
# pass <logfilename> <string to watch> <timeout>
# $1 : logfilename
# $2 : string to watch for.
# $3 : timeout in seconds.
# exits with failure if it times out
wait_logfile () {
local WAIT_THRES=30
local MAX_UP_TRY=`expr $3 + $WAIT_THRES`
local try
for (( try=0 ; try <= $MAX_UP_TRY ; try++ )) ; do
if test -f $1 && grep -F "$2" $1 >/dev/null; then
#echo "done on try $try"
break;
fi
if test $try -eq $MAX_UP_TRY; then
echo "Logfile in $1 did not get $2!"
cat $1
exit 1;
fi
if test $try -ge $WAIT_THRES; then
sleep 1
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 MAX_UP_TRY=120
local try
for (( try=0 ; try <= $MAX_UP_TRY ; try++ )) ; do
if test -f $1 && grep -F "$2" $1 >/dev/null; then
Expand Down Expand Up @@ -239,6 +273,33 @@ wait_server_up_or_fail () {
done
}

# $1: zone
# $2: serial to be expected
# $3: server to query
# $4: port
# $5: # times to try (# seconds dig is ran)
wait_for_soa_serial () {
TS_START=`date +%s`
for i in `seq 1 $5`
do
SERIAL=`dig -p $4 @$3 $1 SOA +short | awk '{ print $3 }'`
if test "$?" != "0"
then
echo "** \"dig -p $4 @$3 $1 SOA +short\" failed!"
return 1
fi
if test "$SERIAL" = "$2"
then
TS_END=`date +%s`
echo "*** Serial $2 was seen in $i tries (`expr $TS_END - $TS_START`) seconds"
return 0
fi
sleep 1
done
echo "** Serial $2 was not seen in $5 tries (did see: $SERIAL)"
return 1
}

# kill a pid, make sure and wait for it to go down.
# $1 : pid to kill
kill_pid () {
Expand Down Expand Up @@ -268,11 +329,58 @@ kill_pid () {

# 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"
if test -x '$HOME/bin/doxygen'; then
export PATH="$HOME/bin:$PATH"
fi
}

# get number of cpus in system
cpu_count()
{
local sys=$(uname -s)
if [ "${sys}" = "Linux" ]; then
nproc
elif [ "${sys}" = "FreeBSD" ]; then
sysctl -n hw.ncpu
fi
}

# get cpu affinity list for process
# $1 : pid
process_cpu_list() {
local pid=${1}
local sys=$(uname -s)

if [ "${sys}" = "Linux" ]; then
local defl=$(taskset -pc ${pid} | sed -n -e 's/^.*: //p' | head -n 1)
elif [ "${sys}" = "FreeBSD" ]; then
local defl=$(cpuset -g -p ${pid} | sed -n -e 's/^.*: //p' | head -n 1)
fi

if [ -n "${defl}" ]; then
local infl
defl=$(echo "${defl}" | sed -e 's/,/ /g')
for i in ${defl}; do
rng=$(echo "${i}-${i}" | sed -e 's/^\([0-9]*\)-\([0-9]*\).*$/\1 \2/')
infl="${infl} $(seq -s ' ' ${rng})"
done
infl=$(echo ${infl} | sed -e 's/ */ /' -e 's/^ *//')
echo "${infl}"
fi
}

#
#
kill_from_pidfile() {
local pidfile="$1"
if test -f "$pidfile"; then
local pid=`head -n 1 "$pidfile"`
if test ! -z "$pid"; then
kill_pid "$pid"
fi
fi
}

# Print the current test step in the output
teststep () {
echo
Expand Down

0 comments on commit 5997355

Please sign in to comment.