compare_tests 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. tmp1=/tmp/$tool-testing.$$a
  31. tmp2=/tmp/$tool-testing.$$b
  32. now_s=/tmp/$tool-testing.$$d
  33. before_s=/tmp/$tool-testing.$$e
  34. lst1=/tmp/$tool-lst1.$$
  35. lst2=/tmp/$tool-lst2.$$
  36. lst3=/tmp/$tool-lst3.$$
  37. lst4=/tmp/$tool-lst4.$$
  38. lst5=/tmp/$tool-lst5.$$
  39. sum1=/tmp/$tool-sum1.$$
  40. sum2=/tmp/$tool-sum2.$$
  41. tmps="$tmp1 $tmp2 $now_s $before_s $lst1 $lst2 $lst3 $lst4 $lst5 $sum1 $sum2"
  42. [ "$1" = "-strict" ] && strict=$1 && shift
  43. [ "$1" = "-?" ] && usage
  44. [ "$2" = "" ] && usage "Must specify both PREVIOUS and CURRENT"
  45. trap "rm -f $tmps" 0 1 2 3 5 9 13 15
  46. exit_status=0
  47. if [ -d "$1" -a -d "$2" ] ; then
  48. find "$1/" -name '*.sum' >$lst1
  49. find "$2/" -name '*.sum' >$lst2
  50. echo "# Comparing directories"
  51. echo "## Dir1=$1: `cat $lst1 | wc -l` sum files"
  52. echo "## Dir2=$2: `cat $lst2 | wc -l` sum files"
  53. echo
  54. # remove leading directory components to compare
  55. sed -e "s|^$1[/]*||" $lst1 | sort >$lst3
  56. sed -e "s|^$2[/]*||" $lst2 | sort >$lst4
  57. comm -23 $lst3 $lst4 >$lst5
  58. if [ -s $lst5 ] ; then
  59. echo "# Extra sum files in Dir1=$1"
  60. sed -e "s|^|< $1/|" $lst5
  61. echo
  62. [ -n "$strict" ] && exit_status=`expr $exit_status + 1`
  63. fi
  64. comm -13 $lst3 $lst4 >$lst5
  65. if [ -s $lst5 ] ; then
  66. echo "# Extra sum files in Dir2=$2"
  67. sed -e "s|^|> $2/|" $lst5
  68. echo
  69. [ -n "$strict" ] && exit_status=`expr $exit_status + 1`
  70. fi
  71. comm -12 $lst3 $lst4 | sort -u >$lst5
  72. if [ ! -s $lst5 ] ; then
  73. echo "# No common sum files"
  74. exit_status=`expr $exit_status + 1`
  75. exit $exit_status
  76. fi
  77. cmnsums=`cat $lst5 | wc -l`
  78. echo "# Comparing $cmnsums common sum files"
  79. ( for fname in `cat $lst5`; do cat $1/$fname; done ) >$sum1
  80. ( for fname in `cat $lst5`; do cat $2/$fname; done ) >$sum2
  81. echo "## ${CONFIG_SHELL-/bin/sh} $0 $strict $sum1 $sum2"
  82. ${CONFIG_SHELL-/bin/sh} $0 $strict $sum1 $sum2
  83. ret=$?
  84. if [ $ret -ne 0 ]; then
  85. exit_status=`expr $exit_status + 1`
  86. echo "## Differences found: $fname"
  87. fi
  88. if [ $exit_status -ne 0 ]; then
  89. echo "# $exit_status differences in $cmnsums common sum files found"
  90. else
  91. echo "# No differences found in $cmnsums common sum files"
  92. fi
  93. exit $exit_status
  94. elif [ -d "$1" -o -d "$2" ] ; then
  95. usage "Must specify either two directories or two files"
  96. fi
  97. sed 's/^XFAIL/FAIL/; s/^XPASS/PASS/' < "$1" | awk '/^Running target / {target = $3} { if (target != "unix") { sub(/: /, "&"target": " ); }; print $0; }' | cut -c1-2000 >$tmp1
  98. sed 's/^XFAIL/FAIL/; s/^XPASS/PASS/' < "$2" | awk '/^Running target / {target = $3} { if (target != "unix") { sub(/: /, "&"target": " ); }; print $0; }' | cut -c1-2000 >$tmp2
  99. before=$tmp1
  100. now=$tmp2
  101. if sort -k 2 </dev/null >/dev/null 2>&1; then
  102. skip1='-k 2'
  103. else
  104. skip1='+1'
  105. fi
  106. sort -t ':' $skip1 "$now" > "$now_s"
  107. sort -t ':' $skip1 "$before" > "$before_s"
  108. grep '^FAIL:' "$now_s" | sed 's/^[^:]*:[ ]//' >$tmp1
  109. grep '^PASS' "$before_s" | sed 's/^[^:]*:[ ]//' | comm -12 $tmp1 - >$tmp2
  110. grep -s . $tmp2 >/dev/null
  111. if [ $? = 0 ]; then
  112. echo "Tests that now fail, but worked before:"
  113. echo
  114. cat $tmp2
  115. echo
  116. exit_status=1
  117. fi
  118. grep '^PASS' "$now_s" | sed 's/^[^:]*:[ ]//' >$tmp1
  119. grep '^FAIL' "$before_s" | sed 's/^[^:]*:[ ]//' | comm -12 $tmp1 - >$tmp2
  120. grep -s . $tmp2 >/dev/null
  121. if [ $? = 0 ]; then
  122. echo "Tests that now work, but didn't before:"
  123. echo
  124. cat $tmp2
  125. [ -n "$strict" ] && echo "Strict test fails" && exit_status=1
  126. echo
  127. fi
  128. grep '^FAIL' "$now_s" | sed 's/^[^:]*:[ ]//' >$tmp1
  129. grep '^[PF]A[SI][SL]' "$before_s" | sed 's/^[^:]*:[ ]//' | comm -23 $tmp1 - >$tmp2
  130. grep -s . $tmp2 >/dev/null
  131. if [ $? = 0 ]; then
  132. echo "New tests that FAIL:"
  133. echo
  134. cat $tmp2
  135. echo
  136. exit_status=1
  137. fi
  138. grep '^PASS' "$now_s" | sed 's/^[^:]*:[ ]//' >$tmp1
  139. grep '^[PF]A[SI][SL]' "$before_s" | sed 's/^[^:]*:[ ]//' | comm -23 $tmp1 - >$tmp2
  140. grep -s . $tmp2 >/dev/null
  141. if [ $? = 0 ]; then
  142. echo "New tests that PASS:"
  143. echo
  144. cat $tmp2
  145. [ -n "$strict" ] && echo "Strict test fails" && exit_status=1
  146. echo
  147. fi
  148. grep '^[PF]A[SI][SL]' "$now_s" | sed 's/^[^:]*:[ ]//' >$tmp1
  149. grep '^PASS' "$before_s" | sed 's/^[^:]*:[ ]//' | comm -13 $tmp1 - >$tmp2
  150. grep -s . $tmp2 >/dev/null
  151. if [ $? = 0 ]; then
  152. echo "Old tests that passed, that have disappeared: (Eeek!)"
  153. echo
  154. cat $tmp2
  155. [ -n "$strict" ] && echo "Strict test fails" && exit_status=1
  156. echo
  157. fi
  158. grep '^[PF]A[SI][SL]' "$now_s" | sed 's/^[^:]*:[ ]//' >$tmp1
  159. grep '^FAIL' "$before_s" | sed 's/^[^:]*:[ ]//' | comm -13 $tmp1 - >$tmp2
  160. grep -s . $tmp2 >/dev/null
  161. if [ $? = 0 ]; then
  162. echo "Old tests that failed, that have disappeared: (Eeek!)"
  163. echo
  164. cat $tmp2
  165. [ -n "$strict" ] && echo "Strict test fails" && exit_status=1
  166. echo
  167. fi
  168. exit $exit_status