noinst_PROGRAMS += $(TESTS)
endif
-noinst_SCRIPTS = console_test.sh
+noinst_SCRIPTS =
+noinst_SCRIPTS += buffer_logger_test.sh
+noinst_SCRIPTS += console_test.sh
noinst_SCRIPTS += destination_test.sh
noinst_SCRIPTS += init_logger_test.sh
noinst_SCRIPTS += local_file_test.sh
# output needs to be compared with stored output (where "cut" and
# "diff" are useful utilities).
check-local:
+ $(SHELL) $(abs_builddir)/buffer_logger_test.sh
$(SHELL) $(abs_builddir)/console_test.sh
$(SHELL) $(abs_builddir)/destination_test.sh
$(SHELL) $(abs_builddir)/init_logger_test.sh
- $(SHELL) $(abs_builddir)/buffer_logger_test.sh
$(SHELL) $(abs_builddir)/local_file_test.sh
$(SHELL) $(abs_builddir)/logger_lock_test.sh
$(SHELL) $(abs_builddir)/severity_test.sh
# used.
set -eu
-# Allow non-zero exit codes to be explicitly checked in this test.
-set +e
+# Include common test library.
+# shellcheck disable=SC1091
+# SC1091: Not following: ... was not specified as input (see shellcheck -x).
+. "@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh"
-testname="bufferLogger test"
-printf '%s\n' "${testname}"
-
-failcount=0
tempfile="@abs_builddir@/buffer_logger_test_tempfile_$$"
-passfail() {
- if [ "${1}" -eq 0 ]; then
- printf ' pass\n'
- else
- printf ' FAIL\n'
- failcount=$((failcount + $1))
- fi
-}
-
-printf '1. Checking that buffer initialization works\n'
+printf 'Checking that buffer initialization works:\n'
-printf ' - Buffer including process() call: '
+test_start 'buffer-logger.buffer-including-process()-call'
cat > $tempfile << .
INFO [buffertest.log] LOG_BAD_SEVERITY unrecognized log severity: info
INFO [buffertest.log] LOG_BAD_SEVERITY unrecognized log severity: info
./buffer_logger_test 2>&1 | \
sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
cut -d' ' -f3- | diff $tempfile -
-passfail $?
+test_finish 0
-printf ' - Buffer excluding process() call: '
+test_start 'buffer-logger.buffer-excluding-process()-call'
cat > $tempfile << .
INFO [buffertest.log]: LOG_BAD_SEVERITY unrecognized log severity: info
DEBUG [buffertest.log]: LOG_BAD_DESTINATION unrecognized log destination: debug-50
INFO [buffertest.log]: LOG_BAD_SEVERITY unrecognized log severity: info
.
./buffer_logger_test -n 2>&1 | diff $tempfile -
-passfail $?
+test_finish 0
# Tidy up.
rm -f $tempfile
-
-exit $failcount
# used.
set -eu
-testname="Console output test"
-printf '%s\n' "${testname}"
+# Include common test library.
+# shellcheck disable=SC1091
+# SC1091: Not following: ... was not specified as input (see shellcheck -x).
+. "@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh"
-failcount=0
tempfile="@abs_builddir@/console_test_tempfile_$$"
# Look at tempfile and check that the count equals the expected count
passfail() {
count=$(wc -l $tempfile | awk '{print $1}')
if [ "${count}" -eq "${1}" ]; then
- printf ' pass\n'
+ test_finish 0
else
- printf ' FAIL\n'
- failcount=$((failcount + $1))
+ test_finish 1
fi
}
-printf '1. Checking that console output to stdout goes to stdout:'
+test_start 'console-output.stdout'
rm -f $tempfile
./logger_example -c stdout -s error 1> $tempfile 2> /dev/null
passfail 4
-printf '2. Checking that console output to stdout does not go to stderr:'
+test_start 'console-output.stdout-not-stderr'
rm -f $tempfile
./logger_example -c stdout -s error 1> /dev/null 2> $tempfile
passfail 0
-printf '3. Checking that console output to stderr goes to stderr:'
+test_start 'console-output.stderr'
rm -f $tempfile
./logger_example -c stderr -s error 1> /dev/null 2> $tempfile
passfail 4
-printf '4. Checking that console output to stderr does not go to stdout:'
+test_start 'console-output.stderr-not-stdout'
rm -f $tempfile
./logger_example -c stderr -s error 1> $tempfile 2> /dev/null
passfail 0
-if [ $failcount -eq 0 ]; then
- echo "PASS: $testname"
-elif [ $failcount -eq 1 ]; then
- echo "FAIL: $testname - 1 test failed"
-else
- echo "FAIL: $testname - $failcount tests failed"
-fi
-
# Tidy up
rm -f $tempfile
-
-exit $failcount
# used.
set -eu
-# Allow non-zero exit codes to be explicitly checked in this test.
-set +e
+# Include common test library.
+# shellcheck disable=SC1091
+# SC1091: Not following: ... was not specified as input (see shellcheck -x).
+. "@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh"
-testname="Destination test"
-printf '%s\n' "${testname}"
-
-failcount=0
tempfile="@abs_builddir@/destination_test_tempfile_$$"
destfile1_tmp="@abs_builddir@/destination_test_destfile_1_tmp_$$"
destfile2_tmp="@abs_builddir@/destination_test_destfile_2_tmp_$$"
destfile1="@abs_builddir@/destination_test_destfile_1_$$"
destfile2="@abs_builddir@/destination_test_destfile_2_$$"
-passfail() {
- if [ "${1}" -eq 0 ]; then
- printf ' pass\n'
- else
- printf ' FAIL\n'
- failcount=$((failcount + $1))
- fi
-}
+printf '1. One logger, multiple destinations:\n'
-echo "1. One logger, multiple destinations:"
cat > $tempfile << .
FATAL [example] LOG_WRITE_ERROR error writing to test1: 42
ERROR [example] LOG_READING_LOCAL_FILE reading local message file dummy/file
sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' < $destfile2_tmp > $destfile2
# strip the thread ids
-printf ' - destination 1:'
+test_start 'logger-destination.one-logger-file-1'
cut -d' ' -f3- $destfile1 | diff $tempfile -
-passfail $?
+test_finish $?
-printf ' - destination 2:'
+test_start 'logger-destination.one-logger-file-2'
cut -d' ' -f3- $destfile2 | diff $tempfile -
-passfail $?
+test_finish $?
# Tidy up.
rm -f $tempfile $destfile1_tmp $destfile2_tmp $destfile1 $destfile2
-printf '2. Two loggers, different destinations and severities\n'
+printf '2. Two loggers, different destinations and severities:\n'
rm -f $destfile1 $destfile2
./logger_example -l example -s info -f $destfile1_tmp -l alpha -s warn -f $destfile2_tmp
# All output for example and example.beta should have gone to destfile1.
# Output for example.alpha should have done to destfile2.
+test_start 'logger-destination.multiples-loggers-file-1'
cat > $tempfile << .
FATAL [example] LOG_WRITE_ERROR error writing to test1: 42
ERROR [example] LOG_READING_LOCAL_FILE reading local message file dummy/file
WARN [example.beta] LOG_BAD_STREAM bad log console output stream: beta_warn
INFO [example.beta] LOG_READ_ERROR error reading from message file beta: info
.
-printf ' - destination 1:'
cut -d' ' -f3- $destfile1 | diff $tempfile -
-passfail $?
+test_finish $?
-printf ' - destination 2:'
+test_start 'logger-destination.multiples-loggers-file-2'
cat > $tempfile << .
WARN [example.alpha] LOG_READ_ERROR error reading from message file a.txt: dummy reason
.
cut -d' ' -f3- $destfile2 | diff $tempfile -
-passfail $?
-if [ $failcount -eq 0 ]; then
- echo "PASS: $testname"
-elif [ $failcount -eq 1 ]; then
- echo "FAIL: $testname - 1 test failed"
-else
- echo "FAIL: $testname - $failcount tests failed"
-fi
+test_finish $?
# Tidy up.
rm -f $tempfile $destfile1_tmp $destfile2_tmp $destfile1 $destfile2
-
-exit $failcount
# used.
set -eu
-# Allow non-zero exit codes to be explicitly checked in this test.
-set +e
+# Include common test library.
+# shellcheck disable=SC1091
+# SC1091: Not following: ... was not specified as input (see shellcheck -x).
+. "@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh"
-testname="initLogger test"
-printf '%s\n' "${testname}"
-
-failcount=0
tempfile="@abs_builddir@/init_logger_test_tempfile_$$"
destfile_tmp="@abs_builddir@/init_logger_test_destfile_tmp_$$"
destfile="@abs_builddir@/init_logger_test_destfile_$$"
-passfail() {
- if [ "${1}" -eq 0 ]; then
- printf ' pass\n'
- else
- printf ' FAIL\n'
- failcount=$((failcount + $1))
- fi
-}
-
-printf '1. Checking that KEA_LOGGER_SEVERITY/KEA_LOGGER_DBGLEVEL work\n'
+printf '1. Checking that KEA_LOGGER_SEVERITY/KEA_LOGGER_DBGLEVEL work:\n'
-printf ' - severity=DEBUG, dbglevel=99: '
+test_start 'init-logger.severity=DEBUG,dbglevel=99'
cat > $tempfile << .
DEBUG [kea.log] LOG_BAD_DESTINATION unrecognized log destination: debug-0
DEBUG [kea.log] LOG_BAD_DESTINATION unrecognized log destination: debug-50
KEA_LOGGER_DESTINATION=stdout KEA_LOGGER_SEVERITY=DEBUG KEA_LOGGER_DBGLEVEL=99 ./init_logger_test | \
sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
cut -d' ' -f3- | diff $tempfile -
-passfail $?
+test_finish $?
-printf ' - severity=DEBUG, dbglevel=50: '
+test_start 'init-logger.severity=DEBUG,dbglevel=50'
cat > $tempfile << .
DEBUG [kea.log] LOG_BAD_DESTINATION unrecognized log destination: debug-0
DEBUG [kea.log] LOG_BAD_DESTINATION unrecognized log destination: debug-50
KEA_LOGGER_DESTINATION=stdout KEA_LOGGER_SEVERITY=DEBUG KEA_LOGGER_DBGLEVEL=50 ./init_logger_test | \
sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
cut -d' ' -f3- | diff $tempfile -
-passfail $?
+test_finish $?
-printf ' - severity=WARN: '
+test_start 'init-logger.severity=WARN'
cat > $tempfile << .
WARN [kea.log] LOG_BAD_STREAM bad log console output stream: warn
ERROR [kea.log] LOG_DUPLICATE_MESSAGE_ID duplicate message ID (error) in compiled code
KEA_LOGGER_DESTINATION=stdout KEA_LOGGER_SEVERITY=WARN ./init_logger_test | \
sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
cut -d' ' -f3- | diff $tempfile -
-passfail $?
+test_finish $?
-printf '2. Checking that KEA_LOGGER_DESTINATION works\n'
+printf '2. Checking that KEA_LOGGER_DESTINATION works:\n'
-printf ' - stdout: '
+test_start 'init-logger.stdout'
cat > $tempfile << .
FATAL [kea.log] LOG_NO_MESSAGE_ID line fatal: message definition line found without a message ID
.
KEA_LOGGER_SEVERITY=FATAL KEA_LOGGER_DESTINATION=stdout ./init_logger_test 1> $destfile_tmp
sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' < $destfile_tmp > $destfile
cut -d' ' -f3- $destfile | diff $tempfile -
-passfail $?
+test_finish $?
-printf ' - stderr: '
+test_start 'init-logger.stderr'
rm -f $destfile_tmp $destfile
KEA_LOGGER_SEVERITY=FATAL KEA_LOGGER_DESTINATION=stderr ./init_logger_test 2> $destfile_tmp
sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' < $destfile_tmp > $destfile
cut -d' ' -f3- $destfile | diff $tempfile -
-passfail $?
+test_finish $?
-printf ' - file: '
+test_start 'init-logger.file'
rm -f $destfile_tmp $destfile
KEA_LOGGER_SEVERITY=FATAL KEA_LOGGER_DESTINATION=$destfile_tmp ./init_logger_test
sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' < $destfile_tmp > $destfile
cut -d' ' -f3- $destfile | diff $tempfile -
-passfail $?
+test_finish $?
# Note: can't automatically test syslog output.
-if [ $failcount -eq 0 ]; then
- printf 'PASS: %s\n' "${testname}"
-elif [ $failcount -eq 1 ]; then
- printf 'FAIL: %s - 1 test failed\n' "${testname}"
-else
- printf 'FAIL: %s - %s tests failed\n' "${testname}" "${failcount}"
-fi
-
# Tidy up.
rm -f $tempfile $destfile_tmp $destfile
-
-exit $failcount
# used.
set -eu
-# Allow non-zero exit codes to be explicitly checked in this test.
-set +e
+# Include common test library.
+# shellcheck disable=SC1091
+# SC1091: Not following: ... was not specified as input (see shellcheck -x).
+. "@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh"
-testname="Local message file test"
-printf '%s\n' "${testname}"
-
-failcount=0
localmes="@abs_builddir@/localdef_mes_$$"
tempfile="@abs_builddir@/run_time_init_test_tempfile_$$"
-passfail() {
- if [ "${1}" -eq 0 ]; then
- printf ' pass\n'
- else
- printf ' FAIL\n'
- failcount=$((failcount + $1))
- fi
-}
-
# Create the local message file for testing
cat > $localmes << .
% LOG_READING_LOCAL_FILE replacement read local message file, parameter is '%1'
.
-printf '1. Local message replacement:'
+test_start 'local-file.local-message-replacement'
cat > $tempfile << .
WARN [example.log] LOG_NO_SUCH_MESSAGE could not replace message text for 'LOG_NOTHERE': no such message
FATAL [example] LOG_WRITE_ERROR error writing to test1: 42
./logger_example -c stdout -s warn $localmes | \
sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
cut -d' ' -f3- | diff $tempfile -
-passfail $?
+test_finish $?
-printf '2. Report error if unable to read local message file:'
+test_start 'local-file.read-error-reporting'
cat > $tempfile << .
ERROR [example.log] LOG_INPUT_OPEN_FAIL unable to open message file $localmes for input: No such file or directory
FATAL [example] LOG_WRITE_ERROR error writing to test1: 42
./logger_example -c stdout -s warn $localmes | \
sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
cut -d' ' -f3- | diff $tempfile -
-passfail $?
-
-if [ $failcount -eq 0 ]; then
- printf 'PASS: %s\n' "$testname"
-elif [ $failcount -eq 1 ]; then
- printf 'FAIL: %s - 1 test failed\n' "$testname"
-else
- printf 'FAIL: %s - %s tests failed\n' "$testname" "$failcount"
-fi
+test_finish $?
# Tidy up.
rm -f $tempfile
-
-exit $failcount
# used.
set -eu
-# Allow non-zero exit codes to be explicitly checked in this test.
-set +e
+# Include common test library.
+# shellcheck disable=SC1091
+# SC1091: Not following: ... was not specified as input (see shellcheck -x).
+. "@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh"
-failcount=0
tempfile="@abs_builddir@/logger_lock_test_tempfile_$$"
destfile="@abs_builddir@/logger_lock_test_destfile_$$"
-passfail() {
- if [ "${1}" -eq 0 ]; then
- printf ' pass\n'
- else
- printf ' FAIL\n'
- failcount=$((failcount + $1))
- fi
-}
-
-printf 'Testing that logger acquires and releases locks correctly:'
+test_start 'logger_lock'
cat > $tempfile << .
LOGGER_LOCK_TEST: MUTEXLOCK
LOGGER_LOCK_TEST: LOCK
KEA_LOGGER_SEVERITY=INFO KEA_LOGGER_DESTINATION=stdout ./logger_lock_test | \
sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' > $destfile
cut -d' ' -f3- $destfile | diff $tempfile -
-passfail $?
+test_finish $?
# Tidy up.
rm -f $tempfile $destfile
-
-exit $failcount
# used.
set -eu
-# Allow non-zero exit codes to be explicitly checked in this test.
-set +e
+# Include common test library.
+# shellcheck disable=SC1091
+# SC1091: Not following: ... was not specified as input (see shellcheck -x).
+. "@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh"
-testname="Severity test"
-printf '%s\n' "${testname}"
-
-failcount=0
tempfile="@abs_builddir@/severity_test_tempfile_$$"
-passfail() {
- if [ "${1}" -eq 0 ]; then
- printf ' pass\n'
- else
- printf ' FAIL\n'
- failcount=$((failcount + $1))
- fi
-}
-
-printf '1. Default parameters:'
+test_start 'severity.default-parameters'
cat > $tempfile << .
FATAL [example] LOG_WRITE_ERROR error writing to test1: 42
ERROR [example] LOG_READING_LOCAL_FILE reading local message file dummy/file
./logger_example -c stdout | \
sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
cut -d' ' -f3- | diff $tempfile -
-passfail $?
+test_finish $?
-printf '2. Severity filter:'
+test_start 'severity.filter'
cat > $tempfile << .
FATAL [example] LOG_WRITE_ERROR error writing to test1: 42
ERROR [example] LOG_READING_LOCAL_FILE reading local message file dummy/file
./logger_example -c stdout -s error | \
sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
cut -d' ' -f3- | diff $tempfile -
-passfail $?
+test_finish $?
-printf '3. Debug level:'
+test_start 'severity.debug-level'
cat > $tempfile << .
FATAL [example] LOG_WRITE_ERROR error writing to test1: 42
ERROR [example] LOG_READING_LOCAL_FILE reading local message file dummy/file
./logger_example -c stdout -s debug -d 25 | \
sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
cut -d' ' -f3- | diff $tempfile -
-passfail $?
-
-if [ $failcount -eq 0 ]; then
- printf 'PASS: %s\n' "$testname"
-elif [ $failcount -eq 1 ]; then
- printf 'FAIL: %s - 1 test failed\n' "$testname"
-else
- printf 'FAIL: %s - %s tests failed\n' "$testname" "$failcount"
-fi
+test_finish $?
# Tidy up
rm -f $tempfile
-
-exit $failcount