2022-08-24 11:40:58 -05:00
|
|
|
use std::ffi::OsStr;
|
|
|
|
use std::fs;
|
2023-06-15 12:56:01 -05:00
|
|
|
use std::path::PathBuf;
|
2022-08-24 11:40:58 -05:00
|
|
|
use std::process::Command;
|
|
|
|
|
2023-08-09 13:20:12 -05:00
|
|
|
use crate::build_sysroot;
|
|
|
|
use crate::config;
|
|
|
|
use crate::path::{Dirs, RelPath};
|
|
|
|
use crate::prepare::{apply_patches, GitRepo};
|
|
|
|
use crate::rustc_info::get_default_sysroot;
|
|
|
|
use crate::shared_utils::rustflags_from_env;
|
2023-10-09 03:52:46 -05:00
|
|
|
use crate::utils::{spawn_and_wait, CargoProject, Compiler, LogGroup};
|
2023-08-09 13:20:12 -05:00
|
|
|
use crate::{CodegenBackend, SysrootKind};
|
|
|
|
|
2022-12-14 12:30:46 -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,
|
2023-01-24 11:56:42 -06:00
|
|
|
cmd: TestCaseCmd,
|
|
|
|
}
|
|
|
|
|
|
|
|
enum TestCaseCmd {
|
2023-06-15 12:56:01 -05:00
|
|
|
Custom { func: &'static dyn Fn(&TestRunner<'_>) },
|
2023-01-24 11:56:42 -06:00
|
|
|
BuildLib { source: &'static str, crate_types: &'static str },
|
2023-07-22 08:32:34 -05:00
|
|
|
BuildBin { source: &'static str },
|
2023-01-24 11:56:42 -06:00
|
|
|
BuildBinAndRun { source: &'static str, args: &'static [&'static str] },
|
|
|
|
JitBin { source: &'static str, args: &'static str },
|
2022-08-24 11:40:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl TestCase {
|
2023-01-24 11:56:42 -06:00
|
|
|
// FIXME reduce usage of custom test case commands
|
2023-06-15 12:56:01 -05:00
|
|
|
const fn custom(config: &'static str, func: &'static dyn Fn(&TestRunner<'_>)) -> Self {
|
2023-01-24 11:56:42 -06:00
|
|
|
Self { config, cmd: TestCaseCmd::Custom { func } }
|
|
|
|
}
|
|
|
|
|
|
|
|
const fn build_lib(
|
|
|
|
config: &'static str,
|
|
|
|
source: &'static str,
|
|
|
|
crate_types: &'static str,
|
|
|
|
) -> Self {
|
|
|
|
Self { config, cmd: TestCaseCmd::BuildLib { source, crate_types } }
|
|
|
|
}
|
|
|
|
|
2023-07-22 08:32:34 -05:00
|
|
|
const fn build_bin(config: &'static str, source: &'static str) -> Self {
|
|
|
|
Self { config, cmd: TestCaseCmd::BuildBin { source } }
|
|
|
|
}
|
|
|
|
|
2023-01-24 11:56:42 -06:00
|
|
|
const fn build_bin_and_run(
|
|
|
|
config: &'static str,
|
|
|
|
source: &'static str,
|
|
|
|
args: &'static [&'static str],
|
|
|
|
) -> Self {
|
|
|
|
Self { config, cmd: TestCaseCmd::BuildBinAndRun { source, args } }
|
|
|
|
}
|
|
|
|
|
|
|
|
const fn jit_bin(config: &'static str, source: &'static str, args: &'static str) -> Self {
|
|
|
|
Self { config, cmd: TestCaseCmd::JitBin { source, args } }
|
2022-08-24 11:40:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const NO_SYSROOT_SUITE: &[TestCase] = &[
|
2023-01-24 11:56:42 -06:00
|
|
|
TestCase::build_lib("build.mini_core", "example/mini_core.rs", "lib,dylib"),
|
|
|
|
TestCase::build_lib("build.example", "example/example.rs", "lib"),
|
|
|
|
TestCase::jit_bin("jit.mini_core_hello_world", "example/mini_core_hello_world.rs", "abc bcd"),
|
|
|
|
TestCase::build_bin_and_run(
|
|
|
|
"aot.mini_core_hello_world",
|
|
|
|
"example/mini_core_hello_world.rs",
|
|
|
|
&["abc", "bcd"],
|
|
|
|
),
|
2022-08-24 11:40:58 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
const BASE_SYSROOT_SUITE: &[TestCase] = &[
|
2023-01-24 11:56:42 -06:00
|
|
|
TestCase::build_bin_and_run(
|
|
|
|
"aot.arbitrary_self_types_pointers_and_wrappers",
|
|
|
|
"example/arbitrary_self_types_pointers_and_wrappers.rs",
|
|
|
|
&[],
|
|
|
|
),
|
|
|
|
TestCase::build_lib("build.alloc_system", "example/alloc_system.rs", "lib"),
|
|
|
|
TestCase::build_bin_and_run("aot.alloc_example", "example/alloc_example.rs", &[]),
|
|
|
|
TestCase::jit_bin("jit.std_example", "example/std_example.rs", ""),
|
|
|
|
TestCase::build_bin_and_run("aot.std_example", "example/std_example.rs", &["arg"]),
|
|
|
|
TestCase::build_bin_and_run("aot.dst_field_align", "example/dst-field-align.rs", &[]),
|
|
|
|
TestCase::build_bin_and_run(
|
|
|
|
"aot.subslice-patterns-const-eval",
|
|
|
|
"example/subslice-patterns-const-eval.rs",
|
|
|
|
&[],
|
|
|
|
),
|
|
|
|
TestCase::build_bin_and_run(
|
|
|
|
"aot.track-caller-attribute",
|
|
|
|
"example/track-caller-attribute.rs",
|
|
|
|
&[],
|
|
|
|
),
|
|
|
|
TestCase::build_bin_and_run("aot.float-minmax-pass", "example/float-minmax-pass.rs", &[]),
|
|
|
|
TestCase::build_bin_and_run("aot.mod_bench", "example/mod_bench.rs", &[]),
|
|
|
|
TestCase::build_bin_and_run("aot.issue-72793", "example/issue-72793.rs", &[]),
|
2023-07-22 08:32:34 -05:00
|
|
|
TestCase::build_bin("aot.issue-59326", "example/issue-59326.rs"),
|
2023-11-25 04:05:52 -06:00
|
|
|
TestCase::custom("aot.polymorphize_coroutine", &|runner| {
|
|
|
|
runner.run_rustc(&["example/polymorphize_coroutine.rs", "-Zpolymorphize"]);
|
|
|
|
runner.run_out_command("polymorphize_coroutine", &[]);
|
|
|
|
}),
|
2023-11-10 05:30:51 -06:00
|
|
|
TestCase::build_bin_and_run("aot.neon", "example/neon.rs", &[]),
|
2023-11-23 14:02:45 -06:00
|
|
|
TestCase::custom("aot.gen_block_iterate", &|runner| {
|
|
|
|
runner.run_rustc([
|
|
|
|
"example/gen_block_iterate.rs",
|
|
|
|
"--edition",
|
|
|
|
"2024",
|
|
|
|
"-Zunstable-options",
|
|
|
|
]);
|
|
|
|
runner.run_out_command("gen_block_iterate", &[]);
|
|
|
|
}),
|
2022-08-24 11:40:58 -05:00
|
|
|
];
|
|
|
|
|
2023-06-15 12:56:01 -05:00
|
|
|
pub(crate) static RAND_REPO: GitRepo = GitRepo::github(
|
|
|
|
"rust-random",
|
|
|
|
"rand",
|
2024-01-26 12:33:45 -06:00
|
|
|
"1f4507a8e1cf8050e4ceef95eeda8f64645b6719",
|
|
|
|
"981f8bf489338978",
|
2023-06-15 12:56:01 -05:00
|
|
|
"rand",
|
|
|
|
);
|
2022-12-14 12:30:46 -06:00
|
|
|
|
2023-06-15 12:56:01 -05:00
|
|
|
pub(crate) static RAND: CargoProject = CargoProject::new(&RAND_REPO.source_dir(), "rand_target");
|
2022-12-14 12:30:46 -06:00
|
|
|
|
2023-06-15 12:56:01 -05:00
|
|
|
pub(crate) static REGEX_REPO: GitRepo = GitRepo::github(
|
|
|
|
"rust-lang",
|
|
|
|
"regex",
|
2023-10-09 03:52:46 -05:00
|
|
|
"061ee815ef2c44101dba7b0b124600fcb03c1912",
|
|
|
|
"dc26aefbeeac03ca",
|
2023-06-15 12:56:01 -05:00
|
|
|
"regex",
|
|
|
|
);
|
2022-12-14 12:30:46 -06:00
|
|
|
|
2023-06-15 12:56:01 -05:00
|
|
|
pub(crate) static REGEX: CargoProject = CargoProject::new(®EX_REPO.source_dir(), "regex_target");
|
2022-12-14 12:30:46 -06:00
|
|
|
|
|
|
|
pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github(
|
|
|
|
"rust-lang",
|
|
|
|
"portable-simd",
|
2024-01-26 12:33:45 -06:00
|
|
|
"97007cc2e70df8c97326ce896a79e2f0ce4dd98b",
|
|
|
|
"e54a16035cedf205",
|
2022-12-14 12:30:46 -06:00
|
|
|
"portable-simd",
|
|
|
|
);
|
|
|
|
|
2023-01-24 11:56:42 -06:00
|
|
|
pub(crate) static PORTABLE_SIMD: CargoProject =
|
2023-06-15 12:56:01 -05:00
|
|
|
CargoProject::new(&PORTABLE_SIMD_REPO.source_dir(), "portable-simd_target");
|
2022-12-14 12:30:46 -06:00
|
|
|
|
2023-06-15 12:56:01 -05:00
|
|
|
static LIBCORE_TESTS_SRC: RelPath = RelPath::BUILD.join("coretests");
|
2023-03-15 09:41:48 -05:00
|
|
|
|
2023-06-15 12:56:01 -05:00
|
|
|
static LIBCORE_TESTS: CargoProject = CargoProject::new(&LIBCORE_TESTS_SRC, "coretests_target");
|
2022-12-14 12:30:46 -06:00
|
|
|
|
2022-08-24 11:40:58 -05:00
|
|
|
const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
|
2023-01-24 11:56:42 -06:00
|
|
|
TestCase::custom("test.rust-random/rand", &|runner| {
|
2023-06-15 12:56:01 -05:00
|
|
|
RAND_REPO.patch(&runner.dirs);
|
|
|
|
|
2023-01-24 11:56:42 -06:00
|
|
|
RAND.clean(&runner.dirs);
|
2022-12-14 12:30:46 -06:00
|
|
|
|
|
|
|
if runner.is_native {
|
|
|
|
let mut test_cmd = RAND.test(&runner.target_compiler, &runner.dirs);
|
2023-03-15 09:41:48 -05:00
|
|
|
test_cmd.arg("--workspace").arg("--").arg("-q");
|
2022-12-14 12:30:46 -06:00
|
|
|
spawn_and_wait(test_cmd);
|
|
|
|
} else {
|
2023-03-15 09:41:48 -05:00
|
|
|
eprintln!("Cross-Compiling: Not running tests");
|
2022-12-14 12:30:46 -06:00
|
|
|
let mut build_cmd = RAND.build(&runner.target_compiler, &runner.dirs);
|
|
|
|
build_cmd.arg("--workspace").arg("--tests");
|
|
|
|
spawn_and_wait(build_cmd);
|
|
|
|
}
|
2022-08-24 11:40:58 -05:00
|
|
|
}),
|
2023-01-24 11:56:42 -06:00
|
|
|
TestCase::custom("test.libcore", &|runner| {
|
2023-06-15 12:56:01 -05:00
|
|
|
apply_patches(
|
|
|
|
&runner.dirs,
|
|
|
|
"coretests",
|
|
|
|
&runner.stdlib_source.join("library/core/tests"),
|
|
|
|
&LIBCORE_TESTS_SRC.to_path(&runner.dirs),
|
|
|
|
);
|
|
|
|
|
|
|
|
let source_lockfile = RelPath::PATCHES.to_path(&runner.dirs).join("coretests-lock.toml");
|
|
|
|
let target_lockfile = LIBCORE_TESTS_SRC.to_path(&runner.dirs).join("Cargo.lock");
|
|
|
|
fs::copy(source_lockfile, target_lockfile).unwrap();
|
|
|
|
|
2023-01-24 11:56:42 -06:00
|
|
|
LIBCORE_TESTS.clean(&runner.dirs);
|
2022-12-14 12:30:46 -06:00
|
|
|
|
|
|
|
if runner.is_native {
|
2023-03-15 09:41:48 -05:00
|
|
|
let mut test_cmd = LIBCORE_TESTS.test(&runner.target_compiler, &runner.dirs);
|
|
|
|
test_cmd.arg("--").arg("-q");
|
|
|
|
spawn_and_wait(test_cmd);
|
2022-12-14 12:30:46 -06:00
|
|
|
} else {
|
|
|
|
eprintln!("Cross-Compiling: Not running tests");
|
|
|
|
let mut build_cmd = LIBCORE_TESTS.build(&runner.target_compiler, &runner.dirs);
|
|
|
|
build_cmd.arg("--tests");
|
|
|
|
spawn_and_wait(build_cmd);
|
|
|
|
}
|
2022-08-24 11:40:58 -05:00
|
|
|
}),
|
2023-01-24 11:56:42 -06:00
|
|
|
TestCase::custom("test.regex", &|runner| {
|
2023-06-15 12:56:01 -05:00
|
|
|
REGEX_REPO.patch(&runner.dirs);
|
|
|
|
|
2023-01-24 11:56:42 -06:00
|
|
|
REGEX.clean(&runner.dirs);
|
2022-12-14 12:30:46 -06:00
|
|
|
|
|
|
|
if runner.is_native {
|
|
|
|
let mut run_cmd = REGEX.test(&runner.target_compiler, &runner.dirs);
|
2023-04-29 07:00:43 -05:00
|
|
|
// regex-capi and regex-debug don't have any tests. Nor do they contain any code
|
|
|
|
// that is useful to test with cg_clif. Skip building them to reduce test time.
|
2023-10-09 03:52:46 -05:00
|
|
|
run_cmd.args([
|
|
|
|
"-p",
|
|
|
|
"regex",
|
|
|
|
"-p",
|
|
|
|
"regex-syntax",
|
|
|
|
"--release",
|
|
|
|
"--all-targets",
|
|
|
|
"--",
|
|
|
|
"-q",
|
|
|
|
]);
|
|
|
|
spawn_and_wait(run_cmd);
|
|
|
|
|
|
|
|
let mut run_cmd = REGEX.test(&runner.target_compiler, &runner.dirs);
|
|
|
|
// don't run integration tests for regex-autonata. they take like 2min each without
|
|
|
|
// much extra coverage of simd usage.
|
|
|
|
run_cmd.args(["-p", "regex-automata", "--release", "--lib", "--", "-q"]);
|
2022-12-14 12:30:46 -06:00
|
|
|
spawn_and_wait(run_cmd);
|
|
|
|
} else {
|
|
|
|
eprintln!("Cross-Compiling: Not running tests");
|
|
|
|
let mut build_cmd = REGEX.build(&runner.target_compiler, &runner.dirs);
|
|
|
|
build_cmd.arg("--tests");
|
|
|
|
spawn_and_wait(build_cmd);
|
|
|
|
}
|
2022-08-24 11:40:58 -05:00
|
|
|
}),
|
2023-01-24 11:56:42 -06:00
|
|
|
TestCase::custom("test.portable-simd", &|runner| {
|
2023-06-15 12:56:01 -05:00
|
|
|
PORTABLE_SIMD_REPO.patch(&runner.dirs);
|
|
|
|
|
2023-01-24 11:56:42 -06:00
|
|
|
PORTABLE_SIMD.clean(&runner.dirs);
|
2022-08-24 11:40:58 -05:00
|
|
|
|
2022-12-14 12:30:46 -06:00
|
|
|
let mut build_cmd = PORTABLE_SIMD.build(&runner.target_compiler, &runner.dirs);
|
|
|
|
build_cmd.arg("--all-targets");
|
|
|
|
spawn_and_wait(build_cmd);
|
|
|
|
|
|
|
|
if runner.is_native {
|
|
|
|
let mut test_cmd = PORTABLE_SIMD.test(&runner.target_compiler, &runner.dirs);
|
|
|
|
test_cmd.arg("-q");
|
2023-12-19 06:46:39 -06:00
|
|
|
// FIXME remove after portable-simd update
|
|
|
|
test_cmd
|
|
|
|
.arg("--")
|
|
|
|
.arg("--skip")
|
|
|
|
.arg("core_simd::swizzle::simd_swizzle")
|
|
|
|
.arg("--skip")
|
|
|
|
.arg("core_simd::vector::Simd<T,N>::lanes");
|
2022-12-14 12:30:46 -06:00
|
|
|
spawn_and_wait(test_cmd);
|
|
|
|
}
|
2022-08-24 11:40:58 -05:00
|
|
|
}),
|
|
|
|
];
|
|
|
|
|
|
|
|
pub(crate) fn run_tests(
|
2022-12-14 12:30:46 -06:00
|
|
|
dirs: &Dirs,
|
2022-08-24 11:40:58 -05:00
|
|
|
channel: &str,
|
|
|
|
sysroot_kind: SysrootKind,
|
2023-06-15 12:56:01 -05:00
|
|
|
use_unstable_features: bool,
|
|
|
|
skip_tests: &[&str],
|
|
|
|
cg_clif_dylib: &CodegenBackend,
|
2023-01-24 11:56:42 -06:00
|
|
|
bootstrap_host_compiler: &Compiler,
|
2023-06-15 12:56:01 -05:00
|
|
|
rustup_toolchain_name: Option<&str>,
|
2023-01-24 11:56:42 -06:00
|
|
|
target_triple: String,
|
2022-08-24 11:40:58 -05:00
|
|
|
) {
|
2023-06-15 12:56:01 -05:00
|
|
|
let stdlib_source =
|
|
|
|
get_default_sysroot(&bootstrap_host_compiler.rustc).join("lib/rustlib/src/rust");
|
|
|
|
assert!(stdlib_source.exists());
|
|
|
|
|
|
|
|
if config::get_bool("testsuite.no_sysroot") && !skip_tests.contains(&"testsuite.no_sysroot") {
|
2023-01-24 11:56:42 -06:00
|
|
|
let target_compiler = build_sysroot::build_sysroot(
|
2022-12-14 12:30:46 -06:00
|
|
|
dirs,
|
2022-08-24 11:40:58 -05:00
|
|
|
channel,
|
|
|
|
SysrootKind::None,
|
2022-10-23 09:22:55 -05:00
|
|
|
cg_clif_dylib,
|
2023-01-24 11:56:42 -06:00
|
|
|
bootstrap_host_compiler,
|
2023-06-15 12:56:01 -05:00
|
|
|
rustup_toolchain_name,
|
2023-01-24 11:56:42 -06:00
|
|
|
target_triple.clone(),
|
2022-08-24 11:40:58 -05:00
|
|
|
);
|
|
|
|
|
2023-04-29 07:00:43 -05:00
|
|
|
let runner = TestRunner::new(
|
|
|
|
dirs.clone(),
|
|
|
|
target_compiler,
|
2023-06-15 12:56:01 -05:00
|
|
|
use_unstable_features,
|
|
|
|
skip_tests,
|
2023-04-29 07:00:43 -05:00
|
|
|
bootstrap_host_compiler.triple == target_triple,
|
2023-06-15 12:56:01 -05:00
|
|
|
stdlib_source.clone(),
|
2023-04-29 07:00:43 -05:00
|
|
|
);
|
2023-01-24 11:56:42 -06:00
|
|
|
|
2022-12-14 12:30:46 -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");
|
|
|
|
}
|
|
|
|
|
2023-06-15 12:56:01 -05:00
|
|
|
let run_base_sysroot = config::get_bool("testsuite.base_sysroot")
|
|
|
|
&& !skip_tests.contains(&"testsuite.base_sysroot");
|
|
|
|
let run_extended_sysroot = config::get_bool("testsuite.extended_sysroot")
|
|
|
|
&& !skip_tests.contains(&"testsuite.extended_sysroot");
|
2022-08-24 11:40:58 -05:00
|
|
|
|
|
|
|
if run_base_sysroot || run_extended_sysroot {
|
2023-06-15 12:56:01 -05:00
|
|
|
let mut target_compiler = build_sysroot::build_sysroot(
|
2022-12-14 12:30:46 -06:00
|
|
|
dirs,
|
2022-08-24 11:40:58 -05:00
|
|
|
channel,
|
|
|
|
sysroot_kind,
|
2022-10-23 09:22:55 -05:00
|
|
|
cg_clif_dylib,
|
2023-01-24 11:56:42 -06:00
|
|
|
bootstrap_host_compiler,
|
2023-06-15 12:56:01 -05:00
|
|
|
rustup_toolchain_name,
|
2023-01-24 11:56:42 -06:00
|
|
|
target_triple.clone(),
|
2022-08-24 11:40:58 -05:00
|
|
|
);
|
2023-06-15 12:56:01 -05:00
|
|
|
// Rust's build system denies a couple of lints that trigger on several of the test
|
|
|
|
// projects. Changing the code to fix them is not worth it, so just silence all lints.
|
2023-08-09 13:20:12 -05:00
|
|
|
target_compiler.rustflags.push("--cap-lints=allow".to_owned());
|
2022-08-24 11:40:58 -05:00
|
|
|
|
2023-04-29 07:00:43 -05:00
|
|
|
let runner = TestRunner::new(
|
|
|
|
dirs.clone(),
|
|
|
|
target_compiler,
|
2023-06-15 12:56:01 -05:00
|
|
|
use_unstable_features,
|
|
|
|
skip_tests,
|
2023-04-29 07:00:43 -05:00
|
|
|
bootstrap_host_compiler.triple == target_triple,
|
2023-06-15 12:56:01 -05:00
|
|
|
stdlib_source,
|
2023-04-29 07:00:43 -05:00
|
|
|
);
|
2022-08-24 11:40:58 -05:00
|
|
|
|
2023-01-24 11:56:42 -06:00
|
|
|
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");
|
|
|
|
}
|
2022-08-24 11:40:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-15 12:56:01 -05:00
|
|
|
struct TestRunner<'a> {
|
2022-12-14 12:30:46 -06:00
|
|
|
is_native: bool,
|
2022-08-24 11:40:58 -05:00
|
|
|
jit_supported: bool,
|
2023-06-15 12:56:01 -05:00
|
|
|
use_unstable_features: bool,
|
|
|
|
skip_tests: &'a [&'a str],
|
2022-12-14 12:30:46 -06:00
|
|
|
dirs: Dirs,
|
|
|
|
target_compiler: Compiler,
|
2023-06-15 12:56:01 -05:00
|
|
|
stdlib_source: PathBuf,
|
2022-08-24 11:40:58 -05:00
|
|
|
}
|
|
|
|
|
2023-06-15 12:56:01 -05:00
|
|
|
impl<'a> TestRunner<'a> {
|
|
|
|
fn new(
|
|
|
|
dirs: Dirs,
|
|
|
|
mut target_compiler: Compiler,
|
|
|
|
use_unstable_features: bool,
|
|
|
|
skip_tests: &'a [&'a str],
|
|
|
|
is_native: bool,
|
|
|
|
stdlib_source: PathBuf,
|
|
|
|
) -> Self {
|
2023-08-09 13:20:12 -05:00
|
|
|
target_compiler.rustflags.extend(rustflags_from_env("RUSTFLAGS"));
|
|
|
|
target_compiler.rustdocflags.extend(rustflags_from_env("RUSTDOCFLAGS"));
|
2022-08-24 11:40:58 -05:00
|
|
|
|
|
|
|
// FIXME fix `#[linkage = "extern_weak"]` without this
|
2023-01-24 11:56:42 -06:00
|
|
|
if target_compiler.triple.contains("darwin") {
|
2023-08-09 13:20:12 -05:00
|
|
|
target_compiler.rustflags.extend([
|
|
|
|
"-Clink-arg=-undefined".to_owned(),
|
|
|
|
"-Clink-arg=dynamic_lookup".to_owned(),
|
|
|
|
]);
|
2022-08-24 11:40:58 -05:00
|
|
|
}
|
|
|
|
|
2023-06-15 12:56:01 -05:00
|
|
|
let jit_supported = use_unstable_features
|
|
|
|
&& is_native
|
2023-01-24 11:56:42 -06:00
|
|
|
&& target_compiler.triple.contains("x86_64")
|
|
|
|
&& !target_compiler.triple.contains("windows");
|
|
|
|
|
2023-06-15 12:56:01 -05:00
|
|
|
Self {
|
|
|
|
is_native,
|
|
|
|
jit_supported,
|
|
|
|
use_unstable_features,
|
|
|
|
skip_tests,
|
|
|
|
dirs,
|
|
|
|
target_compiler,
|
|
|
|
stdlib_source,
|
|
|
|
}
|
2022-08-24 11:40:58 -05:00
|
|
|
}
|
|
|
|
|
2023-04-29 07:00:43 -05:00
|
|
|
fn run_testsuite(&self, tests: &[TestCase]) {
|
2023-01-24 11:56:42 -06:00
|
|
|
for TestCase { config, cmd } in tests {
|
2022-08-24 11:40:58 -05:00
|
|
|
let (tag, testname) = config.split_once('.').unwrap();
|
|
|
|
let tag = tag.to_uppercase();
|
|
|
|
let is_jit_test = tag == "JIT";
|
|
|
|
|
2023-07-22 08:32:34 -05:00
|
|
|
let _guard = if !config::get_bool(config)
|
2023-06-15 12:56:01 -05:00
|
|
|
|| (is_jit_test && !self.jit_supported)
|
|
|
|
|| self.skip_tests.contains(&config)
|
|
|
|
{
|
2022-08-24 11:40:58 -05:00
|
|
|
eprintln!("[{tag}] {testname} (skipped)");
|
|
|
|
continue;
|
|
|
|
} else {
|
2023-07-22 08:32:34 -05:00
|
|
|
let guard = LogGroup::guard(&format!("[{tag}] {testname}"));
|
2022-08-24 11:40:58 -05:00
|
|
|
eprintln!("[{tag}] {testname}");
|
2023-07-22 08:32:34 -05:00
|
|
|
guard
|
|
|
|
};
|
2022-08-24 11:40:58 -05:00
|
|
|
|
2023-01-24 11:56:42 -06:00
|
|
|
match *cmd {
|
|
|
|
TestCaseCmd::Custom { func } => func(self),
|
|
|
|
TestCaseCmd::BuildLib { source, crate_types } => {
|
2023-06-15 12:56:01 -05:00
|
|
|
if self.use_unstable_features {
|
|
|
|
self.run_rustc([source, "--crate-type", crate_types]);
|
|
|
|
} else {
|
|
|
|
self.run_rustc([
|
|
|
|
source,
|
|
|
|
"--crate-type",
|
|
|
|
crate_types,
|
|
|
|
"--cfg",
|
|
|
|
"no_unstable_features",
|
|
|
|
]);
|
|
|
|
}
|
2023-01-24 11:56:42 -06:00
|
|
|
}
|
2023-07-22 08:32:34 -05:00
|
|
|
TestCaseCmd::BuildBin { source } => {
|
|
|
|
if self.use_unstable_features {
|
|
|
|
self.run_rustc([source]);
|
|
|
|
} else {
|
|
|
|
self.run_rustc([source, "--cfg", "no_unstable_features"]);
|
|
|
|
}
|
|
|
|
}
|
2023-01-24 11:56:42 -06:00
|
|
|
TestCaseCmd::BuildBinAndRun { source, args } => {
|
2023-06-15 12:56:01 -05:00
|
|
|
if self.use_unstable_features {
|
|
|
|
self.run_rustc([source]);
|
|
|
|
} else {
|
|
|
|
self.run_rustc([source, "--cfg", "no_unstable_features"]);
|
|
|
|
}
|
2023-01-24 11:56:42 -06:00
|
|
|
self.run_out_command(
|
|
|
|
source.split('/').last().unwrap().split('.').next().unwrap(),
|
|
|
|
args,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
TestCaseCmd::JitBin { source, args } => {
|
|
|
|
let mut jit_cmd = self.rustc_command([
|
|
|
|
"-Zunstable-options",
|
|
|
|
"-Cllvm-args=mode=jit",
|
|
|
|
"-Cprefer-dynamic",
|
|
|
|
source,
|
|
|
|
"--cfg",
|
|
|
|
"jit",
|
|
|
|
]);
|
|
|
|
if !args.is_empty() {
|
|
|
|
jit_cmd.env("CG_CLIF_JIT_ARGS", args);
|
|
|
|
}
|
|
|
|
spawn_and_wait(jit_cmd);
|
|
|
|
|
|
|
|
eprintln!("[JIT-lazy] {testname}");
|
|
|
|
let mut jit_cmd = self.rustc_command([
|
|
|
|
"-Zunstable-options",
|
|
|
|
"-Cllvm-args=mode=jit-lazy",
|
|
|
|
"-Cprefer-dynamic",
|
|
|
|
source,
|
|
|
|
"--cfg",
|
|
|
|
"jit",
|
|
|
|
]);
|
|
|
|
if !args.is_empty() {
|
|
|
|
jit_cmd.env("CG_CLIF_JIT_ARGS", args);
|
|
|
|
}
|
|
|
|
spawn_and_wait(jit_cmd);
|
|
|
|
}
|
|
|
|
}
|
2022-08-24 11:40:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-14 12:30:46 -06: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-12-14 12:30:46 -06:00
|
|
|
let mut cmd = Command::new(&self.target_compiler.rustc);
|
2023-08-09 13:20:12 -05:00
|
|
|
cmd.args(&self.target_compiler.rustflags);
|
2022-08-24 11:40:58 -05:00
|
|
|
cmd.arg("-L");
|
2022-12-14 12:30:46 -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-14 12:30:46 -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");
|
2023-01-24 11:56:42 -06:00
|
|
|
cmd.arg("--target");
|
|
|
|
cmd.arg(&self.target_compiler.triple);
|
|
|
|
cmd.arg("-Cpanic=abort");
|
2023-11-25 04:05:52 -06:00
|
|
|
cmd.arg("-Zunstable-options");
|
2023-11-14 17:31:28 -06:00
|
|
|
cmd.arg("--check-cfg=cfg(no_unstable_features)");
|
|
|
|
cmd.arg("--check-cfg=cfg(jit)");
|
2022-08-24 11:40:58 -05:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2023-04-29 07:00:43 -05:00
|
|
|
fn run_out_command(&self, name: &str, args: &[&str]) {
|
2022-08-24 11:40:58 -05:00
|
|
|
let mut full_cmd = vec![];
|
|
|
|
|
|
|
|
// Prepend the RUN_WRAPPER's
|
2022-12-14 12:30:46 -06: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-14 12:30:46 -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
|
|
|
|
2023-01-24 11:56:42 -06:00
|
|
|
for arg in args {
|
2022-08-24 11:40:58 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|