cranelift: Add heap support to filetest infrastructure (#3154)

* cranelift: Add heap support to filetest infrastructure

* cranelift: Explicit heap pointer placement in filetest annotations

* cranelift: Add documentation about the Heap directive

* cranelift: Clarify that heap filetests pointers must be laid out sequentially

* cranelift: Use wrapping add when computing bound pointer

* cranelift: Better error messages when invalid signatures are found for heap file tests.
This commit is contained in:
Afonso Bordado
2021-08-24 17:28:41 +01:00
committed by GitHub
parent 3f6b889067
commit f4ff7c350a
8 changed files with 631 additions and 5 deletions

View File

@@ -3,8 +3,10 @@
//! The `run` test command compiles each function on the host machine and executes it
use crate::function_runner::SingleFunctionCompiler;
use crate::runtest_environment::RuntestEnvironment;
use crate::subtest::{Context, SubTest};
use cranelift_codegen::ir;
use cranelift_codegen::ir::ArgumentPurpose;
use cranelift_reader::parse_run_command;
use cranelift_reader::TestCommand;
use log::trace;
@@ -48,6 +50,8 @@ impl SubTest for TestRun {
}
let variant = context.isa.unwrap().variant();
let test_env = RuntestEnvironment::parse(&context.details.comments[..])?;
let mut compiler = SingleFunctionCompiler::with_host_isa(context.flags.clone(), variant);
for comment in context.details.comments.iter() {
if let Some(command) = parse_run_command(comment.text, &func.signature)? {
@@ -60,7 +64,31 @@ impl SubTest for TestRun {
// running x86_64 code on aarch64 platforms.
let compiled_fn = compiler.compile(func.clone().into_owned())?;
command
.run(|_, args| Ok(compiled_fn.call(args)))
.run(|_, run_args| {
let runtime_struct = test_env.runtime_struct();
let first_arg_is_vmctx = func
.signature
.params
.first()
.map(|p| p.purpose == ArgumentPurpose::VMContext)
.unwrap_or(false);
if !first_arg_is_vmctx && test_env.is_active() {
return Err(concat!(
"This test requests a heap, but the first argument is not `i64 vmctx`.\n",
"See docs/testing.md for more info on using heap annotations."
).to_string());
}
let mut args = Vec::with_capacity(run_args.len());
if test_env.is_active() {
args.push(runtime_struct.pointer(context.isa.unwrap().pointer_type()));
}
args.extend_from_slice(run_args);
Ok(compiled_fn.call(&args))
})
.map_err(|s| anyhow::anyhow!("{}", s))?;
}
}