Skip to content

Commit 6134df8

Browse files
author
Ellen Arteca
committed
moving extern-so tests to a new dir so we can add compiler flags in compiletests.rs
1 parent 3e784f2 commit 6134df8

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

tests/compiletest.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn miri_path() -> PathBuf {
99
}
1010

1111
// Build the shared object file for testing external C function calls.
12-
fn build_so_for_c_ffi_tests() {
12+
fn build_so_for_c_ffi_tests() -> PathBuf {
1313
let cc = option_env!("CC").unwrap_or("cc");
1414
// Target directory that we can write to.
1515
let so_target_dir = Path::new(&env::var_os("CARGO_TARGET_DIR").unwrap()).join("miri-extern-so");
@@ -34,6 +34,7 @@ fn build_so_for_c_ffi_tests() {
3434
if !cc_output.status.success() {
3535
panic!("error in generating shared object file for testing external C function calls");
3636
}
37+
so_file_path
3738
}
3839

3940
fn run_tests(mode: Mode, path: &str, target: Option<String>) -> Result<()> {
@@ -63,9 +64,14 @@ fn run_tests(mode: Mode, path: &str, target: Option<String>) -> Result<()> {
6364
flags.push(target.into());
6465
}
6566

66-
// If we're on linux, then build the shared object file for testing external C function calls.
67-
if cfg!(target_os = "linux") {
68-
build_so_for_c_ffi_tests();
67+
// If we're on linux, and we're testing the extern-so functionality,
68+
// then build the shared object file for testing external C function calls
69+
// and push the relevant compiler flag.
70+
if cfg!(target_os = "linux") && path.starts_with("tests/extern-so/") {
71+
let so_file_path = build_so_for_c_ffi_tests();
72+
let mut flag = std::ffi::OsString::from("-Zmiri-extern-so-file=");
73+
flag.push(so_file_path.into_os_string());
74+
flags.push(flag);
6975
}
7076

7177
let skip_ui_checks = env::var_os("MIRI_SKIP_UI_CHECKS").is_some();
@@ -192,6 +198,10 @@ fn main() -> Result<()> {
192198
ui(Mode::Pass, "tests/pass")?;
193199
ui(Mode::Panic, "tests/panic")?;
194200
ui(Mode::Fail, "tests/fail")?;
201+
if cfg!(target_os = "linux") {
202+
ui(Mode::Pass, "tests/extern-so/pass")?;
203+
ui(Mode::Fail, "tests/extern-so/fail")?;
204+
}
195205

196206
Ok(())
197207
}

tests/fail/extern-so/function_not_in_so.rs renamed to tests/extern-so/fail/function_not_in_so.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//@only-target-linux
22
//@only-on-host
3-
//@compile-flags: -Zmiri-extern-so-file=target/miri-extern-so/libtestlib.so
43

54
extern "C" {
65
fn foo();

tests/pass/extern-so/call_extern_c_fcts.rs renamed to tests/extern-so/pass/call_extern_c_fcts.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//@only-target-linux
22
//@only-on-host
3-
//@compile-flags: -Zmiri-extern-so-file=target/miri-extern-so/libtestlib.so
43

54
extern "C" {
65
fn add_one_int(x: i32) -> i32;

0 commit comments

Comments
 (0)