#!/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 [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. a program that does not # compile (`zc: N error(s)` in the output of either core) counts as a difference even # when both cores print the same error, since zy can still exit 0 after one. ref=$(realpath "${1:?usage: jit_x64_test.sh [filter]}") jit=$(realpath "${2:?usage: jit_x64_test.sh [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" # embed and include name paths from the root, so the scratch directory links to them for d in tests src examples; do ln -s "$root/$d" "$tmp/cwd/$d"; done # programs whose compile error is the point (tests/test.sh checks the message), or zc0 only expect_error=" decl_undefined manyerrors undefined_call zc0typed " 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=$? ce= grep -qE '^zc: [0-9]+ errors?$' "$tmp/ref.out" "$tmp/jit.out" "$tmp/ref.err" "$tmp/jit.err" && [[ "$expect_error" != *" $(basename "$f" .zc) "* ]] && ce=" compile error" if [ -z "$ce" ] && [ "$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)$ce" diff "$tmp/ref.out" "$tmp/jit.out" | head -6 head -3 "$tmp/jit.err"; [ -n "$ce" ] && head -3 "$tmp/ref.err" fi done echo "$pass of $total programs agree, $fail differ" exit "$fail"