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