Merge pull request #2668 from bytecodealliance/pch/rename_some_wiggle_tests

rename some wiggle tests to reflect new witx ast names
This commit is contained in:
Pat Hickey
2021-02-18 16:11:58 -08:00
committed by GitHub
6 changed files with 25 additions and 28 deletions

View File

@@ -3,13 +3,13 @@ use wiggle::{GuestMemory, GuestPtr, GuestType};
use wiggle_test::{impl_errno, HostMemory, MemArea, MemAreas, WasiCtx}; use wiggle_test::{impl_errno, HostMemory, MemArea, MemAreas, WasiCtx};
wiggle::from_witx!({ wiggle::from_witx!({
witx: ["$CARGO_MANIFEST_DIR/tests/arrays.witx"], witx: ["$CARGO_MANIFEST_DIR/tests/lists.witx"],
ctx: WasiCtx, ctx: WasiCtx,
}); });
impl_errno!(types::Errno, types::GuestErrorConversion); impl_errno!(types::Errno, types::GuestErrorConversion);
impl<'a> arrays::Arrays for WasiCtx<'a> { impl<'a> lists::Lists for WasiCtx<'a> {
fn reduce_excuses( fn reduce_excuses(
&self, &self,
excuses: &types::ConstExcuseArray, excuses: &types::ConstExcuseArray,
@@ -97,7 +97,7 @@ impl ReduceExcusesExcercise {
} }
} }
let res = arrays::reduce_excuses( let res = lists::reduce_excuses(
&ctx, &ctx,
&host_memory, &host_memory,
self.array_ptr_loc.ptr as i32, self.array_ptr_loc.ptr as i32,
@@ -177,7 +177,7 @@ impl PopulateExcusesExcercise {
.expect("failed to write value"); .expect("failed to write value");
} }
let res = arrays::populate_excuses( let res = lists::populate_excuses(
&ctx, &ctx,
&host_memory, &host_memory,
self.array_ptr_loc.ptr as i32, self.array_ptr_loc.ptr as i32,

View File

@@ -4,7 +4,7 @@
(typename $const_excuse_array (list (@witx const_pointer $excuse))) (typename $const_excuse_array (list (@witx const_pointer $excuse)))
(typename $excuse_array (list (@witx pointer $excuse))) (typename $excuse_array (list (@witx pointer $excuse)))
(module $arrays (module $lists
(@interface func (export "reduce_excuses") (@interface func (export "reduce_excuses")
(param $excuses $const_excuse_array) (param $excuses $const_excuse_array)
(result $error (expected $excuse (error $errno))) (result $error (expected $excuse (error $errno)))

View File

@@ -3,13 +3,13 @@ use wiggle::{GuestMemory, GuestPtr};
use wiggle_test::{impl_errno, HostMemory, MemArea, MemAreas, WasiCtx}; use wiggle_test::{impl_errno, HostMemory, MemArea, MemAreas, WasiCtx};
wiggle::from_witx!({ wiggle::from_witx!({
witx: ["$CARGO_MANIFEST_DIR/tests/structs.witx"], witx: ["$CARGO_MANIFEST_DIR/tests/records.witx"],
ctx: WasiCtx, ctx: WasiCtx,
}); });
impl_errno!(types::Errno, types::GuestErrorConversion); impl_errno!(types::Errno, types::GuestErrorConversion);
impl<'a> structs::Structs for WasiCtx<'a> { impl<'a> records::Records for WasiCtx<'a> {
fn sum_of_pair(&self, an_pair: &types::PairInts) -> Result<i64, types::Errno> { fn sum_of_pair(&self, an_pair: &types::PairInts) -> Result<i64, types::Errno> {
Ok(an_pair.first as i64 + an_pair.second as i64) Ok(an_pair.first as i64 + an_pair.second as i64)
} }
@@ -53,17 +53,17 @@ impl<'a> structs::Structs for WasiCtx<'a> {
}) })
} }
fn sum_array<'b>(&self, struct_of_arr: &types::StructOfArray<'b>) -> Result<u16, types::Errno> { fn sum_array<'b>(&self, record_of_list: &types::RecordOfList<'b>) -> Result<u16, types::Errno> {
// my kingdom for try blocks // my kingdom for try blocks
fn aux(struct_of_arr: &types::StructOfArray) -> Result<u16, wiggle::GuestError> { fn aux(record_of_list: &types::RecordOfList) -> Result<u16, wiggle::GuestError> {
let mut s = 0; let mut s = 0;
for elem in struct_of_arr.arr.iter() { for elem in record_of_list.arr.iter() {
let v = elem?.read()?; let v = elem?.read()?;
s += v as u16; s += v as u16;
} }
Ok(s) Ok(s)
} }
match aux(struct_of_arr) { match aux(record_of_list) {
Ok(s) => Ok(s), Ok(s) => Ok(s),
Err(guest_err) => { Err(guest_err) => {
eprintln!("guest error summing array: {:?}", guest_err); eprintln!("guest error summing array: {:?}", guest_err);
@@ -111,7 +111,7 @@ impl SumOfPairExercise {
.ptr(self.input_loc.ptr + 4) .ptr(self.input_loc.ptr + 4)
.write(self.input.second) .write(self.input.second)
.expect("input ref_mut"); .expect("input ref_mut");
let sum_err = structs::sum_of_pair( let sum_err = records::sum_of_pair(
&ctx, &ctx,
&host_memory, &host_memory,
self.input_loc.ptr as i32, self.input_loc.ptr as i32,
@@ -209,7 +209,7 @@ impl SumPairPtrsExercise {
.write(self.input_second_loc.ptr) .write(self.input_second_loc.ptr)
.expect("input_struct ref"); .expect("input_struct ref");
let res = structs::sum_of_pair_of_ptrs( let res = records::sum_of_pair_of_ptrs(
&ctx, &ctx,
&host_memory, &host_memory,
self.input_struct_loc.ptr as i32, self.input_struct_loc.ptr as i32,
@@ -292,7 +292,7 @@ impl SumIntAndPtrExercise {
.write(self.input_second) .write(self.input_second)
.expect("input_struct ref"); .expect("input_struct ref");
let res = structs::sum_of_int_and_ptr( let res = records::sum_of_int_and_ptr(
&ctx, &ctx,
&host_memory, &host_memory,
self.input_struct_loc.ptr as i32, self.input_struct_loc.ptr as i32,
@@ -336,7 +336,7 @@ impl ReturnPairInts {
let ctx = WasiCtx::new(); let ctx = WasiCtx::new();
let host_memory = HostMemory::new(); let host_memory = HostMemory::new();
let err = structs::return_pair_ints(&ctx, &host_memory, self.return_loc.ptr as i32); let err = records::return_pair_ints(&ctx, &host_memory, self.return_loc.ptr as i32);
assert_eq!(err, Ok(types::Errno::Ok as i32), "return struct errno"); assert_eq!(err, Ok(types::Errno::Ok as i32), "return struct errno");
@@ -410,7 +410,7 @@ impl ReturnPairPtrsExercise {
.write(self.input_second) .write(self.input_second)
.expect("input_second ref"); .expect("input_second ref");
let res = structs::return_pair_of_ptrs( let res = records::return_pair_of_ptrs(
&ctx, &ctx,
&host_memory, &host_memory,
self.input_first_loc.ptr as i32, self.input_first_loc.ptr as i32,
@@ -522,7 +522,7 @@ impl SumArrayExercise {
.expect("write len to struct memory"); .expect("write len to struct memory");
// Call wiggle-generated func // Call wiggle-generated func
let res = structs::sum_array( let res = records::sum_array(
&ctx, &ctx,
&host_memory, &host_memory,
self.input_struct_loc.ptr as i32, self.input_struct_loc.ptr as i32,

View File

@@ -18,14 +18,14 @@
(typename $some_bytes (list u8)) (typename $some_bytes (list u8))
(typename $struct_of_array (typename $record_of_list
(record (record
(field $arr $some_bytes))) (field $arr $some_bytes)))
(typename $s64 s64) (typename $s64 s64)
(typename $u16 u16) (typename $u16 u16)
(module $structs (module $records
(@interface func (export "sum_of_pair") (@interface func (export "sum_of_pair")
(param $an_pair $pair_ints) (param $an_pair $pair_ints)
(result $error (expected $s64 (error $errno)))) (result $error (expected $s64 (error $errno))))
@@ -42,6 +42,6 @@
(param $second (@witx const_pointer s32)) (param $second (@witx const_pointer s32))
(result $error (expected $pair_int_ptrs (error $errno)))) (result $error (expected $pair_int_ptrs (error $errno))))
(@interface func (export "sum_array") (@interface func (export "sum_array")
(param $an_arr $struct_of_array) (param $a_list $record_of_list)
(result $error (expected $u16 (error $errno)))) (result $error (expected $u16 (error $errno))))
) )

View File

@@ -3,7 +3,7 @@ use wiggle::{GuestMemory, GuestType};
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx}; use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
wiggle::from_witx!({ wiggle::from_witx!({
witx: ["$CARGO_MANIFEST_DIR/tests/union.witx"], witx: ["$CARGO_MANIFEST_DIR/tests/variant.witx"],
ctx: WasiCtx, ctx: WasiCtx,
}); });
@@ -31,7 +31,7 @@ fn mult_zero_nan(a: f32, b: u32) -> f32 {
} }
} }
impl<'a> union_example::UnionExample for WasiCtx<'a> { impl<'a> variant_example::VariantExample for WasiCtx<'a> {
fn get_tag(&self, u: &types::Reason) -> Result<types::Excuse, types::Errno> { fn get_tag(&self, u: &types::Reason) -> Result<types::Excuse, types::Errno> {
println!("GET TAG: {:?}", u); println!("GET TAG: {:?}", u);
match u { match u {
@@ -126,7 +126,7 @@ impl GetTagExercise {
.expect("input contents ref_mut"), .expect("input contents ref_mut"),
types::Reason::Sleeping => {} // Do nothing types::Reason::Sleeping => {} // Do nothing
} }
let e = union_example::get_tag( let e = variant_example::get_tag(
&ctx, &ctx,
&host_memory, &host_memory,
self.input_loc.ptr as i32, self.input_loc.ptr as i32,
@@ -210,7 +210,7 @@ impl ReasonMultExercise {
} }
types::Reason::Sleeping => {} // Do nothing types::Reason::Sleeping => {} // Do nothing
} }
let e = union_example::reason_mult( let e = variant_example::reason_mult(
&ctx, &ctx,
&host_memory, &host_memory,
self.input_loc.ptr as i32, self.input_loc.ptr as i32,

View File

@@ -1,9 +1,6 @@
(use "errno.witx") (use "errno.witx")
(use "excuse.witx") (use "excuse.witx")
;; Every worker needs a union. Organize your workplace!
;; Fight for the full product of your labor!
(typename $reason (typename $reason
(variant (@witx tag $excuse) (variant (@witx tag $excuse)
(case $dog_ate f32) (case $dog_ate f32)
@@ -16,7 +13,7 @@
(case $traffic (@witx pointer s32)) (case $traffic (@witx pointer s32))
(case $sleeping))) (case $sleeping)))
(module $union_example (module $variant_example
(@interface func (export "get_tag") (@interface func (export "get_tag")
(param $r $reason) (param $r $reason)
(result $error (expected $excuse (error $errno))) (result $error (expected $excuse (error $errno)))