Auto merge of #2253 - RalfJung:only-bits, r=oli-obk
fix behavior of only-Nbits comments Fixes https://github.com/rust-lang/miri/issues/2206
This commit is contained in:
commit
f6641963af
@ -15,9 +15,9 @@ pub(crate) struct Comments {
|
|||||||
/// List of revision names to execute. Can only be speicified once
|
/// List of revision names to execute. Can only be speicified once
|
||||||
pub revisions: Option<Vec<String>>,
|
pub revisions: Option<Vec<String>>,
|
||||||
/// Don't run this test if any of these filters apply
|
/// 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
|
/// 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
|
/// Generate one .stderr file per bit width, by prepending with `.64bit` and similar
|
||||||
pub stderr_per_bitwidth: bool,
|
pub stderr_per_bitwidth: bool,
|
||||||
/// Additional flags to pass to the executable
|
/// Additional flags to pass to the executable
|
||||||
@ -31,6 +31,16 @@ pub(crate) struct Comments {
|
|||||||
pub error_matches: Vec<ErrorMatch>,
|
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)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct ErrorMatch {
|
pub(crate) struct ErrorMatch {
|
||||||
pub matched: String,
|
pub matched: String,
|
||||||
@ -42,6 +52,17 @@ pub(crate) struct ErrorMatch {
|
|||||||
pub line: usize,
|
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 {
|
impl Comments {
|
||||||
pub(crate) fn parse_file(path: &Path) -> Self {
|
pub(crate) fn parse_file(path: &Path) -> Self {
|
||||||
let content = std::fs::read_to_string(path).unwrap();
|
let content = std::fs::read_to_string(path).unwrap();
|
||||||
@ -75,14 +96,14 @@ impl Comments {
|
|||||||
.split_once(|c: char| c == ':' || c.is_whitespace())
|
.split_once(|c: char| c == ':' || c.is_whitespace())
|
||||||
.map(|(s, _)| s)
|
.map(|(s, _)| s)
|
||||||
.unwrap_or(s);
|
.unwrap_or(s);
|
||||||
this.ignore.push(s.to_owned());
|
this.ignore.push(Condition::parse(s));
|
||||||
}
|
}
|
||||||
if let Some(s) = line.strip_prefix("// only-") {
|
if let Some(s) = line.strip_prefix("// only-") {
|
||||||
let s = s
|
let s = s
|
||||||
.split_once(|c: char| c == ':' || c.is_whitespace())
|
.split_once(|c: char| c == ':' || c.is_whitespace())
|
||||||
.map(|(s, _)| s)
|
.map(|(s, _)| s)
|
||||||
.unwrap_or(s);
|
.unwrap_or(s);
|
||||||
this.only.push(s.to_owned());
|
this.only.push(Condition::parse(s));
|
||||||
}
|
}
|
||||||
if line.starts_with("// stderr-per-bitwidth") {
|
if line.starts_with("// stderr-per-bitwidth") {
|
||||||
assert!(
|
assert!(
|
||||||
|
@ -10,7 +10,7 @@ use comments::ErrorMatch;
|
|||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use rustc_stderr::{Level, Message};
|
use rustc_stderr::{Level, Message};
|
||||||
|
|
||||||
use crate::comments::Comments;
|
use crate::comments::{Comments, Condition};
|
||||||
|
|
||||||
mod comments;
|
mod comments;
|
||||||
mod rustc_stderr;
|
mod rustc_stderr;
|
||||||
@ -103,7 +103,7 @@ pub fn run_tests(config: Config) {
|
|||||||
}
|
}
|
||||||
let comments = Comments::parse_file(&path);
|
let comments = Comments::parse_file(&path);
|
||||||
// Ignore file if only/ignore rules do (not) apply
|
// 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);
|
ignored.fetch_add(1, Ordering::Relaxed);
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"{} ... {}",
|
"{} ... {}",
|
||||||
@ -509,42 +509,36 @@ fn check_output(
|
|||||||
|
|
||||||
fn output_path(path: &Path, comments: &Comments, kind: String, target: &str) -> PathBuf {
|
fn output_path(path: &Path, comments: &Comments, kind: String, target: &str) -> PathBuf {
|
||||||
if comments.stderr_per_bitwidth {
|
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)
|
path.with_extension(kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ignore_file(comments: &Comments, target: &str) -> bool {
|
fn test_condition(condition: &Condition, target: &str) -> bool {
|
||||||
for s in &comments.ignore {
|
match condition {
|
||||||
if target.contains(s) {
|
Condition::Bitwidth(bits) => get_pointer_width(target) == *bits,
|
||||||
return true;
|
Condition::Target(t) => target.contains(t),
|
||||||
}
|
|
||||||
if get_pointer_width(target) == s {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for s in &comments.only {
|
}
|
||||||
if !target.contains(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 {
|
||||||
/* FIXME(https://github.com/rust-lang/miri/issues/2206)
|
if comments.ignore.iter().any(|c| test_condition(c, target)) {
|
||||||
if get_pointer_width(target) != s {
|
return false;
|
||||||
return true;
|
|
||||||
} */
|
|
||||||
}
|
}
|
||||||
false
|
comments.only.iter().all(|c| test_condition(c, target))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Taken 1:1 from compiletest-rs
|
// 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"))
|
if (triple.contains("64") && !triple.ends_with("gnux32") && !triple.ends_with("gnu_ilp32"))
|
||||||
|| triple.starts_with("s390x")
|
|| triple.starts_with("s390x")
|
||||||
{
|
{
|
||||||
"64bit"
|
64
|
||||||
} else if triple.starts_with("avr") {
|
} else if triple.starts_with("avr") {
|
||||||
"16bit"
|
16
|
||||||
} else {
|
} else {
|
||||||
"32bit"
|
32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user