Skip to content

Commit

Permalink
test harness informs tests about suitable temp dir
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Mar 23, 2020
1 parent 6e9b1ab commit f5b4caf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions tests/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ fn get_target() -> String {
fn test_runner(_tests: &[&()]) {
// Add a test env var to do environment communication tests.
std::env::set_var("MIRI_ENV_VAR_TEST", "0");
// Let the tests know where to store temp files (they might run for a different target, which can make this hard to find).
std::env::set_var("MIRI_TEMP", std::env::temp_dir());

let target = get_target();
miri_pass("tests/run-pass", &target);
Expand Down
10 changes: 6 additions & 4 deletions tests/run-pass/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ fn main() {
test_directory();
}

fn tmp() -> PathBuf {
std::env::var("MIRI_TEMP").map(PathBuf::from).unwrap_or_else(|_| std::env::temp_dir())
}

/// Prepare: compute filename and make sure the file does not exist.
fn prepare(filename: &str) -> PathBuf {
let tmp = std::env::temp_dir();
let path = tmp.join(filename);
let path = tmp().join(filename);
// Clean the paths for robustness.
remove_file(&path).ok();
path
}

/// Prepare directory: compute directory name and make sure it does not exist.
fn prepare_dir(dirname: &str) -> PathBuf {
let tmp = std::env::temp_dir();
let path = tmp.join(&dirname);
let path = tmp().join(&dirname);
// Clean the directory for robustness.
remove_dir_all(&path).ok();
path
Expand Down
11 changes: 8 additions & 3 deletions tests/run-pass/libc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@
// compile-flags: -Zmiri-disable-isolation

#![feature(rustc_private)]
#![allow(unused)] // necessary on macos due to conditional compilation

use std::path::PathBuf;

#[allow(unused)] // necessary on macos due to conditional compilation
extern crate libc;

fn tmp() -> PathBuf {
std::env::var("MIRI_TEMP").map(PathBuf::from).unwrap_or_else(|_| std::env::temp_dir())
}

#[cfg(not(target_os = "macos"))]
fn test_posix_fadvise() {
use std::convert::TryInto;
use std::env::temp_dir;
use std::fs::{File, remove_file};
use std::io::Write;
use std::os::unix::io::AsRawFd;

let path = temp_dir().join("miri_test_libc.txt");
let path = tmp().join("miri_test_libc.txt");
// Cleanup before test
remove_file(&path).ok();

Expand Down

0 comments on commit f5b4caf

Please sign in to comment.