-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
324 additions
and
31 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// !!! THIS IS A GENERATED FILE !!! | ||
// ANY MANUAL EDITS MAY BE OVERWRITTEN AT ANY TIME | ||
// Files autogenerated with cargo build (build/wasitests.rs). | ||
|
||
#[test] | ||
fn test_fd_close() { | ||
assert_wasi_output!( | ||
"../../wasitests/fd_close.wasm", | ||
"fd_close", | ||
vec![], | ||
vec![( | ||
".".to_string(), | ||
::std::path::PathBuf::from("wasitests/test_fs/hamlet") | ||
),], | ||
vec![], | ||
"../../wasitests/fd_close.out" | ||
); | ||
} |
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,2 @@ | ||
Successfully closed stderr! | ||
Successfully closed stdin! |
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,54 @@ | ||
// Args: | ||
// mapdir: .:wasitests/test_fs/hamlet | ||
|
||
use std::fs; | ||
#[cfg(target_os = "wasi")] | ||
use std::os::wasi::prelude::AsRawFd; | ||
use std::path::PathBuf; | ||
|
||
#[cfg(target_os = "wasi")] | ||
#[link(wasm_import_module = "wasi_unstable")] | ||
extern "C" { | ||
fn fd_close(fd: u32) -> u16; | ||
} | ||
|
||
fn main() { | ||
#[cfg(not(target_os = "wasi"))] | ||
let mut base = PathBuf::from("wasitests/test_fs/hamlet"); | ||
#[cfg(target_os = "wasi")] | ||
let mut base = PathBuf::from("."); | ||
|
||
base.push("act3/scene3.txt"); | ||
let file = fs::File::open(&base).expect("could not open file"); | ||
|
||
#[cfg(target_os = "wasi")] | ||
{ | ||
let stdout_fd = std::io::stdout().as_raw_fd(); | ||
let stderr_fd = std::io::stderr().as_raw_fd(); | ||
let stdin_fd = std::io::stdin().as_raw_fd(); | ||
|
||
let result = unsafe { fd_close(stderr_fd) }; | ||
if result == 0 { | ||
println!("Successfully closed stderr!") | ||
} else { | ||
println!("Could not close stderr"); | ||
} | ||
let result = unsafe { fd_close(stdin_fd) }; | ||
if result == 0 { | ||
println!("Successfully closed stdin!") | ||
} else { | ||
println!("Could not close stdin"); | ||
} | ||
let result = unsafe { fd_close(stdout_fd) }; | ||
if result == 0 { | ||
println!("Successfully closed stdout!") | ||
} else { | ||
println!("Could not close stdout"); | ||
} | ||
} | ||
#[cfg(not(target_os = "wasi"))] | ||
{ | ||
println!("Successfully closed stderr!"); | ||
println!("Successfully closed stdin!"); | ||
} | ||
} |
Binary file not shown.
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
Oops, something went wrong.