From 0b7f87b14cddec5c85df747530a9b562fc86810c Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Thu, 15 Sep 2016 15:27:37 -0700 Subject: [PATCH] Convert parser tests to filetests. Create a new directory hierarchy under 'filetests' for all the tests that are run by 'cton-util test'. Convert the parser tests under 'tests/parser' to use 'test cat' and filecheck directives. --- filetests/parser/branch.cton | 113 +++++++++++++++++++++++ filetests/parser/call.cton | 24 +++++ {tests => filetests}/parser/rewrite.cton | 13 +++ {tests => filetests}/parser/tiny.cton | 39 ++++++++ test-all.sh | 6 +- tests/parser/README.rst | 9 -- tests/parser/branch.cton | 60 ------------ tests/parser/branch.cton.ref | 57 ------------ tests/parser/call.cton | 13 --- tests/parser/call.cton.ref | 11 --- tests/parser/rewrite.cton.ref | 13 --- tests/parser/run.sh | 40 -------- tests/parser/tiny.cton.ref | 43 --------- 13 files changed, 193 insertions(+), 248 deletions(-) create mode 100644 filetests/parser/branch.cton create mode 100644 filetests/parser/call.cton rename {tests => filetests}/parser/rewrite.cton (68%) rename {tests => filetests}/parser/tiny.cton (50%) delete mode 100644 tests/parser/README.rst delete mode 100644 tests/parser/branch.cton delete mode 100644 tests/parser/branch.cton.ref delete mode 100644 tests/parser/call.cton delete mode 100644 tests/parser/call.cton.ref delete mode 100644 tests/parser/rewrite.cton.ref delete mode 100755 tests/parser/run.sh delete mode 100644 tests/parser/tiny.cton.ref diff --git a/filetests/parser/branch.cton b/filetests/parser/branch.cton new file mode 100644 index 0000000000..46612973af --- /dev/null +++ b/filetests/parser/branch.cton @@ -0,0 +1,113 @@ +; Parsing branches and jumps. +test cat + +; Jumps with no arguments. The '()' empty argument list is optional. +function minimal() { +ebb0: + jump ebb1 + +ebb1: + jump ebb0() +} +; sameln: function minimal() { +; nextln: ebb0: +; nextln: jump ebb1 +; nextln: +; nextln: ebb1: +; nextln: jump ebb0 +; nextln: } + +; Jumps with 1 arg. +function onearg(i32) { +ebb0(vx0: i32): + jump ebb1(vx0) + +ebb1(vx1: i32): + jump ebb0(vx1) +} +; sameln: function onearg(i32) { +; nextln: ebb0(vx0: i32): +; nextln: jump ebb1(vx0) +; nextln: +; nextln: ebb1(vx1: i32): +; nextln: jump ebb0(vx1) +; nextln: } + +; Jumps with 2 args. +function twoargs(i32, f32) { +ebb0(vx0: i32, vx1: f32): + jump ebb1(vx0, vx1) + +ebb1(vx2: i32, vx3: f32): + jump ebb0(vx2, vx3) +} +; sameln: function twoargs(i32, f32) { +; nextln: ebb0(vx0: i32, vx1: f32): +; nextln: jump ebb1(vx0, vx1) +; nextln: +; nextln: ebb1(vx2: i32, vx3: f32): +; nextln: jump ebb0(vx2, vx3) +; nextln: } + +; Branches with no arguments. The '()' empty argument list is optional. +function minimal(i32) { +ebb0(vx0: i32): + brz vx0, ebb1 + +ebb1: + brnz vx0, ebb1() +} +; sameln: function minimal(i32) { +; nextln: ebb0(vx0: i32): +; nextln: brz vx0, ebb1 +; nextln: +; nextln: ebb1: +; nextln: brnz vx0, ebb1 +; nextln: } + +function twoargs(i32, f32) { +ebb0(vx0: i32, vx1: f32): + brz vx0, ebb1(vx0, vx1) + +ebb1(vx2: i32, vx3: f32): + brnz vx0, ebb0(vx2, vx3) +} +; sameln: function twoargs(i32, f32) { +; nextln: ebb0(vx0: i32, vx1: f32): +; nextln: brz vx0, ebb1(vx0, vx1) +; nextln: +; nextln: ebb1(vx2: i32, vx3: f32): +; nextln: brnz vx0, ebb0(vx2, vx3) +; nextln: } + +function jumptable(i32) { + jt200 = jump_table 0, 0 + jt2 = jump_table 0, 0, ebb10, ebb40, ebb20, ebb30 + +ebb10(v3: i32): + br_table v3, jt2 + trap +ebb20: + trap +ebb30: + trap +ebb40: + trap +} +; sameln: function jumptable(i32) { +; nextln: jt0 = jump_table 0 +; nextln: jt1 = jump_table 0, 0, ebb0, ebb3, ebb1, ebb2 +; nextln: +; nextln: ebb0(vx0: i32): +; nextln: br_table vx0, jt1 +; nextln: trap +; nextln: +; nextln: ebb1: +; nextln: trap +; nextln: +; nextln: ebb2: +; nextln: trap +; nextln: +; nextln: ebb3: +; nextln: trap +; nextln: } diff --git a/filetests/parser/call.cton b/filetests/parser/call.cton new file mode 100644 index 0000000000..71c7c1efb0 --- /dev/null +++ b/filetests/parser/call.cton @@ -0,0 +1,24 @@ +; Parser tests for call and return syntax. +test cat + +function mini() { +ebb1: + return +} +; sameln: function mini() { +; nextln: ebb0: +; nextln: return +; nextln: } + +function r1() -> i32, f32 { +ebb1: + v1 = iconst.i32 3 + v2 = f32const 0.0 + return v1, v2 +} +; sameln: function r1() -> i32, f32 { +; nextln: ebb0: +; nextln: v0 = iconst.i32 3 +; nextln: v1 = f32const 0.0 +; nextln: return v0, v1 +; nextln: } diff --git a/tests/parser/rewrite.cton b/filetests/parser/rewrite.cton similarity index 68% rename from tests/parser/rewrite.cton rename to filetests/parser/rewrite.cton index 33e5277db6..969572bdbf 100644 --- a/tests/parser/rewrite.cton +++ b/filetests/parser/rewrite.cton @@ -6,6 +6,7 @@ ; It is possible to refer to instructions and EBBs that have not yet been ; defined in the lexical order, so the parser needs to rewrite these references ; after the fact. +test cat ; Check that defining numbers are rewritten. function defs() { @@ -14,6 +15,12 @@ ebb100(v20: i32): vx200 = f64const 0x4.0p0 trap } +; sameln: function defs() { +; nextln: ebb0(vx0: i32): +; nextln: v0 = iconst.i32x8 5 +; nextln: v1 = f64const 0x1.0000000000000p2 +; nextln: trap +; nextln: } ; Using values. function use_value() { @@ -22,3 +29,9 @@ ebb100(v20: i32): vx200 = iadd v20, v1000 jump ebb100(v1000) } +; sameln: function "use_value"() { +; nextln: ebb0(vx0: i32): +; nextln: v0 = iadd_imm vx0, 5 +; nextln: v1 = iadd vx0, v0 +; nextln: jump ebb0(v0) +; nextln: } diff --git a/tests/parser/tiny.cton b/filetests/parser/tiny.cton similarity index 50% rename from tests/parser/tiny.cton rename to filetests/parser/tiny.cton index ae3466b618..588223c521 100644 --- a/tests/parser/tiny.cton +++ b/filetests/parser/tiny.cton @@ -1,8 +1,14 @@ +test cat + ; The smallest possible function. function minimal() { ebb0: trap } +; sameln: function minimal() { +; nextln: ebb0: +; nextln: trap +; nextln: } ; Create and use values. ; Polymorphic instructions with type suffix. @@ -12,12 +18,22 @@ ebb0: v1 = iconst.i8 6 v2 = ishl v0, v1 } +; sameln: function ivalues() { +; nextln: ebb0: +; nextln: v0 = iconst.i32 2 +; nextln: v1 = iconst.i8 6 +; nextln: v2 = ishl v0, v1 +; nextln: } ; Polymorphic istruction controlled by second operand. function select() { ebb0(vx0: i32, vx1: i32, vx2: b1): v0 = select vx2, vx0, vx1 } +; sameln: function select() { +; nextln: ebb0(vx0: i32, vx1: i32, vx2: b1): +; nextln: v0 = select vx2, vx0, vx1 +; nextln: } ; Lane indexes. function lanes() { @@ -26,6 +42,12 @@ ebb0: v1 = extractlane v0, 3 v2 = insertlane v0, 1, v1 } +; sameln: function lanes() { +; nextln: ebb0: +; nextln: v0 = iconst.i32x4 2 +; nextln: v1 = extractlane v0, 3 +; nextln: v2 = insertlane v0, 1, v1 +; nextln: } ; Integer condition codes. function icmp(i32, i32) { @@ -34,6 +56,12 @@ ebb0(vx0: i32, vx1: i32): v1 = icmp ult, vx0, vx1 v2 = icmp sge, vx0, vx1 } +; sameln: function icmp(i32, i32) { +; nextln: ebb0(vx0: i32, vx1: i32): +; nextln: v0 = icmp eq, vx0, vx1 +; nextln: v1 = icmp ult, vx0, vx1 +; nextln: v2 = icmp sge, vx0, vx1 +; nextln: } ; Floating condition codes. function fcmp(f32, f32) { @@ -42,6 +70,12 @@ ebb0(vx0: f32, vx1: f32): v1 = fcmp uno, vx0, vx1 v2 = fcmp lt, vx0, vx1 } +; sameln: function fcmp(f32, f32) { +; nextln: ebb0(vx0: f32, vx1: f32): +; nextln: v0 = fcmp eq, vx0, vx1 +; nextln: v1 = fcmp uno, vx0, vx1 +; nextln: v2 = fcmp lt, vx0, vx1 +; nextln: } ; The bitcast instruction has two type variables: The controlling type variable ; controls the outout type, and the input type is a free variable. @@ -50,3 +84,8 @@ ebb0(vx0: i32, vx1: f32): v0 = bitcast.i8x4 vx0 v1 = bitcast.i32 vx1 } +; sameln: function bitcast(i32, f32) { +; nextln: ebb0(vx0: i32, vx1: f32): +; nextln: v0 = bitcast.i8x4 vx0 +; nextln: v1 = bitcast.i32 vx1 +; nextln: } diff --git a/test-all.sh b/test-all.sh index cd3916d8c3..6c8406493a 100755 --- a/test-all.sh +++ b/test-all.sh @@ -58,10 +58,12 @@ cargo build --release export CTONUTIL="$topdir/src/tools/target/release/cton-util" +cd "$topdir" +banner "File tests" +"$CTONUTIL" test filetests + # Run the parser tests. cd "$topdir/tests" -banner "Parser tests" -parser/run.sh banner "CFG tests" cfg/run.sh diff --git a/tests/parser/README.rst b/tests/parser/README.rst deleted file mode 100644 index 9ac4658d13..0000000000 --- a/tests/parser/README.rst +++ /dev/null @@ -1,9 +0,0 @@ -Parser tests -============ - -This directory contains test cases for the Cretonne IL parser. - -Each test case consists of a `foo.cton` input file and a `foo.ref` reference -output file. Each input file is run through the `cton-util cat` command, and the -output is compared against the reference file. If the two are identical, the -test passes. diff --git a/tests/parser/branch.cton b/tests/parser/branch.cton deleted file mode 100644 index 05526fd910..0000000000 --- a/tests/parser/branch.cton +++ /dev/null @@ -1,60 +0,0 @@ -; Parsing branches and jumps. - -; Jumps with no arguments. The '()' empty argument list is optional. -function minimal() { -ebb0: - jump ebb1 - -ebb1: - jump ebb0() -} - -; Jumps with 1 arg. -function onearg(i32) { -ebb0(vx0: i32): - jump ebb1(vx0) - -ebb1(vx1: i32): - jump ebb0(vx1) -} - -; Jumps with 2 args. -function twoargs(i32, f32) { -ebb0(vx0: i32, vx1: f32): - jump ebb1(vx0, vx1) - -ebb1(vx2: i32, vx3: f32): - jump ebb0(vx2, vx3) -} - -; Branches with no arguments. The '()' empty argument list is optional. -function minimal(i32) { -ebb0(vx0: i32): - brz vx0, ebb1 - -ebb1: - brnz vx0, ebb1() -} - -function twoargs(i32, f32) { -ebb0(vx0: i32, vx1: f32): - brz vx0, ebb1(vx0, vx1) - -ebb1(vx2: i32, vx3: f32): - brnz vx0, ebb0(vx2, vx3) -} - -function jumptable(i32) { - jt200 = jump_table 0, 0 - jt2 = jump_table 0, 0, ebb10, ebb40, ebb20, ebb30 - -ebb10(v3: i32): - br_table v3, jt2 - trap -ebb20: - trap -ebb30: - trap -ebb40: - trap -} diff --git a/tests/parser/branch.cton.ref b/tests/parser/branch.cton.ref deleted file mode 100644 index 8f395c885c..0000000000 --- a/tests/parser/branch.cton.ref +++ /dev/null @@ -1,57 +0,0 @@ -function minimal() { -ebb0: - jump ebb1 - -ebb1: - jump ebb0 -} - -function onearg(i32) { -ebb0(vx0: i32): - jump ebb1(vx0) - -ebb1(vx1: i32): - jump ebb0(vx1) -} - -function twoargs(i32, f32) { -ebb0(vx0: i32, vx1: f32): - jump ebb1(vx0, vx1) - -ebb1(vx2: i32, vx3: f32): - jump ebb0(vx2, vx3) -} - -function minimal(i32) { -ebb0(vx0: i32): - brz vx0, ebb1 - -ebb1: - brnz vx0, ebb1 -} - -function twoargs(i32, f32) { -ebb0(vx0: i32, vx1: f32): - brz vx0, ebb1(vx0, vx1) - -ebb1(vx2: i32, vx3: f32): - brnz vx0, ebb0(vx2, vx3) -} - -function jumptable(i32) { - jt0 = jump_table 0 - jt1 = jump_table 0, 0, ebb0, ebb3, ebb1, ebb2 - -ebb0(vx0: i32): - br_table vx0, jt1 - trap - -ebb1: - trap - -ebb2: - trap - -ebb3: - trap -} diff --git a/tests/parser/call.cton b/tests/parser/call.cton deleted file mode 100644 index 12221c3ff1..0000000000 --- a/tests/parser/call.cton +++ /dev/null @@ -1,13 +0,0 @@ -; Parser tests for call and return syntax. - -function mini() { -ebb1: - return -} - -function r1() -> i32, f32 { -ebb1: - v1 = iconst.i32 3 - v2 = f32const 0.0 - return v1, v2 -} diff --git a/tests/parser/call.cton.ref b/tests/parser/call.cton.ref deleted file mode 100644 index a6d51166f4..0000000000 --- a/tests/parser/call.cton.ref +++ /dev/null @@ -1,11 +0,0 @@ -function mini() { -ebb0: - return -} - -function r1() -> i32, f32 { -ebb0: - v0 = iconst.i32 3 - v1 = f32const 0.0 - return v0, v1 -} diff --git a/tests/parser/rewrite.cton.ref b/tests/parser/rewrite.cton.ref deleted file mode 100644 index 8f379abd64..0000000000 --- a/tests/parser/rewrite.cton.ref +++ /dev/null @@ -1,13 +0,0 @@ -function defs() { -ebb0(vx0: i32): - v0 = iconst.i32x8 5 - v1 = f64const 0x1.0000000000000p2 - trap -} - -function "use_value"() { -ebb0(vx0: i32): - v0 = iadd_imm vx0, 5 - v1 = iadd vx0, v0 - jump ebb0(v0) -} diff --git a/tests/parser/run.sh b/tests/parser/run.sh deleted file mode 100755 index e5795df1da..0000000000 --- a/tests/parser/run.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - -# Go to tests directory. -cd $(dirname "$0")/.. - -# The path to cton-util should be in $CTONUTIL. -if [ -z "$CTONUTIL" ]; then - CTONUTIL=../src/tools/target/debug/cton-util -fi - -if [ ! -x "$CTONUTIL" ]; then - echo "Can't fund executable cton-util: $CTONUTIL" 1>&2 - exit 1 -fi - -declare -a fails - -for testcase in $(find parser -name '*.cton'); do - ref="${testcase}.ref" - if [ ! -r "$ref" ]; then - fails=(${fails[@]} "$testcase") - echo MISSING: $ref - elif diff -u "$ref" <("$CTONUTIL" cat "$testcase"); then - echo OK $testcase - else - fails=(${fails[@]} "$testcase") - echo FAIL $testcase - fi -done - -if [ ${#fails[@]} -ne 0 ]; then - echo - echo Failures: - for f in "${fails[@]}"; do - echo " $f" - done - exit 1 -else - echo "All passed" -fi diff --git a/tests/parser/tiny.cton.ref b/tests/parser/tiny.cton.ref deleted file mode 100644 index f2404bbf94..0000000000 --- a/tests/parser/tiny.cton.ref +++ /dev/null @@ -1,43 +0,0 @@ -function minimal() { -ebb0: - trap -} - -function ivalues() { -ebb0: - v0 = iconst.i32 2 - v1 = iconst.i8 6 - v2 = ishl v0, v1 -} - -function select() { -ebb0(vx0: i32, vx1: i32, vx2: b1): - v0 = select vx2, vx0, vx1 -} - -function lanes() { -ebb0: - v0 = iconst.i32x4 2 - v1 = extractlane v0, 3 - v2 = insertlane v0, 1, v1 -} - -function icmp(i32, i32) { -ebb0(vx0: i32, vx1: i32): - v0 = icmp eq, vx0, vx1 - v1 = icmp ult, vx0, vx1 - v2 = icmp sge, vx0, vx1 -} - -function fcmp(f32, f32) { -ebb0(vx0: f32, vx1: f32): - v0 = fcmp eq, vx0, vx1 - v1 = fcmp uno, vx0, vx1 - v2 = fcmp lt, vx0, vx1 -} - -function bitcast(i32, f32) { -ebb0(vx0: i32, vx1: f32): - v0 = bitcast.i8x4 vx0 - v1 = bitcast.i32 vx1 -}