From 7308f8f3cfbdaf13613278140d256e85ecc1c84c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 21 Jun 2022 22:24:18 -0700 Subject: [PATCH] ui_test: fix behavior of only-Nbits comments --- ui_test/src/comments.rs | 29 ++++++++++++++++++++++++---- ui_test/src/lib.rs | 42 ++++++++++++++++++----------------------- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/ui_test/src/comments.rs b/ui_test/src/comments.rs index cc9870a63be4..d50d6a534573 100644 --- a/ui_test/src/comments.rs +++ b/ui_test/src/comments.rs @@ -15,9 +15,9 @@ pub(crate) struct Comments { /// List of revision names to execute. Can only be speicified once pub revisions: Option>, /// Don't run this test if any of these filters apply - pub ignore: Vec, + pub ignore: Vec, /// Only run this test if all of these filters apply - pub only: Vec, + pub only: Vec, /// Generate one .stderr file per bit width, by prepending with `.64bit` and similar pub stderr_per_bitwidth: bool, /// Additional flags to pass to the executable @@ -31,6 +31,16 @@ pub(crate) struct Comments { pub error_matches: Vec, } + +/// The conditions used for "ignore" and "only" filters. +#[derive(Debug)] +pub(crate) enum Condition { + /// The given string must appear in the target. + Target(String), + /// Tests that the bitwidth is the given one. + Bitwidth(u8), +} + #[derive(Debug)] pub(crate) struct ErrorMatch { pub matched: String, @@ -42,6 +52,17 @@ pub(crate) struct ErrorMatch { pub line: usize, } +impl Condition { + fn parse(c: &str) -> Self { + 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"); + Condition::Bitwidth(bits) + } else { + Condition::Target(c.to_owned()) + } + } +} + impl Comments { pub(crate) fn parse_file(path: &Path) -> Self { let content = std::fs::read_to_string(path).unwrap(); @@ -75,14 +96,14 @@ impl Comments { .split_once(|c: char| c == ':' || c.is_whitespace()) .map(|(s, _)| s) .unwrap_or(s); - this.ignore.push(s.to_owned()); + this.ignore.push(Condition::parse(s)); } if let Some(s) = line.strip_prefix("// only-") { let s = s .split_once(|c: char| c == ':' || c.is_whitespace()) .map(|(s, _)| s) .unwrap_or(s); - this.only.push(s.to_owned()); + this.only.push(Condition::parse(s)); } if line.starts_with("// stderr-per-bitwidth") { assert!( diff --git a/ui_test/src/lib.rs b/ui_test/src/lib.rs index d6938b19bfe4..970622144680 100644 --- a/ui_test/src/lib.rs +++ b/ui_test/src/lib.rs @@ -10,7 +10,7 @@ use comments::ErrorMatch; use regex::Regex; use rustc_stderr::{Level, Message}; -use crate::comments::Comments; +use crate::comments::{Comments, Condition}; mod comments; mod rustc_stderr; @@ -103,7 +103,7 @@ pub fn run_tests(config: Config) { } let comments = Comments::parse_file(&path); // Ignore file if only/ignore rules do (not) apply - if ignore_file(&comments, &target) { + if !test_file_conditions(&comments, &target) { ignored.fetch_add(1, Ordering::Relaxed); eprintln!( "{} ... {}", @@ -509,42 +509,36 @@ fn check_output( fn output_path(path: &Path, comments: &Comments, kind: String, target: &str) -> PathBuf { if comments.stderr_per_bitwidth { - return path.with_extension(format!("{}.{kind}", get_pointer_width(target))); + return path.with_extension(format!("{}bit.{kind}", get_pointer_width(target))); } path.with_extension(kind) } -fn ignore_file(comments: &Comments, target: &str) -> bool { - for s in &comments.ignore { - if target.contains(s) { - return true; - } - if get_pointer_width(target) == s { - return true; - } +fn test_condition(condition: &Condition, target: &str) -> bool { + match condition { + Condition::Bitwidth(bits) => get_pointer_width(target) == *bits, + Condition::Target(t) => target.contains(t), } - for s in &comments.only { - if !target.contains(s) { - return true; - } - /* FIXME(https://github.com/rust-lang/miri/issues/2206) - if get_pointer_width(target) != s { - return true; - } */ +} + +/// 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)) { + return false; } - false + comments.only.iter().all(|c| test_condition(c, target)) } // Taken 1:1 from compiletest-rs -fn get_pointer_width(triple: &str) -> &'static str { +fn get_pointer_width(triple: &str) -> u8 { if (triple.contains("64") && !triple.ends_with("gnux32") && !triple.ends_with("gnu_ilp32")) || triple.starts_with("s390x") { - "64bit" + 64 } else if triple.starts_with("avr") { - "16bit" + 16 } else { - "32bit" + 32 } }