Files
Pat Hickey 0290a83502 wiggle: make wasmtime a mandatory dep, get rid of own Trap enum (#5137)
* wiggle: no longer need to guard wasmtime integration behind a feature

this existed so we could use wiggle in lucet, but lucet is long EOL

* replace wiggle::Trap with wiggle::wasmtime_crate::Trap

* wiggle tests: unwrap traps because we cant assert_eq on them

* wasi-common: emit a wasmtime::Trap instead of a wiggle::Trap

formally add a dependency on wasmtime here to make it obvious, though
we do now have a transitive one via wiggle no matter what (and therefore
can get rid of the default-features=false on the wiggle dep)

* wasi-nn: use wasmtime::Trap instead of wiggle::Trap

there's no way the implementation of this func is actually
a good idea, it will panic the host process on any error,
but I'll ask @mtr to fix that

* wiggle test-helpers examples: fixes

* wasi-common cant cross compile to wasm32-unknown-emscripten anymore

this was originally for the WASI polyfill for web targets. Those days
are way behind us now.

* wasmtime wont compile for armv7-unknown-linux-gnueabihf either
2022-10-27 09:28:10 -07:00

80 lines
2.0 KiB
Rust

use proptest::prelude::*;
use std::convert::TryFrom;
use wiggle::GuestMemory;
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
wiggle::from_witx!({
witx: ["$CARGO_MANIFEST_DIR/tests/ints.witx"],
});
impl_errno!(types::Errno);
impl<'a> ints::Ints for WasiCtx<'a> {
fn cookie_cutter(&mut self, init_cookie: types::Cookie) -> Result<types::Bool, types::Errno> {
let res = if init_cookie == types::COOKIE_START {
types::Bool::True
} else {
types::Bool::False
};
Ok(res)
}
}
fn cookie_strat() -> impl Strategy<Value = types::Cookie> {
(0..std::u64::MAX)
.prop_map(|x| types::Cookie::try_from(x).expect("within range of cookie"))
.boxed()
}
#[derive(Debug)]
struct CookieCutterExercise {
cookie: types::Cookie,
return_ptr_loc: MemArea,
}
impl CookieCutterExercise {
pub fn strat() -> BoxedStrategy<Self> {
(cookie_strat(), HostMemory::mem_area_strat(4))
.prop_map(|(cookie, return_ptr_loc)| Self {
cookie,
return_ptr_loc,
})
.boxed()
}
pub fn test(&self) {
let mut ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let res = ints::cookie_cutter(
&mut ctx,
&host_memory,
self.cookie as i64,
self.return_ptr_loc.ptr as i32,
)
.unwrap();
assert_eq!(res, types::Errno::Ok as i32, "cookie cutter errno");
let is_cookie_start = host_memory
.ptr::<types::Bool>(self.return_ptr_loc.ptr)
.read()
.expect("deref to Bool value");
assert_eq!(
if is_cookie_start == types::Bool::True {
true
} else {
false
},
self.cookie == types::COOKIE_START,
"returned Bool should test if input was Cookie::START",
);
}
}
proptest! {
#[test]
fn cookie_cutter(e in CookieCutterExercise::strat()) {
e.test()
}
}