aboutsummaryrefslogtreecommitdiff
path: root/tools/abifuzz.sh
diff options
context:
space:
mode:
authorQuentin Carbonneaux <[email protected]>2016-03-27 18:17:08 -0400
committerQuentin Carbonneaux <[email protected]>2016-03-27 18:17:08 -0400
commitda640c5a467bfdf7b3bbced52fc13a28fd8b37bd (patch)
treecf5a4af994ac8b8f7357bbf3414c4179f94321ad /tools/abifuzz.sh
parente38c61d95fccd208e13dd14a31a567c3d431677a (diff)
move tools to the root
Diffstat (limited to 'tools/abifuzz.sh')
-rwxr-xr-xtools/abifuzz.sh105
1 files changed, 105 insertions, 0 deletions
diff --git a/tools/abifuzz.sh b/tools/abifuzz.sh
new file mode 100755
index 0000000..5945082
--- /dev/null
+++ b/tools/abifuzz.sh
@@ -0,0 +1,105 @@
+#!/bin/sh
+
+OCAMLC=${OCAMLC:-/usr/bin/ocamlc}
+DIR=`readlink -f $0 | xargs dirname`
+QBE=$DIR/../src/qbe
+
+failure() {
+ echo "Failure at stage:" $1 >&2
+ exit 1
+}
+
+cleanup() {
+ rm -fr $TMP
+}
+
+init() {
+ cp $DIR/callgen.ml $TMP
+ pushd $TMP > /dev/null
+
+ cat > Makefile << EOM
+
+.PHONY: test
+test: caller.o callee.o
+ c99 -o \$@ caller.o callee.o
+%.o: %.c
+ c99 -c -o \$@ \$<
+%.o: %.ssa
+ $QBE -o \$*.s \$<
+ c99 -c -o \$@ \$*.s
+
+EOM
+
+ if ! $OCAMLC callgen.ml -o callgen
+ then
+ popd > /dev/null
+ cleanup
+ failure "abifuzz compilation"
+ fi
+ popd > /dev/null
+}
+
+once() {
+ if test -z "$3"
+ then
+ $TMP/callgen $TMP $1 $2
+ else
+ $TMP/callgen -s $3 $TMP $1 $2
+ fi
+ make -C $TMP test > /dev/null || failure "building"
+ $TMP/test || failure "runtime"
+}
+
+usage() {
+ echo "usage: abitest.sh [-callssa] [-callc] [-s SEED] [-n ITERATIONS]" >&2
+ exit 1
+}
+
+N=1
+CALLER=c
+CALLEE=ssa
+
+while test -n "$1"
+do
+ case "$1" in
+ "-callssa")
+ ;;
+ "-callc")
+ CALLER=ssa
+ CALLEE=c
+ ;;
+ "-s")
+ test -n "$2" || usage
+ shift
+ SEED="$1"
+ ;;
+ "-n")
+ test -n "$2" || usage
+ shift
+ N="$1"
+ ;;
+ *)
+ usage
+ ;;
+ esac
+ shift
+done
+
+TMP=`mktemp -d abifuzz.XXXXXX`
+
+init
+
+if test -n "$S"
+then
+ once $CALLER $CALLEE $SEED
+else
+ for n in `seq $N`
+ do
+ once $CALLER $CALLEE
+ echo "$n" | grep "00$"
+ done
+fi
+
+echo "All done."
+
+cleanup