destination_test.sh.in 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 logger will route messages to the chosen destination.
  16. testname="Destination test"
  17. echo $testname
  18. failcount=0
  19. tempfile=@abs_builddir@/destination_test_tempfile_$$
  20. destfile1_tmp=@abs_builddir@/destination_test_destfile_1_tmp_$$
  21. destfile2_tmp=@abs_builddir@/destination_test_destfile_2_tmp_$$
  22. destfile1=@abs_builddir@/destination_test_destfile_1_$$
  23. destfile2=@abs_builddir@/destination_test_destfile_2_$$
  24. passfail() {
  25. if [ $1 -eq 0 ]; then
  26. echo " pass"
  27. else
  28. echo " FAIL"
  29. failcount=`expr $failcount + $1`
  30. fi
  31. }
  32. echo "1. One logger, multiple destinations:"
  33. cat > $tempfile << .
  34. FATAL [example] LOG_WRITE_ERROR error writing to test1: 42
  35. ERROR [example] LOG_READING_LOCAL_FILE reading local message file dummy/file
  36. FATAL [example.beta] LOG_BAD_SEVERITY unrecognized log severity: beta_fatal
  37. ERROR [example.beta] LOG_BAD_DESTINATION unrecognized log destination: beta_error
  38. .
  39. rm -f $destfile1 $destfile2
  40. ./logger_example -s error -f $destfile1_tmp -f $destfile2_tmp
  41. # strip the pids
  42. sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile1_tmp > $destfile1
  43. sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile2_tmp > $destfile2
  44. echo -n " - destination 1:"
  45. cut -d' ' -f3- $destfile1 | diff $tempfile -
  46. passfail $?
  47. echo -n " - destination 2:"
  48. cut -d' ' -f3- $destfile2 | diff $tempfile -
  49. passfail $?
  50. # Tidy up.
  51. rm -f $tempfile $destfile1_tmp $destfile2_tmp $destfile1 $destfile2
  52. echo "2. Two loggers, different destinations and severities"
  53. rm -f $destfile1 $destfile2
  54. ./logger_example -l example -s info -f $destfile1_tmp -l alpha -s warn -f $destfile2_tmp
  55. # strip the pids
  56. sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile1_tmp > $destfile1
  57. sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile2_tmp > $destfile2
  58. # All output for example and example.beta should have gone to destfile1.
  59. # Output for example.alpha should have done to destfile2.
  60. cat > $tempfile << .
  61. FATAL [example] LOG_WRITE_ERROR error writing to test1: 42
  62. ERROR [example] LOG_READING_LOCAL_FILE reading local message file dummy/file
  63. WARN [example] LOG_BAD_STREAM bad log console output stream: example
  64. FATAL [example.beta] LOG_BAD_SEVERITY unrecognized log severity: beta_fatal
  65. ERROR [example.beta] LOG_BAD_DESTINATION unrecognized log destination: beta_error
  66. WARN [example.beta] LOG_BAD_STREAM bad log console output stream: beta_warn
  67. INFO [example.beta] LOG_READ_ERROR error reading from message file beta: info
  68. .
  69. echo -n " - destination 1:"
  70. cut -d' ' -f3- $destfile1 | diff $tempfile -
  71. passfail $?
  72. echo -n " - destination 2:"
  73. cat > $tempfile << .
  74. WARN [example.alpha] LOG_READ_ERROR error reading from message file a.txt: dummy reason
  75. .
  76. cut -d' ' -f3- $destfile2 | diff $tempfile -
  77. passfail $?
  78. if [ $failcount -eq 0 ]; then
  79. echo "PASS: $testname"
  80. elif [ $failcount -eq 1 ]; then
  81. echo "FAIL: $testname - 1 test failed"
  82. else
  83. echo "FAIL: $testname - $failcount tests failed"
  84. fi
  85. # Tidy up.
  86. rm -f $tempfile $destfile1_tmp $destfile2_tmp $destfile1 $destfile2
  87. exit $failcount