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..56172ddc7c6 100644 --- a/tests/run/simd-ffi.rs +++ b/tests/compile/simd-ffi.rs @@ -1,12 +1,11 @@ // 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 +92,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() {} diff --git a/tests/lang_tests.rs b/tests/lang_tests.rs index b134baad74c..3f2cfde9a49 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, + test_mode: TestMode, ) -> Vec<(&'static str, Command)> { let mut compiler = Command::new("rustc"); compiler.args(compiler_args); @@ -22,31 +23,74 @@ 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 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)]; + 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()); + 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 } else { - let runtime = Command::new(exe); - vec![("Compiler", compiler), ("Run-time", runtime)] + let mut commands = vec![("Compiler", compiler)]; + if test_mode.should_run() { + let runtime = Command::new(exe); + commands.push(("Run-time", runtime)); + } + commands + } +} + +#[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 run_tests(tempdir: PathBuf, current_dir: String, is_debug: bool) { +fn build_test_runner( + tempdir: PathBuf, + current_dir: String, + build_mode: BuildMode, + test_kind: &str, + test_dir: &str, + test_mode: TestMode, + 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" } @@ -66,15 +110,27 @@ 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 ==="); + + // 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("tests/run") - .test_path_filter(filter) + .test_dir(test_dir) + .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") @@ -102,8 +158,6 @@ fn run_tests(tempdir: PathBuf, current_dir: String, is_debug: bool) { 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()]); @@ -118,7 +172,7 @@ fn run_tests(tempdir: PathBuf, current_dir: String, is_debug: bool) { } } - 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() { @@ -134,17 +188,50 @@ 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, test_mode) }) .run(); } +fn compile_tests(tempdir: PathBuf, current_dir: String) { + build_test_runner( + tempdir, + current_dir, + BuildMode::Debug, + "lang compile", + "tests/compile", + TestMode::Compile, + &["simd-ffi.rs"], + ); +} + +fn run_tests(tempdir: PathBuf, current_dir: String) { + build_test_runner( + tempdir.clone(), + current_dir.clone(), + BuildMode::Debug, + "[DEBUG] lang run", + "tests/run", + TestMode::CompileAndRun, + &[], + ); + build_test_runner( + tempdir, + current_dir.to_string(), + BuildMode::Release, + "[RELEASE] lang run", + "tests/run", + TestMode::CompileAndRun, + &[], + ); +} + 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); }