local_file_test.sh.in 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 a local message file can override the definitions in the message
  16. # dictionary.
  17. testname="Local message file test"
  18. echo $testname
  19. failcount=0
  20. localmes=@abs_builddir@/localdef_mes_$$
  21. tempfile=@abs_builddir@/run_time_init_test_tempfile_$$
  22. passfail() {
  23. if [ $1 -eq 0 ]; then
  24. echo " pass"
  25. else
  26. echo " FAIL"
  27. failcount=`expr $failcount + $1`
  28. fi
  29. }
  30. # Create the local message file for testing
  31. cat > $localmes << .
  32. % LOG_NOTHERE this message is not in the global dictionary
  33. % LOG_READ_ERROR replacement read error, parameters: '%1' and '%2'
  34. % LOG_READING_LOCAL_FILE replacement read local message file, parameter is '%1'
  35. .
  36. echo -n "1. Local message replacement:"
  37. cat > $tempfile << .
  38. WARN [example.log] LOG_NO_SUCH_MESSAGE could not replace message text for 'LOG_NOTHERE': no such message
  39. FATAL [example] LOG_WRITE_ERROR error writing to test1: 42
  40. ERROR [example] LOG_READING_LOCAL_FILE replacement read local message file, parameter is 'dummy/file'
  41. WARN [example] LOG_BAD_STREAM bad log console output stream: example
  42. WARN [example.alpha] LOG_READ_ERROR replacement read error, parameters: 'a.txt' and 'dummy reason'
  43. FATAL [example.beta] LOG_BAD_SEVERITY unrecognized log severity: beta_fatal
  44. ERROR [example.beta] LOG_BAD_DESTINATION unrecognized log destination: beta_error
  45. WARN [example.beta] LOG_BAD_STREAM bad log console output stream: beta_warn
  46. .
  47. ./logger_example -c stdout -s warn $localmes | \
  48. sed -e 's/\[\([a-z0-9\.]\+\)\/\([0-9]\+\)\]/[\1]/' | \
  49. cut -d' ' -f3- | diff $tempfile -
  50. passfail $?
  51. echo -n "2. Report error if unable to read local message file:"
  52. cat > $tempfile << .
  53. ERROR [example.log] LOG_INPUT_OPEN_FAIL unable to open message file $localmes for input: No such file or directory
  54. FATAL [example] LOG_WRITE_ERROR error writing to test1: 42
  55. ERROR [example] LOG_READING_LOCAL_FILE reading local message file dummy/file
  56. WARN [example] LOG_BAD_STREAM bad log console output stream: example
  57. WARN [example.alpha] LOG_READ_ERROR error reading from message file a.txt: dummy reason
  58. FATAL [example.beta] LOG_BAD_SEVERITY unrecognized log severity: beta_fatal
  59. ERROR [example.beta] LOG_BAD_DESTINATION unrecognized log destination: beta_error
  60. WARN [example.beta] LOG_BAD_STREAM bad log console output stream: beta_warn
  61. .
  62. rm -f $localmes
  63. ./logger_example -c stdout -s warn $localmes | \
  64. sed -e 's/\[\([a-z0-9\.]\+\)\/\([0-9]\+\)\]/[\1]/' | \
  65. cut -d' ' -f3- | diff $tempfile -
  66. passfail $?
  67. if [ $failcount -eq 0 ]; then
  68. echo "PASS: $testname"
  69. elif [ $failcount -eq 1 ]; then
  70. echo "FAIL: $testname - 1 test failed"
  71. else
  72. echo "FAIL: $testname - $failcount tests failed"
  73. fi
  74. # Tidy up.
  75. rm -f $tempfile
  76. exit $failcount