dg-cmp-results.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #!/bin/bash
  2. # Copyright (C) 2006, 2008 Free Software Foundation
  3. #
  4. # Analyze changes in GCC DejaGNU test logs for binutils, gcc, gdb, etc.
  5. # Original version written in 2005 by James Lemke <jwlemke@wasabisystems.com>.
  6. #
  7. # See usage() below.
  8. usage () {
  9. cat <<EOF >&2
  10. Usage:
  11. dg-cmp-results.sh [-v] [-v] [-v] <variant-name> <old-file> <new-file>
  12. <variant-name> names the desired variant, "/" must be written as "\/".
  13. Use the empty string ("") for the first variant in each file.
  14. Output is to stdout.
  15. Non-verbose output is degradation info like PASS->FAIL.
  16. -v adds improvement info like FAIL->PASS.
  17. -v -v adds info like tests that are no longer run.
  18. -v -v -v adds info for tests that have not changed status.
  19. -v -v -v -v is used for debugging.
  20. EOF
  21. }
  22. verbose=0
  23. while test "$1" = "-v"; do
  24. verbose=`expr $verbose + 1`
  25. shift
  26. done
  27. if test $# -ne 3 ; then
  28. usage
  29. exit 1
  30. fi
  31. if test ! -f "$2"; then
  32. echo "unable to open $2" >&2
  33. exit 1
  34. fi
  35. if test ! -f "$3"; then
  36. echo "unable to open $3" >&2
  37. exit 1
  38. fi
  39. # Command differences for various platforms.
  40. case `uname -s` in
  41. Darwin|NetBSD)
  42. E=-E # sed
  43. ;;
  44. *)
  45. E=-r # sed
  46. ;;
  47. esac
  48. # sections are identified by separator lines beginning with '\t\t==='.
  49. # section 0 identifies run date, target, and host.
  50. # section 1 and subsequent contain test data for a target variant.
  51. # -skip to /^Running target/ and use that line to identify the variant.
  52. # -subsequent lines contain the result data. They begin with:
  53. # '(PASS|FAIL|XFAIL|XPASS|UNTESTED|UNSUPPORTED|UNRESOLVED):'
  54. VARIANT="$1"
  55. OFILE="$2"
  56. OBASE=`basename "$2"`
  57. NFILE="$3"
  58. NBASE=`basename "$3"`
  59. echo "dg-cmp-results.sh: Verbosity is ${verbose}, Variant is \"${VARIANT}\""
  60. echo
  61. header="^Running target $VARIANT"
  62. temp=`grep "$header" $OFILE`
  63. if test -z "$temp"; then
  64. echo "Error: variant \"$VARIANT\" not found in $OFILE."
  65. exit 1
  66. fi
  67. temp=`grep "$header" $NFILE`
  68. if test -z "$temp"; then
  69. echo "Error: variant \"$VARIANT\" not found in $NFILE."
  70. exit 1
  71. fi
  72. unset temp
  73. # Copy out the old file's section 0.
  74. echo "Older log file: $OFILE"
  75. sed $E -e '/^[[:space:]]+===/,$d' $OFILE
  76. # Copy out the new file's section 0.
  77. echo "Newer log file: $NFILE"
  78. sed $E -e '/^[[:space:]]+===/,$d' $NFILE
  79. # Create a temporary file from the old file's interesting section.
  80. sed $E -e "1,/$header/d" \
  81. -e '/^[[:space:]]+===/,$d' \
  82. -e '/^[A-Z]+:/!d' \
  83. -e '/^(WARNING|ERROR):/d' \
  84. -e 's/\r$//' \
  85. -e 's/^/O:/' \
  86. $OFILE |
  87. sort -s -t : -k 3b - \
  88. >/tmp/o$$-$OBASE
  89. # Create a temporary file from the new file's interesting section.
  90. sed $E -e "1,/$header/d" \
  91. -e '/^[[:space:]]+===/,$d' \
  92. -e '/^[A-Z]+:/!d' \
  93. -e '/^(WARNING|ERROR):/d' \
  94. -e 's/\r$//' \
  95. -e 's/^/N:/' \
  96. $NFILE |
  97. sort -s -t : -k 3b - \
  98. >/tmp/n$$-$NBASE
  99. # Merge the two files, then compare adjacent lines.
  100. # Comparison is complicated by tests that may be run multiple times.
  101. # If that case, we assume that the order is the same in both files.
  102. cat <<EOF >compare-$$.awk
  103. BEGIN {
  104. FS = ":"
  105. queue1 = 1; queueN = 0; status[queue1] = ""; name[queue1] = ""
  106. verbose = verbose + 0 # Make sure it's defined.
  107. }
  108. # FIFO circular queue
  109. function push(st, nm) {
  110. queueN += 1; status[queueN] = st; name[queueN] = nm
  111. }
  112. function peek() {
  113. result = 0
  114. if (queueN >= queue1) result = queue1
  115. return result
  116. }
  117. function drop() {
  118. queue1 += 1
  119. if (queue1 > queueN) { queue1 = 1; queueN = 0; }
  120. }
  121. function compare(st, nm) {
  122. old = peek()
  123. if (old == 0) {
  124. # This new test wasn't run last time.
  125. if (verbose >= 2) printf("NA->%s:%s\n", st, nm)
  126. }
  127. else {
  128. # Compare this new test to the first queued old one.
  129. if (verbose >= 4) {
  130. printf("Comparing two lines:\n O:%s:%s\n N:%s:%s\n",
  131. status[old], name[old], st, nm)
  132. }
  133. if (name[old] != nm) {
  134. # The old test wasn't run this time and
  135. # the new test wasn't run last time.
  136. if (verbose >= 2) {
  137. printf("%s->NA:%s\n", status[old], name[old])
  138. if (nm != "") printf("NA->%s:%s\n", st, nm)
  139. }
  140. drop()
  141. }
  142. else {
  143. notable = 0
  144. if (status[old] == st) {
  145. # Status of this test has not changed.
  146. if (verbose >= 3) printf("%s:%s\n", st, nm)
  147. }
  148. else if(status[old] == "PASS" && st == "XFAIL") {
  149. if (verbose >= 1) notable = 1
  150. }
  151. else if(status[old] == "PASS" || st == "FAIL") {
  152. # Test did pass but doesn't now
  153. # or didn't fail but does now.
  154. notable = 1
  155. }
  156. else if(st == "PASS") {
  157. # Test didn't pass but does now.
  158. if (verbose >= 1) notable = 1
  159. }
  160. else if(verbose >= 2) {
  161. # Miscellaneous status change.
  162. notable = 1
  163. }
  164. if (notable > 0) printf("%s->%s:%s\n", status[old], st, nm)
  165. drop()
  166. }
  167. }
  168. }
  169. /^O:/ {
  170. while (old = peek()) {
  171. if (name[old] == \$3) break;
  172. # The queued test is no longer run.
  173. compare("", "");
  174. }
  175. # Save this test for later comparison.
  176. push(\$2, \$3)
  177. }
  178. /^N:/ {
  179. compare(\$2, \$3)
  180. }
  181. END {
  182. while (old = peek()) compare("", "")
  183. }
  184. EOF
  185. sort -m -s -t : -k 3b /tmp/o$$-$OBASE /tmp/n$$-$NBASE |
  186. awk -v verbose=$verbose -f compare-$$.awk /dev/stdin
  187. # Delete the temporary files.
  188. rm -f compare-$$.awk /tmp/o$$-$OBASE /tmp/n$$-$NBASE
  189. exit 0