Implement the 'test print-cfg' sub-test.

Move the CFG tests into the filetests directory.

Remove the tests directory, there are no more shell-driven tests left.
This commit is contained in:
Jakob Stoklund Olesen
2016-09-15 17:20:39 -07:00
parent 1342a0fb71
commit 5ac30b0075
8 changed files with 35 additions and 56 deletions

View File

@@ -1,4 +1,5 @@
; For testing cfg generation. This code is nonsense.
test print-cfg
function nonsense(i32, i32) -> f32 {
; check: digraph nonsense {

View File

@@ -1,5 +1,6 @@
; For testing cfg generation. This code explores the implications of encountering
; a terminating instruction before any connections have been made.
test print-cfg
function nonsense(i32) {
; check: digraph nonsense {

View File

@@ -1,4 +1,5 @@
; For testing cfg generation where some block is never reached.
test print-cfg
function not_reached(i32) -> i32 {
; check: digraph not_reached {

View File

@@ -11,8 +11,10 @@ pub type Result<T> = result::Result<T, String>;
/// Create a new subcommand trait object to match `parsed.command`.
pub fn new(parsed: &TestCommand) -> Result<Box<SubTest>> {
use cat;
use print_cfg;
match parsed.command {
"cat" => cat::subtest(parsed),
"print-cfg" => print_cfg::subtest(parsed),
_ => Err(format!("unknown test command '{}'", parsed.command)),
}
}

View File

@@ -2,14 +2,17 @@
//!
//! Read a series of Cretonne IL files and print their control flow graphs
//! in graphviz format.
use std::borrow::Cow;
use std::fmt::{Result, Write, Display, Formatter};
use CommandResult;
use utils::read_to_string;
use filetest::subtest::{self, SubTest, Context, Result as STResult};
use cretonne::ir::Function;
use cretonne::cfg::ControlFlowGraph;
use cretonne::ir::instructions::BranchInfo;
use cton_reader::parse_functions;
use cton_reader::{parse_functions, TestCommand};
pub fn run(files: Vec<String>) -> CommandResult {
for (i, f) in files.into_iter().enumerate() {
@@ -100,3 +103,29 @@ fn print_cfg(filename: String) -> CommandResult {
Ok(())
}
/// Object implementing the `test print-cfg` sub-test.
struct TestPrintCfg;
pub fn subtest(parsed: &TestCommand) -> STResult<Box<SubTest>> {
assert_eq!(parsed.command, "print-cfg");
if !parsed.options.is_empty() {
Err(format!("No options allowed on {}", parsed))
} else {
Ok(Box::new(TestPrintCfg))
}
}
impl SubTest for TestPrintCfg {
fn name(&self) -> Cow<str> {
Cow::from("print-cfg")
}
fn needs_verifier(&self) -> bool {
false
}
fn run(&self, func: Cow<Function>, context: &Context) -> STResult<()> {
subtest::run_filecheck(&CFGPrinter::new(&func).to_string(), context)
}
}

View File

@@ -62,9 +62,4 @@ cd "$topdir"
banner "File tests"
"$CTONUTIL" test filetests
# Run the parser tests.
cd "$topdir/tests"
banner "CFG tests"
cfg/run.sh
banner "OK"

View File

@@ -1,14 +0,0 @@
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.

View File

@@ -1,36 +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 cfg -name '*.cton'); do
if "${CTONUTIL}" print-cfg "$testcase" | "${CTONUTIL}" filecheck "$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