tests/trealla.nix
λpkgs, filcc, trealla
pkgs.runCommand"filc-trealla-runtime-check" { }
cp -r --no-preserve=mode ${trealla.src} source
cd source
ln -s ${trealla}/bin/tpl tpl
for test in clpz_regression dcg_consult dcg_corpus dcg_differential dcg_quads \
dcg_tabling tabling tabling_incremental tabling_reconstruct \
tabling_restraints tabling_shared tabling_subsumption; do
echo "Checking $test"
timeout 60 ./tpl -q -f -g halt tests/sundry/$test.pl > actual
diff -u tests/sundry/$test.expected actual
done
cd ..
# Exercise the installed libraries away from the source checkout.
timeout 30 ${trealla}/bin/tpl -q -f -g \
'use_module(library(assoc)),empty_assoc(A),put_assoc(key,A,value,B),get_assoc(key,B,value),X is 2^100,X =:= 1267650600228229401496703205376,write(ok),nl,halt.' \
> actual
echo ok > expected
diff -u expected actual
# goal_expansion pasting a bigint into a clause body (CLP(Z) here) used
# to leave the clause pointing at a freed bigint.
cat > bigint_expansion.pl <<'EOF'
:- use_module(library(clpz)).
m(Z, M) :- Z #= 2^63, M #= 18446744073709551621 mod 18446744073709551616.
:- initialization((m(Z, M), write(Z-M), nl, halt)).
EOF
timeout 30 ${trealla}/bin/tpl -q bigint_expansion.pl < /dev/null > actual
echo 9223372036854775808-5 > bigint_expected
diff -u bigint_expected actual
# A tail call whose argument starts a new heap page used to reuse the
# frame and trim the page under it (patches/trealla-heap-page-mark.patch).
cat > heap_page_tco.pl <<'EOF'
merged([], []).
merged([R], [R]) :- !.
merged([A-B, C-D|Rs], Out) :-
( C =< B + 1 -> E is max(B, D), merged([A-E|Rs], Out)
; Out = [A-B|Out1], merged([C-D|Rs], Out1)
).
normal(Rs0, Rs) :- msort(Rs0, Rs1), merged(Rs1, Rs).
pairs(N, N, []) :- !.
pairs(I, N, [I-I|T]) :- I1 is I + 1, pairs(I1, N, T).
main :-
( between(1, 400, N), pairs(0, N, Cs), M is N - 1,
\+ normal(Cs, [0-M]), write(wrong(N)), nl, fail
; write(ok), nl
).
:- initialization((main, halt)).
EOF
timeout 30 ${trealla}/bin/tpl -q heap_page_tco.pl < /dev/null > actual
diff -u expected actual
echo 'int trealla_test_increment(int x) { return x + 1; }' > ffi.c
${filcc}/bin/clang -shared -fPIC ffi.c -o ffi.so
cat > ffi.pl <<EOF
:- use_foreign_module('$PWD/ffi.so', [trealla_test_increment([sint], sint)]).
:- initialization(main).
main :- trealla_test_increment(41, 42), write(ok), nl.
EOF
timeout 30 ${trealla}/bin/tpl -q -f -g halt ffi.pl > actual
diff -u expected actual
touch $out