-
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.
726: Add serialization for WASI state r=MarkMcCaskey a=MarkMcCaskey part of #700 Due to the trait objects from #583 , we can't use `serde` derive for this or use serde traits directly, we have to do some custom serialization (edit: luckily there's a crate for this: `typetag`) Co-authored-by: Mark McCaskey <[email protected]> Co-authored-by: Mark McCaskey <[email protected]> Co-authored-by: Syrus Akbary <[email protected]>
- Loading branch information
Showing
17 changed files
with
538 additions
and
136 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 +1,60 @@ | ||
// nothing to see here | ||
#![cfg(test)] | ||
use wasmer_runtime::{compile, Func}; | ||
use wasmer_runtime_core::vm::Ctx; | ||
use wasmer_wasi::{state::*, *}; | ||
|
||
use std::ffi::c_void; | ||
|
||
#[test] | ||
fn serializing_works() { | ||
let args = vec![ | ||
b"program_name".into_iter().cloned().collect(), | ||
b"arg1".into_iter().cloned().collect(), | ||
]; | ||
let envs = vec![ | ||
b"PATH=/bin".into_iter().cloned().collect(), | ||
b"GOROOT=$HOME/.cargo/bin".into_iter().cloned().collect(), | ||
]; | ||
let wasm_binary = include_bytes!("../wasitests/fd_read.wasm"); | ||
let import_object = generate_import_object( | ||
args.clone(), | ||
envs.clone(), | ||
vec![], | ||
vec![( | ||
".".to_string(), | ||
std::path::PathBuf::from("wasitests/test_fs/hamlet"), | ||
)], | ||
); | ||
let module = compile(&wasm_binary[..]) | ||
.map_err(|e| format!("Can't compile module: {:?}", e)) | ||
.unwrap(); | ||
|
||
let state_bytes = { | ||
let instance = module.instantiate(&import_object).unwrap(); | ||
|
||
let start: Func<(), ()> = instance.func("_start").unwrap(); | ||
start.call().unwrap(); | ||
let state = get_wasi_state(instance.context()); | ||
|
||
assert_eq!(state.args, args); | ||
assert_eq!(state.envs, envs); | ||
let bytes = state.freeze().unwrap(); | ||
|
||
bytes | ||
}; | ||
|
||
let mut instance = module.instantiate(&import_object).unwrap(); | ||
|
||
let wasi_state = Box::new(WasiState::unfreeze(&state_bytes).unwrap()); | ||
|
||
instance.context_mut().data = Box::into_raw(wasi_state) as *mut c_void; | ||
|
||
let second_entry: Func<(), i32> = instance.func("second_entry").unwrap(); | ||
let result = second_entry.call().unwrap(); | ||
assert_eq!(result, true as i32); | ||
} | ||
|
||
#[allow(clippy::mut_from_ref)] | ||
pub(crate) fn get_wasi_state(ctx: &Ctx) -> &mut WasiState { | ||
unsafe { state::get_wasi_state(&mut *(ctx as *const Ctx as *mut Ctx)) } | ||
} |
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_fd_read() { | ||
assert_wasi_output!( | ||
"../../wasitests/fd_read.wasm", | ||
"fd_read", | ||
vec![], | ||
vec![( | ||
".".to_string(), | ||
::std::path::PathBuf::from("wasitests/test_fs/hamlet") | ||
),], | ||
vec![], | ||
"../../wasitests/fd_read.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 @@ | ||
SCENE IV. The Queen's closet. | ||
|
||
Enter QUEEN GERTRUDE and POLO |
Oops, something went wrong.