wiggle: get BorrowChecker from GuestMemory method
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use proptest::prelude::*;
|
||||
use wiggle::{BorrowChecker, GuestMemory, GuestType};
|
||||
use wiggle::{GuestMemory, GuestType};
|
||||
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
||||
|
||||
wiggle::from_witx!({
|
||||
@@ -107,22 +107,21 @@ impl GetTagExercise {
|
||||
pub fn test(&self) {
|
||||
let ctx = WasiCtx::new();
|
||||
let host_memory = HostMemory::new();
|
||||
let bc = unsafe { BorrowChecker::new() };
|
||||
|
||||
let discriminant: u8 = reason_tag(&self.input).into();
|
||||
host_memory
|
||||
.ptr(&bc, self.input_loc.ptr)
|
||||
.ptr(self.input_loc.ptr)
|
||||
.write(discriminant)
|
||||
.expect("input discriminant ptr");
|
||||
match self.input {
|
||||
types::Reason::DogAte(f) => {
|
||||
host_memory
|
||||
.ptr(&bc, self.input_loc.ptr + 4)
|
||||
.ptr(self.input_loc.ptr + 4)
|
||||
.write(f)
|
||||
.expect("input contents ref_mut");
|
||||
}
|
||||
types::Reason::Traffic(v) => host_memory
|
||||
.ptr(&bc, self.input_loc.ptr + 4)
|
||||
.ptr(self.input_loc.ptr + 4)
|
||||
.write(v)
|
||||
.expect("input contents ref_mut"),
|
||||
types::Reason::Sleeping => {} // Do nothing
|
||||
@@ -130,7 +129,6 @@ impl GetTagExercise {
|
||||
let e = union_example::get_tag(
|
||||
&ctx,
|
||||
&host_memory,
|
||||
&bc,
|
||||
self.input_loc.ptr as i32,
|
||||
self.return_loc.ptr as i32,
|
||||
);
|
||||
@@ -138,7 +136,7 @@ impl GetTagExercise {
|
||||
assert_eq!(e, types::Errno::Ok.into(), "get_tag errno");
|
||||
|
||||
let return_val: types::Excuse = host_memory
|
||||
.ptr(&bc, self.return_loc.ptr)
|
||||
.ptr(self.return_loc.ptr)
|
||||
.read()
|
||||
.expect("return ref");
|
||||
|
||||
@@ -186,28 +184,27 @@ impl ReasonMultExercise {
|
||||
pub fn test(&self) {
|
||||
let ctx = WasiCtx::new();
|
||||
let host_memory = HostMemory::new();
|
||||
let bc = unsafe { BorrowChecker::new() };
|
||||
|
||||
let discriminant: u8 = reason_tag(&self.input).into();
|
||||
host_memory
|
||||
.ptr(&bc, self.input_loc.ptr)
|
||||
.ptr(self.input_loc.ptr)
|
||||
.write(discriminant)
|
||||
.expect("input discriminant ref_mut");
|
||||
host_memory
|
||||
.ptr(&bc, self.input_loc.ptr + 4)
|
||||
.ptr(self.input_loc.ptr + 4)
|
||||
.write(self.input_pointee_loc.ptr)
|
||||
.expect("input pointer ref_mut");
|
||||
|
||||
match self.input {
|
||||
types::Reason::DogAte(f) => {
|
||||
host_memory
|
||||
.ptr(&bc, self.input_pointee_loc.ptr)
|
||||
.ptr(self.input_pointee_loc.ptr)
|
||||
.write(f)
|
||||
.expect("input contents ref_mut");
|
||||
}
|
||||
types::Reason::Traffic(v) => {
|
||||
host_memory
|
||||
.ptr(&bc, self.input_pointee_loc.ptr)
|
||||
.ptr(self.input_pointee_loc.ptr)
|
||||
.write(v)
|
||||
.expect("input contents ref_mut");
|
||||
}
|
||||
@@ -216,7 +213,6 @@ impl ReasonMultExercise {
|
||||
let e = union_example::reason_mult(
|
||||
&ctx,
|
||||
&host_memory,
|
||||
&bc,
|
||||
self.input_loc.ptr as i32,
|
||||
self.multiply_by as i32,
|
||||
);
|
||||
@@ -226,7 +222,7 @@ impl ReasonMultExercise {
|
||||
match self.input {
|
||||
types::Reason::DogAte(f) => {
|
||||
let f_result: f32 = host_memory
|
||||
.ptr(&bc, self.input_pointee_loc.ptr)
|
||||
.ptr(self.input_pointee_loc.ptr)
|
||||
.read()
|
||||
.expect("input contents ref_mut");
|
||||
assert_eq!(
|
||||
@@ -237,7 +233,7 @@ impl ReasonMultExercise {
|
||||
}
|
||||
types::Reason::Traffic(v) => {
|
||||
let v_result: i32 = host_memory
|
||||
.ptr(&bc, self.input_pointee_loc.ptr)
|
||||
.ptr(self.input_pointee_loc.ptr)
|
||||
.read()
|
||||
.expect("input contents ref_mut");
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user