test: refactor and generalize setup(), adding a setup2()
This patch refactors the way the primary and secondary syslogd is started by the test framework. The generalizations not only make the code more readable, it hopefully also makes it easier to add new tests in the future. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
parent
7707715c78
commit
f29f31340c
@ -15,8 +15,7 @@ echo "= Phase 2 - syslog() with openlog() & custom facility ==="
|
||||
cat <<EOF >${CONFD}/console.conf
|
||||
console.* -${LOGCONS}
|
||||
EOF
|
||||
kill -HUP `cat ${PID}`
|
||||
sleep 2
|
||||
reload
|
||||
|
||||
./api -i foo
|
||||
grep "foo: ${MSG}" ${LOGCONS}
|
||||
@ -29,8 +28,7 @@ echo "= Phase 4 - Verify RFC5424 API with syslogp() ==========="
|
||||
cat <<EOF >${CONFD}/v1.conf
|
||||
ftp.* -${LOGV1} ;RFC5424
|
||||
EOF
|
||||
kill -HUP `cat ${PID}`
|
||||
sleep 2
|
||||
reload
|
||||
|
||||
./api -i troglobit -p
|
||||
sleep 2
|
||||
|
11
test/fwd.sh
11
test/fwd.sh
@ -5,7 +5,7 @@ if [ x"${srcdir}" = x ]; then
|
||||
fi
|
||||
. ${srcdir}/lib.sh
|
||||
|
||||
setup
|
||||
setup -m0
|
||||
|
||||
MSG="fwd and allow"
|
||||
|
||||
@ -14,19 +14,16 @@ kern.* /dev/null
|
||||
ntp.* @127.0.0.2:${PORT2} ;RFC5424
|
||||
EOF
|
||||
|
||||
reload
|
||||
|
||||
cat <<EOF >${CONFD2}/50-default.conf
|
||||
kern.* /dev/null
|
||||
*.*;kern.none ${LOG2} ;RFC5424
|
||||
EOF
|
||||
|
||||
../src/syslogd -K -a 127.0.0.2:* -b :${PORT2} -d -F -f ${CONF2} -p ${SOCK2} -m1 -C ${CACHE2} -P ${PID2} &
|
||||
setup2 -m0 -a 127.0.0.2:* -b ":${PORT2}"
|
||||
|
||||
kill -HUP `cat ${PID}`
|
||||
sleep 2
|
||||
|
||||
# Enable debug for second syslogd
|
||||
cat ${PID2} >> "$DIR/PIDs"
|
||||
kill -USR1 `cat ${PID2}`
|
||||
|
||||
../src/logger -t fwd -p ntp.notice -u ${SOCK} -m "NTP123" ${MSG}
|
||||
sleep 3
|
||||
|
90
test/lib.sh
90
test/lib.sh
@ -73,40 +73,81 @@ tenacious()
|
||||
FAIL "Timeed out $*"
|
||||
}
|
||||
|
||||
setup()
|
||||
# shellcheck disable=SC2046,SC2086
|
||||
do_setup()
|
||||
{
|
||||
order=$1
|
||||
pidfn=$2
|
||||
shift 2
|
||||
opts="$*"
|
||||
|
||||
ip link set lo up
|
||||
|
||||
cat <<-EOF > ${CONF}
|
||||
# Nothing here yo
|
||||
include ${CONFD}/*.conf
|
||||
EOF
|
||||
print "Starting $order syslogd ..."
|
||||
../src/syslogd -dKF ${opts} &
|
||||
|
||||
mkdir -p ${CONFD2}
|
||||
cat <<-EOF > ${CONF2}
|
||||
# Nothing here yo
|
||||
sleep 2
|
||||
[ -f "${pidfn}" ] || FAIL "Failed starting $order syslogd"
|
||||
cat "${pidfn}" >> "$DIR/PIDs"
|
||||
|
||||
# Enable debugging ...
|
||||
kill -USR1 $(cat "${pidfn}")
|
||||
|
||||
sleep 1
|
||||
}
|
||||
|
||||
# set up and start primary syslogd
|
||||
setup()
|
||||
{
|
||||
if [ ! -f "${CONF}" ]; then
|
||||
cat <<-EOF > "${CONF}"
|
||||
include ${CONFD}/*.conf
|
||||
EOF
|
||||
|
||||
cat <<-EOF > "${CONFD}/foo.conf"
|
||||
# Local log file, avoid sync to disk
|
||||
*.* -${LOG}
|
||||
EOF
|
||||
|
||||
cat <<-EOF > "${CONFD}/bar.conf"
|
||||
# For remote logging
|
||||
*.* @127.0.0.2
|
||||
*.* @127.0.0.2:${PORT2} ;RFC3164
|
||||
EOF
|
||||
fi
|
||||
|
||||
do_setup "primary" "${PID}" "$*" -b ":${PORT}" -f "${CONF}" -p "${SOCK}" \
|
||||
-p "${ALTSOCK}" -C "${CACHE}" -P "${PID}"
|
||||
}
|
||||
|
||||
# set up and start second syslogd, e.g., for remote.sh
|
||||
setup2()
|
||||
{
|
||||
cat <<-EOF > "${CONF2}"
|
||||
include ${CONFD2}/*.conf
|
||||
EOF
|
||||
|
||||
cat <<-EOF > ${CONFD}/foo.conf
|
||||
# Local log file, avoid sync to disk
|
||||
*.* -${LOG}
|
||||
EOF
|
||||
do_setup "secondary" "${PID2}" "$*" -f "${CONF2}" -p "${SOCK2}" \
|
||||
-C "${CACHE2}" -P "${PID2}"
|
||||
}
|
||||
|
||||
cat <<-EOF > ${CONFD}/bar.conf
|
||||
# For remote logging
|
||||
*.* @127.0.0.2
|
||||
*.* @127.0.0.2:${PORT2} ;RFC3164
|
||||
EOF
|
||||
|
||||
../src/syslogd -K -m1 -b :${PORT} -d -sF -f ${CONF} -p ${SOCK} -p ${ALTSOCK} -C ${CACHE} -P ${PID} &
|
||||
|
||||
sleep 2
|
||||
cat ${PID} >> "$DIR/PIDs"
|
||||
kill -USR1 `cat ${PID}`
|
||||
do_reload()
|
||||
{
|
||||
# shellcheck disable=SC2046
|
||||
kill -HUP $(cat "$1")
|
||||
sleep 1
|
||||
}
|
||||
|
||||
reload()
|
||||
{
|
||||
do_reload "${PID}"
|
||||
}
|
||||
|
||||
reload2()
|
||||
{
|
||||
do_reload "${PID2}"
|
||||
}
|
||||
|
||||
# Stop all lingering collectors and other tools
|
||||
kill_pids()
|
||||
{
|
||||
@ -157,6 +198,7 @@ trapit()
|
||||
}
|
||||
|
||||
# Runs once when including lib.sh
|
||||
mkdir -p ${CONFD}
|
||||
mkdir -p "${CONFD}"
|
||||
mkdir -p "${CONFD2}"
|
||||
touch "$DIR/PIDs"
|
||||
trapit signal INT TERM QUIT EXIT
|
||||
|
@ -4,7 +4,9 @@ if [ x"${srcdir}" = x ]; then
|
||||
srcdir=.
|
||||
fi
|
||||
. ${srcdir}/lib.sh
|
||||
setup
|
||||
|
||||
# Enable MARK messages every minute, full secure mode
|
||||
setup -m1 -ss
|
||||
|
||||
check_mark()
|
||||
{
|
||||
|
@ -4,15 +4,11 @@ if [ x"${srcdir}" = x ]; then
|
||||
fi
|
||||
. ${srcdir}/lib.sh
|
||||
|
||||
mkdir -p ${CONFD}
|
||||
cat <<EOF > ${CONF}
|
||||
# Match all log messages, store in RC5424 format and rotate every 10 MiB
|
||||
*.* -${LOG} ;rotate=10M:5,RFC5424
|
||||
EOF
|
||||
|
||||
../src/syslogd -K -m1 -b :${PORT} -d -sF -f ${CONF} -p ${SOCK} -p ${ALTSOCK} >${LOG2} &
|
||||
echo "$!" > ${PID}
|
||||
cat ${PID} >> "$DIR/PIDs"
|
||||
setup -m0 >"${LOG2}"
|
||||
|
||||
sleep 2
|
||||
grep ';RFC5424,rotate=10000000:5' ${LOG2} || FAIL "Failed parsing RFC542 .conf"
|
||||
|
@ -15,10 +15,8 @@ export MSG="kilroy"
|
||||
cat <<-EOF >${CONFD2}/50-default.conf
|
||||
*.* ${LOG2}
|
||||
EOF
|
||||
../src/syslogd -K -a 127.0.0.2:* -b :${PORT2} -d -F -f ${CONF2} -p ${SOCK2} -m1 -C ${CACHE2} -P ${PID2} &
|
||||
sleep 3
|
||||
cat ${PID2} >> "$DIR/PIDs"
|
||||
kill -USR1 `cat ${PID2}`
|
||||
|
||||
setup2 -m0 -a 127.0.0.2:* -b ":${PORT2}"
|
||||
|
||||
# Start collector in background, note: might need sudo!
|
||||
#tshark -Qni lo -w ${CAP} port ${PORT} &
|
||||
|
Loading…
Reference in New Issue
Block a user