123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- #!/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.
- # Checks that the initLogger() call uses for unit tests respects the setting of
- # the environment variables.
- testname="initLogger test"
- echo $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
- 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 << .
- DEBUG [bind10.log] LOG_BAD_DESTINATION unrecognized log destination: debug-0
- DEBUG [bind10.log] LOG_BAD_DESTINATION unrecognized log destination: debug-50
- DEBUG [bind10.log] LOG_BAD_DESTINATION unrecognized log destination: debug-99
- INFO [bind10.log] LOG_BAD_SEVERITY unrecognized log severity: info
- WARN [bind10.log] LOG_BAD_STREAM bad log console output stream: warn
- ERROR [bind10.log] LOG_DUPLICATE_MESSAGE_ID duplicate message ID (error) in compiled code
- FATAL [bind10.log] LOG_NO_MESSAGE_ID line fatal: message definition line found without a message ID
- .
- B10_LOGGER_DESTINATION=stdout B10_LOGGER_SEVERITY=DEBUG B10_LOGGER_DBGLEVEL=99 ./init_logger_test | \
- sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
- cut -d' ' -f3- | diff $tempfile -
- passfail $?
- echo -n " - severity=DEBUG, dbglevel=50: "
- cat > $tempfile << .
- DEBUG [bind10.log] LOG_BAD_DESTINATION unrecognized log destination: debug-0
- DEBUG [bind10.log] LOG_BAD_DESTINATION unrecognized log destination: debug-50
- INFO [bind10.log] LOG_BAD_SEVERITY unrecognized log severity: info
- WARN [bind10.log] LOG_BAD_STREAM bad log console output stream: warn
- ERROR [bind10.log] LOG_DUPLICATE_MESSAGE_ID duplicate message ID (error) in compiled code
- FATAL [bind10.log] LOG_NO_MESSAGE_ID line fatal: message definition line found without a message ID
- .
- B10_LOGGER_DESTINATION=stdout B10_LOGGER_SEVERITY=DEBUG B10_LOGGER_DBGLEVEL=50 ./init_logger_test | \
- sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
- cut -d' ' -f3- | diff $tempfile -
- passfail $?
- echo -n " - severity=WARN: "
- cat > $tempfile << .
- WARN [bind10.log] LOG_BAD_STREAM bad log console output stream: warn
- ERROR [bind10.log] LOG_DUPLICATE_MESSAGE_ID duplicate message ID (error) in compiled code
- FATAL [bind10.log] LOG_NO_MESSAGE_ID line fatal: message definition line found without a message ID
- .
- B10_LOGGER_DESTINATION=stdout B10_LOGGER_SEVERITY=WARN ./init_logger_test | \
- sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
- cut -d' ' -f3- | diff $tempfile -
- passfail $?
- echo "2. Checking that B10_LOGGER_DESTINATION works"
- echo -n " - stdout: "
- cat > $tempfile << .
- FATAL [bind10.log] LOG_NO_MESSAGE_ID line fatal: message definition line found without a message ID
- .
- rm -f $destfile_tmp $destfile
- B10_LOGGER_SEVERITY=FATAL B10_LOGGER_DESTINATION=stdout ./init_logger_test 1> $destfile_tmp
- sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile_tmp > $destfile
- cut -d' ' -f3- $destfile | diff $tempfile -
- passfail $?
- echo -n " - stderr: "
- rm -f $destfile_tmp $destfile
- B10_LOGGER_SEVERITY=FATAL B10_LOGGER_DESTINATION=stderr ./init_logger_test 2> $destfile_tmp
- sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile_tmp > $destfile
- cut -d' ' -f3- $destfile | diff $tempfile -
- passfail $?
- echo -n " - file: "
- rm -f $destfile_tmp $destfile
- B10_LOGGER_SEVERITY=FATAL B10_LOGGER_DESTINATION=$destfile_tmp ./init_logger_test
- sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile_tmp > $destfile
- 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.
- rm -f $tempfile $destfile_tmp $destfile
- exit $failcount
|