Merge pull request #1252 from afonso360/tests-rs
Move test script to y.rs
This commit is contained in:
commit
231f7c6a21
@ -22,4 +22,4 @@ task:
|
||||
- # Reduce amount of benchmark runs as they are slow
|
||||
- export COMPILE_RUNS=2
|
||||
- export RUN_RUNS=2
|
||||
- ./test.sh
|
||||
- ./y.rs test
|
||||
|
10
.github/workflows/main.yml
vendored
10
.github/workflows/main.yml
vendored
@ -103,7 +103,7 @@ jobs:
|
||||
# Enable extra checks
|
||||
export CG_CLIF_ENABLE_VERIFIER=1
|
||||
|
||||
./test.sh
|
||||
./y.rs test
|
||||
|
||||
- name: Package prebuilt cg_clif
|
||||
run: tar cvfJ cg_clif.tar.xz build
|
||||
@ -162,14 +162,14 @@ jobs:
|
||||
#name: Test
|
||||
run: |
|
||||
# Enable backtraces for easier debugging
|
||||
#export RUST_BACKTRACE=1
|
||||
#$Env:RUST_BACKTRACE=1
|
||||
|
||||
# Reduce amount of benchmark runs as they are slow
|
||||
#export COMPILE_RUNS=2
|
||||
#export RUN_RUNS=2
|
||||
#$Env:COMPILE_RUNS=2
|
||||
#$Env:RUN_RUNS=2
|
||||
|
||||
# Enable extra checks
|
||||
#export CG_CLIF_ENABLE_VERIFIER=1
|
||||
#$Env:CG_CLIF_ENABLE_VERIFIER=1
|
||||
|
||||
./y.exe build
|
||||
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -8,6 +8,8 @@ perf.data.old
|
||||
*.string*
|
||||
/y.bin
|
||||
/y.bin.dSYM
|
||||
/y.exe
|
||||
/y.pdb
|
||||
/build
|
||||
/build_sysroot/sysroot_src
|
||||
/build_sysroot/compiler-builtins
|
||||
|
@ -2,7 +2,7 @@ use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{self, Command};
|
||||
|
||||
use super::rustc_info::{get_file_name, get_rustc_version};
|
||||
use super::rustc_info::{get_file_name, get_rustc_version, get_wrapper_file_name};
|
||||
use super::utils::{spawn_and_wait, try_hard_link};
|
||||
use super::SysrootKind;
|
||||
|
||||
@ -10,10 +10,12 @@ pub(crate) fn build_sysroot(
|
||||
channel: &str,
|
||||
sysroot_kind: SysrootKind,
|
||||
target_dir: &Path,
|
||||
cg_clif_build_dir: PathBuf,
|
||||
cg_clif_build_dir: &Path,
|
||||
host_triple: &str,
|
||||
target_triple: &str,
|
||||
) {
|
||||
eprintln!("[BUILD] sysroot {:?}", sysroot_kind);
|
||||
|
||||
if target_dir.exists() {
|
||||
fs::remove_dir_all(target_dir).unwrap();
|
||||
}
|
||||
@ -35,11 +37,13 @@ pub(crate) fn build_sysroot(
|
||||
|
||||
// Build and copy rustc and cargo wrappers
|
||||
for wrapper in ["rustc-clif", "cargo-clif"] {
|
||||
let wrapper_name = get_wrapper_file_name(wrapper, "bin");
|
||||
|
||||
let mut build_cargo_wrapper_cmd = Command::new("rustc");
|
||||
build_cargo_wrapper_cmd
|
||||
.arg(PathBuf::from("scripts").join(format!("{wrapper}.rs")))
|
||||
.arg("-o")
|
||||
.arg(target_dir.join(wrapper))
|
||||
.arg(target_dir.join(wrapper_name))
|
||||
.arg("-g");
|
||||
spawn_and_wait(build_cargo_wrapper_cmd);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ mod build_sysroot;
|
||||
mod config;
|
||||
mod prepare;
|
||||
mod rustc_info;
|
||||
mod tests;
|
||||
mod utils;
|
||||
|
||||
fn usage() {
|
||||
@ -15,6 +16,9 @@ fn usage() {
|
||||
eprintln!(
|
||||
" ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]"
|
||||
);
|
||||
eprintln!(
|
||||
" ./y.rs test [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]"
|
||||
);
|
||||
}
|
||||
|
||||
macro_rules! arg_error {
|
||||
@ -25,11 +29,13 @@ macro_rules! arg_error {
|
||||
}};
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
enum Command {
|
||||
Build,
|
||||
Test,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub(crate) enum SysrootKind {
|
||||
None,
|
||||
Clif,
|
||||
@ -46,12 +52,13 @@ pub fn main() {
|
||||
let command = match args.next().as_deref() {
|
||||
Some("prepare") => {
|
||||
if args.next().is_some() {
|
||||
arg_error!("./x.rs prepare doesn't expect arguments");
|
||||
arg_error!("./y.rs prepare doesn't expect arguments");
|
||||
}
|
||||
prepare::prepare();
|
||||
process::exit(0);
|
||||
}
|
||||
Some("build") => Command::Build,
|
||||
Some("test") => Command::Test,
|
||||
Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
|
||||
Some(command) => arg_error!("Unknown command {}", command),
|
||||
None => {
|
||||
@ -117,12 +124,26 @@ pub fn main() {
|
||||
|
||||
let cg_clif_build_dir =
|
||||
build_backend::build_backend(channel, &host_triple, use_unstable_features);
|
||||
build_sysroot::build_sysroot(
|
||||
channel,
|
||||
sysroot_kind,
|
||||
&target_dir,
|
||||
cg_clif_build_dir,
|
||||
&host_triple,
|
||||
&target_triple,
|
||||
);
|
||||
match command {
|
||||
Command::Test => {
|
||||
tests::run_tests(
|
||||
channel,
|
||||
sysroot_kind,
|
||||
&target_dir,
|
||||
&cg_clif_build_dir,
|
||||
&host_triple,
|
||||
&target_triple,
|
||||
);
|
||||
}
|
||||
Command::Build => {
|
||||
build_sysroot::build_sysroot(
|
||||
channel,
|
||||
sysroot_kind,
|
||||
&target_dir,
|
||||
&cg_clif_build_dir,
|
||||
&host_triple,
|
||||
&target_triple,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,8 +50,7 @@ pub(crate) fn prepare() {
|
||||
spawn_and_wait(build_cmd);
|
||||
fs::copy(
|
||||
Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin")),
|
||||
// FIXME use get_file_name here too once testing is migrated to rust
|
||||
"simple-raytracer/raytracer_cg_llvm",
|
||||
Path::new("simple-raytracer").join(get_file_name("raytracer_cg_llvm", "bin")),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
@ -63,3 +63,12 @@ pub(crate) fn get_file_name(crate_name: &str, crate_type: &str) -> String {
|
||||
assert!(file_name.contains(crate_name));
|
||||
file_name
|
||||
}
|
||||
|
||||
/// Similar to `get_file_name`, but converts any dashes (`-`) in the `crate_name` to
|
||||
/// underscores (`_`). This is specially made for the the rustc and cargo wrappers
|
||||
/// which have a dash in the name, and that is not allowed in a crate name.
|
||||
pub(crate) fn get_wrapper_file_name(crate_name: &str, crate_type: &str) -> String {
|
||||
let crate_name = crate_name.replace('-', "_");
|
||||
let wrapper_name = get_file_name(&crate_name, crate_type);
|
||||
wrapper_name.replace('_', "-")
|
||||
}
|
||||
|
618
build_system/tests.rs
Normal file
618
build_system/tests.rs
Normal file
@ -0,0 +1,618 @@
|
||||
use super::build_sysroot;
|
||||
use super::config;
|
||||
use super::rustc_info::get_wrapper_file_name;
|
||||
use super::utils::{spawn_and_wait, spawn_and_wait_with_input};
|
||||
use build_system::SysrootKind;
|
||||
use std::env;
|
||||
use std::ffi::OsStr;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
struct TestCase {
|
||||
config: &'static str,
|
||||
func: &'static dyn Fn(&TestRunner),
|
||||
}
|
||||
|
||||
impl TestCase {
|
||||
const fn new(config: &'static str, func: &'static dyn Fn(&TestRunner)) -> Self {
|
||||
Self { config, func }
|
||||
}
|
||||
}
|
||||
|
||||
const NO_SYSROOT_SUITE: &[TestCase] = &[
|
||||
TestCase::new("build.mini_core", &|runner| {
|
||||
runner.run_rustc([
|
||||
"example/mini_core.rs",
|
||||
"--crate-name",
|
||||
"mini_core",
|
||||
"--crate-type",
|
||||
"lib,dylib",
|
||||
"--target",
|
||||
&runner.target_triple,
|
||||
]);
|
||||
}),
|
||||
TestCase::new("build.example", &|runner| {
|
||||
runner.run_rustc([
|
||||
"example/example.rs",
|
||||
"--crate-type",
|
||||
"lib",
|
||||
"--target",
|
||||
&runner.target_triple,
|
||||
]);
|
||||
}),
|
||||
TestCase::new("jit.mini_core_hello_world", &|runner| {
|
||||
let mut jit_cmd = runner.rustc_command([
|
||||
"-Zunstable-options",
|
||||
"-Cllvm-args=mode=jit",
|
||||
"-Cprefer-dynamic",
|
||||
"example/mini_core_hello_world.rs",
|
||||
"--cfg",
|
||||
"jit",
|
||||
"--target",
|
||||
&runner.host_triple,
|
||||
]);
|
||||
jit_cmd.env("CG_CLIF_JIT_ARGS", "abc bcd");
|
||||
spawn_and_wait(jit_cmd);
|
||||
|
||||
eprintln!("[JIT-lazy] mini_core_hello_world");
|
||||
let mut jit_cmd = runner.rustc_command([
|
||||
"-Zunstable-options",
|
||||
"-Cllvm-args=mode=jit-lazy",
|
||||
"-Cprefer-dynamic",
|
||||
"example/mini_core_hello_world.rs",
|
||||
"--cfg",
|
||||
"jit",
|
||||
"--target",
|
||||
&runner.host_triple,
|
||||
]);
|
||||
jit_cmd.env("CG_CLIF_JIT_ARGS", "abc bcd");
|
||||
spawn_and_wait(jit_cmd);
|
||||
}),
|
||||
TestCase::new("aot.mini_core_hello_world", &|runner| {
|
||||
runner.run_rustc([
|
||||
"example/mini_core_hello_world.rs",
|
||||
"--crate-name",
|
||||
"mini_core_hello_world",
|
||||
"--crate-type",
|
||||
"bin",
|
||||
"-g",
|
||||
"--target",
|
||||
&runner.target_triple,
|
||||
]);
|
||||
runner.run_out_command("mini_core_hello_world", ["abc", "bcd"]);
|
||||
}),
|
||||
];
|
||||
|
||||
const BASE_SYSROOT_SUITE: &[TestCase] = &[
|
||||
TestCase::new("aot.arbitrary_self_types_pointers_and_wrappers", &|runner| {
|
||||
runner.run_rustc([
|
||||
"example/arbitrary_self_types_pointers_and_wrappers.rs",
|
||||
"--crate-name",
|
||||
"arbitrary_self_types_pointers_and_wrappers",
|
||||
"--crate-type",
|
||||
"bin",
|
||||
"--target",
|
||||
&runner.target_triple,
|
||||
]);
|
||||
runner.run_out_command("arbitrary_self_types_pointers_and_wrappers", []);
|
||||
}),
|
||||
TestCase::new("aot.issue_91827_extern_types", &|runner| {
|
||||
runner.run_rustc([
|
||||
"example/issue-91827-extern-types.rs",
|
||||
"--crate-name",
|
||||
"issue_91827_extern_types",
|
||||
"--crate-type",
|
||||
"bin",
|
||||
"--target",
|
||||
&runner.target_triple,
|
||||
]);
|
||||
runner.run_out_command("issue_91827_extern_types", []);
|
||||
}),
|
||||
TestCase::new("build.alloc_system", &|runner| {
|
||||
runner.run_rustc([
|
||||
"example/alloc_system.rs",
|
||||
"--crate-type",
|
||||
"lib",
|
||||
"--target",
|
||||
&runner.target_triple,
|
||||
]);
|
||||
}),
|
||||
TestCase::new("aot.alloc_example", &|runner| {
|
||||
runner.run_rustc([
|
||||
"example/alloc_example.rs",
|
||||
"--crate-type",
|
||||
"bin",
|
||||
"--target",
|
||||
&runner.target_triple,
|
||||
]);
|
||||
runner.run_out_command("alloc_example", []);
|
||||
}),
|
||||
TestCase::new("jit.std_example", &|runner| {
|
||||
runner.run_rustc([
|
||||
"-Zunstable-options",
|
||||
"-Cllvm-args=mode=jit",
|
||||
"-Cprefer-dynamic",
|
||||
"example/std_example.rs",
|
||||
"--target",
|
||||
&runner.host_triple,
|
||||
]);
|
||||
|
||||
eprintln!("[JIT-lazy] std_example");
|
||||
runner.run_rustc([
|
||||
"-Zunstable-options",
|
||||
"-Cllvm-args=mode=jit-lazy",
|
||||
"-Cprefer-dynamic",
|
||||
"example/std_example.rs",
|
||||
"--target",
|
||||
&runner.host_triple,
|
||||
]);
|
||||
}),
|
||||
TestCase::new("aot.std_example", &|runner| {
|
||||
runner.run_rustc([
|
||||
"example/std_example.rs",
|
||||
"--crate-type",
|
||||
"bin",
|
||||
"--target",
|
||||
&runner.target_triple,
|
||||
]);
|
||||
runner.run_out_command("std_example", ["arg"]);
|
||||
}),
|
||||
TestCase::new("aot.dst_field_align", &|runner| {
|
||||
runner.run_rustc([
|
||||
"example/dst-field-align.rs",
|
||||
"--crate-name",
|
||||
"dst_field_align",
|
||||
"--crate-type",
|
||||
"bin",
|
||||
"--target",
|
||||
&runner.target_triple,
|
||||
]);
|
||||
runner.run_out_command("dst_field_align", []);
|
||||
}),
|
||||
TestCase::new("aot.subslice-patterns-const-eval", &|runner| {
|
||||
runner.run_rustc([
|
||||
"example/subslice-patterns-const-eval.rs",
|
||||
"--crate-type",
|
||||
"bin",
|
||||
"-Cpanic=abort",
|
||||
"--target",
|
||||
&runner.target_triple,
|
||||
]);
|
||||
runner.run_out_command("subslice-patterns-const-eval", []);
|
||||
}),
|
||||
TestCase::new("aot.track-caller-attribute", &|runner| {
|
||||
runner.run_rustc([
|
||||
"example/track-caller-attribute.rs",
|
||||
"--crate-type",
|
||||
"bin",
|
||||
"-Cpanic=abort",
|
||||
"--target",
|
||||
&runner.target_triple,
|
||||
]);
|
||||
runner.run_out_command("track-caller-attribute", []);
|
||||
}),
|
||||
TestCase::new("aot.float-minmax-pass", &|runner| {
|
||||
runner.run_rustc([
|
||||
"example/float-minmax-pass.rs",
|
||||
"--crate-type",
|
||||
"bin",
|
||||
"-Cpanic=abort",
|
||||
"--target",
|
||||
&runner.target_triple,
|
||||
]);
|
||||
runner.run_out_command("float-minmax-pass", []);
|
||||
}),
|
||||
TestCase::new("aot.mod_bench", &|runner| {
|
||||
runner.run_rustc([
|
||||
"example/mod_bench.rs",
|
||||
"--crate-type",
|
||||
"bin",
|
||||
"--target",
|
||||
&runner.target_triple,
|
||||
]);
|
||||
runner.run_out_command("mod_bench", []);
|
||||
}),
|
||||
];
|
||||
|
||||
const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
|
||||
TestCase::new("test.rust-random/rand", &|runner| {
|
||||
runner.in_dir(["rand"], |runner| {
|
||||
runner.run_cargo(["clean"]);
|
||||
|
||||
if runner.host_triple == runner.target_triple {
|
||||
eprintln!("[TEST] rust-random/rand");
|
||||
runner.run_cargo(["test", "--workspace"]);
|
||||
} else {
|
||||
eprintln!("[AOT] rust-random/rand");
|
||||
runner.run_cargo([
|
||||
"build",
|
||||
"--workspace",
|
||||
"--target",
|
||||
&runner.target_triple,
|
||||
"--tests",
|
||||
]);
|
||||
}
|
||||
});
|
||||
}),
|
||||
TestCase::new("bench.simple-raytracer", &|runner| {
|
||||
runner.in_dir(["simple-raytracer"], |runner| {
|
||||
let run_runs = env::var("RUN_RUNS").unwrap_or("10".to_string());
|
||||
|
||||
if runner.host_triple == runner.target_triple {
|
||||
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
|
||||
let mut bench_compile = Command::new("hyperfine");
|
||||
bench_compile.arg("--runs");
|
||||
bench_compile.arg(&run_runs);
|
||||
bench_compile.arg("--warmup");
|
||||
bench_compile.arg("1");
|
||||
bench_compile.arg("--prepare");
|
||||
bench_compile.arg(format!("{:?}", runner.cargo_command(["clean"])));
|
||||
|
||||
if cfg!(windows) {
|
||||
bench_compile.arg("cmd /C \"set RUSTFLAGS= && cargo build\"");
|
||||
} else {
|
||||
bench_compile.arg("RUSTFLAGS='' cargo build");
|
||||
}
|
||||
|
||||
bench_compile.arg(format!("{:?}", runner.cargo_command(["build"])));
|
||||
spawn_and_wait(bench_compile);
|
||||
|
||||
eprintln!("[BENCH RUN] ebobby/simple-raytracer");
|
||||
fs::copy(PathBuf::from("./target/debug/main"), PathBuf::from("raytracer_cg_clif"))
|
||||
.unwrap();
|
||||
|
||||
let mut bench_run = Command::new("hyperfine");
|
||||
bench_run.arg("--runs");
|
||||
bench_run.arg(&run_runs);
|
||||
bench_run.arg(PathBuf::from("./raytracer_cg_llvm"));
|
||||
bench_run.arg(PathBuf::from("./raytracer_cg_clif"));
|
||||
spawn_and_wait(bench_run);
|
||||
} else {
|
||||
runner.run_cargo(["clean"]);
|
||||
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer (skipped)");
|
||||
eprintln!("[COMPILE] ebobby/simple-raytracer");
|
||||
runner.run_cargo(["build", "--target", &runner.target_triple]);
|
||||
eprintln!("[BENCH RUN] ebobby/simple-raytracer (skipped)");
|
||||
}
|
||||
});
|
||||
}),
|
||||
TestCase::new("test.libcore", &|runner| {
|
||||
runner.in_dir(["build_sysroot", "sysroot_src", "library", "core", "tests"], |runner| {
|
||||
runner.run_cargo(["clean"]);
|
||||
|
||||
if runner.host_triple == runner.target_triple {
|
||||
runner.run_cargo(["test"]);
|
||||
} else {
|
||||
eprintln!("Cross-Compiling: Not running tests");
|
||||
runner.run_cargo(["build", "--target", &runner.target_triple, "--tests"]);
|
||||
}
|
||||
});
|
||||
}),
|
||||
TestCase::new("test.regex-shootout-regex-dna", &|runner| {
|
||||
runner.in_dir(["regex"], |runner| {
|
||||
runner.run_cargo(["clean"]);
|
||||
|
||||
// newer aho_corasick versions throw a deprecation warning
|
||||
let lint_rust_flags = format!("{} --cap-lints warn", runner.rust_flags);
|
||||
|
||||
let mut build_cmd = runner.cargo_command([
|
||||
"build",
|
||||
"--example",
|
||||
"shootout-regex-dna",
|
||||
"--target",
|
||||
&runner.target_triple,
|
||||
]);
|
||||
build_cmd.env("RUSTFLAGS", lint_rust_flags.clone());
|
||||
spawn_and_wait(build_cmd);
|
||||
|
||||
if runner.host_triple == runner.target_triple {
|
||||
let mut run_cmd = runner.cargo_command([
|
||||
"run",
|
||||
"--example",
|
||||
"shootout-regex-dna",
|
||||
"--target",
|
||||
&runner.target_triple,
|
||||
]);
|
||||
run_cmd.env("RUSTFLAGS", lint_rust_flags);
|
||||
|
||||
let input =
|
||||
fs::read_to_string(PathBuf::from("examples/regexdna-input.txt")).unwrap();
|
||||
let expected_path = PathBuf::from("examples/regexdna-output.txt");
|
||||
let expected = fs::read_to_string(&expected_path).unwrap();
|
||||
|
||||
let output = spawn_and_wait_with_input(run_cmd, input);
|
||||
// Make sure `[codegen mono items] start` doesn't poison the diff
|
||||
let output = output
|
||||
.lines()
|
||||
.filter(|line| !line.contains("codegen mono items"))
|
||||
.chain(Some("")) // This just adds the trailing newline
|
||||
.collect::<Vec<&str>>()
|
||||
.join("\r\n");
|
||||
|
||||
let output_matches = expected.lines().eq(output.lines());
|
||||
if !output_matches {
|
||||
let res_path = PathBuf::from("res.txt");
|
||||
fs::write(&res_path, &output).unwrap();
|
||||
|
||||
if cfg!(windows) {
|
||||
println!("Output files don't match!");
|
||||
println!("Expected Output:\n{}", expected);
|
||||
println!("Actual Output:\n{}", output);
|
||||
} else {
|
||||
let mut diff = Command::new("diff");
|
||||
diff.arg("-u");
|
||||
diff.arg(res_path);
|
||||
diff.arg(expected_path);
|
||||
spawn_and_wait(diff);
|
||||
}
|
||||
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}),
|
||||
TestCase::new("test.regex", &|runner| {
|
||||
runner.in_dir(["regex"], |runner| {
|
||||
runner.run_cargo(["clean"]);
|
||||
|
||||
// newer aho_corasick versions throw a deprecation warning
|
||||
let lint_rust_flags = format!("{} --cap-lints warn", runner.rust_flags);
|
||||
|
||||
if runner.host_triple == runner.target_triple {
|
||||
let mut run_cmd = runner.cargo_command([
|
||||
"test",
|
||||
"--tests",
|
||||
"--",
|
||||
"--exclude-should-panic",
|
||||
"--test-threads",
|
||||
"1",
|
||||
"-Zunstable-options",
|
||||
"-q",
|
||||
]);
|
||||
run_cmd.env("RUSTFLAGS", lint_rust_flags);
|
||||
spawn_and_wait(run_cmd);
|
||||
} else {
|
||||
eprintln!("Cross-Compiling: Not running tests");
|
||||
let mut build_cmd =
|
||||
runner.cargo_command(["build", "--tests", "--target", &runner.target_triple]);
|
||||
build_cmd.env("RUSTFLAGS", lint_rust_flags.clone());
|
||||
spawn_and_wait(build_cmd);
|
||||
}
|
||||
});
|
||||
}),
|
||||
TestCase::new("test.portable-simd", &|runner| {
|
||||
runner.in_dir(["portable-simd"], |runner| {
|
||||
runner.run_cargo(["clean"]);
|
||||
runner.run_cargo(["build", "--all-targets", "--target", &runner.target_triple]);
|
||||
|
||||
if runner.host_triple == runner.target_triple {
|
||||
runner.run_cargo(["test", "-q"]);
|
||||
}
|
||||
});
|
||||
}),
|
||||
];
|
||||
|
||||
pub(crate) fn run_tests(
|
||||
channel: &str,
|
||||
sysroot_kind: SysrootKind,
|
||||
target_dir: &Path,
|
||||
cg_clif_build_dir: &Path,
|
||||
host_triple: &str,
|
||||
target_triple: &str,
|
||||
) {
|
||||
let runner = TestRunner::new(host_triple.to_string(), target_triple.to_string());
|
||||
|
||||
if config::get_bool("testsuite.no_sysroot") {
|
||||
build_sysroot::build_sysroot(
|
||||
channel,
|
||||
SysrootKind::None,
|
||||
&target_dir,
|
||||
cg_clif_build_dir,
|
||||
&host_triple,
|
||||
&target_triple,
|
||||
);
|
||||
|
||||
let _ = fs::remove_dir_all(Path::new("target").join("out"));
|
||||
runner.run_testsuite(NO_SYSROOT_SUITE);
|
||||
} else {
|
||||
eprintln!("[SKIP] no_sysroot tests");
|
||||
}
|
||||
|
||||
let run_base_sysroot = config::get_bool("testsuite.base_sysroot");
|
||||
let run_extended_sysroot = config::get_bool("testsuite.extended_sysroot");
|
||||
|
||||
if run_base_sysroot || run_extended_sysroot {
|
||||
build_sysroot::build_sysroot(
|
||||
channel,
|
||||
sysroot_kind,
|
||||
&target_dir,
|
||||
cg_clif_build_dir,
|
||||
&host_triple,
|
||||
&target_triple,
|
||||
);
|
||||
}
|
||||
|
||||
if run_base_sysroot {
|
||||
runner.run_testsuite(BASE_SYSROOT_SUITE);
|
||||
} else {
|
||||
eprintln!("[SKIP] base_sysroot tests");
|
||||
}
|
||||
|
||||
if run_extended_sysroot {
|
||||
runner.run_testsuite(EXTENDED_SYSROOT_SUITE);
|
||||
} else {
|
||||
eprintln!("[SKIP] extended_sysroot tests");
|
||||
}
|
||||
}
|
||||
|
||||
struct TestRunner {
|
||||
root_dir: PathBuf,
|
||||
out_dir: PathBuf,
|
||||
jit_supported: bool,
|
||||
rust_flags: String,
|
||||
run_wrapper: Vec<String>,
|
||||
host_triple: String,
|
||||
target_triple: String,
|
||||
}
|
||||
|
||||
impl TestRunner {
|
||||
pub fn new(host_triple: String, target_triple: String) -> Self {
|
||||
let root_dir = env::current_dir().unwrap();
|
||||
|
||||
let mut out_dir = root_dir.clone();
|
||||
out_dir.push("target");
|
||||
out_dir.push("out");
|
||||
|
||||
let is_native = host_triple == target_triple;
|
||||
let jit_supported = target_triple.contains("x86_64") && is_native;
|
||||
|
||||
let mut rust_flags = env::var("RUSTFLAGS").ok().unwrap_or("".to_string());
|
||||
let mut run_wrapper = Vec::new();
|
||||
|
||||
if !is_native {
|
||||
match target_triple.as_str() {
|
||||
"aarch64-unknown-linux-gnu" => {
|
||||
// We are cross-compiling for aarch64. Use the correct linker and run tests in qemu.
|
||||
rust_flags = format!("-Clinker=aarch64-linux-gnu-gcc{}", rust_flags);
|
||||
run_wrapper = vec!["qemu-aarch64", "-L", "/usr/aarch64-linux-gnu"];
|
||||
}
|
||||
"x86_64-pc-windows-gnu" => {
|
||||
// We are cross-compiling for Windows. Run tests in wine.
|
||||
run_wrapper = vec!["wine"];
|
||||
}
|
||||
_ => {
|
||||
println!("Unknown non-native platform");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME fix `#[linkage = "extern_weak"]` without this
|
||||
if host_triple.contains("darwin") {
|
||||
rust_flags = format!("{} -Clink-arg=-undefined -Clink-arg=dynamic_lookup", rust_flags);
|
||||
}
|
||||
|
||||
Self {
|
||||
root_dir,
|
||||
out_dir,
|
||||
jit_supported,
|
||||
rust_flags,
|
||||
run_wrapper: run_wrapper.iter().map(|s| s.to_string()).collect(),
|
||||
host_triple,
|
||||
target_triple,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_testsuite(&self, tests: &[TestCase]) {
|
||||
for &TestCase { config, func } in tests {
|
||||
let (tag, testname) = config.split_once('.').unwrap();
|
||||
let tag = tag.to_uppercase();
|
||||
let is_jit_test = tag == "JIT";
|
||||
|
||||
if !config::get_bool(config) || (is_jit_test && !self.jit_supported) {
|
||||
eprintln!("[{tag}] {testname} (skipped)");
|
||||
continue;
|
||||
} else {
|
||||
eprintln!("[{tag}] {testname}");
|
||||
}
|
||||
|
||||
func(self);
|
||||
}
|
||||
}
|
||||
|
||||
fn in_dir<'a, I, F>(&self, dir: I, callback: F)
|
||||
where
|
||||
I: IntoIterator<Item = &'a str>,
|
||||
F: FnOnce(&TestRunner),
|
||||
{
|
||||
let current = env::current_dir().unwrap();
|
||||
let mut new = current.clone();
|
||||
for d in dir {
|
||||
new.push(d);
|
||||
}
|
||||
|
||||
env::set_current_dir(new).unwrap();
|
||||
callback(self);
|
||||
env::set_current_dir(current).unwrap();
|
||||
}
|
||||
|
||||
fn rustc_command<I, S>(&self, args: I) -> Command
|
||||
where
|
||||
I: IntoIterator<Item = S>,
|
||||
S: AsRef<OsStr>,
|
||||
{
|
||||
let mut rustc_clif = self.root_dir.clone();
|
||||
rustc_clif.push("build");
|
||||
rustc_clif.push(get_wrapper_file_name("rustc-clif", "bin"));
|
||||
|
||||
let mut cmd = Command::new(rustc_clif);
|
||||
cmd.args(self.rust_flags.split_whitespace());
|
||||
cmd.arg("-L");
|
||||
cmd.arg(format!("crate={}", self.out_dir.display()));
|
||||
cmd.arg("--out-dir");
|
||||
cmd.arg(format!("{}", self.out_dir.display()));
|
||||
cmd.arg("-Cdebuginfo=2");
|
||||
cmd.args(args);
|
||||
cmd
|
||||
}
|
||||
|
||||
fn run_rustc<I, S>(&self, args: I)
|
||||
where
|
||||
I: IntoIterator<Item = S>,
|
||||
S: AsRef<OsStr>,
|
||||
{
|
||||
spawn_and_wait(self.rustc_command(args));
|
||||
}
|
||||
|
||||
fn run_out_command<'a, I>(&self, name: &str, args: I)
|
||||
where
|
||||
I: IntoIterator<Item = &'a str>,
|
||||
{
|
||||
let mut full_cmd = vec![];
|
||||
|
||||
// Prepend the RUN_WRAPPER's
|
||||
if !self.run_wrapper.is_empty() {
|
||||
full_cmd.extend(self.run_wrapper.iter().cloned());
|
||||
}
|
||||
|
||||
full_cmd.push({
|
||||
let mut out_path = self.out_dir.clone();
|
||||
out_path.push(name);
|
||||
out_path.to_str().unwrap().to_string()
|
||||
});
|
||||
|
||||
for arg in args.into_iter() {
|
||||
full_cmd.push(arg.to_string());
|
||||
}
|
||||
|
||||
let mut cmd_iter = full_cmd.into_iter();
|
||||
let first = cmd_iter.next().unwrap();
|
||||
|
||||
let mut cmd = Command::new(first);
|
||||
cmd.args(cmd_iter);
|
||||
|
||||
spawn_and_wait(cmd);
|
||||
}
|
||||
|
||||
fn cargo_command<I, S>(&self, args: I) -> Command
|
||||
where
|
||||
I: IntoIterator<Item = S>,
|
||||
S: AsRef<OsStr>,
|
||||
{
|
||||
let mut cargo_clif = self.root_dir.clone();
|
||||
cargo_clif.push("build");
|
||||
cargo_clif.push(get_wrapper_file_name("cargo-clif", "bin"));
|
||||
|
||||
let mut cmd = Command::new(cargo_clif);
|
||||
cmd.args(args);
|
||||
cmd.env("RUSTFLAGS", &self.rust_flags);
|
||||
cmd
|
||||
}
|
||||
|
||||
fn run_cargo<'a, I>(&self, args: I)
|
||||
where
|
||||
I: IntoIterator<Item = &'a str>,
|
||||
{
|
||||
spawn_and_wait(self.cargo_command(args));
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::process::{self, Command};
|
||||
use std::process::{self, Command, Stdio};
|
||||
|
||||
#[track_caller]
|
||||
pub(crate) fn try_hard_link(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
|
||||
@ -18,6 +19,27 @@ pub(crate) fn spawn_and_wait(mut cmd: Command) {
|
||||
}
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub(crate) fn spawn_and_wait_with_input(mut cmd: Command, input: String) -> String {
|
||||
let mut child = cmd
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
.expect("Failed to spawn child process");
|
||||
|
||||
let mut stdin = child.stdin.take().expect("Failed to open stdin");
|
||||
std::thread::spawn(move || {
|
||||
stdin.write_all(input.as_bytes()).expect("Failed to write to stdin");
|
||||
});
|
||||
|
||||
let output = child.wait_with_output().expect("Failed to read stdout");
|
||||
if !output.status.success() {
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
String::from_utf8(output.stdout).unwrap()
|
||||
}
|
||||
|
||||
pub(crate) fn copy_dir_recursively(from: &Path, to: &Path) {
|
||||
for entry in fs::read_dir(from).unwrap() {
|
||||
let entry = entry.unwrap();
|
||||
|
33
config.txt
33
config.txt
@ -15,3 +15,36 @@
|
||||
# This option can be changed while the build system is already running for as long as sysroot
|
||||
# building hasn't started yet.
|
||||
#keep_sysroot
|
||||
|
||||
|
||||
# Testsuite
|
||||
#
|
||||
# Each test suite item has a corresponding key here. The default is to run all tests.
|
||||
# Comment any of these lines to skip individual tests.
|
||||
|
||||
testsuite.no_sysroot
|
||||
build.mini_core
|
||||
build.example
|
||||
jit.mini_core_hello_world
|
||||
aot.mini_core_hello_world
|
||||
|
||||
testsuite.base_sysroot
|
||||
aot.arbitrary_self_types_pointers_and_wrappers
|
||||
aot.issue_91827_extern_types
|
||||
build.alloc_system
|
||||
aot.alloc_example
|
||||
jit.std_example
|
||||
aot.std_example
|
||||
aot.dst_field_align
|
||||
aot.subslice-patterns-const-eval
|
||||
aot.track-caller-attribute
|
||||
aot.float-minmax-pass
|
||||
aot.mod_bench
|
||||
|
||||
testsuite.extended_sysroot
|
||||
test.rust-random/rand
|
||||
bench.simple-raytracer
|
||||
test.libcore
|
||||
test.regex-shootout-regex-dna
|
||||
test.regex
|
||||
test.portable-simd
|
||||
|
203
scripts/tests.sh
203
scripts/tests.sh
@ -1,203 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
export CG_CLIF_DISPLAY_CG_TIME=1
|
||||
export CG_CLIF_DISABLE_INCR_CACHE=1
|
||||
|
||||
export HOST_TRIPLE=$(rustc -vV | grep host | cut -d: -f2 | tr -d " ")
|
||||
export TARGET_TRIPLE=${TARGET_TRIPLE:-$HOST_TRIPLE}
|
||||
|
||||
export RUN_WRAPPER=''
|
||||
|
||||
case "$TARGET_TRIPLE" in
|
||||
x86_64*)
|
||||
export JIT_SUPPORTED=1
|
||||
;;
|
||||
*)
|
||||
export JIT_SUPPORTED=0
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
|
||||
export JIT_SUPPORTED=0
|
||||
if [[ "$TARGET_TRIPLE" == "aarch64-unknown-linux-gnu" ]]; then
|
||||
# We are cross-compiling for aarch64. Use the correct linker and run tests in qemu.
|
||||
export RUSTFLAGS='-Clinker=aarch64-linux-gnu-gcc '$RUSTFLAGS
|
||||
export RUN_WRAPPER='qemu-aarch64 -L /usr/aarch64-linux-gnu'
|
||||
elif [[ "$TARGET_TRIPLE" == "x86_64-pc-windows-gnu" ]]; then
|
||||
# We are cross-compiling for Windows. Run tests in wine.
|
||||
export RUN_WRAPPER='wine'
|
||||
else
|
||||
echo "Unknown non-native platform"
|
||||
fi
|
||||
fi
|
||||
|
||||
# FIXME fix `#[linkage = "extern_weak"]` without this
|
||||
if [[ "$(uname)" == 'Darwin' ]]; then
|
||||
export RUSTFLAGS="$RUSTFLAGS -Clink-arg=-undefined -Clink-arg=dynamic_lookup"
|
||||
fi
|
||||
|
||||
MY_RUSTC="$(pwd)/build/rustc-clif $RUSTFLAGS -L crate=target/out --out-dir target/out -Cdebuginfo=2"
|
||||
|
||||
function no_sysroot_tests() {
|
||||
echo "[BUILD] mini_core"
|
||||
$MY_RUSTC example/mini_core.rs --crate-name mini_core --crate-type lib,dylib --target "$TARGET_TRIPLE"
|
||||
|
||||
echo "[BUILD] example"
|
||||
$MY_RUSTC example/example.rs --crate-type lib --target "$TARGET_TRIPLE"
|
||||
|
||||
if [[ "$JIT_SUPPORTED" = "1" ]]; then
|
||||
echo "[JIT] mini_core_hello_world"
|
||||
CG_CLIF_JIT_ARGS="abc bcd" $MY_RUSTC -Zunstable-options -Cllvm-args=mode=jit -Cprefer-dynamic example/mini_core_hello_world.rs --cfg jit --target "$HOST_TRIPLE"
|
||||
|
||||
echo "[JIT-lazy] mini_core_hello_world"
|
||||
CG_CLIF_JIT_ARGS="abc bcd" $MY_RUSTC -Zunstable-options -Cllvm-args=mode=jit-lazy -Cprefer-dynamic example/mini_core_hello_world.rs --cfg jit --target "$HOST_TRIPLE"
|
||||
else
|
||||
echo "[JIT] mini_core_hello_world (skipped)"
|
||||
fi
|
||||
|
||||
echo "[AOT] mini_core_hello_world"
|
||||
$MY_RUSTC example/mini_core_hello_world.rs --crate-name mini_core_hello_world --crate-type bin -g --target "$TARGET_TRIPLE"
|
||||
$RUN_WRAPPER ./target/out/mini_core_hello_world abc bcd
|
||||
# (echo "break set -n main"; echo "run"; sleep 1; echo "si -c 10"; sleep 1; echo "frame variable") | lldb -- ./target/out/mini_core_hello_world abc bcd
|
||||
}
|
||||
|
||||
function base_sysroot_tests() {
|
||||
echo "[AOT] arbitrary_self_types_pointers_and_wrappers"
|
||||
$MY_RUSTC example/arbitrary_self_types_pointers_and_wrappers.rs --crate-name arbitrary_self_types_pointers_and_wrappers --crate-type bin --target "$TARGET_TRIPLE"
|
||||
$RUN_WRAPPER ./target/out/arbitrary_self_types_pointers_and_wrappers
|
||||
|
||||
echo "[AOT] issue_91827_extern_types"
|
||||
$MY_RUSTC example/issue-91827-extern-types.rs --crate-name issue_91827_extern_types --crate-type bin --target "$TARGET_TRIPLE"
|
||||
$RUN_WRAPPER ./target/out/issue_91827_extern_types
|
||||
|
||||
echo "[BUILD] alloc_system"
|
||||
$MY_RUSTC example/alloc_system.rs --crate-type lib --target "$TARGET_TRIPLE"
|
||||
|
||||
echo "[AOT] alloc_example"
|
||||
$MY_RUSTC example/alloc_example.rs --crate-type bin --target "$TARGET_TRIPLE"
|
||||
$RUN_WRAPPER ./target/out/alloc_example
|
||||
|
||||
if [[ "$JIT_SUPPORTED" = "1" ]]; then
|
||||
echo "[JIT] std_example"
|
||||
$MY_RUSTC -Zunstable-options -Cllvm-args=mode=jit -Cprefer-dynamic example/std_example.rs --target "$HOST_TRIPLE"
|
||||
|
||||
echo "[JIT-lazy] std_example"
|
||||
$MY_RUSTC -Zunstable-options -Cllvm-args=mode=jit-lazy -Cprefer-dynamic example/std_example.rs --target "$HOST_TRIPLE"
|
||||
else
|
||||
echo "[JIT] std_example (skipped)"
|
||||
fi
|
||||
|
||||
echo "[AOT] std_example"
|
||||
$MY_RUSTC example/std_example.rs --crate-type bin --target "$TARGET_TRIPLE"
|
||||
$RUN_WRAPPER ./target/out/std_example arg
|
||||
|
||||
echo "[AOT] dst_field_align"
|
||||
$MY_RUSTC example/dst-field-align.rs --crate-name dst_field_align --crate-type bin --target "$TARGET_TRIPLE"
|
||||
$RUN_WRAPPER ./target/out/dst_field_align
|
||||
|
||||
echo "[AOT] subslice-patterns-const-eval"
|
||||
$MY_RUSTC example/subslice-patterns-const-eval.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE"
|
||||
$RUN_WRAPPER ./target/out/subslice-patterns-const-eval
|
||||
|
||||
echo "[AOT] track-caller-attribute"
|
||||
$MY_RUSTC example/track-caller-attribute.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE"
|
||||
$RUN_WRAPPER ./target/out/track-caller-attribute
|
||||
|
||||
echo "[AOT] float-minmax-pass"
|
||||
$MY_RUSTC example/float-minmax-pass.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE"
|
||||
$RUN_WRAPPER ./target/out/float-minmax-pass
|
||||
|
||||
echo "[AOT] mod_bench"
|
||||
$MY_RUSTC example/mod_bench.rs --crate-type bin --target "$TARGET_TRIPLE"
|
||||
$RUN_WRAPPER ./target/out/mod_bench
|
||||
}
|
||||
|
||||
function extended_sysroot_tests() {
|
||||
pushd rand
|
||||
../build/cargo-clif clean
|
||||
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
|
||||
echo "[TEST] rust-random/rand"
|
||||
../build/cargo-clif test --workspace
|
||||
else
|
||||
echo "[AOT] rust-random/rand"
|
||||
../build/cargo-clif build --workspace --target $TARGET_TRIPLE --tests
|
||||
fi
|
||||
popd
|
||||
|
||||
pushd simple-raytracer
|
||||
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
|
||||
echo "[BENCH COMPILE] ebobby/simple-raytracer"
|
||||
hyperfine --runs "${RUN_RUNS:-10}" --warmup 1 --prepare "../build/cargo-clif clean" \
|
||||
"RUSTFLAGS='' cargo build" \
|
||||
"../build/cargo-clif build"
|
||||
|
||||
echo "[BENCH RUN] ebobby/simple-raytracer"
|
||||
cp ./target/debug/main ./raytracer_cg_clif
|
||||
hyperfine --runs "${RUN_RUNS:-10}" ./raytracer_cg_llvm ./raytracer_cg_clif
|
||||
else
|
||||
../build/cargo-clif clean
|
||||
echo "[BENCH COMPILE] ebobby/simple-raytracer (skipped)"
|
||||
echo "[COMPILE] ebobby/simple-raytracer"
|
||||
../build/cargo-clif build --target $TARGET_TRIPLE
|
||||
echo "[BENCH RUN] ebobby/simple-raytracer (skipped)"
|
||||
fi
|
||||
popd
|
||||
|
||||
pushd build_sysroot/sysroot_src/library/core/tests
|
||||
echo "[TEST] libcore"
|
||||
../../../../../build/cargo-clif clean
|
||||
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
|
||||
../../../../../build/cargo-clif test
|
||||
else
|
||||
../../../../../build/cargo-clif build --target $TARGET_TRIPLE --tests
|
||||
fi
|
||||
popd
|
||||
|
||||
pushd regex
|
||||
echo "[TEST] rust-lang/regex example shootout-regex-dna"
|
||||
../build/cargo-clif clean
|
||||
export RUSTFLAGS="$RUSTFLAGS --cap-lints warn" # newer aho_corasick versions throw a deprecation warning
|
||||
# Make sure `[codegen mono items] start` doesn't poison the diff
|
||||
../build/cargo-clif build --example shootout-regex-dna --target $TARGET_TRIPLE
|
||||
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
|
||||
cat examples/regexdna-input.txt \
|
||||
| ../build/cargo-clif run --example shootout-regex-dna --target $TARGET_TRIPLE \
|
||||
| grep -v "Spawned thread" > res.txt
|
||||
diff -u res.txt examples/regexdna-output.txt
|
||||
fi
|
||||
|
||||
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
|
||||
echo "[TEST] rust-lang/regex tests"
|
||||
../build/cargo-clif test --tests -- --exclude-should-panic --test-threads 1 -Zunstable-options -q
|
||||
else
|
||||
echo "[AOT] rust-lang/regex tests"
|
||||
../build/cargo-clif build --tests --target $TARGET_TRIPLE
|
||||
fi
|
||||
popd
|
||||
|
||||
pushd portable-simd
|
||||
echo "[TEST] rust-lang/portable-simd"
|
||||
../build/cargo-clif clean
|
||||
../build/cargo-clif build --all-targets --target $TARGET_TRIPLE
|
||||
if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
|
||||
../build/cargo-clif test -q
|
||||
fi
|
||||
popd
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
"no_sysroot")
|
||||
no_sysroot_tests
|
||||
;;
|
||||
"base_sysroot")
|
||||
base_sysroot_tests
|
||||
;;
|
||||
"extended_sysroot")
|
||||
extended_sysroot_tests
|
||||
;;
|
||||
*)
|
||||
echo "unknown test suite"
|
||||
;;
|
||||
esac
|
Loading…
x
Reference in New Issue
Block a user