test: initial refactor to support running in parallel in an unshare

The release suite fails with no permissions to dump loopback, so let's
run tests in an unshare, one per test, with and start as many syslogd as
needed for each test -- also easier to debug since all are then fully
stand-alone.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg 2021-11-22 04:59:23 +01:00
parent 81eee2185e
commit 523926a07d
8 changed files with 91 additions and 45 deletions

View File

@ -2,6 +2,7 @@ EXTRA_DIST = test.rc opts.sh start.sh stop.sh
EXTRA_DIST += api.sh local.sh remote.sh fwd.sh mark.sh
CLEANFILES = *~ *.trs *.log
TEST_EXTENSIONS = .sh
TESTS_ENVIRONMENT= unshare -mrun
check_PROGRAMS = api
api_SOURCES = api.c
@ -10,12 +11,10 @@ api_LDFLAGS = -static
api_LDADD = ../src/libsyslog.la
TESTS = opts.sh
TESTS += start.sh
TESTS += local.sh
TESTS += remote.sh
TESTS += api.sh
TESTS += fwd.sh
TESTS += mark.sh
TESTS += stop.sh
programs: $(check_PROGRAMS)

View File

@ -1,9 +1,5 @@
#!/bin/sh
set -ex
if [ x"${srcdir}" = x ]; then
srcdir=.
fi
. ${srcdir}/test.rc
. ./start.sh
export MSG="no-openlog-apitest"
@ -42,3 +38,4 @@ echo "= Phase 4 - Verify RFC5424 API with logger(1) ==========="
sleep 2
grep "exampleSDID@32473" ${LOGV1} || (echo "== ${LOGV1}"; tail -10 ${LOGV1}; false)
. ./stop.sh

View File

@ -1,10 +1,6 @@
#!/bin/sh
# Test FWD between two syslogd, second binds 127.0.0.2:5555
set -ex
if [ x"${srcdir}" = x ]; then
srcdir=.
fi
. ${srcdir}/test.rc
. ./start.sh
MSG="fwd and allow"
@ -29,3 +25,5 @@ kill -USR1 `cat ${PID2}`
../src/logger -t fwd -p ntp.notice -u ${SOCK} -m "NTP123" ${MSG}
sleep 3
grep "fwd - NTP123 - ${MSG}" ${LOG2}
. ./stop.sh

View File

@ -1,8 +1,5 @@
#!/bin/sh
if [ x"${srcdir}" = x ]; then
srcdir=.
fi
. ${srcdir}/test.rc
. ./start.sh
MSG="foobar"
MSG2="xyzzy"
@ -12,3 +9,5 @@ grep ${MSG} ${LOG}
../src/logger -u ${ALTSOCK} ${MSG2}
grep ${MSG2} ${LOG}
. ./stop.sh

View File

@ -1,10 +1,14 @@
#!/bin/sh -e
# Test '-- MARK --' in log, depends on fwd.sh
. ./start.sh
if [ x"${srcdir}" = x ]; then
srcdir=.
fi
. ${srcdir}/test.rc
check_mark()
{
grep "MARK" "${LOG}" && return 0
sleep 1
return 1
}
sleep 120
grep "MARK" ${LOG2}
tenacious 120 check_mark
. ./stop.sh

View File

@ -1,9 +1,5 @@
#!/bin/sh
set -ex
if [ x"${srcdir}" = x ]; then
srcdir=.
fi
. ${srcdir}/test.rc
. ./start.sh
MSG="kilroy"
@ -29,3 +25,4 @@ wait ${TPID}
tshark -r ${CAP} | grep ${MSG}
rm ${CAP}
. ./stop.sh

View File

@ -4,6 +4,54 @@ if [ x"${srcdir}" = x ]; then
fi
. ${srcdir}/test.rc
# Print heading for test phases
print()
{
printf "\e[7m>> %-76s\e[0m\n" "$1"
}
dprint()
{
printf "\e[2m%-76s\e[0m\n" "$1"
}
SKIP()
{
print "TEST: SKIP"
[ $# -gt 0 ] && echo "$*"
exit 77
}
FAIL()
{
print "TEST: FAIL"
[ $# -gt 0 ] && echo "$*"
exit 99
}
OK()
{
print "TEST: OK"
[ $# -gt 0 ] && echo "$*"
exit 0
}
# shellcheck disable=SC2068
tenacious()
{
timeout=$1
shift
while [ $timeout -gt 0 ]; do
$@ && return
timeout=$((timeout - 1))
done
FAIL "Timeed out $*"
}
ip link set lo up
mkdir -p ${CONFD}
cat <<EOF > ${CONF}
# Nothing here yo

View File

@ -1,21 +1,25 @@
NM=syslog-test
NM2=syslog-test2
LOG=/tmp/${NM}.log
LOG2=/tmp/${NM2}.log
LOGV1=/tmp/${NM}-v1.log
LOGCONS=/tmp/${NM}-cons.log
PID=/tmp/${NM}.pid
PID2=/tmp/${NM2}.pid
CAP=/tmp/${NM}.pcapng
CACHE=/tmp/${NM}.cache
CACHE2=/tmp/${NM2}.cache
CONF=/tmp/${NM}.conf
CONF2=/tmp/${NM2}.conf
CONFD=/tmp/${NM}.d
CONFD2=/tmp/${NM2}.d
SOCK=/tmp/${NM}.sock
SOCK2=/tmp/${NM2}.sock
ALTSOCK=/tmp/${NM}-alt.sock
# Test name, used everywhere as /tmp/sysklogd/$NM/foo
NM=$(basename "$0" .sh)
DIR=/tmp/sysklogd/$NM
FN=syslog-test
FN2=syslog-test2
LOG=$DIR/${FN}.log
LOG2=$DIR/${FN2}.log
LOGV1=$DIR/${FN}-v1.log
LOGCONS=$DIR/${FN}-cons.log
PID=$DIR/${FN}.pid
PID2=$DIR/${FN2}.pid
CAP=$DIR/${FN}.pcapng
CACHE=$DIR/${FN}.cache
CACHE2=$DIR/${FN2}.cache
CONF=$DIR/${FN}.conf
CONF2=$DIR/${FN2}.conf
CONFD=$DIR/${FN}.d
CONFD2=$DIR/${FN2}.d
SOCK=$DIR/${FN}.sock
SOCK2=$DIR/${FN2}.sock
ALTSOCK=$DIR/${FN}-alt.sock
PORT=5514
PORT2=5555