summaryrefslogtreecommitdiffstats
path: root/src/tools/miropt-test-tools
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /src/tools/miropt-test-tools
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/miropt-test-tools')
-rw-r--r--src/tools/miropt-test-tools/src/lib.rs53
1 files changed, 44 insertions, 9 deletions
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<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;