init_logger_test.sh.in 4.65 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/bin/sh
# Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

16 17
# Checks that the initLogger() call uses for unit tests respects the setting of
# the environment variables.
18 19 20 21 22 23

testname="initLogger test"
echo $testname

failcount=0
tempfile=@abs_builddir@/init_logger_test_tempfile_$$
24
destfile_tmp=@abs_builddir@/init_logger_test_destfile_tmp_$$
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
destfile=@abs_builddir@/init_logger_test_destfile_$$

passfail() {
    if [ $1 -eq 0 ]; then
        echo " pass"
    else
        echo " FAIL"
        failcount=`expr $failcount + $1`
    fi
}

echo "1. Checking that B10_LOGGER_SEVERITY/B10_LOGGER_DBGLEVEL work"

echo -n  "   - severity=DEBUG, dbglevel=99: "
cat > $tempfile << .
40 41 42 43 44 45 46
DEBUG [kea.log] LOG_BAD_DESTINATION unrecognized log destination: debug-0
DEBUG [kea.log] LOG_BAD_DESTINATION unrecognized log destination: debug-50
DEBUG [kea.log] LOG_BAD_DESTINATION unrecognized log destination: debug-99
INFO  [kea.log] LOG_BAD_SEVERITY unrecognized log severity: info
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
FATAL [kea.log] LOG_NO_MESSAGE_ID line fatal: message definition line found without a message ID
47
.
48
B10_LOGGER_DESTINATION=stdout B10_LOGGER_SEVERITY=DEBUG B10_LOGGER_DBGLEVEL=99 ./init_logger_test | \
49
    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
50
    cut -d' ' -f3- | diff $tempfile -
51 52 53 54
passfail $?

echo -n  "   - severity=DEBUG, dbglevel=50: "
cat > $tempfile << .
55 56 57 58 59 60
DEBUG [kea.log] LOG_BAD_DESTINATION unrecognized log destination: debug-0
DEBUG [kea.log] LOG_BAD_DESTINATION unrecognized log destination: debug-50
INFO  [kea.log] LOG_BAD_SEVERITY unrecognized log severity: info
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
FATAL [kea.log] LOG_NO_MESSAGE_ID line fatal: message definition line found without a message ID
61
.
62
B10_LOGGER_DESTINATION=stdout B10_LOGGER_SEVERITY=DEBUG B10_LOGGER_DBGLEVEL=50 ./init_logger_test | \
63
    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
64
    cut -d' ' -f3- | diff $tempfile -
65 66 67 68
passfail $?

echo -n  "   - severity=WARN: "
cat > $tempfile << .
69 70 71
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
FATAL [kea.log] LOG_NO_MESSAGE_ID line fatal: message definition line found without a message ID
72
.
73
B10_LOGGER_DESTINATION=stdout B10_LOGGER_SEVERITY=WARN ./init_logger_test | \
74
    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
75
    cut -d' ' -f3- | diff $tempfile -
76 77 78 79 80 81
passfail $?

echo "2. Checking that B10_LOGGER_DESTINATION works"

echo -n  "   - stdout: "
cat > $tempfile << .
82
FATAL [kea.log] LOG_NO_MESSAGE_ID line fatal: message definition line found without a message ID
83
.
84 85
rm -f $destfile_tmp $destfile
B10_LOGGER_SEVERITY=FATAL B10_LOGGER_DESTINATION=stdout ./init_logger_test 1> $destfile_tmp
86
sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile_tmp > $destfile
87 88 89 90
cut -d' ' -f3- $destfile | diff $tempfile -
passfail $?

echo -n  "   - stderr: "
91 92
rm -f $destfile_tmp $destfile
B10_LOGGER_SEVERITY=FATAL B10_LOGGER_DESTINATION=stderr ./init_logger_test 2> $destfile_tmp
93
sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile_tmp > $destfile
94 95 96 97
cut -d' ' -f3- $destfile | diff $tempfile -
passfail $?

echo -n  "   - file: "
98 99
rm -f $destfile_tmp $destfile
B10_LOGGER_SEVERITY=FATAL B10_LOGGER_DESTINATION=$destfile_tmp ./init_logger_test
100
sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile_tmp > $destfile
101 102 103 104 105 106 107 108 109 110 111 112 113 114
cut -d' ' -f3- $destfile | diff $tempfile -
passfail $?

# Note: can't automatically test syslog output.

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.
115
rm -f $tempfile $destfile_tmp $destfile
116 117

exit $failcount