compare_tests 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #!/bin/sh
  2. # This script automatically test the given tool with the tool's test cases,
  3. # reporting anything of interest.
  4. # Written by Mike Stump <mrs@cygnus.com>
  5. # Subdir comparison added by Quentin Neill <quentin.neill@amd.com>
  6. usage()
  7. {
  8. if [ -n "$1" ] ; then
  9. echo "$0: Error: $1" >&2
  10. echo >&2
  11. fi
  12. cat >&2 <<EOUSAGE
  13. Usage: $0 [-strict] PREVIOUS CURRENT
  14. Compare the PREVIOUS and CURRENT test case .sum files, reporting anything of interest.
  15. If PREVIOUS and CURRENT are directories, find and compare any *.sum files.
  16. Unless -strict is given, these discrepancies are not counted as errors:
  17. missing/extra .sum files when comparing directories
  18. tests that failed in PREVIOUS but pass in CURRENT
  19. tests that were not in PREVIOUS but appear in CURRENT
  20. tests in PREVIOUS that are missing in CURRENT
  21. Exit with the following values:
  22. 0 if there is nothing of interest
  23. 1 if there are errors when comparing single test case files
  24. N for the number of errors found when comparing directories
  25. EOUSAGE
  26. exit 2
  27. }
  28. export LC_ALL=C
  29. tool=gxx
  30. TMPDIR=${TMPDIR:-/tmp}
  31. tmp1=$TMPDIR/$tool-testing.$$a
  32. tmp2=$TMPDIR/$tool-testing.$$b
  33. now_s=$TMPDIR/$tool-testing.$$d
  34. before_s=$TMPDIR/$tool-testing.$$e
  35. lst1=$TMPDIR/$tool-lst1.$$
  36. lst2=$TMPDIR/$tool-lst2.$$
  37. lst3=$TMPDIR/$tool-lst3.$$
  38. lst4=$TMPDIR/$tool-lst4.$$
  39. lst5=$TMPDIR/$tool-lst5.$$
  40. sum1=$TMPDIR/$tool-sum1.$$
  41. sum2=$TMPDIR/$tool-sum2.$$
  42. tmps="$tmp1 $tmp2 $now_s $before_s $lst1 $lst2 $lst3 $lst4 $lst5 $sum1 $sum2"
  43. [ "$1" = "-strict" ] && strict=$1 && shift
  44. [ "$1" = "-?" ] && usage
  45. [ "$2" = "" ] && usage "Must specify both PREVIOUS and CURRENT"
  46. trap "rm -f $tmps" 0 1 2 3 5 9 13 15
  47. exit_status=0
  48. if [ -d "$1" -a -d "$2" ] ; then
  49. find "$1/" -name '*.sum' >$lst1
  50. find "$2/" -name '*.sum' >$lst2
  51. echo "# Comparing directories"
  52. echo "## Dir1=$1: `cat $lst1 | wc -l` sum files"
  53. echo "## Dir2=$2: `cat $lst2 | wc -l` sum files"
  54. echo
  55. # remove leading directory components to compare
  56. sed -e "s|^$1[/]*||" $lst1 | sort >$lst3
  57. sed -e "s|^$2[/]*||" $lst2 | sort >$lst4
  58. comm -23 $lst3 $lst4 >$lst5
  59. if [ -s $lst5 ] ; then
  60. echo "# Extra sum files in Dir1=$1"
  61. sed -e "s|^|< $1/|" $lst5
  62. echo
  63. [ -n "$strict" ] && exit_status=`expr $exit_status + 1`
  64. fi
  65. comm -13 $lst3 $lst4 >$lst5
  66. if [ -s $lst5 ] ; then
  67. echo "# Extra sum files in Dir2=$2"
  68. sed -e "s|^|> $2/|" $lst5
  69. echo
  70. [ -n "$strict" ] && exit_status=`expr $exit_status + 1`
  71. fi
  72. comm -12 $lst3 $lst4 | sort -u >$lst5
  73. if [ ! -s $lst5 ] ; then
  74. echo "# No common sum files"
  75. exit_status=`expr $exit_status + 1`
  76. exit $exit_status
  77. fi
  78. cmnsums=`cat $lst5 | wc -l`
  79. echo "# Comparing $cmnsums common sum files"
  80. ( for fname in `cat $lst5`; do cat $1/$fname; done ) >$sum1
  81. ( for fname in `cat $lst5`; do cat $2/$fname; done ) >$sum2
  82. echo "## ${CONFIG_SHELL-/bin/sh} $0 $strict $sum1 $sum2"
  83. ${CONFIG_SHELL-/bin/sh} $0 $strict $sum1 $sum2
  84. ret=$?
  85. if [ $ret -ne 0 ]; then
  86. exit_status=`expr $exit_status + 1`
  87. echo "## Differences found: $fname"
  88. fi
  89. if [ $exit_status -ne 0 ]; then
  90. echo "# $exit_status differences in $cmnsums common sum files found"
  91. else
  92. echo "# No differences found in $cmnsums common sum files"
  93. fi
  94. exit $exit_status
  95. elif [ -d "$1" -o -d "$2" ] ; then
  96. usage "Must specify either two directories or two files"
  97. fi
  98. sed 's/^XFAIL/FAIL/; s/^ERROR/FAIL/; s/^XPASS/PASS/' < "$1" | awk '/^Running target / {target = $3} { if (target != "unix") { sub(/: /, "&"target": " ); }; print $0; }' | cut -c1-2000 >$tmp1
  99. sed 's/^XFAIL/FAIL/; s/^ERROR/FAIL/; s/^XPASS/PASS/' < "$2" | awk '/^Running target / {target = $3} { if (target != "unix") { sub(/: /, "&"target": " ); }; print $0; }' | cut -c1-2000 >$tmp2
  100. before=$tmp1
  101. now=$tmp2
  102. if sort -k 2 </dev/null >/dev/null 2>&1; then
  103. skip1='-k 2'
  104. else
  105. skip1='+1'
  106. fi
  107. sort -t ':' $skip1 "$now" > "$now_s"
  108. sort -t ':' $skip1 "$before" > "$before_s"
  109. grep '^FAIL:' "$now_s" | sed 's/^[^:]*:[ ]//' >$tmp1
  110. grep '^PASS' "$before_s" | sed 's/^[^:]*:[ ]//' | comm -12 $tmp1 - >$tmp2
  111. grep -s . $tmp2 >/dev/null
  112. if [ $? = 0 ]; then
  113. num=`cat $tmp2 | wc -l`
  114. echo "Tests that now fail, but worked before ($num tests):"
  115. echo
  116. cat $tmp2
  117. echo
  118. exit_status=1
  119. fi
  120. grep '^PASS' "$now_s" | sed 's/^[^:]*:[ ]//' >$tmp1
  121. grep '^FAIL' "$before_s" | sed 's/^[^:]*:[ ]//' | comm -12 $tmp1 - >$tmp2
  122. grep -s . $tmp2 >/dev/null
  123. if [ $? = 0 ]; then
  124. num=`cat $tmp2 | wc -l`
  125. echo "Tests that now work, but didn't before ($num tests):"
  126. echo
  127. cat $tmp2
  128. [ -n "$strict" ] && echo "Strict test fails" && exit_status=1
  129. echo
  130. fi
  131. grep '^FAIL' "$now_s" | sed 's/^[^:]*:[ ]//' >$tmp1
  132. grep '^[PF]A[SI][SL]' "$before_s" | sed 's/^[^:]*:[ ]//' | comm -23 $tmp1 - >$tmp2
  133. grep -s . $tmp2 >/dev/null
  134. if [ $? = 0 ]; then
  135. num=`cat $tmp2 | wc -l`
  136. echo "New tests that FAIL ($num tests):"
  137. echo
  138. cat $tmp2
  139. echo
  140. exit_status=1
  141. fi
  142. grep '^PASS' "$now_s" | sed 's/^[^:]*:[ ]//' >$tmp1
  143. grep '^[PF]A[SI][SL]' "$before_s" | sed 's/^[^:]*:[ ]//' | comm -23 $tmp1 - >$tmp2
  144. grep -s . $tmp2 >/dev/null
  145. if [ $? = 0 ]; then
  146. num=`cat $tmp2 | wc -l`
  147. echo "New tests that PASS ($num tests):"
  148. echo
  149. cat $tmp2
  150. [ -n "$strict" ] && echo "Strict test fails" && exit_status=1
  151. echo
  152. fi
  153. grep '^[PF]A[SI][SL]' "$now_s" | sed 's/^[^:]*:[ ]//' >$tmp1
  154. grep '^PASS' "$before_s" | sed 's/^[^:]*:[ ]//' | comm -13 $tmp1 - >$tmp2
  155. grep -s . $tmp2 >/dev/null
  156. if [ $? = 0 ]; then
  157. num=`cat $tmp2 | wc -l`
  158. echo "Old tests that passed, that have disappeared ($num tests): (Eeek!)"
  159. echo
  160. cat $tmp2
  161. [ -n "$strict" ] && echo "Strict test fails" && exit_status=1
  162. echo
  163. fi
  164. grep '^[PF]A[SI][SL]' "$now_s" | sed 's/^[^:]*:[ ]//' >$tmp1
  165. grep '^FAIL' "$before_s" | sed 's/^[^:]*:[ ]//' | comm -13 $tmp1 - >$tmp2
  166. grep -s . $tmp2 >/dev/null
  167. if [ $? = 0 ]; then
  168. num=`cat $tmp2 | wc -l`
  169. echo "Old tests that failed, that have disappeared ($num tests): (Eeek!)"
  170. echo
  171. cat $tmp2
  172. [ -n "$strict" ] && echo "Strict test fails" && exit_status=1
  173. echo
  174. fi
  175. exit $exit_status