From ea89e82d92e85a4b5adaad1589d1e813788328af Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 23 Feb 2026 17:51:25 +0100 Subject: [PATCH 1/5] Allow to have compile-only tests --- tests/lang_tests.rs | 69 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/tests/lang_tests.rs b/tests/lang_tests.rs index b134baad74c..81fc816db7b 100644 --- a/tests/lang_tests.rs +++ b/tests/lang_tests.rs @@ -11,6 +11,7 @@ fn compile_and_run_cmds( compiler_args: Vec, test_target: &Option, exe: &Path, + run_binary: bool, ) -> Vec<(&'static str, Command)> { let mut compiler = Command::new("rustc"); compiler.args(compiler_args); @@ -35,18 +36,33 @@ fn compile_and_run_cmds( copy.arg("cp"); copy.args([exe, &vm_exe_path]); - let mut runtime = Command::new("sudo"); - runtime.args(["chroot", vm_dir, "qemu-m68k-static"]); - runtime.arg(inside_vm_exe_path); - runtime.current_dir(vm_parent_dir); - vec![("Compiler", compiler), ("Copy", copy), ("Run-time", runtime)] + let mut commands = vec![("Compiler", compiler), ("Copy", copy)]; + if run_binary { + let mut runtime = Command::new("sudo"); + runtime.args(["chroot", vm_dir, "qemu-m68k-static"]); + runtime.arg(inside_vm_exe_path); + runtime.current_dir(vm_parent_dir); + commands.push(("Run-time", runtime)); + } + commands } else { - let runtime = Command::new(exe); - vec![("Compiler", compiler), ("Run-time", runtime)] + let mut commands = vec![("Compiler", compiler)]; + if run_binary { + let runtime = Command::new(exe); + commands.push(("Run-time", runtime)); + } + commands } } -fn run_tests(tempdir: PathBuf, current_dir: String, is_debug: bool) { +fn build_test_runner( + tempdir: PathBuf, + current_dir: String, + is_debug: bool, + test_kind: &str, + test_dir: &str, + run_binary: bool, +) { fn rust_filter(path: &Path) -> bool { path.is_file() && path.extension().expect("extension").to_str().expect("to_str") == "rs" } @@ -66,14 +82,10 @@ fn run_tests(tempdir: PathBuf, current_dir: String, is_debug: bool) { rust_filter(filename) } - if is_debug { - println!("=== [DEBUG] lang tests ==="); - } else { - println!("=== [RELEASE] lang tests ==="); - } + println!("=== {test_kind} tests ==="); LangTester::new() - .test_dir("tests/run") + .test_dir(test_dir) .test_path_filter(filter) .test_extract(|path| { std::fs::read_to_string(path) @@ -134,17 +146,40 @@ fn run_tests(tempdir: PathBuf, current_dir: String, is_debug: bool) { ]); } - compile_and_run_cmds(compiler_args, &test_target, &exe) + compile_and_run_cmds(compiler_args, &test_target, &exe, run_binary) }) .run(); } +fn compile_tests(tempdir: PathBuf, current_dir: String) { + build_test_runner(tempdir, current_dir, true, "lang compile", "tests/compile", false); +} + +fn run_tests(tempdir: PathBuf, current_dir: String) { + build_test_runner( + tempdir.clone(), + current_dir.clone(), + true, + "[DEBUG] lang run", + "tests/run", + true, + ); + build_test_runner( + tempdir, + current_dir.to_string(), + false, + "[RELEASE] lang run", + "tests/run", + true, + ); +} + fn main() { let tempdir = TempDir::new().expect("temp dir"); let current_dir = current_dir().expect("current dir"); let current_dir = current_dir.to_str().expect("current dir").to_string(); let tempdir_path: PathBuf = tempdir.as_ref().into(); - run_tests(tempdir_path.clone(), current_dir.clone(), true); - run_tests(tempdir_path, current_dir, false); + compile_tests(tempdir_path.clone(), current_dir.clone()); + run_tests(tempdir_path, current_dir); } From 615476a1a109bcb6f2f1a039b3e14a003497f52c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 30 Jan 2026 00:28:49 +0100 Subject: [PATCH 2/5] Move intrinsics tests into `tests/compile` since they only need to compile --- tests/{run => compile}/call-llvm-intrinsics.rs | 8 +------- tests/{run => compile}/simd-ffi.rs | 11 +---------- 2 files changed, 2 insertions(+), 17 deletions(-) rename tests/{run => compile}/call-llvm-intrinsics.rs (91%) rename tests/{run => compile}/simd-ffi.rs (92%) diff --git a/tests/run/call-llvm-intrinsics.rs b/tests/compile/call-llvm-intrinsics.rs similarity index 91% rename from tests/run/call-llvm-intrinsics.rs rename to tests/compile/call-llvm-intrinsics.rs index 86e041c3a2f..4c790994c77 100644 --- a/tests/run/call-llvm-intrinsics.rs +++ b/tests/compile/call-llvm-intrinsics.rs @@ -1,12 +1,10 @@ // Compiler: -// -// Run-time: -// status: 0 // FIXME: Remove this test once rustc's `./tests/codegen/riscv-abi/call-llvm-intrinsics.rs` // stops ignoring GCC backend. #![feature(link_llvm_intrinsics)] +#![crate_type = "lib"] #![allow(internal_features)] struct A; @@ -32,7 +30,3 @@ pub fn do_call() { sqrt(4.0); } } - -fn main() { - do_call(); -} diff --git a/tests/run/simd-ffi.rs b/tests/compile/simd-ffi.rs similarity index 92% rename from tests/run/simd-ffi.rs rename to tests/compile/simd-ffi.rs index 67cc2e5b96e..1aba87aac56 100644 --- a/tests/run/simd-ffi.rs +++ b/tests/compile/simd-ffi.rs @@ -1,12 +1,10 @@ // Compiler: -// -// Run-time: -// status: 0 // FIXME: Remove this test once stops // ignoring GCC backend. #![allow(internal_features, non_camel_case_types)] +#![crate_type = "lib"] // we can compile to a variety of platforms, because we don't need // cross-compiled standard libraries. #![feature(no_core, auto_traits)] @@ -93,10 +91,3 @@ macro_rules! Copy { macro_rules! derive { () => {}; } - -#[lang = "start"] -fn start(_main: fn() -> T, _argc: isize, _argv: *const *const u8, _sigpipe: u8) -> isize { - 0 -} - -fn main() {} From ec14a11ee43b4d2edf840bae1c8719ab32baf8e0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 23 Feb 2026 21:47:18 +0100 Subject: [PATCH 3/5] Move more code between the `run_binary` condition since it's only needed in this case --- tests/compile/simd-ffi.rs | 1 + tests/lang_tests.rs | 31 +++++++++++++++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/tests/compile/simd-ffi.rs b/tests/compile/simd-ffi.rs index 1aba87aac56..56172ddc7c6 100644 --- a/tests/compile/simd-ffi.rs +++ b/tests/compile/simd-ffi.rs @@ -5,6 +5,7 @@ #![allow(internal_features, non_camel_case_types)] #![crate_type = "lib"] + // we can compile to a variety of platforms, because we don't need // cross-compiled standard libraries. #![feature(no_core, auto_traits)] diff --git a/tests/lang_tests.rs b/tests/lang_tests.rs index 81fc816db7b..6c52b2de771 100644 --- a/tests/lang_tests.rs +++ b/tests/lang_tests.rs @@ -23,25 +23,28 @@ fn compile_and_run_cmds( env_path = format!("/opt/m68k-unknown-linux-gnu/bin:{}", env_path); compiler.env("PATH", env_path); - let vm_parent_dir = std::env::var("CG_GCC_VM_DIR") - .map(PathBuf::from) - .unwrap_or_else(|_| std::env::current_dir().unwrap()); - let vm_dir = "vm"; - let exe_filename = exe.file_name().unwrap(); - let vm_home_dir = vm_parent_dir.join(vm_dir).join("home"); - let vm_exe_path = vm_home_dir.join(exe_filename); - // FIXME(antoyo): panicking here makes the test pass. - let inside_vm_exe_path = PathBuf::from("/home").join(exe_filename); - let mut copy = Command::new("sudo"); - copy.arg("cp"); - copy.args([exe, &vm_exe_path]); - - let mut commands = vec![("Compiler", compiler), ("Copy", copy)]; + let mut commands = vec![("Compiler", compiler)]; if run_binary { + let vm_parent_dir = std::env::var("CG_GCC_VM_DIR") + .map(PathBuf::from) + .unwrap_or_else(|_| std::env::current_dir().unwrap()); + let vm_dir = "vm"; + let exe_filename = exe.file_name().unwrap(); + let vm_home_dir = vm_parent_dir.join(vm_dir).join("home"); + let vm_exe_path = vm_home_dir.join(exe_filename); + // FIXME(antoyo): panicking here makes the test pass. + let inside_vm_exe_path = PathBuf::from("/home").join(exe_filename); + + let mut copy = Command::new("sudo"); + copy.arg("cp"); + copy.args([exe, &vm_exe_path]); + let mut runtime = Command::new("sudo"); runtime.args(["chroot", vm_dir, "qemu-m68k-static"]); runtime.arg(inside_vm_exe_path); runtime.current_dir(vm_parent_dir); + + commands.push(("Copy", copy)); commands.push(("Run-time", runtime)); } commands From 01cda7d674853dedf842dc161df02d0724aee5ca Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 23 Feb 2026 21:59:28 +0100 Subject: [PATCH 4/5] Ignore `compile/simd-ffi.rs` test on `m68k` target --- tests/lang_tests.rs | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/tests/lang_tests.rs b/tests/lang_tests.rs index 6c52b2de771..cf8ceeafe86 100644 --- a/tests/lang_tests.rs +++ b/tests/lang_tests.rs @@ -65,6 +65,7 @@ fn build_test_runner( test_kind: &str, test_dir: &str, run_binary: bool, + files_to_ignore_on_m68k: &'static [&'static str], ) { fn rust_filter(path: &Path) -> bool { path.is_file() && path.extension().expect("extension").to_str().expect("to_str") == "rs" @@ -87,9 +88,25 @@ fn build_test_runner( println!("=== {test_kind} tests ==="); + // TODO(antoyo): find a way to send this via a cli argument. + let test_target = std::env::var("CG_GCC_TEST_TARGET").ok(); + let test_target_filter = test_target.clone(); + LangTester::new() .test_dir(test_dir) - .test_path_filter(filter) + .test_path_filter(move |filename| { + if !filter(filename) { + return false; + } + if test_target_filter.is_some() + && let Some(filename) = filename.file_name() + && let Some(filename) = filename.to_str() + && files_to_ignore_on_m68k.contains(&filename) + { + return false; + } + true + }) .test_extract(|path| { std::fs::read_to_string(path) .expect("read file") @@ -117,8 +134,6 @@ fn build_test_runner( exe.to_str().expect("to_str").into(), path.to_str().expect("to_str").into(), ]; - // TODO(antoyo): find a way to send this via a cli argument. - let test_target = std::env::var("CG_GCC_TEST_TARGET").ok(); if let Some(ref target) = test_target { compiler_args.extend_from_slice(&["--target".into(), target.into()]); @@ -155,7 +170,15 @@ fn build_test_runner( } fn compile_tests(tempdir: PathBuf, current_dir: String) { - build_test_runner(tempdir, current_dir, true, "lang compile", "tests/compile", false); + build_test_runner( + tempdir, + current_dir, + true, + "lang compile", + "tests/compile", + false, + &["simd-ffi.rs"], + ); } fn run_tests(tempdir: PathBuf, current_dir: String) { @@ -166,6 +189,7 @@ fn run_tests(tempdir: PathBuf, current_dir: String) { "[DEBUG] lang run", "tests/run", true, + &[], ); build_test_runner( tempdir, @@ -174,6 +198,7 @@ fn run_tests(tempdir: PathBuf, current_dir: String) { "[RELEASE] lang run", "tests/run", true, + &[], ); } From 2bb1a43cc50fa83237e59a28139761b2ba1fe0e7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 23 Feb 2026 22:42:21 +0100 Subject: [PATCH 5/5] Improve code readability of `tests/lang_tests.rs` --- tests/lang_tests.rs | 50 +++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/tests/lang_tests.rs b/tests/lang_tests.rs index cf8ceeafe86..3f2cfde9a49 100644 --- a/tests/lang_tests.rs +++ b/tests/lang_tests.rs @@ -11,7 +11,7 @@ fn compile_and_run_cmds( compiler_args: Vec, test_target: &Option, exe: &Path, - run_binary: bool, + test_mode: TestMode, ) -> Vec<(&'static str, Command)> { let mut compiler = Command::new("rustc"); compiler.args(compiler_args); @@ -24,7 +24,7 @@ fn compile_and_run_cmds( compiler.env("PATH", env_path); let mut commands = vec![("Compiler", compiler)]; - if run_binary { + if test_mode.should_run() { let vm_parent_dir = std::env::var("CG_GCC_VM_DIR") .map(PathBuf::from) .unwrap_or_else(|_| std::env::current_dir().unwrap()); @@ -50,7 +50,7 @@ fn compile_and_run_cmds( commands } else { let mut commands = vec![("Compiler", compiler)]; - if run_binary { + if test_mode.should_run() { let runtime = Command::new(exe); commands.push(("Run-time", runtime)); } @@ -58,13 +58,37 @@ fn compile_and_run_cmds( } } +#[derive(Clone, Copy)] +enum BuildMode { + Debug, + Release, +} + +impl BuildMode { + fn is_debug(self) -> bool { + matches!(self, Self::Debug) + } +} + +#[derive(Clone, Copy)] +enum TestMode { + Compile, + CompileAndRun, +} + +impl TestMode { + fn should_run(self) -> bool { + matches!(self, Self::CompileAndRun) + } +} + fn build_test_runner( tempdir: PathBuf, current_dir: String, - is_debug: bool, + build_mode: BuildMode, test_kind: &str, test_dir: &str, - run_binary: bool, + test_mode: TestMode, files_to_ignore_on_m68k: &'static [&'static str], ) { fn rust_filter(path: &Path) -> bool { @@ -148,7 +172,7 @@ fn build_test_runner( } } - if is_debug { + if build_mode.is_debug() { compiler_args .extend_from_slice(&["-C".to_string(), "llvm-args=sanitize-undefined".into()]); if test_target.is_none() { @@ -164,7 +188,7 @@ fn build_test_runner( ]); } - compile_and_run_cmds(compiler_args, &test_target, &exe, run_binary) + compile_and_run_cmds(compiler_args, &test_target, &exe, test_mode) }) .run(); } @@ -173,10 +197,10 @@ fn compile_tests(tempdir: PathBuf, current_dir: String) { build_test_runner( tempdir, current_dir, - true, + BuildMode::Debug, "lang compile", "tests/compile", - false, + TestMode::Compile, &["simd-ffi.rs"], ); } @@ -185,19 +209,19 @@ fn run_tests(tempdir: PathBuf, current_dir: String) { build_test_runner( tempdir.clone(), current_dir.clone(), - true, + BuildMode::Debug, "[DEBUG] lang run", "tests/run", - true, + TestMode::CompileAndRun, &[], ); build_test_runner( tempdir, current_dir.to_string(), - false, + BuildMode::Release, "[RELEASE] lang run", "tests/run", - true, + TestMode::CompileAndRun, &[], ); }