Skip to content

Commit dc273bf

Browse files
Merge pull request #846 from GuillaumeGomez/compile-only
Split `compile` tests from `run` tests
2 parents 2640671 + 2bb1a43 commit dc273bf

File tree

3 files changed

+124
-51
lines changed

3 files changed

+124
-51
lines changed
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// Compiler:
2-
//
3-
// Run-time:
4-
// status: 0
52

63
// FIXME: Remove this test once rustc's `./tests/codegen/riscv-abi/call-llvm-intrinsics.rs`
74
// stops ignoring GCC backend.
85

96
#![feature(link_llvm_intrinsics)]
7+
#![crate_type = "lib"]
108
#![allow(internal_features)]
119

1210
struct A;
@@ -32,7 +30,3 @@ pub fn do_call() {
3230
sqrt(4.0);
3331
}
3432
}
35-
36-
fn main() {
37-
do_call();
38-
}
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// Compiler:
2-
//
3-
// Run-time:
4-
// status: 0
52

63
// FIXME: Remove this test once <tests/run-make/simd-ffi/simd.rs> stops
74
// ignoring GCC backend.
85

96
#![allow(internal_features, non_camel_case_types)]
7+
#![crate_type = "lib"]
8+
109
// we can compile to a variety of platforms, because we don't need
1110
// cross-compiled standard libraries.
1211
#![feature(no_core, auto_traits)]
@@ -93,10 +92,3 @@ macro_rules! Copy {
9392
macro_rules! derive {
9493
() => {};
9594
}
96-
97-
#[lang = "start"]
98-
fn start<T>(_main: fn() -> T, _argc: isize, _argv: *const *const u8, _sigpipe: u8) -> isize {
99-
0
100-
}
101-
102-
fn main() {}

tests/lang_tests.rs

Lines changed: 121 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ fn compile_and_run_cmds(
1111
compiler_args: Vec<String>,
1212
test_target: &Option<String>,
1313
exe: &Path,
14+
test_mode: TestMode,
1415
) -> Vec<(&'static str, Command)> {
1516
let mut compiler = Command::new("rustc");
1617
compiler.args(compiler_args);
@@ -22,31 +23,74 @@ fn compile_and_run_cmds(
2223
env_path = format!("/opt/m68k-unknown-linux-gnu/bin:{}", env_path);
2324
compiler.env("PATH", env_path);
2425

25-
let vm_parent_dir = std::env::var("CG_GCC_VM_DIR")
26-
.map(PathBuf::from)
27-
.unwrap_or_else(|_| std::env::current_dir().unwrap());
28-
let vm_dir = "vm";
29-
let exe_filename = exe.file_name().unwrap();
30-
let vm_home_dir = vm_parent_dir.join(vm_dir).join("home");
31-
let vm_exe_path = vm_home_dir.join(exe_filename);
32-
// FIXME(antoyo): panicking here makes the test pass.
33-
let inside_vm_exe_path = PathBuf::from("/home").join(exe_filename);
34-
let mut copy = Command::new("sudo");
35-
copy.arg("cp");
36-
copy.args([exe, &vm_exe_path]);
37-
38-
let mut runtime = Command::new("sudo");
39-
runtime.args(["chroot", vm_dir, "qemu-m68k-static"]);
40-
runtime.arg(inside_vm_exe_path);
41-
runtime.current_dir(vm_parent_dir);
42-
vec![("Compiler", compiler), ("Copy", copy), ("Run-time", runtime)]
26+
let mut commands = vec![("Compiler", compiler)];
27+
if test_mode.should_run() {
28+
let vm_parent_dir = std::env::var("CG_GCC_VM_DIR")
29+
.map(PathBuf::from)
30+
.unwrap_or_else(|_| std::env::current_dir().unwrap());
31+
let vm_dir = "vm";
32+
let exe_filename = exe.file_name().unwrap();
33+
let vm_home_dir = vm_parent_dir.join(vm_dir).join("home");
34+
let vm_exe_path = vm_home_dir.join(exe_filename);
35+
// FIXME(antoyo): panicking here makes the test pass.
36+
let inside_vm_exe_path = PathBuf::from("/home").join(exe_filename);
37+
38+
let mut copy = Command::new("sudo");
39+
copy.arg("cp");
40+
copy.args([exe, &vm_exe_path]);
41+
42+
let mut runtime = Command::new("sudo");
43+
runtime.args(["chroot", vm_dir, "qemu-m68k-static"]);
44+
runtime.arg(inside_vm_exe_path);
45+
runtime.current_dir(vm_parent_dir);
46+
47+
commands.push(("Copy", copy));
48+
commands.push(("Run-time", runtime));
49+
}
50+
commands
4351
} else {
44-
let runtime = Command::new(exe);
45-
vec![("Compiler", compiler), ("Run-time", runtime)]
52+
let mut commands = vec![("Compiler", compiler)];
53+
if test_mode.should_run() {
54+
let runtime = Command::new(exe);
55+
commands.push(("Run-time", runtime));
56+
}
57+
commands
58+
}
59+
}
60+
61+
#[derive(Clone, Copy)]
62+
enum BuildMode {
63+
Debug,
64+
Release,
65+
}
66+
67+
impl BuildMode {
68+
fn is_debug(self) -> bool {
69+
matches!(self, Self::Debug)
70+
}
71+
}
72+
73+
#[derive(Clone, Copy)]
74+
enum TestMode {
75+
Compile,
76+
CompileAndRun,
77+
}
78+
79+
impl TestMode {
80+
fn should_run(self) -> bool {
81+
matches!(self, Self::CompileAndRun)
4682
}
4783
}
4884

49-
fn run_tests(tempdir: PathBuf, current_dir: String, is_debug: bool) {
85+
fn build_test_runner(
86+
tempdir: PathBuf,
87+
current_dir: String,
88+
build_mode: BuildMode,
89+
test_kind: &str,
90+
test_dir: &str,
91+
test_mode: TestMode,
92+
files_to_ignore_on_m68k: &'static [&'static str],
93+
) {
5094
fn rust_filter(path: &Path) -> bool {
5195
path.is_file() && path.extension().expect("extension").to_str().expect("to_str") == "rs"
5296
}
@@ -66,15 +110,27 @@ fn run_tests(tempdir: PathBuf, current_dir: String, is_debug: bool) {
66110
rust_filter(filename)
67111
}
68112

69-
if is_debug {
70-
println!("=== [DEBUG] lang tests ===");
71-
} else {
72-
println!("=== [RELEASE] lang tests ===");
73-
}
113+
println!("=== {test_kind} tests ===");
114+
115+
// TODO(antoyo): find a way to send this via a cli argument.
116+
let test_target = std::env::var("CG_GCC_TEST_TARGET").ok();
117+
let test_target_filter = test_target.clone();
74118

75119
LangTester::new()
76-
.test_dir("tests/run")
77-
.test_path_filter(filter)
120+
.test_dir(test_dir)
121+
.test_path_filter(move |filename| {
122+
if !filter(filename) {
123+
return false;
124+
}
125+
if test_target_filter.is_some()
126+
&& let Some(filename) = filename.file_name()
127+
&& let Some(filename) = filename.to_str()
128+
&& files_to_ignore_on_m68k.contains(&filename)
129+
{
130+
return false;
131+
}
132+
true
133+
})
78134
.test_extract(|path| {
79135
std::fs::read_to_string(path)
80136
.expect("read file")
@@ -102,8 +158,6 @@ fn run_tests(tempdir: PathBuf, current_dir: String, is_debug: bool) {
102158
exe.to_str().expect("to_str").into(),
103159
path.to_str().expect("to_str").into(),
104160
];
105-
// TODO(antoyo): find a way to send this via a cli argument.
106-
let test_target = std::env::var("CG_GCC_TEST_TARGET").ok();
107161

108162
if let Some(ref target) = test_target {
109163
compiler_args.extend_from_slice(&["--target".into(), target.into()]);
@@ -118,7 +172,7 @@ fn run_tests(tempdir: PathBuf, current_dir: String, is_debug: bool) {
118172
}
119173
}
120174

121-
if is_debug {
175+
if build_mode.is_debug() {
122176
compiler_args
123177
.extend_from_slice(&["-C".to_string(), "llvm-args=sanitize-undefined".into()]);
124178
if test_target.is_none() {
@@ -134,17 +188,50 @@ fn run_tests(tempdir: PathBuf, current_dir: String, is_debug: bool) {
134188
]);
135189
}
136190

137-
compile_and_run_cmds(compiler_args, &test_target, &exe)
191+
compile_and_run_cmds(compiler_args, &test_target, &exe, test_mode)
138192
})
139193
.run();
140194
}
141195

196+
fn compile_tests(tempdir: PathBuf, current_dir: String) {
197+
build_test_runner(
198+
tempdir,
199+
current_dir,
200+
BuildMode::Debug,
201+
"lang compile",
202+
"tests/compile",
203+
TestMode::Compile,
204+
&["simd-ffi.rs"],
205+
);
206+
}
207+
208+
fn run_tests(tempdir: PathBuf, current_dir: String) {
209+
build_test_runner(
210+
tempdir.clone(),
211+
current_dir.clone(),
212+
BuildMode::Debug,
213+
"[DEBUG] lang run",
214+
"tests/run",
215+
TestMode::CompileAndRun,
216+
&[],
217+
);
218+
build_test_runner(
219+
tempdir,
220+
current_dir.to_string(),
221+
BuildMode::Release,
222+
"[RELEASE] lang run",
223+
"tests/run",
224+
TestMode::CompileAndRun,
225+
&[],
226+
);
227+
}
228+
142229
fn main() {
143230
let tempdir = TempDir::new().expect("temp dir");
144231
let current_dir = current_dir().expect("current dir");
145232
let current_dir = current_dir.to_str().expect("current dir").to_string();
146233

147234
let tempdir_path: PathBuf = tempdir.as_ref().into();
148-
run_tests(tempdir_path.clone(), current_dir.clone(), true);
149-
run_tests(tempdir_path, current_dir, false);
235+
compile_tests(tempdir_path.clone(), current_dir.clone());
236+
run_tests(tempdir_path, current_dir);
150237
}

0 commit comments

Comments
 (0)