-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(isolation): introduce UhyveFileMap integration tests
Introduces a test for UhyveFileMap. Some refactoring was done so as to keep the two tests, fs-test and uhyvefilemap, in separate files. Some filesystem-related functions were moved into common.rs, because: - we anticipate that they will be necessary for further filesystem-related tests - putting two test functions in a single test (e.g. fs-test) causes the second test to hang for some mysterious reason - more descriptive errors
- Loading branch information
Showing
4 changed files
with
80 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,16 @@ | ||
mod common; | ||
|
||
use std::{ | ||
fs::{read, remove_file}, | ||
path::PathBuf, | ||
}; | ||
use std::{fs::remove_file, path::PathBuf}; | ||
|
||
use common::{build_hermit_bin, run_simple_vm}; | ||
use common::{build_hermit_bin, remove_file_if_exists, run_simple_vm, verify_file_contents}; | ||
|
||
#[test] | ||
fn new_file_test() { | ||
let testfile = PathBuf::from("foo.txt"); | ||
if testfile.exists() { | ||
println!("Removing existing file {}", testfile.display()); | ||
remove_file(&testfile).unwrap_or_else(|_| panic!("Can't remove {}", testfile.display())); | ||
} | ||
remove_file_if_exists(&testfile); | ||
let bin_path = build_hermit_bin("create_file"); | ||
run_simple_vm(bin_path); | ||
|
||
assert!(testfile.exists()); | ||
let file_content = read("foo.txt").unwrap(); | ||
assert_eq!(file_content, "Hello, world!".as_bytes()); | ||
assert_eq!(0, run_simple_vm(bin_path)); | ||
verify_file_contents(&testfile, true); | ||
remove_file(&testfile).unwrap_or_else(|_| panic!("Can't remove {}", testfile.display())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
mod common; | ||
|
||
use std::{fs::remove_file, path::PathBuf}; | ||
|
||
use common::{build_hermit_bin, remove_file_if_exists, run_vm_with_file_map, verify_file_contents}; | ||
|
||
#[test] | ||
fn uhyvefilemap_test() { | ||
let testfile = PathBuf::from("foo.txt"); | ||
remove_file_if_exists(&testfile); | ||
let bin_path = build_hermit_bin("create_file"); | ||
|
||
// The file should not exist on the host OS. | ||
let mut code = run_vm_with_file_map(bin_path.clone(), vec!["foo.txt:wrong.txt".to_string()]); | ||
assert_eq!(-1, code); | ||
verify_file_contents(&testfile, false); | ||
|
||
code = run_vm_with_file_map(bin_path, vec!["foo.txt:foo.txt".to_string()]); | ||
assert_eq!(0, code); | ||
verify_file_contents(&testfile, true); | ||
remove_file(&testfile).unwrap_or_else(|_| panic!("Can't remove {}", testfile.display())); | ||
} |