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