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:
Nicolas B. Pierron
2019-08-27 14:25:21 +02:00
committed by Nicolas B. Pierron
parent 26efc696c6
commit 04b10b3fde
7 changed files with 130 additions and 7 deletions

View File

@@ -5,7 +5,7 @@ use crate::isaspec;
use crate::lexer::{LexError, Lexer, LocatedError, LocatedToken, Token};
use crate::sourcemap::SourceMap;
use crate::testcommand::TestCommand;
use crate::testfile::{Comment, Details, TestFile};
use crate::testfile::{Comment, Details, Feature, TestFile};
use cranelift_codegen::entity::EntityRef;
use cranelift_codegen::ir;
use cranelift_codegen::ir::entities::AnyEntity;
@@ -82,6 +82,7 @@ pub fn parse_test<'a>(text: &'a str, options: ParseOptions<'a>) -> ParseResult<T
isa_spec = parser.parse_target_specs()?;
}
};
let features = parser.parse_cranelift_features()?;
// Decide between using the calling convention passed in the options or using the
// host's calling convention--if any tests are to be run on the host we should default to the
@@ -102,6 +103,7 @@ pub fn parse_test<'a>(text: &'a str, options: ParseOptions<'a>) -> ParseResult<T
Ok(TestFile {
commands,
isa_spec,
features,
preamble_comments,
functions,
})
@@ -948,6 +950,27 @@ impl<'a> Parser<'a> {
}
}
/// Parse a list of expected features that Cranelift should be compiled with, or without.
pub fn parse_cranelift_features(&mut self) -> ParseResult<Vec<Feature<'a>>> {
let mut list = Vec::new();
while self.token() == Some(Token::Identifier("feature")) {
self.consume();
let has = !self.optional(Token::Not);
match (self.token(), has) {
(Some(Token::String(flag)), true) => list.push(Feature::With(flag)),
(Some(Token::String(flag)), false) => list.push(Feature::Without(flag)),
(tok, _) => {
return err!(
self.loc,
format!("Expected feature flag string, got {:?}", tok)
)
}
}
self.consume();
}
Ok(list)
}
/// Parse a list of function definitions.
///
/// This is the top-level parse function matching the whole contents of a file.
@@ -2992,12 +3015,14 @@ mod tests {
#[test]
fn test_file() {
let tf = parse_test(
"; before
r#"; before
test cfg option=5
test verify
set enable_float=false
feature "foo"
feature !"bar"
; still preamble
function %comment() system_v {}",
function %comment() system_v {}"#,
ParseOptions::default(),
)
.unwrap();
@@ -3011,6 +3036,8 @@ mod tests {
}
_ => panic!("unexpected ISAs"),
}
assert_eq!(tf.features[0], Feature::With(&"foo"));
assert_eq!(tf.features[1], Feature::Without(&"bar"));
assert_eq!(tf.preamble_comments.len(), 2);
assert_eq!(tf.preamble_comments[0].text, "; before");
assert_eq!(tf.preamble_comments[1].text, "; still preamble");