Skip to content

intrinsic-test: use runner also for rust #1852

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/intrinsic-test/src/arm/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ pub const AARCH_CONFIGURATIONS: &str = r#"
#![cfg_attr(any(target_arch = "aarch64", target_arch = "arm64ec"), feature(stdarch_neon_fcma))]
#![cfg_attr(any(target_arch = "aarch64", target_arch = "arm64ec"), feature(stdarch_neon_dotprod))]
#![cfg_attr(any(target_arch = "aarch64", target_arch = "arm64ec"), feature(stdarch_neon_i8mm))]
#![cfg_attr(any(target_arch = "aarch64", target_arch = "arm64ec"), feature(stdarch_neon_sha3))]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this target feature has been stable for some time, and was generating warning spam.

#![cfg_attr(any(target_arch = "aarch64", target_arch = "arm64ec"), feature(stdarch_neon_sm4))]
#![cfg_attr(any(target_arch = "aarch64", target_arch = "arm64ec"), feature(stdarch_neon_ftts))]
#![feature(fmt_helpers_for_derive)]
Expand Down
5 changes: 2 additions & 3 deletions crates/intrinsic-test/src/arm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
}

fn compare_outputs(&self) -> bool {
if let Some(ref toolchain) = self.cli_options.toolchain {
if self.cli_options.toolchain.is_some() {
let intrinsics_name_list = self
.intrinsics
.iter()
Expand All @@ -113,8 +113,7 @@ impl SupportedArchitectureTest for ArmArchitectureTest {

compare_outputs(
&intrinsics_name_list,
toolchain,
&self.cli_options.c_runner,
&self.cli_options.runner,
&self.cli_options.target,
)
} else {
Expand Down
6 changes: 3 additions & 3 deletions crates/intrinsic-test/src/common/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct ProcessedCli {
pub filename: PathBuf,
pub toolchain: Option<String>,
pub cpp_compiler: Option<String>,
pub c_runner: String,
pub runner: String,
pub target: String,
pub linker: Option<String>,
pub cxx_toolchain_dir: Option<String>,
Expand All @@ -70,7 +70,7 @@ pub struct ProcessedCli {
impl ProcessedCli {
pub fn new(cli_options: Cli) -> Self {
let filename = cli_options.input;
let c_runner = cli_options.runner.unwrap_or_default();
let runner = cli_options.runner.unwrap_or_default();
let target = cli_options.target;
let linker = cli_options.linker;
let cxx_toolchain_dir = cli_options.cxx_toolchain_dir;
Expand Down Expand Up @@ -102,7 +102,7 @@ impl ProcessedCli {
Self {
toolchain,
cpp_compiler,
c_runner,
runner,
target,
linker,
cxx_toolchain_dir,
Expand Down
32 changes: 15 additions & 17 deletions crates/intrinsic-test/src/common/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@ use super::cli::FailureReason;
use rayon::prelude::*;
use std::process::Command;

pub fn compare_outputs(
intrinsic_name_list: &Vec<String>,
toolchain: &str,
runner: &str,
target: &str,
) -> bool {
pub fn compare_outputs(intrinsic_name_list: &Vec<String>, runner: &str, target: &str) -> bool {
fn runner_command(runner: &str) -> Command {
let mut it = runner.split_whitespace();
let mut cmd = Command::new(it.next().unwrap());
cmd.args(it);

cmd
}

let intrinsics = intrinsic_name_list
.par_iter()
.filter_map(|intrinsic_name| {
let c = Command::new("sh")
.arg("-c")
.arg(format!("{runner} ./c_programs/{intrinsic_name}"))
let c = runner_command(runner)
.arg(format!("./c_programs/{intrinsic_name}"))
.output();

let rust = Command::new("sh")
.current_dir("rust_programs")
.arg("-c")
.arg(format!(
"cargo {toolchain} run --target {target} --bin {intrinsic_name} --release",
))
let rust = runner_command(runner)
.arg(format!("target/{target}/release/{intrinsic_name}"))
.env("RUSTFLAGS", "-Cdebuginfo=0")
.output();

Expand All @@ -42,8 +40,8 @@ pub fn compare_outputs(
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(""),
stdout = String::from_utf8_lossy(&rust.stdout),
stderr = String::from_utf8_lossy(&rust.stderr),
);
return Some(FailureReason::RunRust(intrinsic_name.clone()));
}
Expand Down
99 changes: 49 additions & 50 deletions crates/intrinsic-test/src/common/gen_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use itertools::Itertools;
use rayon::prelude::*;
use std::collections::BTreeMap;
use std::fs::File;
use std::io::Write;
use std::process::Command;

use super::argument::Argument;
Expand All @@ -23,8 +22,8 @@ pub fn format_rust_main_template(
) -> String {
format!(
r#"{notices}#![feature(simd_ffi)]
#![feature(link_llvm_intrinsics)]
#![feature(f16)]
#![allow(unused)]
{configurations}
{definitions}

Expand All @@ -38,75 +37,75 @@ fn main() {{
)
}

fn write_cargo_toml(w: &mut impl std::io::Write, binaries: &[String]) -> std::io::Result<()> {
writeln!(
w,
concat!(
"[package]\n",
"name = \"intrinsic-test-programs\"\n",
"version = \"{version}\"\n",
"authors = [{authors}]\n",
"license = \"{license}\"\n",
"edition = \"2018\"\n",
"[workspace]\n",
"[dependencies]\n",
"core_arch = {{ path = \"../crates/core_arch\" }}",
),
version = env!("CARGO_PKG_VERSION"),
authors = env!("CARGO_PKG_AUTHORS")
.split(":")
.format_with(", ", |author, fmt| fmt(&format_args!("\"{author}\""))),
license = env!("CARGO_PKG_LICENSE"),
)?;

for binary in binaries {
writeln!(
w,
concat!(
"[[bin]]\n",
"name = \"{binary}\"\n",
"path = \"{binary}/main.rs\"\n",
),
binary = binary,
)?;
}

Ok(())
}

pub fn compile_rust_programs(
binaries: Vec<String>,
toolchain: Option<&str>,
target: &str,
linker: Option<&str>,
) -> bool {
let mut cargo = File::create("rust_programs/Cargo.toml").unwrap();
cargo
.write_all(
format!(
r#"[package]
name = "intrinsic-test-programs"
version = "{version}"
authors = [{authors}]
license = "{license}"
edition = "2018"
[workspace]
[dependencies]
core_arch = {{ path = "../crates/core_arch" }}
{binaries}"#,
version = env!("CARGO_PKG_VERSION"),
authors = env!("CARGO_PKG_AUTHORS")
.split(":")
.format_with(", ", |author, fmt| fmt(&format_args!("\"{author}\""))),
license = env!("CARGO_PKG_LICENSE"),
binaries = binaries
.iter()
.map(|binary| {
format!(
r#"[[bin]]
name = "{binary}"
path = "{binary}/main.rs""#,
)
})
.collect::<Vec<_>>()
.join("\n")
)
.into_bytes()
.as_slice(),
)
.unwrap();

let toolchain = match toolchain {
None => return true,
Some(t) => t,
};
write_cargo_toml(&mut cargo, &binaries).unwrap();

/* If there has been a linker explicitly set from the command line then
* we want to set it via setting it in the RUSTFLAGS*/

let cargo_command = format!("cargo {toolchain} build --target {target} --release");
let mut cargo_command = Command::new("cargo");
cargo_command.current_dir("rust_programs");

let mut command = Command::new("sh");
command
.current_dir("rust_programs")
.arg("-c")
.arg(cargo_command);
if let Some(toolchain) = toolchain {
if !toolchain.is_empty() {
cargo_command.arg(toolchain);
}
}
cargo_command.args(["build", "--target", target, "--release"]);

let mut rust_flags = "-Cdebuginfo=0".to_string();
if let Some(linker) = linker {
rust_flags.push_str(" -C linker=");
rust_flags.push_str(linker);
rust_flags.push_str(" -C link-args=-static");

command.env("CPPFLAGS", "-fuse-ld=lld");
cargo_command.env("CPPFLAGS", "-fuse-ld=lld");
}

command.env("RUSTFLAGS", rust_flags);
let output = command.output();
cargo_command.env("RUSTFLAGS", rust_flags);
let output = cargo_command.output();

if let Ok(output) = output {
if output.status.success() {
Expand Down
3 changes: 3 additions & 0 deletions crates/intrinsic-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ fn main() {

let test_environment = test_environment_result.unwrap();

info!("building C binaries");
if !test_environment.build_c_file() {
std::process::exit(2);
}
info!("building Rust binaries");
if !test_environment.build_rust_file() {
std::process::exit(3);
}
info!("comaparing outputs");
if !test_environment.compare_outputs() {
std::process::exit(1);
}
Expand Down