summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJon French2019-02-25 12:10:30 +0000
committerJon French2019-02-25 12:10:30 +0000
commit915d75f9c49fa2c2a9d47d189e4224cee16582c9 (patch)
tree77a93e682796977898af0b56e0a61d7689db112e /test
parenta8a5308e4981b3d09fb2bf0c59d592ef6ae4417e (diff)
parent38656b50ad24df6a29f3a84e50adfcf409131fb0 (diff)
Merge branch 'sail2' into rmem_interpreter
Diffstat (limited to 'test')
-rw-r--r--test/c/dead_branch.expect2
-rw-r--r--test/c/dead_branch.sail42
-rw-r--r--test/c/encdec.expect2
-rw-r--r--test/c/encdec.sail38
-rwxr-xr-xtest/c/run_tests.py1
-rw-r--r--test/typecheck/pass/complex_exist_sat.sail7
-rw-r--r--test/typecheck/pass/complex_exist_sat/v1.expect8
-rw-r--r--test/typecheck/pass/complex_exist_sat/v1.sail3
-rw-r--r--test/typecheck/pass/complex_exist_sat/v2.expect8
-rw-r--r--test/typecheck/pass/complex_exist_sat/v2.sail3
-rw-r--r--test/typecheck/pass/int_synonym.sail18
-rw-r--r--test/typecheck/pass/pow_32_64.sail14
-rwxr-xr-xtest/typecheck/run_tests.sh6
13 files changed, 149 insertions, 3 deletions
diff --git a/test/c/dead_branch.expect b/test/c/dead_branch.expect
new file mode 100644
index 00000000..ca6ef09a
--- /dev/null
+++ b/test/c/dead_branch.expect
@@ -0,0 +1,2 @@
+v = 0x5678EF91
+v = 0xABCD12345678EF91
diff --git a/test/c/dead_branch.sail b/test/c/dead_branch.sail
new file mode 100644
index 00000000..4d7900eb
--- /dev/null
+++ b/test/c/dead_branch.sail
@@ -0,0 +1,42 @@
+default Order dec
+
+$include <arith.sail>
+$include <vector_dec.sail>
+
+type xlen : Int = 32
+type xlenbits = bits(xlen)
+
+register reg : bits(64)
+
+function read_xlen (arg : bool) -> xlenbits = {
+ match (arg, sizeof(xlen)) {
+ (_, 32) => reg[31 .. 0],
+ (_, 64) => reg,
+ (_, _) => if sizeof(xlen) == 32
+ then reg[31 .. 0]
+ else reg[63 .. 32]
+ }
+}
+
+type ylen : Int = 64
+type ylenbits = bits(ylen)
+
+function read_ylen (arg : bool) -> ylenbits = {
+ match (arg, sizeof(ylen)) {
+ (_, 32) => reg[31 .. 0],
+ (_, 64) => reg,
+ (_, _) => if sizeof(ylen) == 32
+ then reg[31 .. 0]
+ else reg
+ }
+}
+
+val main : unit -> unit effect {rreg, wreg}
+function main() = {
+ reg = 0xABCD_1234_5678_EF91;
+ let v = read_xlen(true);
+ print_bits("v = ", v);
+ let v = read_ylen(true);
+ print_bits("v = ", v);
+ ()
+}
diff --git a/test/c/encdec.expect b/test/c/encdec.expect
new file mode 100644
index 00000000..18fab89a
--- /dev/null
+++ b/test/c/encdec.expect
@@ -0,0 +1,2 @@
+bin = 0x9FFF
+bin' = 0x9FFF
diff --git a/test/c/encdec.sail b/test/c/encdec.sail
new file mode 100644
index 00000000..bac55c8d
--- /dev/null
+++ b/test/c/encdec.sail
@@ -0,0 +1,38 @@
+default Order dec
+
+$include <prelude.sail>
+$include <exception_basic.sail>
+
+enum pred = {
+ P_false,
+ P_true
+}
+
+mapping decenc_p : bits(2) <-> pred = {
+ 0b00 <-> P_true,
+ 0b01 <-> P_false
+}
+
+scattered union ast
+
+val encdec : ast <-> bits(16)
+
+union clause ast = ABS : (pred, bits(10))
+
+mapping clause encdec =
+ ABS(decenc_p(0b0 @ p), rd @ rs)
+ <-> 0b10011 @ p : bits(1) @ rd : bits(5) @ rs : bits(5)
+
+function fetch(_: unit) -> bits(16) = {
+ 0b10011 @ 0xFF @ 0b111
+}
+
+val main : unit -> unit effect {barr, eamem, escape, exmem, rmem, rreg, wmv, wreg}
+function main () = {
+ let bin = fetch();
+ let ast = encdec(bin);
+ let bin' = encdec(ast);
+ assert(bin == bin');
+ print_bits("bin = ", bin);
+ print_bits("bin' = ", bin')
+}
diff --git a/test/c/run_tests.py b/test/c/run_tests.py
index 4927e281..4a02dd78 100755
--- a/test/c/run_tests.py
+++ b/test/c/run_tests.py
@@ -93,6 +93,7 @@ xml = '<testsuites>\n'
xml += test_c('unoptimized C', '', '', True)
xml += test_c('optimized C', '-O2', '-O', True)
xml += test_c('constant folding', '', '-Oconstant_fold', True)
+xml += test_c('monomorphised C', '-O2', '-O -Oconstant_fold -auto_mono', True)
xml += test_c('full optimizations', '-O2 -mbmi2 -DINTRINSICS', '-O -Oconstant_fold', True)
xml += test_c('address sanitised', '-O2 -fsanitize=undefined', '-O', False)
diff --git a/test/typecheck/pass/complex_exist_sat.sail b/test/typecheck/pass/complex_exist_sat.sail
new file mode 100644
index 00000000..65c3b6a9
--- /dev/null
+++ b/test/typecheck/pass/complex_exist_sat.sail
@@ -0,0 +1,7 @@
+val foo : int -> {'q, 'q in {0, 1}. atom(2 * 'q)}
+
+function foo(x) = 2
+
+val bar : int -> {'q, 'q in {0, 1}. atom(2 * 'q)}
+
+function bar(x) = 0
diff --git a/test/typecheck/pass/complex_exist_sat/v1.expect b/test/typecheck/pass/complex_exist_sat/v1.expect
new file mode 100644
index 00000000..b1937f47
--- /dev/null
+++ b/test/typecheck/pass/complex_exist_sat/v1.expect
@@ -0,0 +1,8 @@
+Type error:
+[complex_exist_sat/v1.sail]:3:18-19
+3 |function foo(x) = 3
+  | ^
+  | Tried performing type coercion from int(3) to {('q : Int), 'q in {0, 1}. int((2 * 'q))} on 3
+  | Coercion failed because:
+  | Constraint 3 == (2 * 'ex1#) is not satisfiable
+  |
diff --git a/test/typecheck/pass/complex_exist_sat/v1.sail b/test/typecheck/pass/complex_exist_sat/v1.sail
new file mode 100644
index 00000000..f36f2dda
--- /dev/null
+++ b/test/typecheck/pass/complex_exist_sat/v1.sail
@@ -0,0 +1,3 @@
+val foo : int -> {'q, 'q in {0, 1}. atom(2 * 'q)}
+
+function foo(x) = 3 \ No newline at end of file
diff --git a/test/typecheck/pass/complex_exist_sat/v2.expect b/test/typecheck/pass/complex_exist_sat/v2.expect
new file mode 100644
index 00000000..27af46d2
--- /dev/null
+++ b/test/typecheck/pass/complex_exist_sat/v2.expect
@@ -0,0 +1,8 @@
+Type error:
+[complex_exist_sat/v2.sail]:3:18-19
+3 |function foo(x) = 4
+  | ^
+  | Tried performing type coercion from int(4) to {('q : Int), 'q in {0, 1}. int((2 * 'q))} on 4
+  | Coercion failed because:
+  | int(4) is not a subtype of {('q : Int), 'q in {0, 1}. int((2 * 'q))}
+  |
diff --git a/test/typecheck/pass/complex_exist_sat/v2.sail b/test/typecheck/pass/complex_exist_sat/v2.sail
new file mode 100644
index 00000000..e3e18e8c
--- /dev/null
+++ b/test/typecheck/pass/complex_exist_sat/v2.sail
@@ -0,0 +1,3 @@
+val foo : int -> {'q, 'q in {0, 1}. atom(2 * 'q)}
+
+function foo(x) = 4 \ No newline at end of file
diff --git a/test/typecheck/pass/int_synonym.sail b/test/typecheck/pass/int_synonym.sail
new file mode 100644
index 00000000..33bdaf0c
--- /dev/null
+++ b/test/typecheck/pass/int_synonym.sail
@@ -0,0 +1,18 @@
+/* from prelude */
+default Order dec
+
+$include <flow.sail>
+
+type bits ('n : Int) = vector('n, dec, bit)
+
+type xlen : Int = 64
+type xlen_bytes : Int = 8
+type xlenbits = bits(xlen)
+
+val "sign_extend" : forall 'n 'm, 'm >= 'n. (bits('n), atom('m)) -> bits('m)
+val EXTS : forall 'n 'm, 'm >= 'n. (implicit('m), bits('n)) -> bits('m)
+function EXTS(m, v) = sign_extend(v, m)
+
+val extend : forall 'n, 'n <= xlen_bytes. (bool, bits(8 * 'n)) -> xlenbits
+
+function extend(flag, value) = EXTS(value)
diff --git a/test/typecheck/pass/pow_32_64.sail b/test/typecheck/pass/pow_32_64.sail
new file mode 100644
index 00000000..bb4f207a
--- /dev/null
+++ b/test/typecheck/pass/pow_32_64.sail
@@ -0,0 +1,14 @@
+default Order dec
+
+$include <prelude.sail>
+
+$option -smt_linearize
+
+val bar : forall 'n, 'n <= 2 ^ 64 - 1. int('n) -> unit
+
+val foo : forall 'n, 'n in {32, 64}. bits('n) -> unit
+
+function foo(xs) = {
+ let x = unsigned(xs);
+ bar(x)
+}
diff --git a/test/typecheck/run_tests.sh b/test/typecheck/run_tests.sh
index ad2592df..e5650646 100755
--- a/test/typecheck/run_tests.sh
+++ b/test/typecheck/run_tests.sh
@@ -50,9 +50,9 @@ printf "<testsuites>\n" >> $DIR/tests.xml
for i in `ls $DIR/pass/ | grep sail`;
do
- if $SAILDIR/sail -just_check -ddump_tc_ast -dsanity $DIR/pass/$i 2> /dev/null 1> $DIR/rtpass/$i;
+ if $SAILDIR/sail -no_memo_z3 -just_check -ddump_tc_ast -dsanity $DIR/pass/$i 2> /dev/null 1> $DIR/rtpass/$i;
then
- if $SAILDIR/sail -just_check -ddump_tc_ast -dmagic_hash -dno_cast -dsanity $DIR/rtpass/$i 2> /dev/null 1> $DIR/rtpass2/$i;
+ if $SAILDIR/sail -no_memo_z3 -just_check -ddump_tc_ast -dmagic_hash -dno_cast -dsanity $DIR/rtpass/$i 2> /dev/null 1> $DIR/rtpass2/$i;
then
if diff $DIR/rtpass/$i $DIR/rtpass2/$i;
then
@@ -71,7 +71,7 @@ do
for file in $DIR/pass/${i%.sail}/*.sail;
do
pushd $DIR/pass > /dev/null;
- if $SAILDIR/sail ${i%.sail}/$(basename $file) 2> result;
+ if $SAILDIR/sail -no_memo_z3 ${i%.sail}/$(basename $file) 2> result;
then
red "failing variant of $i $(basename $file) passed" "fail"
else