Add test flag for running a test only on the host

This commit is contained in:
Oli Scherer 2022-07-17 07:56:57 +00:00
parent 43100f5f4b
commit 444841bba9
3 changed files with 14 additions and 5 deletions

View File

@ -25,8 +25,10 @@ their command specifies, or the test will fail without even being run.
* `//@ignore-XXX` avoids running the test on targets whose triple contains `XXX`
* `XXX` can also be one of `64bit`, `32bit` or `16bit`
* `XXX` can also be `on-host`, which will only run the test during cross compilation testing.
* `//@only-XXX` avoids running the test on targets whose triple **does not** contain `XXX`
* `XXX` can also be one of `64bit`, `32bit` or `16bit`
* `XXX` can also be `on-host`, which will not run the test during cross compilation testing
* `//@stderr-per-bitwidth` produces one stderr file per bitwidth, as they may differ significantly sometimes
* `//@error-pattern: XXX` make sure the stderr output contains `XXX`
* `//@revisions: XXX YYY` runs the test once for each space separated name in the list

View File

@ -109,7 +109,7 @@ pub fn run_tests(config: Config) -> Result<()> {
}
let comments = Comments::parse_file(&path)?;
// Ignore file if only/ignore rules do (not) apply
if !test_file_conditions(&comments, &target) {
if !test_file_conditions(&comments, &target, &config) {
ignored.fetch_add(1, Ordering::Relaxed);
eprintln!(
"{} ... {}",
@ -499,19 +499,20 @@ fn output_path(path: &Path, comments: &Comments, kind: String, target: &str) ->
path.with_extension(kind)
}
fn test_condition(condition: &Condition, target: &str) -> bool {
fn test_condition(condition: &Condition, target: &str, config: &Config) -> bool {
match condition {
Condition::Bitwidth(bits) => get_pointer_width(target) == *bits,
Condition::Target(t) => target.contains(t),
Condition::OnHost => config.target.is_none(),
}
}
/// Returns whether according to the in-file conditions, this file should be run.
fn test_file_conditions(comments: &Comments, target: &str) -> bool {
if comments.ignore.iter().any(|c| test_condition(c, target)) {
fn test_file_conditions(comments: &Comments, target: &str, config: &Config) -> bool {
if comments.ignore.iter().any(|c| test_condition(c, target, config)) {
return false;
}
comments.only.iter().all(|c| test_condition(c, target))
comments.only.iter().all(|c| test_condition(c, target, config))
}
// Taken 1:1 from compiletest-rs

View File

@ -43,6 +43,8 @@ pub(crate) enum Condition {
Target(String),
/// Tests that the bitwidth is the given one.
Bitwidth(u8),
/// Tests that the target is the host.
OnHost,
}
#[derive(Debug, Clone)]
@ -64,6 +66,10 @@ pub(crate) struct ErrorMatch {
impl Condition {
fn parse(c: &str) -> Self {
match c {
"on-host" => return Condition::OnHost,
_ => {}
}
if let Some(bits) = c.strip_suffix("bit") {
let bits: u8 = bits.parse().expect(
"ignore/only filter ending in 'bit' must be of the form 'Nbit' for some integer N",