add way to split mir-opt into panic=abort and panic=unwind

This commit is contained in:
Pietro Albini 2023-06-07 16:39:47 +02:00
parent 6fd0d1ba14
commit a4e8904ce8
No known key found for this signature in database
GPG Key ID: CD76B35F7734769E
4 changed files with 68 additions and 20 deletions

View File

@ -131,6 +131,15 @@ pub enum PanicStrategy {
Abort,
}
impl PanicStrategy {
pub(crate) fn for_miropt_test_tools(&self) -> miropt_test_tools::PanicStrategy {
match self {
PanicStrategy::Unwind => miropt_test_tools::PanicStrategy::Unwind,
PanicStrategy::Abort => miropt_test_tools::PanicStrategy::Abort,
}
}
}
/// Configuration for compiletest
#[derive(Debug, Default, Clone)]
pub struct Config {
@ -572,7 +581,7 @@ pub struct TargetCfg {
#[serde(rename = "target-endian", default)]
endian: Endian,
#[serde(rename = "panic-strategy", default)]
panic: PanicStrategy,
pub(crate) panic: PanicStrategy,
}
impl TargetCfg {

View File

@ -3565,6 +3565,7 @@ fn get_passes(&self) -> Vec<String> {
let files = miropt_test_tools::files_for_miropt_test(
&self.testpaths.file,
self.config.get_pointer_width(),
self.config.target_cfg().panic.for_miropt_test_tools(),
);
let mut out = Vec::new();
@ -3582,25 +3583,24 @@ fn get_passes(&self) -> Vec<String> {
}
fn check_mir_dump(&self) {
let test_file_contents = fs::read_to_string(&self.testpaths.file).unwrap();
let test_dir = self.testpaths.file.parent().unwrap();
let test_crate =
self.testpaths.file.file_stem().unwrap().to_str().unwrap().replace("-", "_");
let mut bit_width = String::new();
if test_file_contents.lines().any(|l| l == "// EMIT_MIR_FOR_EACH_BIT_WIDTH") {
bit_width = format!(".{}bit", self.config.get_pointer_width());
}
let suffix = miropt_test_tools::output_file_suffix(
&self.testpaths.file,
self.config.get_pointer_width(),
self.config.target_cfg().panic.for_miropt_test_tools(),
);
if self.config.bless {
for e in
glob(&format!("{}/{}.*{}.mir", test_dir.display(), test_crate, bit_width)).unwrap()
glob(&format!("{}/{}.*{}.mir", test_dir.display(), test_crate, suffix)).unwrap()
{
std::fs::remove_file(e.unwrap()).unwrap();
}
for e in
glob(&format!("{}/{}.*{}.diff", test_dir.display(), test_crate, bit_width)).unwrap()
glob(&format!("{}/{}.*{}.diff", test_dir.display(), test_crate, suffix)).unwrap()
{
std::fs::remove_file(e.unwrap()).unwrap();
}
@ -3609,6 +3609,7 @@ fn check_mir_dump(&self) {
let files = miropt_test_tools::files_for_miropt_test(
&self.testpaths.file,
self.config.get_pointer_width(),
self.config.target_cfg().panic.for_miropt_test_tools(),
);
for miropt_test_tools::MiroptTestFiles { from_file, to_file, expected_file, passes: _ } in
files

View File

@ -1,4 +1,5 @@
use std::fs;
use std::path::Path;
pub struct MiroptTestFiles {
pub expected_file: std::path::PathBuf,
@ -8,18 +9,52 @@ pub struct MiroptTestFiles {
pub passes: Vec<String>,
}
pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<MiroptTestFiles> {
pub enum PanicStrategy {
Unwind,
Abort,
}
pub fn output_file_suffix(
testfile: &Path,
bit_width: u32,
panic_strategy: PanicStrategy,
) -> String {
let mut each_bit_width = false;
let mut each_panic_strategy = false;
for line in fs::read_to_string(testfile).unwrap().lines() {
if line == "// EMIT_MIR_FOR_EACH_BIT_WIDTH" {
each_bit_width = true;
}
if line == "// EMIT_MIR_FOR_EACH_PANIC_STRATEGY" {
each_panic_strategy = true;
}
}
let mut suffix = String::new();
if each_bit_width {
suffix.push_str(&format!(".{}bit", bit_width));
}
if each_panic_strategy {
match panic_strategy {
PanicStrategy::Unwind => suffix.push_str(".panic-unwind"),
PanicStrategy::Abort => suffix.push_str(".panic-abort"),
}
}
suffix
}
pub fn files_for_miropt_test(
testfile: &std::path::Path,
bit_width: u32,
panic_strategy: PanicStrategy,
) -> Vec<MiroptTestFiles> {
let mut out = Vec::new();
let test_file_contents = fs::read_to_string(&testfile).unwrap();
let test_dir = testfile.parent().unwrap();
let test_crate = testfile.file_stem().unwrap().to_str().unwrap().replace('-', "_");
let bit_width = if test_file_contents.lines().any(|l| l == "// EMIT_MIR_FOR_EACH_BIT_WIDTH") {
format!(".{}bit", bit_width)
} else {
String::new()
};
let suffix = output_file_suffix(testfile, bit_width, panic_strategy);
for l in test_file_contents.lines() {
if l.starts_with("// EMIT_MIR ") {
@ -37,7 +72,7 @@ pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<
passes.push(trimmed.split('.').last().unwrap().to_owned());
let test_against = format!("{}.after.mir", trimmed);
from_file = format!("{}.before.mir", trimmed);
expected_file = format!("{}{}.diff", trimmed, bit_width);
expected_file = format!("{}{}.diff", trimmed, suffix);
assert!(test_names.next().is_none(), "two mir pass names specified for MIR diff");
to_file = Some(test_against);
} else if let Some(first_pass) = test_names.next() {
@ -51,7 +86,7 @@ pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<
assert!(test_names.next().is_none(), "three mir pass names specified for MIR diff");
expected_file =
format!("{}{}.{}-{}.diff", test_name, bit_width, first_pass, second_pass);
format!("{}{}.{}-{}.diff", test_name, suffix, first_pass, second_pass);
let second_file = format!("{}.{}.mir", test_name, second_pass);
from_file = format!("{}.{}.mir", test_name, first_pass);
to_file = Some(second_file);
@ -64,7 +99,7 @@ pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<
let extension = cap.get(1).unwrap().as_str();
expected_file =
format!("{}{}{}", test_name.trim_end_matches(extension), bit_width, extension,);
format!("{}{}{}", test_name.trim_end_matches(extension), suffix, extension,);
from_file = test_name.to_string();
assert!(test_names.next().is_none(), "two mir pass names specified for MIR dump");
to_file = None;

View File

@ -1,5 +1,6 @@
//! Tidy check to ensure that mir opt directories do not have stale files or dashes in file names
use miropt_test_tools::PanicStrategy;
use std::collections::HashSet;
use std::path::{Path, PathBuf};
@ -24,11 +25,13 @@ fn check_unused_files(path: &Path, bless: bool, bad: &mut bool) {
for file in rs_files {
for bw in [32, 64] {
for output_file in miropt_test_tools::files_for_miropt_test(&file, bw) {
for ps in [PanicStrategy::Unwind, PanicStrategy::Abort] {
for output_file in miropt_test_tools::files_for_miropt_test(&file, bw, ps) {
output_files.remove(&output_file.expected_file);
}
}
}
}
for extra in output_files {
if !bless {