2022-08-24 11:40:58 -05:00
|
|
|
use super::build_sysroot;
|
|
|
|
use super::config;
|
2022-12-01 08:54:37 -06:00
|
|
|
use super::path::{Dirs, RelPath};
|
2022-10-26 09:51:03 -05:00
|
|
|
use super::prepare::GitRepo;
|
2022-12-01 07:30:03 -06:00
|
|
|
use super::rustc_info::{get_cargo_path, get_wrapper_file_name};
|
2022-10-26 09:51:03 -05:00
|
|
|
use super::utils::{
|
|
|
|
hyperfine_command, spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler,
|
|
|
|
};
|
2022-10-28 04:54:05 -05:00
|
|
|
use super::SysrootKind;
|
2022-08-24 11:40:58 -05:00
|
|
|
use std::env;
|
|
|
|
use std::ffi::OsStr;
|
|
|
|
use std::fs;
|
2022-12-01 07:30:03 -06:00
|
|
|
use std::path::Path;
|
2022-08-24 11:40:58 -05:00
|
|
|
use std::process::Command;
|
|
|
|
|
2022-12-01 07:30:03 -06:00
|
|
|
static BUILD_EXAMPLE_OUT_DIR: RelPath = RelPath::BUILD.join("example");
|
|
|
|
|
2022-08-24 11:40:58 -05:00
|
|
|
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",
|
2022-10-26 09:51:03 -05:00
|
|
|
&runner.target_compiler.triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
]);
|
|
|
|
}),
|
|
|
|
TestCase::new("build.example", &|runner| {
|
|
|
|
runner.run_rustc([
|
|
|
|
"example/example.rs",
|
|
|
|
"--crate-type",
|
|
|
|
"lib",
|
|
|
|
"--target",
|
2022-10-26 09:51:03 -05:00
|
|
|
&runner.target_compiler.triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
]);
|
|
|
|
}),
|
|
|
|
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",
|
2022-10-26 09:51:03 -05:00
|
|
|
&runner.target_compiler.triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
]);
|
|
|
|
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",
|
2022-10-26 09:51:03 -05:00
|
|
|
&runner.target_compiler.triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
]);
|
|
|
|
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",
|
2022-10-26 09:51:03 -05:00
|
|
|
&runner.target_compiler.triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
]);
|
|
|
|
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",
|
2022-10-26 09:51:03 -05:00
|
|
|
&runner.target_compiler.triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
]);
|
|
|
|
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",
|
2022-10-26 09:51:03 -05:00
|
|
|
&runner.target_compiler.triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
]);
|
|
|
|
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",
|
2022-10-26 09:51:03 -05:00
|
|
|
&runner.target_compiler.triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
]);
|
|
|
|
}),
|
|
|
|
TestCase::new("aot.alloc_example", &|runner| {
|
|
|
|
runner.run_rustc([
|
|
|
|
"example/alloc_example.rs",
|
|
|
|
"--crate-type",
|
|
|
|
"bin",
|
|
|
|
"--target",
|
2022-10-26 09:51:03 -05:00
|
|
|
&runner.target_compiler.triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
]);
|
|
|
|
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",
|
2022-10-26 09:51:03 -05:00
|
|
|
&runner.target_compiler.triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
]);
|
|
|
|
|
|
|
|
eprintln!("[JIT-lazy] std_example");
|
|
|
|
runner.run_rustc([
|
|
|
|
"-Zunstable-options",
|
|
|
|
"-Cllvm-args=mode=jit-lazy",
|
|
|
|
"-Cprefer-dynamic",
|
|
|
|
"example/std_example.rs",
|
|
|
|
"--target",
|
2022-10-26 09:51:03 -05:00
|
|
|
&runner.target_compiler.triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
]);
|
|
|
|
}),
|
|
|
|
TestCase::new("aot.std_example", &|runner| {
|
|
|
|
runner.run_rustc([
|
|
|
|
"example/std_example.rs",
|
|
|
|
"--crate-type",
|
|
|
|
"bin",
|
|
|
|
"--target",
|
2022-10-26 09:51:03 -05:00
|
|
|
&runner.target_compiler.triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
]);
|
|
|
|
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",
|
2022-10-26 09:51:03 -05:00
|
|
|
&runner.target_compiler.triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
]);
|
|
|
|
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",
|
2022-10-26 09:51:03 -05:00
|
|
|
&runner.target_compiler.triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
]);
|
|
|
|
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",
|
2022-10-26 09:51:03 -05:00
|
|
|
&runner.target_compiler.triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
]);
|
|
|
|
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",
|
2022-10-26 09:51:03 -05:00
|
|
|
&runner.target_compiler.triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
]);
|
|
|
|
runner.run_out_command("float-minmax-pass", []);
|
|
|
|
}),
|
|
|
|
TestCase::new("aot.mod_bench", &|runner| {
|
|
|
|
runner.run_rustc([
|
|
|
|
"example/mod_bench.rs",
|
|
|
|
"--crate-type",
|
|
|
|
"bin",
|
|
|
|
"--target",
|
2022-10-26 09:51:03 -05:00
|
|
|
&runner.target_compiler.triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
]);
|
|
|
|
runner.run_out_command("mod_bench", []);
|
|
|
|
}),
|
2022-12-02 06:44:14 -06:00
|
|
|
TestCase::new("aot.issue-72793", &|runner| {
|
|
|
|
runner.run_rustc([
|
|
|
|
"example/issue-72793.rs",
|
|
|
|
"--crate-type",
|
|
|
|
"bin",
|
|
|
|
"--target",
|
|
|
|
&runner.target_compiler.triple,
|
|
|
|
]);
|
|
|
|
runner.run_out_command("issue-72793", []);
|
|
|
|
}),
|
2022-08-24 11:40:58 -05:00
|
|
|
];
|
|
|
|
|
2022-10-26 09:51:03 -05:00
|
|
|
pub(crate) static RAND_REPO: GitRepo =
|
|
|
|
GitRepo::github("rust-random", "rand", "0f933f9c7176e53b2a3c7952ded484e1783f0bf1", "rand");
|
2022-08-24 11:40:58 -05:00
|
|
|
|
2022-12-01 07:30:03 -06:00
|
|
|
static RAND: CargoProject = CargoProject::new(&RAND_REPO.source_dir(), "rand");
|
2022-08-24 11:40:58 -05:00
|
|
|
|
2022-10-26 09:51:03 -05:00
|
|
|
pub(crate) static REGEX_REPO: GitRepo =
|
|
|
|
GitRepo::github("rust-lang", "regex", "341f207c1071f7290e3f228c710817c280c8dca1", "regex");
|
2022-08-24 11:40:58 -05:00
|
|
|
|
2022-12-01 07:30:03 -06:00
|
|
|
static REGEX: CargoProject = CargoProject::new(®EX_REPO.source_dir(), "regex");
|
2022-08-24 11:40:58 -05:00
|
|
|
|
2022-10-26 09:51:03 -05:00
|
|
|
pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github(
|
|
|
|
"rust-lang",
|
|
|
|
"portable-simd",
|
|
|
|
"d5cd4a8112d958bd3a252327e0d069a6363249bd",
|
|
|
|
"portable-simd",
|
|
|
|
);
|
2022-08-28 12:41:36 -05:00
|
|
|
|
2022-12-01 07:30:03 -06:00
|
|
|
static PORTABLE_SIMD: CargoProject =
|
|
|
|
CargoProject::new(&PORTABLE_SIMD_REPO.source_dir(), "portable_simd");
|
2022-08-28 11:38:09 -05:00
|
|
|
|
2022-10-26 09:51:03 -05:00
|
|
|
pub(crate) static SIMPLE_RAYTRACER_REPO: GitRepo = GitRepo::github(
|
|
|
|
"ebobby",
|
|
|
|
"simple-raytracer",
|
|
|
|
"804a7a21b9e673a482797aa289a18ed480e4d813",
|
|
|
|
"<none>",
|
|
|
|
);
|
2022-08-24 11:40:58 -05:00
|
|
|
|
2022-11-28 11:37:30 -06:00
|
|
|
pub(crate) static SIMPLE_RAYTRACER: CargoProject =
|
2022-12-01 07:30:03 -06:00
|
|
|
CargoProject::new(&SIMPLE_RAYTRACER_REPO.source_dir(), "simple_raytracer");
|
2022-08-24 11:40:58 -05:00
|
|
|
|
2022-10-26 09:51:03 -05:00
|
|
|
static LIBCORE_TESTS: CargoProject =
|
2022-12-01 07:30:03 -06:00
|
|
|
CargoProject::new(&RelPath::BUILD_SYSROOT.join("sysroot_src/library/core/tests"), "core_tests");
|
2022-10-26 09:51:03 -05:00
|
|
|
|
|
|
|
const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
|
|
|
|
TestCase::new("test.rust-random/rand", &|runner| {
|
2022-12-01 08:54:37 -06:00
|
|
|
spawn_and_wait(RAND.clean(&runner.target_compiler.cargo, &runner.dirs));
|
2022-10-26 09:51:03 -05:00
|
|
|
|
|
|
|
if runner.is_native {
|
|
|
|
eprintln!("[TEST] rust-random/rand");
|
2022-12-01 08:54:37 -06:00
|
|
|
let mut test_cmd = RAND.test(&runner.target_compiler, &runner.dirs);
|
2022-10-26 09:51:03 -05:00
|
|
|
test_cmd.arg("--workspace");
|
|
|
|
spawn_and_wait(test_cmd);
|
|
|
|
} else {
|
|
|
|
eprintln!("[AOT] rust-random/rand");
|
2022-12-01 08:54:37 -06:00
|
|
|
let mut build_cmd = RAND.build(&runner.target_compiler, &runner.dirs);
|
2022-10-26 09:51:03 -05:00
|
|
|
build_cmd.arg("--workspace").arg("--tests");
|
|
|
|
spawn_and_wait(build_cmd);
|
|
|
|
}
|
2022-08-24 11:40:58 -05:00
|
|
|
}),
|
2022-10-26 09:51:03 -05:00
|
|
|
TestCase::new("bench.simple-raytracer", &|runner| {
|
|
|
|
let run_runs = env::var("RUN_RUNS").unwrap_or("10".to_string()).parse().unwrap();
|
|
|
|
|
|
|
|
if runner.is_native {
|
|
|
|
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
|
2022-12-01 08:54:37 -06:00
|
|
|
let cargo_clif = RelPath::DIST
|
|
|
|
.to_path(&runner.dirs)
|
|
|
|
.join(get_wrapper_file_name("cargo-clif", "bin"));
|
|
|
|
let manifest_path = SIMPLE_RAYTRACER.manifest_path(&runner.dirs);
|
|
|
|
let target_dir = SIMPLE_RAYTRACER.target_dir(&runner.dirs);
|
2022-10-26 09:51:03 -05:00
|
|
|
|
|
|
|
let clean_cmd = format!(
|
|
|
|
"cargo clean --manifest-path {manifest_path} --target-dir {target_dir}",
|
|
|
|
manifest_path = manifest_path.display(),
|
|
|
|
target_dir = target_dir.display(),
|
|
|
|
);
|
|
|
|
let llvm_build_cmd = format!(
|
|
|
|
"cargo build --manifest-path {manifest_path} --target-dir {target_dir}",
|
|
|
|
manifest_path = manifest_path.display(),
|
|
|
|
target_dir = target_dir.display(),
|
|
|
|
);
|
|
|
|
let clif_build_cmd = format!(
|
|
|
|
"{cargo_clif} build --manifest-path {manifest_path} --target-dir {target_dir}",
|
|
|
|
cargo_clif = cargo_clif.display(),
|
|
|
|
manifest_path = manifest_path.display(),
|
|
|
|
target_dir = target_dir.display(),
|
|
|
|
);
|
|
|
|
|
|
|
|
let bench_compile =
|
|
|
|
hyperfine_command(1, run_runs, Some(&clean_cmd), &llvm_build_cmd, &clif_build_cmd);
|
|
|
|
|
|
|
|
spawn_and_wait(bench_compile);
|
|
|
|
|
|
|
|
eprintln!("[BENCH RUN] ebobby/simple-raytracer");
|
2022-11-28 11:37:30 -06:00
|
|
|
fs::copy(
|
|
|
|
target_dir.join("debug").join("main"),
|
2022-12-01 08:54:37 -06:00
|
|
|
RelPath::BUILD.to_path(&runner.dirs).join("raytracer_cg_clif"),
|
2022-11-28 11:37:30 -06:00
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let mut bench_run =
|
|
|
|
hyperfine_command(0, run_runs, None, "./raytracer_cg_llvm", "./raytracer_cg_clif");
|
2022-12-01 08:54:37 -06:00
|
|
|
bench_run.current_dir(RelPath::BUILD.to_path(&runner.dirs));
|
2022-10-26 09:51:03 -05:00
|
|
|
spawn_and_wait(bench_run);
|
|
|
|
} else {
|
2022-12-01 08:54:37 -06:00
|
|
|
spawn_and_wait(SIMPLE_RAYTRACER.clean(&runner.target_compiler.cargo, &runner.dirs));
|
2022-10-26 09:51:03 -05:00
|
|
|
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer (skipped)");
|
|
|
|
eprintln!("[COMPILE] ebobby/simple-raytracer");
|
2022-12-01 08:54:37 -06:00
|
|
|
spawn_and_wait(SIMPLE_RAYTRACER.build(&runner.target_compiler, &runner.dirs));
|
2022-10-26 09:51:03 -05:00
|
|
|
eprintln!("[BENCH RUN] ebobby/simple-raytracer (skipped)");
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
TestCase::new("test.libcore", &|runner| {
|
2022-12-01 08:54:37 -06:00
|
|
|
spawn_and_wait(LIBCORE_TESTS.clean(&runner.host_compiler.cargo, &runner.dirs));
|
2022-10-26 09:51:03 -05:00
|
|
|
|
|
|
|
if runner.is_native {
|
2022-12-01 08:54:37 -06:00
|
|
|
spawn_and_wait(LIBCORE_TESTS.test(&runner.target_compiler, &runner.dirs));
|
2022-10-26 09:51:03 -05:00
|
|
|
} else {
|
|
|
|
eprintln!("Cross-Compiling: Not running tests");
|
2022-12-01 08:54:37 -06:00
|
|
|
let mut build_cmd = LIBCORE_TESTS.build(&runner.target_compiler, &runner.dirs);
|
2022-10-26 09:51:03 -05:00
|
|
|
build_cmd.arg("--tests");
|
|
|
|
spawn_and_wait(build_cmd);
|
|
|
|
}
|
2022-08-24 11:40:58 -05:00
|
|
|
}),
|
|
|
|
TestCase::new("test.regex-shootout-regex-dna", &|runner| {
|
2022-12-01 08:54:37 -06:00
|
|
|
spawn_and_wait(REGEX.clean(&runner.target_compiler.cargo, &runner.dirs));
|
2022-08-24 11:40:58 -05:00
|
|
|
|
2022-10-26 09:51:03 -05:00
|
|
|
// newer aho_corasick versions throw a deprecation warning
|
|
|
|
let lint_rust_flags = format!("{} --cap-lints warn", runner.target_compiler.rustflags);
|
2022-08-24 11:40:58 -05:00
|
|
|
|
2022-12-01 08:54:37 -06:00
|
|
|
let mut build_cmd = REGEX.build(&runner.target_compiler, &runner.dirs);
|
2022-10-26 09:51:03 -05:00
|
|
|
build_cmd.arg("--example").arg("shootout-regex-dna");
|
|
|
|
build_cmd.env("RUSTFLAGS", lint_rust_flags.clone());
|
|
|
|
spawn_and_wait(build_cmd);
|
|
|
|
|
|
|
|
if runner.is_native {
|
2022-12-01 08:54:37 -06:00
|
|
|
let mut run_cmd = REGEX.run(&runner.target_compiler, &runner.dirs);
|
2022-10-26 09:51:03 -05:00
|
|
|
run_cmd.arg("--example").arg("shootout-regex-dna");
|
|
|
|
run_cmd.env("RUSTFLAGS", lint_rust_flags);
|
2022-08-24 11:40:58 -05:00
|
|
|
|
2022-12-01 08:54:37 -06:00
|
|
|
let input = fs::read_to_string(
|
|
|
|
REGEX.source_dir(&runner.dirs).join("examples").join("regexdna-input.txt"),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
let expected_path =
|
|
|
|
REGEX.source_dir(&runner.dirs).join("examples").join("regexdna-output.txt");
|
2022-10-26 09:51:03 -05:00
|
|
|
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 {
|
2022-12-01 08:54:37 -06:00
|
|
|
let res_path = REGEX.source_dir(&runner.dirs).join("res.txt");
|
2022-10-26 09:51:03 -05:00
|
|
|
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);
|
2022-08-24 11:40:58 -05:00
|
|
|
}
|
2022-10-26 09:51:03 -05:00
|
|
|
|
|
|
|
std::process::exit(1);
|
2022-08-24 11:40:58 -05:00
|
|
|
}
|
2022-10-26 09:51:03 -05:00
|
|
|
}
|
2022-08-24 11:40:58 -05:00
|
|
|
}),
|
|
|
|
TestCase::new("test.regex", &|runner| {
|
2022-12-01 08:54:37 -06:00
|
|
|
spawn_and_wait(REGEX.clean(&runner.host_compiler.cargo, &runner.dirs));
|
2022-10-26 09:51:03 -05:00
|
|
|
|
|
|
|
// newer aho_corasick versions throw a deprecation warning
|
|
|
|
let lint_rust_flags = format!("{} --cap-lints warn", runner.target_compiler.rustflags);
|
|
|
|
|
|
|
|
if runner.is_native {
|
2022-12-01 08:54:37 -06:00
|
|
|
let mut run_cmd = REGEX.test(&runner.target_compiler, &runner.dirs);
|
2022-10-26 09:51:03 -05:00
|
|
|
run_cmd.args([
|
|
|
|
"--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");
|
2022-12-01 08:54:37 -06:00
|
|
|
let mut build_cmd = REGEX.build(&runner.target_compiler, &runner.dirs);
|
2022-10-26 09:51:03 -05:00
|
|
|
build_cmd.arg("--tests");
|
|
|
|
build_cmd.env("RUSTFLAGS", lint_rust_flags.clone());
|
|
|
|
spawn_and_wait(build_cmd);
|
|
|
|
}
|
2022-08-24 11:40:58 -05:00
|
|
|
}),
|
|
|
|
TestCase::new("test.portable-simd", &|runner| {
|
2022-12-01 08:54:37 -06:00
|
|
|
spawn_and_wait(PORTABLE_SIMD.clean(&runner.host_compiler.cargo, &runner.dirs));
|
2022-08-24 11:40:58 -05:00
|
|
|
|
2022-12-01 08:54:37 -06:00
|
|
|
let mut build_cmd = PORTABLE_SIMD.build(&runner.target_compiler, &runner.dirs);
|
2022-10-26 09:51:03 -05:00
|
|
|
build_cmd.arg("--all-targets");
|
|
|
|
spawn_and_wait(build_cmd);
|
|
|
|
|
|
|
|
if runner.is_native {
|
2022-12-01 08:54:37 -06:00
|
|
|
let mut test_cmd = PORTABLE_SIMD.test(&runner.target_compiler, &runner.dirs);
|
2022-10-26 09:51:03 -05:00
|
|
|
test_cmd.arg("-q");
|
|
|
|
spawn_and_wait(test_cmd);
|
|
|
|
}
|
2022-08-24 11:40:58 -05:00
|
|
|
}),
|
|
|
|
];
|
|
|
|
|
|
|
|
pub(crate) fn run_tests(
|
2022-12-01 08:54:37 -06:00
|
|
|
dirs: &Dirs,
|
2022-08-24 11:40:58 -05:00
|
|
|
channel: &str,
|
|
|
|
sysroot_kind: SysrootKind,
|
2022-08-28 11:46:09 -05:00
|
|
|
cg_clif_dylib: &Path,
|
2022-08-24 11:40:58 -05:00
|
|
|
host_triple: &str,
|
|
|
|
target_triple: &str,
|
|
|
|
) {
|
2022-12-01 08:54:37 -06:00
|
|
|
let runner = TestRunner::new(dirs.clone(), host_triple.to_string(), target_triple.to_string());
|
2022-08-24 11:40:58 -05:00
|
|
|
|
|
|
|
if config::get_bool("testsuite.no_sysroot") {
|
|
|
|
build_sysroot::build_sysroot(
|
2022-12-01 08:54:37 -06:00
|
|
|
dirs,
|
2022-08-24 11:40:58 -05:00
|
|
|
channel,
|
|
|
|
SysrootKind::None,
|
2022-08-28 11:46:09 -05:00
|
|
|
cg_clif_dylib,
|
2022-08-24 11:40:58 -05:00
|
|
|
&host_triple,
|
|
|
|
&target_triple,
|
|
|
|
);
|
|
|
|
|
2022-12-01 08:54:37 -06:00
|
|
|
BUILD_EXAMPLE_OUT_DIR.ensure_fresh(dirs);
|
2022-08-24 11:40:58 -05:00
|
|
|
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(
|
2022-12-01 08:54:37 -06:00
|
|
|
dirs,
|
2022-08-24 11:40:58 -05:00
|
|
|
channel,
|
|
|
|
sysroot_kind,
|
2022-08-28 11:46:09 -05:00
|
|
|
cg_clif_dylib,
|
2022-08-24 11:40:58 -05:00
|
|
|
&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 {
|
2022-10-26 09:51:03 -05:00
|
|
|
is_native: bool,
|
2022-08-24 11:40:58 -05:00
|
|
|
jit_supported: bool,
|
2022-12-01 08:54:37 -06:00
|
|
|
dirs: Dirs,
|
2022-10-26 09:51:03 -05:00
|
|
|
host_compiler: Compiler,
|
|
|
|
target_compiler: Compiler,
|
2022-08-24 11:40:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl TestRunner {
|
2022-12-01 08:54:37 -06:00
|
|
|
pub fn new(dirs: Dirs, host_triple: String, target_triple: String) -> Self {
|
2022-08-24 11:40:58 -05:00
|
|
|
let is_native = host_triple == target_triple;
|
2022-09-26 07:38:53 -05:00
|
|
|
let jit_supported =
|
|
|
|
target_triple.contains("x86_64") && is_native && !host_triple.contains("windows");
|
2022-08-24 11:40:58 -05:00
|
|
|
|
2022-12-01 08:54:37 -06:00
|
|
|
let rustc_clif =
|
|
|
|
RelPath::DIST.to_path(&dirs).join(get_wrapper_file_name("rustc-clif", "bin"));
|
2022-12-01 07:30:03 -06:00
|
|
|
let rustdoc_clif =
|
2022-12-01 08:54:37 -06:00
|
|
|
RelPath::DIST.to_path(&dirs).join(get_wrapper_file_name("rustdoc-clif", "bin"));
|
2022-10-26 09:51:03 -05:00
|
|
|
|
|
|
|
let mut rustflags = env::var("RUSTFLAGS").ok().unwrap_or("".to_string());
|
|
|
|
let mut runner = vec![];
|
2022-08-24 11:40:58 -05:00
|
|
|
|
|
|
|
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.
|
2022-10-26 09:51:03 -05:00
|
|
|
rustflags = format!("-Clinker=aarch64-linux-gnu-gcc{}", rustflags);
|
|
|
|
runner = vec![
|
|
|
|
"qemu-aarch64".to_owned(),
|
|
|
|
"-L".to_owned(),
|
|
|
|
"/usr/aarch64-linux-gnu".to_owned(),
|
|
|
|
];
|
2022-08-24 11:40:58 -05:00
|
|
|
}
|
2022-12-03 17:23:01 -06:00
|
|
|
"s390x-unknown-linux-gnu" => {
|
|
|
|
// We are cross-compiling for s390x. Use the correct linker and run tests in qemu.
|
|
|
|
rustflags = format!("-Clinker=s390x-linux-gnu-gcc{}", rustflags);
|
|
|
|
runner = vec![
|
|
|
|
"qemu-s390x".to_owned(),
|
|
|
|
"-L".to_owned(),
|
|
|
|
"/usr/s390x-linux-gnu".to_owned(),
|
|
|
|
];
|
|
|
|
}
|
2022-08-24 11:40:58 -05:00
|
|
|
"x86_64-pc-windows-gnu" => {
|
|
|
|
// We are cross-compiling for Windows. Run tests in wine.
|
2022-10-26 09:51:03 -05:00
|
|
|
runner = vec!["wine".to_owned()];
|
2022-08-24 11:40:58 -05:00
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
println!("Unknown non-native platform");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME fix `#[linkage = "extern_weak"]` without this
|
2022-10-26 09:51:03 -05:00
|
|
|
if target_triple.contains("darwin") {
|
|
|
|
rustflags = format!("{} -Clink-arg=-undefined -Clink-arg=dynamic_lookup", rustflags);
|
2022-08-24 11:40:58 -05:00
|
|
|
}
|
|
|
|
|
2022-10-26 09:51:03 -05:00
|
|
|
let host_compiler = Compiler {
|
|
|
|
cargo: get_cargo_path(),
|
|
|
|
rustc: rustc_clif.clone(),
|
|
|
|
rustdoc: rustdoc_clif.clone(),
|
|
|
|
rustflags: String::new(),
|
|
|
|
rustdocflags: String::new(),
|
|
|
|
triple: host_triple,
|
|
|
|
runner: vec![],
|
|
|
|
};
|
|
|
|
|
|
|
|
let target_compiler = Compiler {
|
|
|
|
cargo: get_cargo_path(),
|
2022-12-01 07:30:03 -06:00
|
|
|
rustc: rustc_clif,
|
|
|
|
rustdoc: rustdoc_clif,
|
2022-10-26 09:51:03 -05:00
|
|
|
rustflags: rustflags.clone(),
|
|
|
|
rustdocflags: rustflags,
|
|
|
|
triple: target_triple,
|
|
|
|
runner,
|
|
|
|
};
|
|
|
|
|
2022-12-01 08:54:37 -06:00
|
|
|
Self { is_native, jit_supported, dirs, host_compiler, target_compiler }
|
2022-08-24 11:40:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-26 09:51:03 -05:00
|
|
|
#[must_use]
|
2022-08-24 11:40:58 -05:00
|
|
|
fn rustc_command<I, S>(&self, args: I) -> Command
|
|
|
|
where
|
|
|
|
I: IntoIterator<Item = S>,
|
|
|
|
S: AsRef<OsStr>,
|
|
|
|
{
|
2022-10-26 09:51:03 -05:00
|
|
|
let mut cmd = Command::new(&self.target_compiler.rustc);
|
|
|
|
cmd.args(self.target_compiler.rustflags.split_whitespace());
|
2022-08-24 11:40:58 -05:00
|
|
|
cmd.arg("-L");
|
2022-12-01 08:54:37 -06:00
|
|
|
cmd.arg(format!("crate={}", BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).display()));
|
2022-08-24 11:40:58 -05:00
|
|
|
cmd.arg("--out-dir");
|
2022-12-01 08:54:37 -06:00
|
|
|
cmd.arg(format!("{}", BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).display()));
|
2022-08-24 11:40:58 -05:00
|
|
|
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
|
2022-10-26 09:51:03 -05:00
|
|
|
if !self.target_compiler.runner.is_empty() {
|
|
|
|
full_cmd.extend(self.target_compiler.runner.iter().cloned());
|
2022-08-24 11:40:58 -05:00
|
|
|
}
|
|
|
|
|
2022-12-01 08:54:37 -06:00
|
|
|
full_cmd.push(
|
|
|
|
BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).join(name).to_str().unwrap().to_string(),
|
|
|
|
);
|
2022-08-24 11:40:58 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|