local_file_test.sh.in 3.3 KB

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