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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,6 +4,54 @@ if [ x"${srcdir}" = x ]; then
fi fi
. ${srcdir}/test.rc . ${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} mkdir -p ${CONFD}
cat <<EOF > ${CONF} cat <<EOF > ${CONF}
# Nothing here yo # Nothing here yo

View File

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