summary refs log tree commit diff
path: root/tools/abifuzz.sh
blob: 5945082f6f335a5b6026cd1714ba4a9c03238f68 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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