aboutsummaryrefslogtreecommitdiff
path: root/tests/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'tests/drivers')
-rw-r--r--tests/drivers/jit_x64_test.sh36
-rw-r--r--tests/drivers/lsp_test.js12
-rw-r--r--tests/drivers/runtime_image_test.py2
3 files changed, 50 insertions, 0 deletions
diff --git a/tests/drivers/jit_x64_test.sh b/tests/drivers/jit_x64_test.sh
new file mode 100644
index 0000000..39e1583
--- /dev/null
+++ b/tests/drivers/jit_x64_test.sh
@@ -0,0 +1,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"
diff --git a/tests/drivers/lsp_test.js b/tests/drivers/lsp_test.js
index 0f4abe1..2ad9181 100644
--- a/tests/drivers/lsp_test.js
+++ b/tests/drivers/lsp_test.js
@@ -199,6 +199,18 @@ const tmsrc = 'struct point {\n\tlet x;\n\t// the sum of the parts\n\tint sum(in
hv = hover(tmsrc, 7, at(tmsrc, 7, 'sum'));
check(hv && hv.includes('int sum(int k)') && hv.includes('the sum of the parts'), 'a typed method shows its return type and parameters', hv);
+// members of the embedded standard library hover like the document's own: the group's static
+// function, the group, and a top-level function, each with the comment from std.zc
+const stdsrc = 'include rt, std;\nfn main() { char[24] b; rt.put_s(std.Text.itoa(5, b)); return std.array_contains; }\n';
+hv = hover(stdsrc, 1, at(stdsrc, 1, 'itoa'));
+check(hv && hv.includes('static int itoa(int n, char* dst)') && hv.includes('writes n in decimal into dst'), 'hover on a std group function shows its signature and doc from std.zc', hv);
+hv = hover(stdsrc, 1, at(stdsrc, 1, 'Text'));
+check(hv && hv.includes('struct Text') && hv.includes('helpers for char* strings'), 'hover on a std group shows the comment of the group', hv);
+hv = hover(stdsrc, 1, at(stdsrc, 1, 'array_contains'));
+check(hv && hv.includes('array_contains<T>') && hv.includes('true when an element equals value'), 'hover on a top-level std function shows its doc', hv);
+hv = hover(stdsrc, 1, at(stdsrc, 1, 'put_s'));
+check(hv && hv.includes('int put_s(char* s)'), 'hover on a runtime function still works beside the std ones', hv);
+
// externs are declarations, so they draw no "never reassigned" hint
const ext = 'extern double sqrt(double);\nextern double pow(double x, double y);\nfn main() {\n\treturn 0;\n}\n';
r = run([init(1), open(A, ext)]);
diff --git a/tests/drivers/runtime_image_test.py b/tests/drivers/runtime_image_test.py
index d214613..6c44349 100644
--- a/tests/drivers/runtime_image_test.py
+++ b/tests/drivers/runtime_image_test.py
@@ -18,6 +18,8 @@ cases = [
('enhancements', 'include rt; fn main() { rt.put_n(17 % 5); rt.put_c(32); rt.put_n(17 / 5); }', b'2 3'),
('array algorithms', Path('examples/learn/31-array-algorithms.zc').read_text(), Path('examples/learn/31-array-algorithms.out').read_bytes()),
('owned pop', 'include rt; int*.u take() { int*[?] a = rt.new(int*[?]); int* p = rt.new(int); *p = 8; a.push(p); return a.pop(); } fn main() { let p = take(); rt.put_n(rt.isobj(p)); rt.put_c(32); rt.put_n(*p); }', b'1 8'),
+ # main may be void: run.zc's prototype of main must not fix its type (docs/SPEC.md 5.2.5)
+ ('void main', Path('tests/programs/void_main.zc').read_text(), b'void main\n'),
]
prefix = b''.join(Path(f).read_bytes() + b'\n' for f in ['src/runtime/rt.zc', 'src/core/core.zc', 'src/runtime/run.zc'])
for name, source, expected in cases: