summary refs log tree commit diff
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin@c9x.me>2017-04-08 21:39:37 -0400
committerQuentin Carbonneaux <quentin@c9x.me>2017-04-08 22:10:01 -0400
commite4bc35149cc790e3ad034f6643f75c33765b142c (patch)
treec2a0c816b6a56aaad74d9ff4df50e53a0bad44ce
parent61090c758d36f3919a222efe01c9794fdf7987ef (diff)
downloadroux-e4bc35149cc790e3ad034f6643f75c33765b142c.tar.gz
add cross testing for arm64
-rw-r--r--Makefile2
-rwxr-xr-xtools/test.sh168
-rwxr-xr-xtools/unit.sh128
3 files changed, 169 insertions, 129 deletions
diff --git a/Makefile b/Makefile
index 6c0b429..45e4b50 100644
--- a/Makefile
+++ b/Makefile
@@ -67,7 +67,7 @@ clean-gen: clean
 	rm -f config.h
 
 check: $(OBJDIR)/$(BIN)
-	tools/unit.sh all
+	tools/test.sh all
 
 80:
 	@for F in $(SRCALL);                       \
diff --git a/tools/test.sh b/tools/test.sh
new file mode 100755
index 0000000..5430ccd
--- /dev/null
+++ b/tools/test.sh
@@ -0,0 +1,168 @@
+#!/bin/sh
+
+dir=`cd $(dirname "$0"); pwd`
+bin=$dir/../obj/qbe
+
+tmp=/tmp/qbe.zzzz
+
+drv=$tmp.c
+asm=$tmp.s
+exe=$tmp.exe
+out=$tmp.out
+
+init() {
+	case "$TARGET" in
+	arm64)
+		for p in aarch64-linux-musl aarch64-linux-gnu
+		do
+			cc=$p-gcc
+			qemu="qemu-aarch64 -L /usr/$p"
+			if
+				$cc -v >/dev/null 2>&1 &&
+				$qemu -version >/dev/null 2>&1 &&
+				test -d /usr/$p
+			then
+				break
+			fi
+			cc=
+		done
+		if test -z "$cc"
+		then
+			echo "Cannot find arm64 compiler or qemu."
+			exit 1
+		fi
+                bin="$bin -t arm64"
+		;;
+	"")
+		case `uname` in
+		*OpenBSD*)
+			cc="cc -nopie"
+			;;
+		*)
+			cc="cc"
+			;;
+		esac
+		;;
+	*)
+		echo "Unknown target '$TARGET'."
+		exit 1
+		;;
+	esac
+}
+
+cleanup() {
+	rm -f $drv $asm $exe $out
+}
+
+extract() {
+	WHAT="$1"
+	FILE="$2"
+
+	awk "
+		/^# >>> $WHAT/ {
+			p = 1
+			next
+		}
+		/^# <<</ {
+			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
+
+	if
+		sed -e 1q $t |
+		grep "skip.* $TARGET\( .*\)\?$" \
+		>/dev/null
+	then
+		return 0
+	fi
+
+	printf "%-45s" "$(basename $t)..."
+
+	if ! $bin -o $asm $t
+	then
+		echo "[qbe fail]"
+		return 1
+	fi
+
+	extract driver $t > $drv
+	extract output $t > $out
+
+	if test -s $drv
+	then
+		src="$drv $asm"
+	else
+		src="$asm"
+	fi
+
+	if ! $cc -g -o $exe $src
+	then
+		echo "[cc fail]"
+		return 1
+	fi
+
+	if test -s $out
+	then
+		$qemu $exe a b c | diff - $out
+		ret=$?
+		reason="output"
+	else
+		$qemu $exe a b c
+		ret=$?
+		reason="returned $RET"
+	fi
+
+	if test $ret -ne 0
+	then
+		echo "[$reason fail]"
+		return 1
+	fi
+
+	echo "[ok]"
+}
+
+#trap cleanup TERM QUIT
+
+init
+
+if test -z "$1"
+then
+	echo "usage: tools/test.sh {all, SSAFILE}" 2>&1
+	exit 1
+fi
+
+case "$1" in
+"all")
+	fail=0
+	for t in $dir/../test/[!_]*.ssa
+	do
+		once $t
+		fail=`expr $fail + $?`
+	done
+	if test $fail -ge 1
+	then
+		echo
+		echo "$fail test(s) failed!"
+	else
+		echo
+		echo "All is fine!"
+	fi
+	exit $fail
+	;;
+*)
+	once $1
+	exit $?
+	;;
+esac
diff --git a/tools/unit.sh b/tools/unit.sh
deleted file mode 100755
index ace28fb..0000000
--- a/tools/unit.sh
+++ /dev/null
@@ -1,128 +0,0 @@
-#!/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
-		}
-		/^# <<</ {
-			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
-
-	printf "%-45s" "$(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 $PIE -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
-
-	echo "[ok]"
-}
-
-
-#trap cleanup TERM QUIT
-
-if test -z "$1"
-then
-	echo "usage: tools/unit.sh {all, SSAFILE}" 2>&1
-	exit 1
-fi
-
-for wtf in -nopie -no-pie
-do
-	if echo "int main() { return 0; }" |
-	   cc $wtf -x c -o /dev/null - >/dev/null 2>&1
-	then
-		PIE=$wtf
-	fi
-done
-
-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
-		exit $F
-		;;
-	*)
-		once $1
-		exit $?
-		;;
-esac