wiggle: get BorrowChecker from GuestMemory method
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use proptest::prelude::*;
|
||||
use wiggle::{BorrowChecker, GuestMemory, GuestPtr};
|
||||
use wiggle::{GuestMemory, GuestPtr};
|
||||
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
||||
|
||||
wiggle::from_witx!({
|
||||
@@ -77,25 +77,22 @@ impl ReduceExcusesExcercise {
|
||||
pub fn test(&self) {
|
||||
let ctx = WasiCtx::new();
|
||||
let host_memory = HostMemory::new();
|
||||
let bc = unsafe { BorrowChecker::new() };
|
||||
|
||||
// Populate memory with pointers to generated Excuse values
|
||||
for (&excuse, ptr) in self.excuse_values.iter().zip(self.excuse_ptr_locs.iter()) {
|
||||
host_memory
|
||||
.ptr(&bc, ptr.ptr)
|
||||
.ptr(ptr.ptr)
|
||||
.write(excuse)
|
||||
.expect("deref ptr mut to Excuse value");
|
||||
}
|
||||
|
||||
// Populate the array with pointers to generated Excuse values
|
||||
{
|
||||
let array: GuestPtr<'_, [GuestPtr<types::Excuse>]> = host_memory.ptr(
|
||||
&bc,
|
||||
(self.array_ptr_loc.ptr, self.excuse_ptr_locs.len() as u32),
|
||||
);
|
||||
let array: GuestPtr<'_, [GuestPtr<types::Excuse>]> =
|
||||
host_memory.ptr((self.array_ptr_loc.ptr, self.excuse_ptr_locs.len() as u32));
|
||||
for (slot, ptr) in array.iter().zip(&self.excuse_ptr_locs) {
|
||||
let slot = slot.expect("array should be in bounds");
|
||||
slot.write(host_memory.ptr(&bc, ptr.ptr))
|
||||
slot.write(host_memory.ptr(ptr.ptr))
|
||||
.expect("should succeed in writing array");
|
||||
}
|
||||
}
|
||||
@@ -103,7 +100,6 @@ impl ReduceExcusesExcercise {
|
||||
let res = arrays::reduce_excuses(
|
||||
&ctx,
|
||||
&host_memory,
|
||||
&bc,
|
||||
self.array_ptr_loc.ptr as i32,
|
||||
self.excuse_ptr_locs.len() as i32,
|
||||
self.return_ptr_loc.ptr as i32,
|
||||
@@ -116,7 +112,7 @@ impl ReduceExcusesExcercise {
|
||||
.last()
|
||||
.expect("generated vec of excuses should be non-empty");
|
||||
let given: types::Excuse = host_memory
|
||||
.ptr(&bc, self.return_ptr_loc.ptr)
|
||||
.ptr(self.return_ptr_loc.ptr)
|
||||
.read()
|
||||
.expect("deref ptr to returned value");
|
||||
assert_eq!(expected, given, "reduce excuses return val");
|
||||
@@ -169,30 +165,28 @@ impl PopulateExcusesExcercise {
|
||||
pub fn test(&self) {
|
||||
let ctx = WasiCtx::new();
|
||||
let host_memory = HostMemory::new();
|
||||
let bc = unsafe { BorrowChecker::new() };
|
||||
|
||||
// Populate array with valid pointers to Excuse type in memory
|
||||
let ptr = host_memory.ptr::<[GuestPtr<'_, types::Excuse>]>(
|
||||
&bc,
|
||||
(self.array_ptr_loc.ptr, self.elements.len() as u32),
|
||||
);
|
||||
let ptr = host_memory.ptr::<[GuestPtr<'_, types::Excuse>]>((
|
||||
self.array_ptr_loc.ptr,
|
||||
self.elements.len() as u32,
|
||||
));
|
||||
for (ptr, val) in ptr.iter().zip(&self.elements) {
|
||||
ptr.expect("should be valid pointer")
|
||||
.write(host_memory.ptr(&bc, val.ptr))
|
||||
.write(host_memory.ptr(val.ptr))
|
||||
.expect("failed to write value");
|
||||
}
|
||||
|
||||
let res = arrays::populate_excuses(
|
||||
&ctx,
|
||||
&host_memory,
|
||||
&bc,
|
||||
self.array_ptr_loc.ptr as i32,
|
||||
self.elements.len() as i32,
|
||||
);
|
||||
assert_eq!(res, types::Errno::Ok.into(), "populate excuses errno");
|
||||
|
||||
let arr: GuestPtr<'_, [GuestPtr<'_, types::Excuse>]> =
|
||||
host_memory.ptr(&bc, (self.array_ptr_loc.ptr, self.elements.len() as u32));
|
||||
host_memory.ptr((self.array_ptr_loc.ptr, self.elements.len() as u32));
|
||||
for el in arr.iter() {
|
||||
let ptr_to_ptr = el
|
||||
.expect("valid ptr to ptr")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use proptest::prelude::*;
|
||||
use wiggle::{BorrowChecker, GuestMemory};
|
||||
use wiggle::GuestMemory;
|
||||
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
||||
|
||||
wiggle::from_witx!({
|
||||
@@ -31,9 +31,8 @@ impl IntFloatExercise {
|
||||
pub fn test(&self) {
|
||||
let ctx = WasiCtx::new();
|
||||
let host_memory = HostMemory::new();
|
||||
let bc = unsafe { BorrowChecker::new() };
|
||||
|
||||
let e = atoms::int_float_args(&ctx, &host_memory, &bc, self.an_int as i32, self.an_float);
|
||||
let e = atoms::int_float_args(&ctx, &host_memory, self.an_int as i32, self.an_float);
|
||||
|
||||
assert_eq!(e, types::Errno::Ok.into(), "int_float_args error");
|
||||
}
|
||||
@@ -61,18 +60,16 @@ impl DoubleIntExercise {
|
||||
pub fn test(&self) {
|
||||
let ctx = WasiCtx::new();
|
||||
let host_memory = HostMemory::new();
|
||||
let bc = unsafe { BorrowChecker::new() };
|
||||
|
||||
let e = atoms::double_int_return_float(
|
||||
&ctx,
|
||||
&host_memory,
|
||||
&bc,
|
||||
self.input as i32,
|
||||
self.return_loc.ptr as i32,
|
||||
);
|
||||
|
||||
let return_val = host_memory
|
||||
.ptr::<types::AliasToFloat>(&bc, self.return_loc.ptr)
|
||||
.ptr::<types::AliasToFloat>(self.return_loc.ptr)
|
||||
.read()
|
||||
.expect("failed to read return");
|
||||
assert_eq!(e, types::Errno::Ok.into(), "errno");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use proptest::prelude::*;
|
||||
use std::convert::TryFrom;
|
||||
use wiggle::{BorrowChecker, GuestMemory, GuestPtr};
|
||||
use wiggle::{GuestMemory, GuestPtr};
|
||||
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
||||
|
||||
wiggle::from_witx!({
|
||||
@@ -65,18 +65,16 @@ impl ConfigureCarExercise {
|
||||
pub fn test(&self) {
|
||||
let ctx = WasiCtx::new();
|
||||
let host_memory = HostMemory::new();
|
||||
let bc = unsafe { BorrowChecker::new() };
|
||||
|
||||
// Populate input ptr
|
||||
host_memory
|
||||
.ptr(&bc, self.other_config_by_ptr.ptr)
|
||||
.ptr(self.other_config_by_ptr.ptr)
|
||||
.write(self.other_config)
|
||||
.expect("deref ptr mut to CarConfig");
|
||||
|
||||
let res = flags::configure_car(
|
||||
&ctx,
|
||||
&host_memory,
|
||||
&bc,
|
||||
self.old_config.into(),
|
||||
self.other_config_by_ptr.ptr as i32,
|
||||
self.return_ptr_loc.ptr as i32,
|
||||
@@ -84,7 +82,7 @@ impl ConfigureCarExercise {
|
||||
assert_eq!(res, types::Errno::Ok.into(), "configure car errno");
|
||||
|
||||
let res_config = host_memory
|
||||
.ptr::<types::CarConfig>(&bc, self.return_ptr_loc.ptr)
|
||||
.ptr::<types::CarConfig>(self.return_ptr_loc.ptr)
|
||||
.read()
|
||||
.expect("deref to CarConfig value");
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use proptest::prelude::*;
|
||||
use wiggle::{BorrowChecker, GuestMemory, GuestType};
|
||||
use wiggle::{GuestMemory, GuestType};
|
||||
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
||||
|
||||
const FD_VAL: u32 = 123;
|
||||
@@ -34,24 +34,23 @@ impl HandleExercise {
|
||||
pub fn test(&self) {
|
||||
let ctx = WasiCtx::new();
|
||||
let host_memory = HostMemory::new();
|
||||
let bc = unsafe { BorrowChecker::new() };
|
||||
|
||||
let e = handle_examples::fd_create(&ctx, &host_memory, &bc, self.return_loc.ptr as i32);
|
||||
let e = handle_examples::fd_create(&ctx, &host_memory, self.return_loc.ptr as i32);
|
||||
|
||||
assert_eq!(e, types::Errno::Ok.into(), "fd_create error");
|
||||
|
||||
let h_got: u32 = host_memory
|
||||
.ptr(&bc, self.return_loc.ptr)
|
||||
.ptr(self.return_loc.ptr)
|
||||
.read()
|
||||
.expect("return ref_mut");
|
||||
|
||||
assert_eq!(h_got, 123, "fd_create return val");
|
||||
|
||||
let e = handle_examples::fd_consume(&ctx, &host_memory, &bc, h_got as i32);
|
||||
let e = handle_examples::fd_consume(&ctx, &host_memory, h_got as i32);
|
||||
|
||||
assert_eq!(e, types::Errno::Ok.into(), "fd_consume error");
|
||||
|
||||
let e = handle_examples::fd_consume(&ctx, &host_memory, &bc, h_got as i32 + 1);
|
||||
let e = handle_examples::fd_consume(&ctx, &host_memory, h_got as i32 + 1);
|
||||
|
||||
assert_eq!(
|
||||
e,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use proptest::prelude::*;
|
||||
use std::convert::TryFrom;
|
||||
use wiggle::{BorrowChecker, GuestMemory};
|
||||
use wiggle::GuestMemory;
|
||||
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
||||
|
||||
wiggle::from_witx!({
|
||||
@@ -46,19 +46,17 @@ impl CookieCutterExercise {
|
||||
pub fn test(&self) {
|
||||
let ctx = WasiCtx::new();
|
||||
let host_memory = HostMemory::new();
|
||||
let bc = unsafe { BorrowChecker::new() };
|
||||
|
||||
let res = ints::cookie_cutter(
|
||||
&ctx,
|
||||
&host_memory,
|
||||
&bc,
|
||||
self.cookie.into(),
|
||||
self.return_ptr_loc.ptr as i32,
|
||||
);
|
||||
assert_eq!(res, types::Errno::Ok.into(), "cookie cutter errno");
|
||||
|
||||
let is_cookie_start = host_memory
|
||||
.ptr::<types::Bool>(&bc, self.return_ptr_loc.ptr)
|
||||
.ptr::<types::Bool>(self.return_ptr_loc.ptr)
|
||||
.read()
|
||||
.expect("deref to Bool value");
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use proptest::prelude::*;
|
||||
use wiggle::{BorrowChecker, GuestMemory, GuestPtr};
|
||||
use wiggle::{GuestMemory, GuestPtr};
|
||||
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
||||
|
||||
wiggle::from_witx!({
|
||||
@@ -128,32 +128,30 @@ impl PointersAndEnumsExercise {
|
||||
pub fn test(&self) {
|
||||
let ctx = WasiCtx::new();
|
||||
let host_memory = HostMemory::new();
|
||||
let bc = unsafe { BorrowChecker::new() };
|
||||
|
||||
host_memory
|
||||
.ptr(&bc, self.input2_loc.ptr)
|
||||
.ptr(self.input2_loc.ptr)
|
||||
.write(self.input2)
|
||||
.expect("input2 ref_mut");
|
||||
|
||||
host_memory
|
||||
.ptr(&bc, self.input3_loc.ptr)
|
||||
.ptr(self.input3_loc.ptr)
|
||||
.write(self.input3)
|
||||
.expect("input3 ref_mut");
|
||||
|
||||
host_memory
|
||||
.ptr(&bc, self.input4_loc.ptr)
|
||||
.ptr(self.input4_loc.ptr)
|
||||
.write(self.input4)
|
||||
.expect("input4 ref_mut");
|
||||
|
||||
host_memory
|
||||
.ptr(&bc, self.input4_ptr_loc.ptr)
|
||||
.ptr(self.input4_ptr_loc.ptr)
|
||||
.write(self.input4_loc.ptr)
|
||||
.expect("input4 ptr ref_mut");
|
||||
|
||||
let e = pointers::pointers_and_enums(
|
||||
&ctx,
|
||||
&host_memory,
|
||||
&bc,
|
||||
self.input1.into(),
|
||||
self.input2_loc.ptr as i32,
|
||||
self.input3_loc.ptr as i32,
|
||||
@@ -163,7 +161,7 @@ impl PointersAndEnumsExercise {
|
||||
|
||||
// Implementation of pointers_and_enums writes input3 to the input2_loc:
|
||||
let written_to_input2_loc: i32 = host_memory
|
||||
.ptr(&bc, self.input2_loc.ptr)
|
||||
.ptr(self.input2_loc.ptr)
|
||||
.read()
|
||||
.expect("input2 ref");
|
||||
|
||||
@@ -175,7 +173,7 @@ impl PointersAndEnumsExercise {
|
||||
|
||||
// Implementation of pointers_and_enums writes input2_loc to input4_ptr_loc:
|
||||
let written_to_input4_ptr: u32 = host_memory
|
||||
.ptr(&bc, self.input4_ptr_loc.ptr)
|
||||
.ptr(self.input4_ptr_loc.ptr)
|
||||
.read()
|
||||
.expect("input4_ptr_loc ref");
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use proptest::prelude::*;
|
||||
use wiggle::{BorrowChecker, GuestMemory, GuestPtr};
|
||||
use wiggle::{GuestMemory, GuestPtr};
|
||||
use wiggle_test::{impl_errno, HostMemory, MemArea, MemAreas, WasiCtx};
|
||||
|
||||
wiggle::from_witx!({
|
||||
@@ -69,11 +69,9 @@ impl HelloStringExercise {
|
||||
pub fn test(&self) {
|
||||
let ctx = WasiCtx::new();
|
||||
let host_memory = HostMemory::new();
|
||||
let bc = unsafe { BorrowChecker::new() };
|
||||
|
||||
// Populate string in guest's memory
|
||||
let ptr =
|
||||
host_memory.ptr::<str>(&bc, (self.string_ptr_loc.ptr, self.test_word.len() as u32));
|
||||
let ptr = host_memory.ptr::<str>((self.string_ptr_loc.ptr, self.test_word.len() as u32));
|
||||
for (slot, byte) in ptr.as_bytes().iter().zip(self.test_word.bytes()) {
|
||||
slot.expect("should be valid pointer")
|
||||
.write(byte)
|
||||
@@ -83,7 +81,6 @@ impl HelloStringExercise {
|
||||
let res = strings::hello_string(
|
||||
&ctx,
|
||||
&host_memory,
|
||||
&bc,
|
||||
self.string_ptr_loc.ptr as i32,
|
||||
self.test_word.len() as i32,
|
||||
self.return_ptr_loc.ptr as i32,
|
||||
@@ -91,7 +88,7 @@ impl HelloStringExercise {
|
||||
assert_eq!(res, types::Errno::Ok.into(), "hello string errno");
|
||||
|
||||
let given = host_memory
|
||||
.ptr::<u32>(&bc, self.return_ptr_loc.ptr)
|
||||
.ptr::<u32>(self.return_ptr_loc.ptr)
|
||||
.read()
|
||||
.expect("deref ptr to return value");
|
||||
assert_eq!(self.test_word.len() as u32, given);
|
||||
@@ -178,10 +175,9 @@ impl MultiStringExercise {
|
||||
pub fn test(&self) {
|
||||
let ctx = WasiCtx::new();
|
||||
let host_memory = HostMemory::new();
|
||||
let bc = unsafe { BorrowChecker::new() };
|
||||
|
||||
let write_string = |val: &str, loc: MemArea| {
|
||||
let ptr = host_memory.ptr::<str>(&bc, (loc.ptr, val.len() as u32));
|
||||
let ptr = host_memory.ptr::<str>((loc.ptr, val.len() as u32));
|
||||
for (slot, byte) in ptr.as_bytes().iter().zip(val.bytes()) {
|
||||
slot.expect("should be valid pointer")
|
||||
.write(byte)
|
||||
@@ -196,7 +192,6 @@ impl MultiStringExercise {
|
||||
let res = strings::multi_string(
|
||||
&ctx,
|
||||
&host_memory,
|
||||
&bc,
|
||||
self.sa_ptr_loc.ptr as i32,
|
||||
self.a.len() as i32,
|
||||
self.sb_ptr_loc.ptr as i32,
|
||||
@@ -208,7 +203,7 @@ impl MultiStringExercise {
|
||||
assert_eq!(res, types::Errno::Ok.into(), "multi string errno");
|
||||
|
||||
let given = host_memory
|
||||
.ptr::<u32>(&bc, self.return_ptr_loc.ptr)
|
||||
.ptr::<u32>(self.return_ptr_loc.ptr)
|
||||
.read()
|
||||
.expect("deref ptr to return value");
|
||||
assert_eq!((self.a.len() + self.b.len() + self.c.len()) as u32, given);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use proptest::prelude::*;
|
||||
use wiggle::{BorrowChecker, GuestMemory, GuestPtr};
|
||||
use wiggle::{GuestMemory, GuestPtr};
|
||||
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
|
||||
|
||||
wiggle::from_witx!({
|
||||
@@ -83,20 +83,18 @@ impl SumOfPairExercise {
|
||||
pub fn test(&self) {
|
||||
let ctx = WasiCtx::new();
|
||||
let host_memory = HostMemory::new();
|
||||
let bc = unsafe { BorrowChecker::new() };
|
||||
|
||||
host_memory
|
||||
.ptr(&bc, self.input_loc.ptr)
|
||||
.ptr(self.input_loc.ptr)
|
||||
.write(self.input.first)
|
||||
.expect("input ref_mut");
|
||||
host_memory
|
||||
.ptr(&bc, self.input_loc.ptr + 4)
|
||||
.ptr(self.input_loc.ptr + 4)
|
||||
.write(self.input.second)
|
||||
.expect("input ref_mut");
|
||||
let sum_err = structs::sum_of_pair(
|
||||
&ctx,
|
||||
&host_memory,
|
||||
&bc,
|
||||
self.input_loc.ptr as i32,
|
||||
self.return_loc.ptr as i32,
|
||||
);
|
||||
@@ -104,7 +102,7 @@ impl SumOfPairExercise {
|
||||
assert_eq!(sum_err, types::Errno::Ok.into(), "sum errno");
|
||||
|
||||
let return_val: i64 = host_memory
|
||||
.ptr(&bc, self.return_loc.ptr)
|
||||
.ptr(self.return_loc.ptr)
|
||||
.read()
|
||||
.expect("return ref");
|
||||
|
||||
@@ -173,30 +171,28 @@ impl SumPairPtrsExercise {
|
||||
pub fn test(&self) {
|
||||
let ctx = WasiCtx::new();
|
||||
let host_memory = HostMemory::new();
|
||||
let bc = unsafe { BorrowChecker::new() };
|
||||
|
||||
host_memory
|
||||
.ptr(&bc, self.input_first_loc.ptr)
|
||||
.ptr(self.input_first_loc.ptr)
|
||||
.write(self.input_first)
|
||||
.expect("input_first ref");
|
||||
host_memory
|
||||
.ptr(&bc, self.input_second_loc.ptr)
|
||||
.ptr(self.input_second_loc.ptr)
|
||||
.write(self.input_second)
|
||||
.expect("input_second ref");
|
||||
|
||||
host_memory
|
||||
.ptr(&bc, self.input_struct_loc.ptr)
|
||||
.ptr(self.input_struct_loc.ptr)
|
||||
.write(self.input_first_loc.ptr)
|
||||
.expect("input_struct ref");
|
||||
host_memory
|
||||
.ptr(&bc, self.input_struct_loc.ptr + 4)
|
||||
.ptr(self.input_struct_loc.ptr + 4)
|
||||
.write(self.input_second_loc.ptr)
|
||||
.expect("input_struct ref");
|
||||
|
||||
let res = structs::sum_of_pair_of_ptrs(
|
||||
&ctx,
|
||||
&host_memory,
|
||||
&bc,
|
||||
self.input_struct_loc.ptr as i32,
|
||||
self.return_loc.ptr as i32,
|
||||
);
|
||||
@@ -204,7 +200,7 @@ impl SumPairPtrsExercise {
|
||||
assert_eq!(res, types::Errno::Ok.into(), "sum of pair of ptrs errno");
|
||||
|
||||
let doubled: i64 = host_memory
|
||||
.ptr(&bc, self.return_loc.ptr)
|
||||
.ptr(self.return_loc.ptr)
|
||||
.read()
|
||||
.expect("return ref");
|
||||
|
||||
@@ -259,25 +255,23 @@ impl SumIntAndPtrExercise {
|
||||
pub fn test(&self) {
|
||||
let ctx = WasiCtx::new();
|
||||
let host_memory = HostMemory::new();
|
||||
let bc = unsafe { BorrowChecker::new() };
|
||||
|
||||
host_memory
|
||||
.ptr(&bc, self.input_first_loc.ptr)
|
||||
.ptr(self.input_first_loc.ptr)
|
||||
.write(self.input_first)
|
||||
.expect("input_first ref");
|
||||
host_memory
|
||||
.ptr(&bc, self.input_struct_loc.ptr)
|
||||
.ptr(self.input_struct_loc.ptr)
|
||||
.write(self.input_first_loc.ptr)
|
||||
.expect("input_struct ref");
|
||||
host_memory
|
||||
.ptr(&bc, self.input_struct_loc.ptr + 4)
|
||||
.ptr(self.input_struct_loc.ptr + 4)
|
||||
.write(self.input_second)
|
||||
.expect("input_struct ref");
|
||||
|
||||
let res = structs::sum_of_int_and_ptr(
|
||||
&ctx,
|
||||
&host_memory,
|
||||
&bc,
|
||||
self.input_struct_loc.ptr as i32,
|
||||
self.return_loc.ptr as i32,
|
||||
);
|
||||
@@ -285,7 +279,7 @@ impl SumIntAndPtrExercise {
|
||||
assert_eq!(res, types::Errno::Ok.into(), "sum of int and ptr errno");
|
||||
|
||||
let doubled: i64 = host_memory
|
||||
.ptr(&bc, self.return_loc.ptr)
|
||||
.ptr(self.return_loc.ptr)
|
||||
.read()
|
||||
.expect("return ref");
|
||||
|
||||
@@ -318,14 +312,13 @@ impl ReturnPairInts {
|
||||
pub fn test(&self) {
|
||||
let ctx = WasiCtx::new();
|
||||
let host_memory = HostMemory::new();
|
||||
let bc = unsafe { BorrowChecker::new() };
|
||||
|
||||
let err = structs::return_pair_ints(&ctx, &host_memory, &bc, self.return_loc.ptr as i32);
|
||||
let err = structs::return_pair_ints(&ctx, &host_memory, self.return_loc.ptr as i32);
|
||||
|
||||
assert_eq!(err, types::Errno::Ok.into(), "return struct errno");
|
||||
|
||||
let return_struct: types::PairInts = host_memory
|
||||
.ptr(&bc, self.return_loc.ptr)
|
||||
.ptr(self.return_loc.ptr)
|
||||
.read()
|
||||
.expect("return ref");
|
||||
|
||||
@@ -384,21 +377,19 @@ impl ReturnPairPtrsExercise {
|
||||
pub fn test(&self) {
|
||||
let ctx = WasiCtx::new();
|
||||
let host_memory = HostMemory::new();
|
||||
let bc = unsafe { BorrowChecker::new() };
|
||||
|
||||
host_memory
|
||||
.ptr(&bc, self.input_first_loc.ptr)
|
||||
.ptr(self.input_first_loc.ptr)
|
||||
.write(self.input_first)
|
||||
.expect("input_first ref");
|
||||
host_memory
|
||||
.ptr(&bc, self.input_second_loc.ptr)
|
||||
.ptr(self.input_second_loc.ptr)
|
||||
.write(self.input_second)
|
||||
.expect("input_second ref");
|
||||
|
||||
let res = structs::return_pair_of_ptrs(
|
||||
&ctx,
|
||||
&host_memory,
|
||||
&bc,
|
||||
self.input_first_loc.ptr as i32,
|
||||
self.input_second_loc.ptr as i32,
|
||||
self.return_loc.ptr as i32,
|
||||
@@ -407,7 +398,7 @@ impl ReturnPairPtrsExercise {
|
||||
assert_eq!(res, types::Errno::Ok.into(), "return pair of ptrs errno");
|
||||
|
||||
let ptr_pair_int_ptrs: types::PairIntPtrs<'_> = host_memory
|
||||
.ptr(&bc, self.return_loc.ptr)
|
||||
.ptr(self.return_loc.ptr)
|
||||
.read()
|
||||
.expect("failed to read return location");
|
||||
let ret_first_ptr = ptr_pair_int_ptrs.first;
|
||||
|
||||
@@ -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