diff options
| author | Pietro Albini <pietro.albini@ferrous-systems.com> | 2023-06-07 16:39:47 +0200 |
|---|---|---|
| committer | Pietro Albini <pietro.albini@ferrous-systems.com> | 2023-06-12 09:34:14 +0200 |
| commit | a4e8904ce8a3de49cd211123ed24c44b45711705 (patch) | |
| tree | 7099f392c768d8f0e5b022d1094011406a8b1eb6 | |
| parent | 6fd0d1ba149a7049f2acb78ed4a93570ce36e3e4 (diff) | |
| download | rust-a4e8904ce8a3de49cd211123ed24c44b45711705.tar.gz rust-a4e8904ce8a3de49cd211123ed24c44b45711705.zip | |
add way to split mir-opt into panic=abort and panic=unwind
| -rw-r--r-- | src/tools/compiletest/src/common.rs | 11 | ||||
| -rw-r--r-- | src/tools/compiletest/src/runtest.rs | 17 | ||||
| -rw-r--r-- | src/tools/miropt-test-tools/src/lib.rs | 53 | ||||
| -rw-r--r-- | src/tools/tidy/src/mir_opt_tests.rs | 7 |
4 files changed, 68 insertions, 20 deletions
diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 96fe720630c..1b46c42fa4c 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -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 { diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 6582b534488..7c6668b1c5d 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -3565,6 +3565,7 @@ impl<'test> TestCx<'test> { 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 @@ impl<'test> TestCx<'test> { } 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 @@ impl<'test> TestCx<'test> { 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 diff --git a/src/tools/miropt-test-tools/src/lib.rs b/src/tools/miropt-test-tools/src/lib.rs index f86c3ce0afe..e33ecfe8eab 100644 --- a/src/tools/miropt-test-tools/src/lib.rs +++ b/src/tools/miropt-test-tools/src/lib.rs @@ -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; diff --git a/src/tools/tidy/src/mir_opt_tests.rs b/src/tools/tidy/src/mir_opt_tests.rs index 2f6918510e8..c307bcb9390 100644 --- a/src/tools/tidy/src/mir_opt_tests.rs +++ b/src/tools/tidy/src/mir_opt_tests.rs @@ -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,8 +25,10 @@ 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) { - output_files.remove(&output_file.expected_file); + 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); + } } } } |
