From dc0db358abe19481e475e10c32149b53370f1a1c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 05:57:31 +0200 Subject: Merging upstream version 1.72.1+dfsg1. Signed-off-by: Daniel Baumann --- src/tools/miropt-test-tools/src/lib.rs | 53 ++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 9 deletions(-) (limited to 'src/tools/miropt-test-tools') diff --git a/src/tools/miropt-test-tools/src/lib.rs b/src/tools/miropt-test-tools/src/lib.rs index f86c3ce0a..e33ecfe8e 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, } -pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec { +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 { 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; -- cgit v1.2.3