summary refs log tree commit diff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/abifuzz.sh2
-rw-r--r--tools/fptox.c18
-rw-r--r--tools/pmov.c2
-rwxr-xr-xtools/regress.sh17
-rwxr-xr-xtools/unit.sh119
5 files changed, 121 insertions, 37 deletions
diff --git a/tools/abifuzz.sh b/tools/abifuzz.sh
index 57930fb..e715b3d 100755
--- a/tools/abifuzz.sh
+++ b/tools/abifuzz.sh
@@ -2,7 +2,7 @@
 
 OCAMLC=${OCAMLC:-/usr/bin/ocamlc}
 DIR=`cd $(dirname "$0"); pwd`
-QBE=$DIR/../src/qbe
+QBE=$DIR/../obj/qbe
 
 failure() {
 	echo "Failure at stage:" $1 >&2
diff --git a/tools/fptox.c b/tools/fptox.c
deleted file mode 100644
index a2bc155..0000000
--- a/tools/fptox.c
+++ /dev/null
@@ -1,18 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-int
-main(int ac, char *av[])
-{
-	double d;
-	float f;
-
-	if (ac < 2) {
-	usage:
-		fputs("usage: fptox NUMBER\n", stderr);
-		return 1;
-	}
-	f = d = strtod(av[1], 0);
-	printf("0x%08x 0x%016llx\n", *(unsigned *)&f, *(unsigned long long*)&d);
-	return 0;
-}
diff --git a/tools/pmov.c b/tools/pmov.c
index 9136374..62d3921 100644
--- a/tools/pmov.c
+++ b/tools/pmov.c
@@ -13,7 +13,7 @@
 
 static void assert_test(char *, int), fail(void), iexec(int *);
 
-#include "../src/rega.c"
+#include "../../rega.c"
 
 static void bsinit_(BSet *, uint);
 
diff --git a/tools/regress.sh b/tools/regress.sh
deleted file mode 100755
index 5aaea35..0000000
--- a/tools/regress.sh
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/sh
-
-for t in ../test/*
-do
-	printf "Test $t ... "
-
-	./qbe   $t >/tmp/out.0 2>&1
-	./qbe.1 $t >/tmp/out.1 2>&1
-
-	if diff /tmp/out.0 /tmp/out.1 > /dev/null
-	then
-		echo "OK"
-	else
-		echo "KO"
-		break
-	fi
-done
diff --git a/tools/unit.sh b/tools/unit.sh
new file mode 100755
index 0000000..c4a85d2
--- /dev/null
+++ b/tools/unit.sh
@@ -0,0 +1,119 @@
+#!/bin/sh
+
+DIR=`cd $(dirname "$0"); pwd`
+QBE=$DIR/../obj/qbe
+
+TMP=/tmp/qbe.zzzz
+
+DRV=$TMP.c
+ASM=$TMP.s
+BIN=$TMP.bin
+OUT=$TMP.out
+
+cleanup() {
+	rm -f $DRV $ASM $BIN $OUT
+}
+
+extract() {
+	WHAT="$1"
+	FILE="$2"
+
+	awk "
+		/^# >>> $WHAT/ {
+			p = 1
+			next
+		}
+		/^# <<</ {
+			if (p)
+				p = 0
+		}
+		p
+	" $FILE \
+	| sed -e 's/# //' \
+	| sed -e 's/#$//'
+}
+
+once() {
+	T="$1"
+
+	if ! test -f $T
+	then
+		echo "invalid test file $T" >&2
+		exit 1
+	fi
+
+	echo "$(basename $T)..."
+
+	if ! $QBE -o $ASM $T
+	then
+		echo "[qbe fail]"
+		return 1
+	fi
+
+	extract driver $T > $DRV
+	extract output $T > $OUT
+
+	if test -s $DRV
+	then
+		LNK="$DRV $ASM"
+	else
+		LNK="$ASM"
+	fi
+
+	if ! cc -g -o $BIN $LNK
+	then
+		echo "[cc fail]"
+		return 1
+	fi
+
+	if test -s $OUT
+	then
+		$BIN a b c | diff - $OUT
+		RET=$?
+		REASON="output"
+	else
+		$BIN a b c
+		RET=$?
+		REASON="returned $RET"
+	fi
+
+	if test $RET -ne 0
+	then
+		echo "[$REASON fail]"
+		return 1
+	fi
+
+	printf "\033[1A\033[45C[ok]\n"
+}
+
+
+#trap cleanup TERM QUIT
+
+if test -z "$1"
+then
+	echo "usage: test/go.sh {all, SSAFILE}" 2>&1
+	exit 1
+fi
+
+case $1 in
+	"all")
+		F=0
+		for T in $DIR/../test/[!_]*.ssa
+		do
+			once $T
+			F=`expr $F + $?`
+		done
+		if test $F -ge 1
+		then
+			echo
+			echo "$F test(s) failed!"
+		else
+			echo
+			echo "All is fine!"
+		fi
+		;;
+	*)
+		once $1
+		exit $?
+		;;
+esac