Browse Source

TestFile preamble comments apply to all functions.

Include the test file preamble comments when building a filecheck
instance for every function in the file.

This makes it possible to define common regex variables in the preamble
and use these definitions for all the functions.
pull/3/head
Jakob Stoklund Olesen 8 years ago
parent
commit
a038279717
  1. 4
      docs/testing.rst
  2. 9
      filetests/isa/riscv/legalize-i64.cton
  3. 1
      src/filetest/runone.rs
  4. 17
      src/filetest/subtest.rs

4
docs/testing.rst

@ -150,6 +150,10 @@ use filecheck will extract comments associated with each function (or its
entities) and scan them for filecheck directives. The test output for each
function is then matched against the filecheck directives for that function.
Comments appearing before the first function in a file apply to every function.
This is useful for defining common regular expression variables with the
``regex:`` directive, for example.
Note that LLVM's file tests don't separate filecheck directives by their
associated function. It verifies the concatenated output against all filecheck
directives in the test file. LLVM's :command:`FileCheck` command has a

9
filetests/isa/riscv/legalize-i64.cton

@ -2,13 +2,14 @@
test legalizer
isa riscv supports_m=1
; regex: V=v\d+
; regex: VX=vx\d+
function bitwise_and(i64, i64) -> i64 {
ebb0(v1: i64, v2: i64):
v3 = band v1, v2
return v3
}
; regex: V=v\d+
; regex: VX=vx\d+
; check: $(v1l=$V), $(v1h=$VX) = isplit_lohi $v1
; check: $(v2l=$V), $(v2h=$VX) = isplit_lohi $v2
; check: [R#ec
@ -22,8 +23,6 @@ ebb0(v1: i64, v2: i64):
v3 = bor v1, v2
return v3
}
; regex: V=v\d+
; regex: VX=vx\d+
; check: $(v1l=$V), $(v1h=$VX) = isplit_lohi $v1
; check: $(v2l=$V), $(v2h=$VX) = isplit_lohi $v2
; check: [R#cc
@ -37,8 +36,6 @@ ebb0(v1: i64, v2: i64):
v3 = bxor v1, v2
return v3
}
; regex: V=v\d+
; regex: VX=vx\d+
; check: $(v1l=$V), $(v1h=$VX) = isplit_lohi $v1
; check: $(v2l=$V), $(v2h=$VX) = isplit_lohi $v2
; check: [R#8c

1
src/filetest/runone.rs

@ -50,6 +50,7 @@ pub fn run(path: &Path) -> TestResult {
for (func, details) in testfile.functions {
let mut context = Context {
preamble_comments: &testfile.preamble_comments,
details: details,
verified: false,
flags: flags,

17
src/filetest/subtest.rs

@ -5,13 +5,16 @@ use std::borrow::Cow;
use cretonne::ir::Function;
use cretonne::isa::TargetIsa;
use cretonne::settings::Flags;
use cton_reader::Details;
use cton_reader::{Details, Comment};
use filecheck::{self, CheckerBuilder, Checker, Value as FCValue};
pub type Result<T> = result::Result<T, String>;
/// Context for running a a test on a single function.
pub struct Context<'a> {
/// Comments from the preamble f the test file. These apply to all functions.
pub preamble_comments: &'a [Comment<'a>],
/// Additional details about the function from the parser.
pub details: Details<'a>,
@ -69,7 +72,7 @@ impl<'a> filecheck::VariableMap for Context<'a> {
/// Run filecheck on `text`, using directives extracted from `context`.
pub fn run_filecheck(text: &str, context: &Context) -> Result<()> {
let checker = try!(build_filechecker(&context.details));
let checker = try!(build_filechecker(context));
if try!(checker.check(&text, context).map_err(|e| format!("filecheck: {}", e))) {
Ok(())
} else {
@ -80,10 +83,14 @@ pub fn run_filecheck(text: &str, context: &Context) -> Result<()> {
}
}
/// Build a filechecker using the directives in the function's comments.
pub fn build_filechecker(details: &Details) -> Result<Checker> {
/// Build a filechecker using the directives in the file preamble and the function's comments.
pub fn build_filechecker(context: &Context) -> Result<Checker> {
let mut builder = CheckerBuilder::new();
for comment in &details.comments {
// Preamble comments apply to all functions.
for comment in context.preamble_comments {
try!(builder.directive(comment.text).map_err(|e| format!("filecheck: {}", e)));
}
for comment in &context.details.comments {
try!(builder.directive(comment.text).map_err(|e| format!("filecheck: {}", e)));
}
let checker = builder.finish();

Loading…
Cancel
Save