aboutsummaryrefslogtreecommitdiff
path: root/tests/drivers/jit_x64_test.sh
blob: 39e1583d5e832ffead39daefd8ed02d6fbe3525e (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
#!/bin/bash
# runs every program in tests/programs, examples and examples/learn on two cores
# and compares stdout and the exit status. usage:
#   bash tests/drivers/jit_x64_test.sh <reference core> <jit core> [name-filter]
# the reference is normally the interpreter (built with -DZYINTERP) and the second
# core the x86-64 jit. each program is the core's stdin, with nothing after it, and
# runs with a timeout (JIT_TEST_TIMEOUT seconds, 120 by default). a program that
# differs is listed with the first lines of the difference; the exit status of
# this script is the number of programs that differ.
ref=$(realpath "${1:?usage: jit_x64_test.sh <reference core> <jit core> [filter]}")
jit=$(realpath "${2:?usage: jit_x64_test.sh <reference core> <jit core> [filter]}")
filter=${3:-}
limit=${JIT_TEST_TIMEOUT:-120}
root=$(cd "$(dirname "$0")/../.." && pwd)
cd "$root" || exit 2
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
# programs run in a scratch directory, so files they create (bareio writes `note`) stay out of the tree
mkdir "$tmp/cwd"
pass=0 fail=0 total=0
for f in tests/programs/*.zc examples/*.zc examples/learn/*.zc; do
	[ -n "$filter" ] && [[ "$f" != *$filter* ]] && continue
	total=$((total + 1))
	(cd "$tmp/cwd" && timeout "$limit" "$ref" < "$root/$f" > "$tmp/ref.out" 2> "$tmp/ref.err"); rr=$?
	(cd "$tmp/cwd" && timeout "$limit" "$jit" < "$root/$f" > "$tmp/jit.out" 2> "$tmp/jit.err"); rj=$?
	if [ "$rr" = "$rj" ] && cmp -s "$tmp/ref.out" "$tmp/jit.out"; then
		pass=$((pass + 1))
	else
		fail=$((fail + 1))
		echo "DIFF $f (status $rr vs $rj)"
		diff "$tmp/ref.out" "$tmp/jit.out" | head -6
		head -3 "$tmp/jit.err"
	fi
done
echo "$pass of $total programs agree, $fail differ"
exit "$fail"