/contrib/cvs/contrib/debug_check_log.sh

https://bitbucket.org/freebsd/freebsd-head/ · Shell · 201 lines · 121 code · 26 blank · 54 comment · 17 complexity · 41586ca08b11dc1e0bbbe6534e6e4ecd MD5 · raw file

  1. #!/bin/sh
  2. # Copyright (C) 2000-2005 The Free Software Foundation, Inc.
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2, or (at your option)
  6. # any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # This program is intended to take a check.log file generated by a failed run of
  14. # sanity.sh as input and run expr line by line on it. It seems a much easier
  15. # way of spotting a single failed line in a 100 line test result.
  16. #
  17. #
  18. # Contributed by Derek R. Price <derek.price@openavenue.com>
  19. #
  20. usage ()
  21. {
  22. echo "\
  23. usage: $0 [-afh] [file...]
  24. -a process alternate pattern
  25. -f process first pattern (default)
  26. -h print this text
  27. file files to process (default = check.log)"
  28. }
  29. # Do a line by line match with expr
  30. #
  31. # INPUTS
  32. # $1 = text file name
  33. # $2 = pattern file name
  34. expr_line_by_line ()
  35. {
  36. dcl_line=0
  37. dcl_wrong=
  38. # We are assuming a newline at the end of the file. The way sanity.sh
  39. # uses echo to create the log message guarantees this newline and since
  40. # expr ignores the last newline when the anchor is present anyhow, no
  41. # information is being lost in the transition
  42. while test $dcl_line -lt `wc -l <$1` -a $dcl_line -lt `wc -l <$2`; do
  43. dcl_line=`expr $dcl_line + 1`
  44. if test `sed -ne${dcl_line}p <$1 |wc -c` -eq 1 \
  45. -a `sed -ne${dcl_line}p <$2 |wc -c` -eq 1; then
  46. # This is a workaround for what I am calling a bug in GNU
  47. # expr - it won't match the empty string to the empty
  48. # string. In this case the assumption is that a single
  49. # character is always a newline. Since we already checked
  50. # for the end of the file, we know sed will echo the
  51. # newline.
  52. :
  53. elif expr "`sed -ne${dcl_line}p <$1`" : \
  54. "`sed -ne${dcl_line}p <$2`\$" >/dev/null; then
  55. :
  56. else
  57. echo "$dcl_line: `sed -ne${dcl_line}p <$1`"
  58. echo "$dcl_line: `sed -ne${dcl_line}p <$2`\$"
  59. dcl_wrong="$dcl_wrong $dcl_line"
  60. fi
  61. done
  62. if test `wc -l <$1` -ne `wc -l <$2`; then
  63. echo "output & pattern contain differing number of lines"
  64. elif test -z "$dcl_wrong"; then
  65. echo "no mismatched lines"
  66. else
  67. echo "mismatched lines: $dcl_wrong"
  68. fi
  69. }
  70. # Process a single check.log file
  71. #
  72. # INPUTS
  73. # $1 = filename
  74. process_check_log ()
  75. {
  76. # abort if we can't find any expressions
  77. if grep '^\*\* got: $' <$1 >/dev/null; then
  78. :
  79. else
  80. echo "WARNING: No expressions in file: $1" >&2
  81. echo " Either not a check.log or sanity.sh exited for some other reason," >&2
  82. echo " like bad exit status. Try tail." >&2
  83. return
  84. fi
  85. dcl_exprfiles=""
  86. if grep '^\*\* or: $' <$1 >/dev/null; then
  87. # file contains a second regex
  88. if test $dcl_dofirst -eq 1; then
  89. # get the first pattern
  90. sed -ne '/^\*\* expected: $/,/^\*\* or: $/p' <$1 >/tmp/dcle$$
  91. dcl_exprfiles="$dcl_exprfiles /tmp/dcle$$"
  92. fi
  93. if test $dcl_doalternate -eq 1; then
  94. # get the alternate pattern
  95. sed -ne '/^\*\* or: $/,/^\*\* got: $/p' <$1 >/tmp/dclo$$
  96. dcl_exprfiles="$dcl_exprfiles /tmp/dclo$$"
  97. else
  98. echo "WARNING: Ignoring alternate pattern in file: $1" >&2
  99. fi
  100. else
  101. # file doesn't contain a second regex
  102. if test $dcl_dofirst = 1; then
  103. # get the only pattern
  104. sed -ne '/^\*\* expected: $/,/^\*\* got: $/p' <$1 >/tmp/dcle$$
  105. dcl_exprfiles="$dcl_exprfiles /tmp/dcle$$"
  106. fi
  107. if test $dcl_doalternate -eq 1; then
  108. echo "WARNING: No alternate pattern in file: $1" >&2
  109. fi
  110. fi
  111. # and get the actual output
  112. sed -ne '/^\*\* got: $/,$p' <$1 >/tmp/dclg$$
  113. sed -ne '1D
  114. $D
  115. p' </tmp/dclg$$ >/tmp/dclh$$
  116. mv /tmp/dclh$$ /tmp/dclg$$
  117. # compare the output against each pattern requested
  118. for dcl_f in $dcl_exprfiles; do
  119. sed -ne '1D
  120. $D
  121. p' <$dcl_f >/tmp/dclp$$
  122. mv /tmp/dclp$$ $dcl_f
  123. case $dcl_f in
  124. /tmp/dcle*)
  125. echo "********** $1 : Primary **********"
  126. ;;
  127. /tmp/dclo*)
  128. echo "********** $1 : Alternate **********"
  129. ;;
  130. esac
  131. expr_line_by_line /tmp/dclg$$ $dcl_f
  132. rm $dcl_f
  133. done
  134. rm /tmp/dclg$$
  135. }
  136. ###
  137. ### MAIN
  138. ###
  139. # set up defaults
  140. dcl_doalternate=0
  141. dcl_dofirst=0
  142. # process options
  143. while getopts afh arg; do
  144. case $arg in
  145. a)
  146. dcl_doalternate=1
  147. ;;
  148. f)
  149. dcl_dofirst=1
  150. ;;
  151. \?|h)
  152. usage
  153. exit 1
  154. ;;
  155. esac
  156. done
  157. # dispose of processed args
  158. shift `expr $OPTIND - 1`
  159. OPTIND=1
  160. # set the default mode
  161. if test $dcl_doalternate -eq 0; then
  162. dcl_dofirst=1
  163. fi
  164. # set default arg
  165. if test $# -eq 0; then
  166. if test -f src/check.log && test -r src/check.log; then
  167. set src/check.log
  168. else
  169. set check.log
  170. fi
  171. fi
  172. for file in "$@"; do
  173. process_check_log $file;
  174. done
  175. exit 0