Morgan Phillips
8 years ago
6 changed files with 118 additions and 1 deletions
@ -0,0 +1,14 @@ |
|||
CFG tests |
|||
============ |
|||
|
|||
This directory contains test cases for the Cretonne cfg printer. |
|||
|
|||
Each test case consists of a `foo.cton` input file annotated with its expected connections. |
|||
Annotations are comments of the form: `ebbx:insty -> ebbz` where ebbx is connected to ebbz via |
|||
a branch or jump instruction at line y. Instructions are labeled by line number starting from zero: `inst0` .. `instn`. |
|||
|
|||
|
|||
Each input file is run through the `cton-util print-cfg` command and the |
|||
output is compared against the specially formatted comments to ensure that |
|||
expected connections exist. This scheme allows for changes to graph style |
|||
without the need to update tests. |
@ -0,0 +1,30 @@ |
|||
; For testing cfg generation. This code is nonsense. |
|||
|
|||
function nonsense(i32, i32) -> f32 { |
|||
|
|||
ebb0(v1: i32, v2: i32): |
|||
v3 = f64const 0x0.0 |
|||
brz v2, ebb2 ;;;; ebb0:inst1 -> ebb2 |
|||
v4 = iconst.i32 0 |
|||
jump ebb1(v4) ;;;; ebb0:inst3 -> ebb1 |
|||
|
|||
ebb1(v5: i32): |
|||
v6 = imul_imm v5, 4 |
|||
v7 = iadd v1, v6 |
|||
v8 = f32const 0.0 |
|||
v9 = f32const 0.0 |
|||
v10 = f32const 0.0 |
|||
v11 = fadd v9, v10 |
|||
v12 = iadd_imm v5, 1 |
|||
v13 = icmp ult, v12, v2 |
|||
brnz v13, ebb1(v12) ;;;; ebb1:inst12 -> ebb1 |
|||
v14 = f64const 0.0 |
|||
v15 = f64const 0.0 |
|||
v16 = fdiv v14, v15 |
|||
v17 = f32const 0.0 |
|||
return v17 |
|||
|
|||
ebb2: |
|||
v100 = f32const 0.0 |
|||
return v100 |
|||
} |
@ -0,0 +1,38 @@ |
|||
#!/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 cfg -name '*.cton'); do |
|||
annotations=$(cat $testcase | awk /';;;;'/ | awk -F ";;;;" '{print $2}' | sort) |
|||
connections=$("${CTONUTIL}" print-cfg "$testcase" | awk /"->"/ | sort) |
|||
if diff -u <(echo $annotations) <(echo $connections); 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 |
@ -0,0 +1,18 @@ |
|||
; For testing cfg generation. This code explores the implications of encountering |
|||
; a terminating instruction before any connections have been made. |
|||
|
|||
function nonsense(i32) { |
|||
|
|||
ebb0(v1: i32): |
|||
trap |
|||
brnz v1, ebb2 ;;;; ebb0:inst1 -> ebb2 |
|||
jump ebb1 ;;;; ebb0:inst2 -> ebb1 |
|||
|
|||
ebb1: |
|||
v2 = iconst.i32 0 |
|||
v3 = iadd v1, v3 |
|||
jump ebb0(v3) ;;;; ebb1:inst5 -> ebb0 |
|||
|
|||
ebb2: |
|||
return v1 |
|||
} |
@ -0,0 +1,16 @@ |
|||
; For testing cfg generation where some block is never reached. |
|||
|
|||
function not_reached(i32) -> i32 { |
|||
|
|||
ebb0(v0: i32): |
|||
brnz v0, ebb2 ;;;; ebb0:inst0 -> ebb2 |
|||
trap |
|||
|
|||
ebb1: |
|||
v1 = iconst.i32 1 |
|||
v2 = iadd v0, v1 |
|||
jump ebb0(v2) ;;;; ebb1:inst4 -> ebb0 |
|||
|
|||
ebb2: |
|||
return v0 |
|||
} |
Loading…
Reference in new issue