add passes to miroptfiles struct and passed to -zdump-mir args
blessed new test
This commit is contained in:
parent
eb7a743421
commit
c19959f4c3
8 changed files with 176 additions and 114 deletions
|
|
@ -319,7 +319,8 @@ impl<'test> TestCx<'test> {
|
|||
|
||||
fn run_cfail_test(&self) {
|
||||
let pm = self.pass_mode();
|
||||
let proc_res = self.compile_test(WillExecute::No, self.should_emit_metadata(pm));
|
||||
let proc_res =
|
||||
self.compile_test(WillExecute::No, self.should_emit_metadata(pm), Vec::new());
|
||||
self.check_if_test_should_compile(&proc_res, pm);
|
||||
self.check_no_compiler_crash(&proc_res, self.props.should_ice);
|
||||
|
||||
|
|
@ -347,7 +348,7 @@ impl<'test> TestCx<'test> {
|
|||
fn run_rfail_test(&self) {
|
||||
let pm = self.pass_mode();
|
||||
let should_run = self.run_if_enabled();
|
||||
let proc_res = self.compile_test(should_run, self.should_emit_metadata(pm));
|
||||
let proc_res = self.compile_test(should_run, self.should_emit_metadata(pm), Vec::new());
|
||||
|
||||
if !proc_res.status.success() {
|
||||
self.fatal_proc_rec("compilation failed!", &proc_res);
|
||||
|
|
@ -395,7 +396,7 @@ impl<'test> TestCx<'test> {
|
|||
|
||||
fn run_cpass_test(&self) {
|
||||
let emit_metadata = self.should_emit_metadata(self.pass_mode());
|
||||
let proc_res = self.compile_test(WillExecute::No, emit_metadata);
|
||||
let proc_res = self.compile_test(WillExecute::No, emit_metadata, Vec::new());
|
||||
|
||||
if !proc_res.status.success() {
|
||||
self.fatal_proc_rec("compilation failed!", &proc_res);
|
||||
|
|
@ -410,7 +411,7 @@ impl<'test> TestCx<'test> {
|
|||
fn run_rpass_test(&self) {
|
||||
let emit_metadata = self.should_emit_metadata(self.pass_mode());
|
||||
let should_run = self.run_if_enabled();
|
||||
let proc_res = self.compile_test(should_run, emit_metadata);
|
||||
let proc_res = self.compile_test(should_run, emit_metadata, Vec::new());
|
||||
|
||||
if !proc_res.status.success() {
|
||||
self.fatal_proc_rec("compilation failed!", &proc_res);
|
||||
|
|
@ -440,7 +441,7 @@ impl<'test> TestCx<'test> {
|
|||
}
|
||||
|
||||
let should_run = self.run_if_enabled();
|
||||
let mut proc_res = self.compile_test(should_run, Emit::None);
|
||||
let mut proc_res = self.compile_test(should_run, Emit::None, Vec::new());
|
||||
|
||||
if !proc_res.status.success() {
|
||||
self.fatal_proc_rec("compilation failed!", &proc_res);
|
||||
|
|
@ -686,7 +687,7 @@ impl<'test> TestCx<'test> {
|
|||
|
||||
// compile test file (it should have 'compile-flags:-g' in the header)
|
||||
let should_run = self.run_if_enabled();
|
||||
let compile_result = self.compile_test(should_run, Emit::None);
|
||||
let compile_result = self.compile_test(should_run, Emit::None, Vec::new());
|
||||
if !compile_result.status.success() {
|
||||
self.fatal_proc_rec("compilation failed!", &compile_result);
|
||||
}
|
||||
|
|
@ -806,7 +807,7 @@ impl<'test> TestCx<'test> {
|
|||
|
||||
// compile test file (it should have 'compile-flags:-g' in the header)
|
||||
let should_run = self.run_if_enabled();
|
||||
let compiler_run_result = self.compile_test(should_run, Emit::None);
|
||||
let compiler_run_result = self.compile_test(should_run, Emit::None, Vec::new());
|
||||
if !compiler_run_result.status.success() {
|
||||
self.fatal_proc_rec("compilation failed!", &compiler_run_result);
|
||||
}
|
||||
|
|
@ -1043,7 +1044,7 @@ impl<'test> TestCx<'test> {
|
|||
fn run_debuginfo_lldb_test_no_opt(&self) {
|
||||
// compile test file (it should have 'compile-flags:-g' in the header)
|
||||
let should_run = self.run_if_enabled();
|
||||
let compile_result = self.compile_test(should_run, Emit::None);
|
||||
let compile_result = self.compile_test(should_run, Emit::None, Vec::new());
|
||||
if !compile_result.status.success() {
|
||||
self.fatal_proc_rec("compilation failed!", &compile_result);
|
||||
}
|
||||
|
|
@ -1482,8 +1483,8 @@ impl<'test> TestCx<'test> {
|
|||
}
|
||||
}
|
||||
|
||||
fn compile_test(&self, will_execute: WillExecute, emit: Emit) -> ProcRes {
|
||||
self.compile_test_general(will_execute, emit, self.props.local_pass_mode())
|
||||
fn compile_test(&self, will_execute: WillExecute, emit: Emit, passes: Vec<String>) -> ProcRes {
|
||||
self.compile_test_general(will_execute, emit, self.props.local_pass_mode(), passes)
|
||||
}
|
||||
|
||||
fn compile_test_general(
|
||||
|
|
@ -1491,6 +1492,7 @@ impl<'test> TestCx<'test> {
|
|||
will_execute: WillExecute,
|
||||
emit: Emit,
|
||||
local_pm: Option<PassMode>,
|
||||
passes: Vec<String>,
|
||||
) -> ProcRes {
|
||||
// Only use `make_exe_name` when the test ends up being executed.
|
||||
let output_file = match will_execute {
|
||||
|
|
@ -1527,6 +1529,7 @@ impl<'test> TestCx<'test> {
|
|||
emit,
|
||||
allow_unused,
|
||||
LinkToAux::Yes,
|
||||
passes,
|
||||
);
|
||||
|
||||
self.compose_and_run_compiler(rustc, None)
|
||||
|
|
@ -1777,6 +1780,7 @@ impl<'test> TestCx<'test> {
|
|||
Emit::None,
|
||||
AllowUnused::No,
|
||||
LinkToAux::No,
|
||||
Vec::new(),
|
||||
);
|
||||
|
||||
for key in &aux_props.unset_rustc_env {
|
||||
|
|
@ -1908,6 +1912,7 @@ impl<'test> TestCx<'test> {
|
|||
emit: Emit,
|
||||
allow_unused: AllowUnused,
|
||||
link_to_aux: LinkToAux,
|
||||
passes: Vec<String>, // Vec of passes under mir-opt test to be dumped
|
||||
) -> Command {
|
||||
let is_aux = input_file.components().map(|c| c.as_os_str()).any(|c| c == "auxiliary");
|
||||
let is_rustdoc = self.is_rustdoc() && !is_aux;
|
||||
|
|
@ -2008,9 +2013,18 @@ impl<'test> TestCx<'test> {
|
|||
rustc.arg("-Cstrip=debuginfo");
|
||||
}
|
||||
MirOpt => {
|
||||
// We check passes under test to minimize the mir-opt test dump
|
||||
// if files_for_miropt_test parses the passes, we dump only those passes
|
||||
// otherwise we conservatively pass -Zdump-mir=all
|
||||
let zdump_arg = if !passes.is_empty() {
|
||||
format!("-Zdump-mir={}", passes.join(" | "))
|
||||
} else {
|
||||
"-Zdump-mir=all".to_string()
|
||||
};
|
||||
|
||||
rustc.args(&[
|
||||
"-Copt-level=1",
|
||||
"-Zdump-mir=all",
|
||||
&zdump_arg,
|
||||
"-Zvalidate-mir",
|
||||
"-Zdump-mir-exclude-pass-number",
|
||||
"-Zmir-pretty-relative-line-numbers=yes",
|
||||
|
|
@ -2333,6 +2347,7 @@ impl<'test> TestCx<'test> {
|
|||
Emit::LlvmIr,
|
||||
AllowUnused::No,
|
||||
LinkToAux::Yes,
|
||||
Vec::new(),
|
||||
);
|
||||
|
||||
self.compose_and_run_compiler(rustc, None)
|
||||
|
|
@ -2364,8 +2379,14 @@ impl<'test> TestCx<'test> {
|
|||
None => self.fatal("missing 'assembly-output' header"),
|
||||
}
|
||||
|
||||
let rustc =
|
||||
self.make_compile_args(input_file, output_file, emit, AllowUnused::No, LinkToAux::Yes);
|
||||
let rustc = self.make_compile_args(
|
||||
input_file,
|
||||
output_file,
|
||||
emit,
|
||||
AllowUnused::No,
|
||||
LinkToAux::Yes,
|
||||
Vec::new(),
|
||||
);
|
||||
|
||||
(self.compose_and_run_compiler(rustc, None), output_path)
|
||||
}
|
||||
|
|
@ -2496,6 +2517,7 @@ impl<'test> TestCx<'test> {
|
|||
Emit::None,
|
||||
AllowUnused::Yes,
|
||||
LinkToAux::Yes,
|
||||
Vec::new(),
|
||||
);
|
||||
new_rustdoc.build_all_auxiliary(&mut rustc);
|
||||
|
||||
|
|
@ -2769,7 +2791,7 @@ impl<'test> TestCx<'test> {
|
|||
fn run_codegen_units_test(&self) {
|
||||
assert!(self.revision.is_none(), "revisions not relevant here");
|
||||
|
||||
let proc_res = self.compile_test(WillExecute::No, Emit::None);
|
||||
let proc_res = self.compile_test(WillExecute::No, Emit::None, Vec::new());
|
||||
|
||||
if !proc_res.status.success() {
|
||||
self.fatal_proc_rec("compilation failed!", &proc_res);
|
||||
|
|
@ -3310,14 +3332,15 @@ impl<'test> TestCx<'test> {
|
|||
if let Some(FailMode::Build) = self.props.fail_mode {
|
||||
// Make sure a build-fail test cannot fail due to failing analysis (e.g. typeck).
|
||||
let pm = Some(PassMode::Check);
|
||||
let proc_res = self.compile_test_general(WillExecute::No, Emit::Metadata, pm);
|
||||
let proc_res =
|
||||
self.compile_test_general(WillExecute::No, Emit::Metadata, pm, Vec::new());
|
||||
self.check_if_test_should_compile(&proc_res, pm);
|
||||
}
|
||||
|
||||
let pm = self.pass_mode();
|
||||
let should_run = self.should_run(pm);
|
||||
let emit_metadata = self.should_emit_metadata(pm);
|
||||
let proc_res = self.compile_test(should_run, emit_metadata);
|
||||
let proc_res = self.compile_test(should_run, emit_metadata, Vec::new());
|
||||
self.check_if_test_should_compile(&proc_res, pm);
|
||||
|
||||
// if the user specified a format in the ui test
|
||||
|
|
@ -3479,6 +3502,7 @@ impl<'test> TestCx<'test> {
|
|||
emit_metadata,
|
||||
AllowUnused::No,
|
||||
LinkToAux::Yes,
|
||||
Vec::new(),
|
||||
);
|
||||
let res = self.compose_and_run_compiler(rustc, None);
|
||||
if !res.status.success() {
|
||||
|
|
@ -3497,14 +3521,14 @@ impl<'test> TestCx<'test> {
|
|||
let pm = self.pass_mode();
|
||||
let should_run = self.should_run(pm);
|
||||
let emit_metadata = self.should_emit_metadata(pm);
|
||||
let proc_res = self.compile_test(should_run, emit_metadata);
|
||||
let passes = self.get_passes();
|
||||
|
||||
let proc_res = self.compile_test(should_run, emit_metadata, passes);
|
||||
self.check_mir_dump();
|
||||
if !proc_res.status.success() {
|
||||
self.fatal_proc_rec("compilation failed!", &proc_res);
|
||||
}
|
||||
|
||||
self.check_mir_dump();
|
||||
|
||||
if let WillExecute::Yes = should_run {
|
||||
let proc_res = self.exec_compiled_test();
|
||||
|
||||
|
|
@ -3514,6 +3538,26 @@ impl<'test> TestCx<'test> {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_passes(&self) -> Vec<String> {
|
||||
let files = miropt_test_tools::files_for_miropt_test(
|
||||
&self.testpaths.file,
|
||||
self.config.get_pointer_width(),
|
||||
);
|
||||
|
||||
let mut out = Vec::new();
|
||||
|
||||
for miropt_test_tools::MiroptTestFiles {
|
||||
from_file: _,
|
||||
to_file: _,
|
||||
expected_file: _,
|
||||
passes,
|
||||
} in files
|
||||
{
|
||||
out.extend(passes);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
fn check_mir_dump(&self) {
|
||||
let test_file_contents = fs::read_to_string(&self.testpaths.file).unwrap();
|
||||
|
||||
|
|
@ -3543,8 +3587,9 @@ impl<'test> TestCx<'test> {
|
|||
&self.testpaths.file,
|
||||
self.config.get_pointer_width(),
|
||||
);
|
||||
|
||||
for miropt_test_tools::MiroptTestFiles { from_file, to_file, expected_file } in files {
|
||||
for miropt_test_tools::MiroptTestFiles { from_file, to_file, expected_file, passes: _ } in
|
||||
files
|
||||
{
|
||||
let dumped_string = if let Some(after) = to_file {
|
||||
self.diff_mir_files(from_file.into(), after.into())
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ pub struct MiroptTestFiles {
|
|||
pub expected_file: std::path::PathBuf,
|
||||
pub from_file: String,
|
||||
pub to_file: Option<String>,
|
||||
/// Vec of passes under test to be dumped
|
||||
pub passes: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<MiroptTestFiles> {
|
||||
|
|
@ -28,9 +30,11 @@ pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<
|
|||
let mut expected_file;
|
||||
let from_file;
|
||||
let to_file;
|
||||
let mut passes = Vec::new();
|
||||
|
||||
if test_name.ends_with(".diff") {
|
||||
let trimmed = test_name.trim_end_matches(".diff");
|
||||
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);
|
||||
|
|
@ -38,7 +42,14 @@ pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<
|
|||
to_file = Some(test_against);
|
||||
} else if let Some(first_pass) = test_names.next() {
|
||||
let second_pass = test_names.next().unwrap();
|
||||
if let Some((first_pass_name, _)) = first_pass.split_once('.') {
|
||||
passes.push(first_pass_name.to_owned());
|
||||
}
|
||||
if let Some((second_pass_name, _)) = second_pass.split_once('.') {
|
||||
passes.push(second_pass_name.to_owned());
|
||||
}
|
||||
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);
|
||||
let second_file = format!("{}.{}.mir", test_name, second_pass);
|
||||
|
|
@ -51,18 +62,24 @@ pub fn files_for_miropt_test(testfile: &std::path::Path, bit_width: u32) -> Vec<
|
|||
.next()
|
||||
.expect("test_name has an invalid extension");
|
||||
let extension = cap.get(1).unwrap().as_str();
|
||||
|
||||
expected_file =
|
||||
format!("{}{}{}", test_name.trim_end_matches(extension), bit_width, extension,);
|
||||
from_file = test_name.to_string();
|
||||
assert!(test_names.next().is_none(), "two mir pass names specified for MIR dump");
|
||||
to_file = None;
|
||||
// the pass name is the third to last string in the test name
|
||||
// this gets pushed into passes
|
||||
passes.push(
|
||||
test_name.split('.').rev().nth(2).expect("invalid test format").to_string(),
|
||||
);
|
||||
};
|
||||
if !expected_file.starts_with(&test_crate) {
|
||||
expected_file = format!("{}.{}", test_crate, expected_file);
|
||||
}
|
||||
let expected_file = test_dir.join(expected_file);
|
||||
|
||||
out.push(MiroptTestFiles { expected_file, from_file, to_file });
|
||||
out.push(MiroptTestFiles { expected_file, from_file, to_file, passes });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue