add more wasi tests

This commit is contained in:
Mark McCaskey 2019-05-17 15:31:02 -07:00
parent faa4d058ec
commit 542e47ff82
18 changed files with 123 additions and 8 deletions

View File

@ -50,6 +50,10 @@ pub fn compile(file: &str, ignores: &HashSet<String>) -> Option<String> {
perm.set_mode(0o766); perm.set_mode(0o766);
fs::set_permissions(normal_path, perm).expect("set permissions"); fs::set_permissions(normal_path, perm).expect("set permissions");
} }
let rs_module_name = {
let temp = PathBuf::from(&normalized_name);
temp.file_name().unwrap().to_string_lossy().to_string()
};
let result = Command::new(&normalized_name) let result = Command::new(&normalized_name)
.output() .output()
@ -65,15 +69,12 @@ pub fn compile(file: &str, ignores: &HashSet<String>) -> Option<String> {
.output() .output()
.expect("Failed to compile program to native code"); .expect("Failed to compile program to native code");
let ignored = if ignores.contains(&normalized_name) { let ignored = if ignores.contains(&rs_module_name) {
"\n#[ignore]" "\n#[ignore]"
} else { } else {
"" ""
}; };
let rs_module_name = {
let temp = PathBuf::from(&normalized_name);
temp.file_name().unwrap().to_string_lossy().to_string()
};
let contents = format!( let contents = format!(
"#[test]{ignore} "#[test]{ignore}
fn test_{rs_module_name}() {{ fn test_{rs_module_name}() {{
@ -106,7 +107,6 @@ pub fn build() {
let mut modules: Vec<String> = Vec::new(); let mut modules: Vec<String> = Vec::new();
let ignores = read_ignore_list(); let ignores = read_ignore_list();
for entry in glob("wasitests/*.rs").unwrap() { for entry in glob("wasitests/*.rs").unwrap() {
match entry { match entry {
Ok(path) => { Ok(path) => {
@ -128,7 +128,7 @@ pub fn build() {
modules.push("".to_string()); modules.push("".to_string());
let modfile: String = modules.join("\n"); let modfile: String = modules.join("\n");
let source = fs::read(dbg!(&rust_test_modpath)).unwrap(); let source = fs::read(&rust_test_modpath).unwrap();
// We only modify the mod file if has changed // We only modify the mod file if has changed
if source != modfile.as_bytes() { if source != modfile.as_bytes() {
fs::write(&rust_test_modpath, modfile.as_bytes()).unwrap(); fs::write(&rust_test_modpath, modfile.as_bytes()).unwrap();

View File

@ -0,0 +1,10 @@
#[test]
#[ignore]
fn test_create_dir() {
assert_wasi_output!(
"../../wasitests/create_dir.wasm",
"create_dir",
vec![],
"../../wasitests/create_dir.out"
);
}

View File

@ -0,0 +1,10 @@
#[test]
#[ignore]
fn test_file_metadata() {
assert_wasi_output!(
"../../wasitests/file_metadata.wasm",
"file_metadata",
vec![],
"../../wasitests/file_metadata.out"
);
}

View File

@ -5,4 +5,7 @@
// The _common module is not autogenerated. It provides common macros for the wasitests // The _common module is not autogenerated. It provides common macros for the wasitests
#[macro_use] #[macro_use]
mod _common; mod _common;
mod create_dir;
mod file_metadata;
mod hello; mod hello;
mod quine;

View File

@ -0,0 +1,9 @@
#[test]
fn test_quine() {
assert_wasi_output!(
"../../wasitests/quine.wasm",
"quine",
vec![],
"../../wasitests/quine.out"
);
}

BIN
lib/wasi/wasitests/create_dir Executable file

Binary file not shown.

View File

@ -0,0 +1,5 @@
Test file exists: false
Dir exists: false
Dir exists: false
Dir exists: false
Success

View File

@ -0,0 +1,37 @@
use std::fs;
use std::io::{Read, Seek, SeekFrom, Write};
use std::path::*;
fn main() {
let mut path = PathBuf::from("wasitests/testing/nested/directories");
let test_file = path.join("test.file");
fs::create_dir_all(&path).unwrap();
{
let mut file = fs::OpenOptions::new()
.read(true)
.write(true)
.truncate(true)
.create(true)
.open(&test_file)
.unwrap();
assert_eq!(file.write(b"hello").unwrap(), 5);
file.flush().unwrap();
file.seek(SeekFrom::Start(0)).unwrap();
let mut in_str = String::new();
file.read_to_string(&mut in_str).unwrap();
assert_eq!(&in_str, "hello");
}
fs::remove_file(&test_file).unwrap();
println!("Test file exists: {}", test_file.exists());
assert!(!test_file.exists());
for _ in 0..3 {
fs::remove_dir_all(&path).unwrap();
println!("Dir exists: {}", path.exists());
assert!(!path.exists());
path.pop();
}
println!("Success");
}

Binary file not shown.

BIN
lib/wasi/wasitests/file_metadata Executable file

Binary file not shown.

View File

@ -0,0 +1,2 @@
is dir: false
file info: FileType(FileType { mode: 33188 }) 419 Ok(SystemTime { tv_sec: 1558132188, tv_nsec: 545288295 }) Ok(SystemTime { tv_sec: 1558132188, tv_nsec: 545243056 }) Ok(SystemTime { tv_sec: 1558132191, tv_nsec: 359031112 })

View File

@ -0,0 +1,17 @@
use std::fs;
use std::io::Read;
fn main() {
let mut this_file =
fs::File::open("wasitests/file_metadata.rs").expect("could not find src file");
let md = this_file.metadata().unwrap();
println!("is dir: {}", md.is_dir());
println!(
"file info: {:?} {} {:?} {:?} {:?}",
md.file_type(),
md.len(),
md.modified(),
md.created(),
md.accessed()
);
}

Binary file not shown.

View File

@ -1 +1,2 @@
file_metadata
create_dir

BIN
lib/wasi/wasitests/quine Executable file

Binary file not shown.

View File

@ -0,0 +1,11 @@
use std::fs;
use std::io::Read;
fn main() {
let mut this_file = fs::File::open("wasitests/quine.rs").expect("could not find src file");
let md = this_file.metadata().unwrap();
let mut in_str = String::new();
this_file.read_to_string(&mut in_str).unwrap();
println!("{}", in_str);
}

View File

@ -0,0 +1,10 @@
use std::fs;
use std::io::Read;
fn main() {
let mut this_file = fs::File::open("wasitests/quine.rs").expect("could not find src file");
let md = this_file.metadata().unwrap();
let mut in_str = String::new();
this_file.read_to_string(&mut in_str).unwrap();
println!("{}", in_str);
}

BIN
lib/wasi/wasitests/quine.wasm Executable file

Binary file not shown.