1 use super::build_sysroot::{self, SYSROOT_SRC};
3 use super::path::{Dirs, RelPath};
4 use super::prepare::GitRepo;
5 use super::rustc_info::get_host_triple;
6 use super::utils::{spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler};
7 use super::SysrootKind;
12 use std::process::Command;
14 static BUILD_EXAMPLE_OUT_DIR: RelPath = RelPath::BUILD.join("example");
22 Custom { func: &'static dyn Fn(&TestRunner) },
23 BuildLib { source: &'static str, crate_types: &'static str },
24 BuildBinAndRun { source: &'static str, args: &'static [&'static str] },
25 JitBin { source: &'static str, args: &'static str },
29 // FIXME reduce usage of custom test case commands
30 const fn custom(config: &'static str, func: &'static dyn Fn(&TestRunner)) -> Self {
31 Self { config, cmd: TestCaseCmd::Custom { func } }
37 crate_types: &'static str,
39 Self { config, cmd: TestCaseCmd::BuildLib { source, crate_types } }
42 const fn build_bin_and_run(
45 args: &'static [&'static str],
47 Self { config, cmd: TestCaseCmd::BuildBinAndRun { source, args } }
50 const fn jit_bin(config: &'static str, source: &'static str, args: &'static str) -> Self {
51 Self { config, cmd: TestCaseCmd::JitBin { source, args } }
55 const NO_SYSROOT_SUITE: &[TestCase] = &[
56 TestCase::build_lib("build.mini_core", "example/mini_core.rs", "lib,dylib"),
57 TestCase::build_lib("build.example", "example/example.rs", "lib"),
58 TestCase::jit_bin("jit.mini_core_hello_world", "example/mini_core_hello_world.rs", "abc bcd"),
59 TestCase::build_bin_and_run(
60 "aot.mini_core_hello_world",
61 "example/mini_core_hello_world.rs",
66 const BASE_SYSROOT_SUITE: &[TestCase] = &[
67 TestCase::build_bin_and_run(
68 "aot.arbitrary_self_types_pointers_and_wrappers",
69 "example/arbitrary_self_types_pointers_and_wrappers.rs",
72 TestCase::build_bin_and_run(
73 "aot.issue_91827_extern_types",
74 "example/issue-91827-extern-types.rs",
77 TestCase::build_lib("build.alloc_system", "example/alloc_system.rs", "lib"),
78 TestCase::build_bin_and_run("aot.alloc_example", "example/alloc_example.rs", &[]),
79 TestCase::jit_bin("jit.std_example", "example/std_example.rs", ""),
80 TestCase::build_bin_and_run("aot.std_example", "example/std_example.rs", &["arg"]),
81 TestCase::build_bin_and_run("aot.dst_field_align", "example/dst-field-align.rs", &[]),
82 TestCase::build_bin_and_run(
83 "aot.subslice-patterns-const-eval",
84 "example/subslice-patterns-const-eval.rs",
87 TestCase::build_bin_and_run(
88 "aot.track-caller-attribute",
89 "example/track-caller-attribute.rs",
92 TestCase::build_bin_and_run("aot.float-minmax-pass", "example/float-minmax-pass.rs", &[]),
93 TestCase::build_bin_and_run("aot.mod_bench", "example/mod_bench.rs", &[]),
94 TestCase::build_bin_and_run("aot.issue-72793", "example/issue-72793.rs", &[]),
97 pub(crate) static RAND_REPO: GitRepo =
98 GitRepo::github("rust-random", "rand", "0f933f9c7176e53b2a3c7952ded484e1783f0bf1", "rand");
100 pub(crate) static RAND: CargoProject = CargoProject::new(&RAND_REPO.source_dir(), "rand");
102 pub(crate) static REGEX_REPO: GitRepo =
103 GitRepo::github("rust-lang", "regex", "341f207c1071f7290e3f228c710817c280c8dca1", "regex");
105 pub(crate) static REGEX: CargoProject = CargoProject::new(®EX_REPO.source_dir(), "regex");
107 pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github(
110 "582239ac3b32007613df04d7ffa78dc30f4c5645",
114 pub(crate) static PORTABLE_SIMD: CargoProject =
115 CargoProject::new(&PORTABLE_SIMD_REPO.source_dir(), "portable_simd");
117 pub(crate) static LIBCORE_TESTS: CargoProject =
118 CargoProject::new(&SYSROOT_SRC.join("library/core/tests"), "core_tests");
120 const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
121 TestCase::custom("test.rust-random/rand", &|runner| {
122 RAND.clean(&runner.dirs);
124 if runner.is_native {
125 eprintln!("[TEST] rust-random/rand");
126 let mut test_cmd = RAND.test(&runner.target_compiler, &runner.dirs);
127 test_cmd.arg("--workspace");
128 spawn_and_wait(test_cmd);
130 eprintln!("[AOT] rust-random/rand");
131 let mut build_cmd = RAND.build(&runner.target_compiler, &runner.dirs);
132 build_cmd.arg("--workspace").arg("--tests");
133 spawn_and_wait(build_cmd);
136 TestCase::custom("test.libcore", &|runner| {
137 LIBCORE_TESTS.clean(&runner.dirs);
139 if runner.is_native {
140 spawn_and_wait(LIBCORE_TESTS.test(&runner.target_compiler, &runner.dirs));
142 eprintln!("Cross-Compiling: Not running tests");
143 let mut build_cmd = LIBCORE_TESTS.build(&runner.target_compiler, &runner.dirs);
144 build_cmd.arg("--tests");
145 spawn_and_wait(build_cmd);
148 TestCase::custom("test.regex-shootout-regex-dna", &|runner| {
149 REGEX.clean(&runner.dirs);
151 // newer aho_corasick versions throw a deprecation warning
152 let lint_rust_flags = format!("{} --cap-lints warn", runner.target_compiler.rustflags);
154 let mut build_cmd = REGEX.build(&runner.target_compiler, &runner.dirs);
155 build_cmd.arg("--example").arg("shootout-regex-dna");
156 build_cmd.env("RUSTFLAGS", lint_rust_flags.clone());
157 spawn_and_wait(build_cmd);
159 if runner.is_native {
160 let mut run_cmd = REGEX.run(&runner.target_compiler, &runner.dirs);
161 run_cmd.arg("--example").arg("shootout-regex-dna");
162 run_cmd.env("RUSTFLAGS", lint_rust_flags);
164 let input = fs::read_to_string(
165 REGEX.source_dir(&runner.dirs).join("examples").join("regexdna-input.txt"),
168 let expected = fs::read_to_string(
169 REGEX.source_dir(&runner.dirs).join("examples").join("regexdna-output.txt"),
173 let output = spawn_and_wait_with_input(run_cmd, input);
174 // Make sure `[codegen mono items] start` doesn't poison the diff
177 .filter(|line| !line.contains("codegen mono items"))
178 .chain(Some("")) // This just adds the trailing newline
179 .collect::<Vec<&str>>()
182 let output_matches = expected.lines().eq(output.lines());
184 println!("Output files don't match!");
185 println!("Expected Output:\n{}", expected);
186 println!("Actual Output:\n{}", output);
188 std::process::exit(1);
192 TestCase::custom("test.regex", &|runner| {
193 REGEX.clean(&runner.dirs);
195 // newer aho_corasick versions throw a deprecation warning
196 let lint_rust_flags = format!("{} --cap-lints warn", runner.target_compiler.rustflags);
198 if runner.is_native {
199 let mut run_cmd = REGEX.test(&runner.target_compiler, &runner.dirs);
203 "--exclude-should-panic",
206 "-Zunstable-options",
209 run_cmd.env("RUSTFLAGS", lint_rust_flags);
210 spawn_and_wait(run_cmd);
212 eprintln!("Cross-Compiling: Not running tests");
213 let mut build_cmd = REGEX.build(&runner.target_compiler, &runner.dirs);
214 build_cmd.arg("--tests");
215 build_cmd.env("RUSTFLAGS", lint_rust_flags.clone());
216 spawn_and_wait(build_cmd);
219 TestCase::custom("test.portable-simd", &|runner| {
220 PORTABLE_SIMD.clean(&runner.dirs);
222 let mut build_cmd = PORTABLE_SIMD.build(&runner.target_compiler, &runner.dirs);
223 build_cmd.arg("--all-targets");
224 spawn_and_wait(build_cmd);
226 if runner.is_native {
227 let mut test_cmd = PORTABLE_SIMD.test(&runner.target_compiler, &runner.dirs);
229 spawn_and_wait(test_cmd);
234 pub(crate) fn run_tests(
237 sysroot_kind: SysrootKind,
238 cg_clif_dylib: &Path,
239 bootstrap_host_compiler: &Compiler,
240 target_triple: String,
242 if config::get_bool("testsuite.no_sysroot") {
243 let target_compiler = build_sysroot::build_sysroot(
248 bootstrap_host_compiler,
249 target_triple.clone(),
253 TestRunner::new(dirs.clone(), target_compiler, get_host_triple() == target_triple);
255 BUILD_EXAMPLE_OUT_DIR.ensure_fresh(dirs);
256 runner.run_testsuite(NO_SYSROOT_SUITE);
258 eprintln!("[SKIP] no_sysroot tests");
261 let run_base_sysroot = config::get_bool("testsuite.base_sysroot");
262 let run_extended_sysroot = config::get_bool("testsuite.extended_sysroot");
264 if run_base_sysroot || run_extended_sysroot {
265 let target_compiler = build_sysroot::build_sysroot(
270 bootstrap_host_compiler,
271 target_triple.clone(),
275 TestRunner::new(dirs.clone(), target_compiler, get_host_triple() == target_triple);
277 if run_base_sysroot {
278 runner.run_testsuite(BASE_SYSROOT_SUITE);
280 eprintln!("[SKIP] base_sysroot tests");
283 if run_extended_sysroot {
284 runner.run_testsuite(EXTENDED_SYSROOT_SUITE);
286 eprintln!("[SKIP] extended_sysroot tests");
295 target_compiler: Compiler,
299 pub fn new(dirs: Dirs, mut target_compiler: Compiler, is_native: bool) -> Self {
300 if let Ok(rustflags) = env::var("RUSTFLAGS") {
301 target_compiler.rustflags.push(' ');
302 target_compiler.rustflags.push_str(&rustflags);
304 if let Ok(rustdocflags) = env::var("RUSTDOCFLAGS") {
305 target_compiler.rustdocflags.push(' ');
306 target_compiler.rustdocflags.push_str(&rustdocflags);
309 // FIXME fix `#[linkage = "extern_weak"]` without this
310 if target_compiler.triple.contains("darwin") {
311 target_compiler.rustflags.push_str(" -Clink-arg=-undefined -Clink-arg=dynamic_lookup");
314 let jit_supported = is_native
315 && target_compiler.triple.contains("x86_64")
316 && !target_compiler.triple.contains("windows");
318 Self { is_native, jit_supported, dirs, target_compiler }
321 pub fn run_testsuite(&self, tests: &[TestCase]) {
322 for TestCase { config, cmd } in tests {
323 let (tag, testname) = config.split_once('.').unwrap();
324 let tag = tag.to_uppercase();
325 let is_jit_test = tag == "JIT";
327 if !config::get_bool(config) || (is_jit_test && !self.jit_supported) {
328 eprintln!("[{tag}] {testname} (skipped)");
331 eprintln!("[{tag}] {testname}");
335 TestCaseCmd::Custom { func } => func(self),
336 TestCaseCmd::BuildLib { source, crate_types } => {
337 self.run_rustc([source, "--crate-type", crate_types]);
339 TestCaseCmd::BuildBinAndRun { source, args } => {
340 self.run_rustc([source]);
341 self.run_out_command(
342 source.split('/').last().unwrap().split('.').next().unwrap(),
346 TestCaseCmd::JitBin { source, args } => {
347 let mut jit_cmd = self.rustc_command([
348 "-Zunstable-options",
349 "-Cllvm-args=mode=jit",
355 if !args.is_empty() {
356 jit_cmd.env("CG_CLIF_JIT_ARGS", args);
358 spawn_and_wait(jit_cmd);
360 eprintln!("[JIT-lazy] {testname}");
361 let mut jit_cmd = self.rustc_command([
362 "-Zunstable-options",
363 "-Cllvm-args=mode=jit-lazy",
369 if !args.is_empty() {
370 jit_cmd.env("CG_CLIF_JIT_ARGS", args);
372 spawn_and_wait(jit_cmd);
379 fn rustc_command<I, S>(&self, args: I) -> Command
381 I: IntoIterator<Item = S>,
384 let mut cmd = Command::new(&self.target_compiler.rustc);
385 cmd.args(self.target_compiler.rustflags.split_whitespace());
387 cmd.arg(format!("crate={}", BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).display()));
388 cmd.arg("--out-dir");
389 cmd.arg(format!("{}", BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).display()));
390 cmd.arg("-Cdebuginfo=2");
392 cmd.arg(&self.target_compiler.triple);
393 cmd.arg("-Cpanic=abort");
398 fn run_rustc<I, S>(&self, args: I)
400 I: IntoIterator<Item = S>,
403 spawn_and_wait(self.rustc_command(args));
406 fn run_out_command<'a>(&self, name: &str, args: &[&str]) {
407 let mut full_cmd = vec![];
409 // Prepend the RUN_WRAPPER's
410 if !self.target_compiler.runner.is_empty() {
411 full_cmd.extend(self.target_compiler.runner.iter().cloned());
415 BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).join(name).to_str().unwrap().to_string(),
419 full_cmd.push(arg.to_string());
422 let mut cmd_iter = full_cmd.into_iter();
423 let first = cmd_iter.next().unwrap();
425 let mut cmd = Command::new(first);