ui_test: fix behavior of only-Nbits comments

This commit is contained in:
Ralf Jung 2022-06-21 22:24:18 -07:00
parent 7a1b08e46e
commit 7308f8f3cf
2 changed files with 43 additions and 28 deletions

View File

@ -15,9 +15,9 @@ pub(crate) struct Comments {
/// List of revision names to execute. Can only be speicified once
pub revisions: Option<Vec<String>>,
/// Don't run this test if any of these filters apply
pub ignore: Vec<String>,
pub ignore: Vec<Condition>,
/// Only run this test if all of these filters apply
pub only: Vec<String>,
pub only: Vec<Condition>,
/// 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<ErrorMatch>,
}
/// 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 @@ pub(crate) fn parse(path: &Path, content: &str) -> Self {
.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!(

View File

@ -10,7 +10,7 @@
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
}
}