diff --git a/cranelift/docs/testing.rst b/cranelift/docs/testing.rst index edc8ee6570..6df29d6fd1 100644 --- a/cranelift/docs/testing.rst +++ b/cranelift/docs/testing.rst @@ -352,3 +352,14 @@ Test the simple GVN pass. The simple GVN pass is run on each function, and then results are run through filecheck. + +`test compile` +-------------- + +Test the whole code generation pipeline. + +Each function is passed through the full ``Context::compile()`` function +which is normally used to compile code. This type of test often depends +on assertions or verifier errors, but it is also possible to use +filecheck directives which will be matched against the final form of the +Cretonne IL right before binary machine code emission. diff --git a/cranelift/src/filetest/compile.rs b/cranelift/src/filetest/compile.rs index 3aaa0a6b8a..0e271b7db4 100644 --- a/cranelift/src/filetest/compile.rs +++ b/cranelift/src/filetest/compile.rs @@ -6,8 +6,9 @@ use cretonne::binemit; use cretonne::ir; use cretonne; use cton_reader::TestCommand; -use filetest::subtest::{SubTest, Context, Result}; +use filetest::subtest::{SubTest, Context, Result, run_filecheck}; use std::borrow::Cow; +use std::fmt::Write; use utils::pretty_error; struct TestCompile; @@ -51,7 +52,7 @@ impl SubTest for TestCompile { comp_ctx.func.display(isa) ); - // Finally verify that the returned code size matches the emitted bytes. + // Verify that the returned code size matches the emitted bytes. let mut sink = SizeSink { offset: 0 }; binemit::emit_function( &comp_ctx.func, @@ -67,7 +68,11 @@ impl SubTest for TestCompile { )); } - Ok(()) + // Run final code through filecheck. + let mut text = String::new(); + write!(&mut text, "{}", &comp_ctx.func.display(Some(isa))) + .map_err(|e| e.to_string())?; + run_filecheck(&text, context) } }