abifuzz.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/bin/sh
  2. OCAMLC=${OCAMLC:-/usr/bin/ocamlc}
  3. DIR=`cd $(dirname "$0"); pwd`
  4. QBE=$DIR/../qbe
  5. failure() {
  6. echo "Failure at stage:" $1 >&2
  7. exit 1
  8. }
  9. cleanup() {
  10. rm -fr $TMP
  11. }
  12. init() {
  13. cp $DIR/callgen.ml $TMP
  14. pushd $TMP > /dev/null
  15. cat > Makefile << EOM
  16. .PHONY: test
  17. test: caller.o callee.o
  18. c99 -o \$@ caller.o callee.o
  19. %.o: %.c
  20. c99 -c -o \$@ \$<
  21. %.o: %.ssa
  22. $QBE -o \$*.s \$<
  23. c99 -c -o \$@ \$*.s
  24. EOM
  25. if ! $OCAMLC callgen.ml -o callgen
  26. then
  27. popd > /dev/null
  28. cleanup
  29. failure "abifuzz compilation"
  30. fi
  31. popd > /dev/null
  32. }
  33. once() {
  34. if test -z "$3"
  35. then
  36. $TMP/callgen $TMP $1 $2
  37. else
  38. $TMP/callgen -s $3 $TMP $1 $2
  39. fi
  40. make -C $TMP test > /dev/null || failure "building"
  41. $TMP/test || failure "runtime"
  42. }
  43. usage() {
  44. echo "usage: abitest.sh [-callssa] [-callc] [-s SEED] [-n ITERATIONS]" >&2
  45. exit 1
  46. }
  47. N=1
  48. CALLER=c
  49. CALLEE=ssa
  50. while test -n "$1"
  51. do
  52. case "$1" in
  53. "-callssa")
  54. CALLER=c
  55. CALLEE=ssa
  56. ;;
  57. "-callc")
  58. CALLER=ssa
  59. CALLEE=c
  60. ;;
  61. "-s")
  62. test -n "$2" || usage
  63. shift
  64. SEED="$1"
  65. ;;
  66. "-n")
  67. test -n "$2" || usage
  68. shift
  69. N="$1"
  70. ;;
  71. *)
  72. usage
  73. ;;
  74. esac
  75. shift
  76. done
  77. TMP=`mktemp -d abifuzz.XXXXXX`
  78. init
  79. if test -n "$S"
  80. then
  81. once $CALLER $CALLEE $SEED
  82. else
  83. for n in `seq $N`
  84. do
  85. once $CALLER $CALLEE
  86. echo "$n" | grep "00$"
  87. done
  88. fi
  89. echo "All done."
  90. cleanup