diff --git a/test/Makefile.am b/test/Makefile.am index 19d8ac7..31fdde3 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -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) diff --git a/test/api.sh b/test/api.sh index 2235938..81e0623 100755 --- a/test/api.sh +++ b/test/api.sh @@ -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 diff --git a/test/fwd.sh b/test/fwd.sh index 3fadbce..927c405 100755 --- a/test/fwd.sh +++ b/test/fwd.sh @@ -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 diff --git a/test/local.sh b/test/local.sh index 2954ac1..721fb55 100755 --- a/test/local.sh +++ b/test/local.sh @@ -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 diff --git a/test/mark.sh b/test/mark.sh index eb900e6..406cbe8 100755 --- a/test/mark.sh +++ b/test/mark.sh @@ -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 diff --git a/test/remote.sh b/test/remote.sh index 7f14ab8..590f425 100755 --- a/test/remote.sh +++ b/test/remote.sh @@ -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 diff --git a/test/start.sh b/test/start.sh index 295ad4f..9059f40 100755 --- a/test/start.sh +++ b/test/start.sh @@ -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 < ${CONF} # Nothing here yo diff --git a/test/test.rc b/test/test.rc index dff079c..d5e31f2 100644 --- a/test/test.rc +++ b/test/test.rc @@ -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