-
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
7 changed files
with
126 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#[test] | ||
fn test_close_preopen_fd() { | ||
assert_wasi_output!( | ||
"../../wasitests/close_preopen_fd.wasm", | ||
"close_preopen_fd", | ||
vec![], | ||
vec![( | ||
"hamlet".to_string(), | ||
::std::path::PathBuf::from("wasitests/test_fs/hamlet") | ||
),], | ||
vec![], | ||
"../../wasitests/close_preopen_fd.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,3 @@ | ||
accessing preopen fd was a success | ||
Closing preopen fd was a success | ||
accessing closed preopen fd was an EBADF error: true |
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,44 @@ | ||
// Args: | ||
// mapdir: hamlet:wasitests/test_fs/hamlet | ||
|
||
use std::fs; | ||
use std::path::PathBuf; | ||
|
||
#[cfg(target_os = "wasi")] | ||
#[link(wasm_import_module = "wasi_unstable")] | ||
extern "C" { | ||
fn fd_close(fd: u32) -> u16; | ||
fn fd_fdstat_set_flags(fd: u32, flags: u16) -> u16; | ||
} | ||
|
||
const FIRST_PREOPEN_FD: u32 = 4; | ||
|
||
fn main() { | ||
#[cfg(target_os = "wasi")] | ||
{ | ||
let result = unsafe { fd_fdstat_set_flags(FIRST_PREOPEN_FD, 1 << 2) }; | ||
println!( | ||
"accessing preopen fd was a {}", | ||
if result == 0 { "success" } else { "failure" } | ||
); | ||
|
||
let result = unsafe { fd_close(FIRST_PREOPEN_FD) }; | ||
println!( | ||
"Closing preopen fd was a {}", | ||
if result == 0 { "success" } else { "failure" } | ||
); | ||
|
||
let result = unsafe { fd_fdstat_set_flags(FIRST_PREOPEN_FD, 1 << 2) }; | ||
println!( | ||
"accessing closed preopen fd was an EBADF error: {}", | ||
if result == 8 { "true" } else { "false" } | ||
); | ||
} | ||
|
||
#[cfg(not(target_os = "wasi"))] | ||
{ | ||
println!("accessing preopen fd was a success"); | ||
println!("Closing preopen fd was a success"); | ||
println!("accessing closed preopen fd was an EBADF error: true"); | ||
} | ||
} |
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
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