Add feature flags to test files.
Cranelift can be compiled with feature flags which can change its output. To accomodate changes of output related to feature flags, test file can now include `feature "..."` and `feature ! "..."` directives in the preamble of the test file. The test runner would skip the test if the flag does not match the expectation of the test case.
This commit is contained in:
committed by
Nicolas B. Pierron
parent
26efc696c6
commit
04b10b3fde
@@ -20,3 +20,6 @@ log = "0.4.6"
|
||||
memmap = "0.7.0"
|
||||
num_cpus = "1.8.0"
|
||||
region = "2.1.2"
|
||||
|
||||
[features]
|
||||
basic-blocks = []
|
||||
|
||||
@@ -8,8 +8,7 @@ use cranelift_codegen::print_errors::pretty_verifier_error;
|
||||
use cranelift_codegen::settings::Flags;
|
||||
use cranelift_codegen::timing;
|
||||
use cranelift_codegen::verify_function;
|
||||
use cranelift_reader::IsaSpec;
|
||||
use cranelift_reader::{parse_test, ParseOptions};
|
||||
use cranelift_reader::{parse_test, Feature, IsaSpec, ParseOptions};
|
||||
use log::info;
|
||||
use std::borrow::Cow;
|
||||
use std::fs;
|
||||
@@ -53,6 +52,31 @@ pub fn run(path: &Path, passes: Option<&[String]>, target: Option<&str>) -> Test
|
||||
}
|
||||
};
|
||||
|
||||
for feature in testfile.features.iter() {
|
||||
let (flag, test_expect) = match feature {
|
||||
Feature::With(name) => (name, true),
|
||||
Feature::Without(name) => (name, false),
|
||||
};
|
||||
let cranelift_has = match flag {
|
||||
// Add any cranelift feature flag here, and make sure that it is forwarded to the
|
||||
// cranelift-filetest crate in the top-level Cargo.toml.
|
||||
&"basic-blocks" => cfg!(feature = "basic-blocks"),
|
||||
_ => {
|
||||
return Err(format!(
|
||||
r#"{:?}: Unknown feature flag named "{}""#,
|
||||
path, flag
|
||||
))
|
||||
}
|
||||
};
|
||||
if cranelift_has != test_expect {
|
||||
println!(
|
||||
r#"skipping test {:?}: non-matching feature flag "{}""#,
|
||||
path, flag
|
||||
);
|
||||
return Ok(started.elapsed());
|
||||
}
|
||||
}
|
||||
|
||||
if testfile.functions.is_empty() {
|
||||
return Err("no functions found".to_string());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user