-
Notifications
You must be signed in to change notification settings - Fork 306
intrinsic-test: Coalescing all intrinsic tests into a single run of the test-file binaries
#1952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
5ac2233
3ccbb94
fd1c9c5
3c30d91
290c761
4c4cefd
76067f7
4153c4e
c94fd76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| use super::cli::FailureReason; | ||
| use itertools::Itertools; | ||
| use rayon::prelude::*; | ||
| use std::process::Command; | ||
| use std::{collections::HashMap, process::Command}; | ||
|
|
||
| fn runner_command(runner: &str) -> Command { | ||
| let mut it = runner.split_whitespace(); | ||
|
|
@@ -11,85 +11,103 @@ fn runner_command(runner: &str) -> Command { | |
| } | ||
|
|
||
| pub fn compare_outputs(intrinsic_name_list: &Vec<String>, runner: &str, target: &str) -> bool { | ||
| let intrinsics = intrinsic_name_list | ||
| .par_iter() | ||
| .filter_map(|intrinsic_name| { | ||
| let c = runner_command(runner) | ||
| let (c, rust) = rayon::join( | ||
| || { | ||
| runner_command(runner) | ||
| .arg("./intrinsic-test-programs") | ||
| .arg(intrinsic_name) | ||
| .current_dir("c_programs") | ||
| .output(); | ||
|
|
||
| let rust = runner_command(runner) | ||
| .output() | ||
| }, | ||
| || { | ||
| runner_command(runner) | ||
| .arg(format!("./target/{target}/release/intrinsic-test-programs")) | ||
| .arg(intrinsic_name) | ||
| .current_dir("rust_programs") | ||
| .output(); | ||
|
|
||
| let (c, rust) = match (c, rust) { | ||
| (Ok(c), Ok(rust)) => (c, rust), | ||
| a => panic!("{a:#?}"), | ||
| }; | ||
| .output() | ||
| }, | ||
| ); | ||
| let (c, rust) = match (c, rust) { | ||
| (Ok(c), Ok(rust)) => (c, rust), | ||
| a => panic!("{a:#?}"), | ||
|
||
| }; | ||
|
|
||
| if !c.status.success() { | ||
| error!( | ||
| "Failed to run C program for intrinsic `{intrinsic_name}`\nstdout: {stdout}\nstderr: {stderr}", | ||
| stdout = std::str::from_utf8(&c.stdout).unwrap_or(""), | ||
| stderr = std::str::from_utf8(&c.stderr).unwrap_or(""), | ||
| ); | ||
| return Some(FailureReason::RunC(intrinsic_name.clone())); | ||
| } | ||
| if !c.status.success() { | ||
| error!( | ||
| "Failed to run C program.\nstdout: {stdout}\nstderr: {stderr}", | ||
| stdout = std::str::from_utf8(&c.stdout).unwrap_or(""), | ||
| stderr = std::str::from_utf8(&c.stderr).unwrap_or(""), | ||
| ); | ||
| } | ||
|
|
||
| if !rust.status.success() { | ||
| error!( | ||
| "Failed to run Rust program for intrinsic `{intrinsic_name}`\nstdout: {stdout}\nstderr: {stderr}", | ||
| stdout = std::str::from_utf8(&rust.stdout).unwrap_or(""), | ||
| stderr = std::str::from_utf8(&rust.stderr).unwrap_or(""), | ||
| ); | ||
| return Some(FailureReason::RunRust(intrinsic_name.clone())); | ||
| } | ||
| if !rust.status.success() { | ||
| error!( | ||
| "Failed to run Rust program.\nstdout: {stdout}\nstderr: {stderr}", | ||
| stdout = std::str::from_utf8(&rust.stdout).unwrap_or(""), | ||
| stderr = std::str::from_utf8(&rust.stderr).unwrap_or(""), | ||
| ); | ||
| } | ||
|
|
||
| info!("Comparing intrinsic: {intrinsic_name}"); | ||
| let c = std::str::from_utf8(&c.stdout) | ||
| .unwrap() | ||
| .to_lowercase() | ||
| .replace("-nan", "nan"); | ||
| let rust = std::str::from_utf8(&rust.stdout) | ||
| .unwrap() | ||
| .to_lowercase() | ||
| .replace("-nan", "nan"); | ||
|
|
||
| let c = std::str::from_utf8(&c.stdout) | ||
| .unwrap() | ||
| .to_lowercase() | ||
| .replace("-nan", "nan"); | ||
| let rust = std::str::from_utf8(&rust.stdout) | ||
| .unwrap() | ||
| .to_lowercase() | ||
| .replace("-nan", "nan"); | ||
| let c_output_map = c | ||
| .split("############") | ||
|
||
| .filter_map(|output| output.trim().split_once("\n")) | ||
| .collect::<HashMap<&str, &str>>(); | ||
| let rust_output_map = rust | ||
| .split("############") | ||
| .filter_map(|output| output.trim().split_once("\n")) | ||
| .collect::<HashMap<&str, &str>>(); | ||
|
|
||
| if c == rust { | ||
| let intrinsics = c_output_map | ||
| .keys() | ||
| .chain(rust_output_map.keys()) | ||
| .unique() | ||
| .collect_vec(); | ||
| let intrinsics_diff_count = intrinsics | ||
| .par_iter() | ||
| .filter_map(|&&intrinsic| { | ||
| let c_output = c_output_map.get(intrinsic).unwrap(); | ||
| let rust_output = rust_output_map.get(intrinsic).unwrap(); | ||
| if rust_output.to_string() == c_output.to_string() { | ||
| None | ||
| } else { | ||
| Some(FailureReason::Difference(intrinsic_name.clone(), c, rust)) | ||
| let diff = diff::lines(c_output, rust_output); | ||
| let diffs = diff | ||
| .into_iter() | ||
| .filter_map(|diff| match diff { | ||
| diff::Result::Left(_) | diff::Result::Right(_) => Some(diff), | ||
| diff::Result::Both(_, _) => None, | ||
| }) | ||
| .collect_vec(); | ||
| if diffs.len() > 0 { | ||
| Some((intrinsic, diffs)) | ||
| } else { | ||
| None | ||
| } | ||
| } | ||
| }) | ||
| .collect::<Vec<_>>(); | ||
|
|
||
| intrinsics.iter().for_each(|reason| match reason { | ||
| FailureReason::Difference(intrinsic, c, rust) => { | ||
| .inspect(|(intrinsic, diffs)| { | ||
| println!("Difference for intrinsic: {intrinsic}"); | ||
| let diff = diff::lines(c, rust); | ||
| diff.iter().for_each(|diff| match diff { | ||
| diffs.into_iter().for_each(|diff| match diff { | ||
| diff::Result::Left(c) => println!("C: {c}"), | ||
| diff::Result::Right(rust) => println!("Rust: {rust}"), | ||
| diff::Result::Both(_, _) => (), | ||
| _ => (), | ||
| }); | ||
| println!("****************************************************************"); | ||
| } | ||
| FailureReason::RunC(intrinsic) => { | ||
| println!("Failed to run C program for intrinsic {intrinsic}") | ||
| } | ||
| FailureReason::RunRust(intrinsic) => { | ||
| println!("Failed to run rust program for intrinsic {intrinsic}") | ||
| } | ||
| }); | ||
| }) | ||
| .count(); | ||
|
|
||
| println!( | ||
| "{} differences found (tested {} intrinsics)", | ||
| intrinsics.len(), | ||
| intrinsics_diff_count, | ||
| intrinsic_name_list.len() | ||
| ); | ||
| intrinsics.is_empty() | ||
|
|
||
| intrinsics_diff_count == 0 | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please adjust this so that it is not the longest CI job. I think the next-longest job is 11 minutes now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, let me dial it down to 20%.