init_logger_test.sh.in 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/bin/sh
  2. # Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  3. #
  4. # Permission to use, copy, modify, and/or distribute this software for any
  5. # purpose with or without fee is hereby granted, provided that the above
  6. # copyright notice and this permission notice appear in all copies.
  7. #
  8. # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  9. # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  10. # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  12. # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  13. # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  14. # PERFORMANCE OF THIS SOFTWARE.
  15. # Checks that the initLogger() call uses for unit tests respects the setting of
  16. # the environment variables.
  17. testname="initLogger test"
  18. echo $testname
  19. failcount=0
  20. tempfile=@abs_builddir@/init_logger_test_tempfile_$$
  21. destfile_tmp=@abs_builddir@/init_logger_test_destfile_tmp_$$
  22. destfile=@abs_builddir@/init_logger_test_destfile_$$
  23. passfail() {
  24. if [ $1 -eq 0 ]; then
  25. echo " pass"
  26. else
  27. echo " FAIL"
  28. failcount=`expr $failcount + $1`
  29. fi
  30. }
  31. echo "1. Checking that B10_LOGGER_SEVERITY/B10_LOGGER_DBGLEVEL work"
  32. echo -n " - severity=DEBUG, dbglevel=99: "
  33. cat > $tempfile << .
  34. DEBUG [bind10.log] LOG_BAD_DESTINATION unrecognized log destination: debug-0
  35. DEBUG [bind10.log] LOG_BAD_DESTINATION unrecognized log destination: debug-50
  36. DEBUG [bind10.log] LOG_BAD_DESTINATION unrecognized log destination: debug-99
  37. INFO [bind10.log] LOG_BAD_SEVERITY unrecognized log severity: info
  38. WARN [bind10.log] LOG_BAD_STREAM bad log console output stream: warn
  39. ERROR [bind10.log] LOG_DUPLICATE_MESSAGE_ID duplicate message ID (error) in compiled code
  40. FATAL [bind10.log] LOG_NO_MESSAGE_ID line fatal: message definition line found without a message ID
  41. .
  42. B10_LOGGER_DESTINATION=stdout B10_LOGGER_SEVERITY=DEBUG B10_LOGGER_DBGLEVEL=99 ./init_logger_test | \
  43. sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
  44. cut -d' ' -f3- | diff $tempfile -
  45. passfail $?
  46. echo -n " - severity=DEBUG, dbglevel=50: "
  47. cat > $tempfile << .
  48. DEBUG [bind10.log] LOG_BAD_DESTINATION unrecognized log destination: debug-0
  49. DEBUG [bind10.log] LOG_BAD_DESTINATION unrecognized log destination: debug-50
  50. INFO [bind10.log] LOG_BAD_SEVERITY unrecognized log severity: info
  51. WARN [bind10.log] LOG_BAD_STREAM bad log console output stream: warn
  52. ERROR [bind10.log] LOG_DUPLICATE_MESSAGE_ID duplicate message ID (error) in compiled code
  53. FATAL [bind10.log] LOG_NO_MESSAGE_ID line fatal: message definition line found without a message ID
  54. .
  55. B10_LOGGER_DESTINATION=stdout B10_LOGGER_SEVERITY=DEBUG B10_LOGGER_DBGLEVEL=50 ./init_logger_test | \
  56. sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
  57. cut -d' ' -f3- | diff $tempfile -
  58. passfail $?
  59. echo -n " - severity=WARN: "
  60. cat > $tempfile << .
  61. WARN [bind10.log] LOG_BAD_STREAM bad log console output stream: warn
  62. ERROR [bind10.log] LOG_DUPLICATE_MESSAGE_ID duplicate message ID (error) in compiled code
  63. FATAL [bind10.log] LOG_NO_MESSAGE_ID line fatal: message definition line found without a message ID
  64. .
  65. B10_LOGGER_DESTINATION=stdout B10_LOGGER_SEVERITY=WARN ./init_logger_test | \
  66. sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
  67. cut -d' ' -f3- | diff $tempfile -
  68. passfail $?
  69. echo "2. Checking that B10_LOGGER_DESTINATION works"
  70. echo -n " - stdout: "
  71. cat > $tempfile << .
  72. FATAL [bind10.log] LOG_NO_MESSAGE_ID line fatal: message definition line found without a message ID
  73. .
  74. rm -f $destfile_tmp $destfile
  75. B10_LOGGER_SEVERITY=FATAL B10_LOGGER_DESTINATION=stdout ./init_logger_test 1> $destfile_tmp
  76. sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile_tmp > $destfile
  77. cut -d' ' -f3- $destfile | diff $tempfile -
  78. passfail $?
  79. echo -n " - stderr: "
  80. rm -f $destfile_tmp $destfile
  81. B10_LOGGER_SEVERITY=FATAL B10_LOGGER_DESTINATION=stderr ./init_logger_test 2> $destfile_tmp
  82. sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile_tmp > $destfile
  83. cut -d' ' -f3- $destfile | diff $tempfile -
  84. passfail $?
  85. echo -n " - file: "
  86. rm -f $destfile_tmp $destfile
  87. B10_LOGGER_SEVERITY=FATAL B10_LOGGER_DESTINATION=$destfile_tmp ./init_logger_test
  88. sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile_tmp > $destfile
  89. cut -d' ' -f3- $destfile | diff $tempfile -
  90. passfail $?
  91. # Note: can't automatically test syslog output.
  92. if [ $failcount -eq 0 ]; then
  93. echo "PASS: $testname"
  94. elif [ $failcount -eq 1 ]; then
  95. echo "FAIL: $testname - 1 test failed"
  96. else
  97. echo "FAIL: $testname - $failcount tests failed"
  98. fi
  99. # Tidy up.
  100. rm -f $tempfile $destfile_tmp $destfile
  101. exit $failcount