Files
wasmtime/tests/test.witx
Jakub Konka 2ad77538f5 Add array generation to wiggle-generate crate (#9)
* Add array generation to wiggle-generate crate

This commit:
* adds array generation to `wiggle-generate` crate which implies
  that we can now generate arrays from `witx` files
* introduces two test interface functions `foo::reduce_excuses` and
  `foo::populate_excuses`, and adds matching prop-tests
* adds an out-of-boundary check to `HostMemory::mem_area_strat` since
  now, given we're generating arrays for testing with an arbitrary
  but bounded number of elements, it is possible to violate the boundary
* refactors `Region::extend` to a new signature `extend(times: u32)`
  which multiplies the current pointer `len` by `times`
* fixes bug in `GuestArray::as_ref` and `GuestArrayMut::as_ref_mut` methods
  where we were not validating the first element (we always started the
  validation from the second element)

* Fix generation of arrays in witx

This commit fixes how `arrays` are auto-generated from `witx` files.
In particular, the changes include:
* Since by design every `array` in `witx` represents an immutable
  slab of memory, we will only ever operate on `GuestArray` in which
  case I've gone ahead and removed `GuestArrayMut` so as to unclutter
  the code somewhat. If we find ourselves in need for it in the future,
  I reckon it will be better to write it from scratch (since the codebase
  will inevitably evolve by then considerably) rather than maintaining an
  unused implementation.
* I've rewritten `GuestArrayRef<T>` to be a wrapper for `Vec<GuestRef<T>>`.
  Also, `GuestArray::as_ref` now borrows each underlying "element" of the
  array one-by-one rather than borrowing the entire chunk of memory at once.
  This change is motivated by the inability to coerce type parameter `T` in
  `GuestArray<T>` in more complicated cases such as arrays of guest pointers
  `GuestPtr<T>` to `*const T` for reuse in `std::slice::from_raw_parts` call.
  (In general, the size of Wasm32 pointer is 4 bytes, while

```
std::mem::size_of::<T>() == std::mem::size_of::<GuestPtr<S>>() == 16
```

  which is problematic; i.e., I can't see how I could properly extract guest
  pointers from slices of 4 bytes and at the same time not allocate.)
* I've augmented fuzz tests by (re-)defining two `array` types:

```
(typename $const_excuse_array (array (@witx const_pointer $excuse)))
(typename $excuse_array (array (@witx pointer $excuse)))
```

  This should hopefully emulate and test the `iovec` and `ciovec` arrays
  present in WASI spec.
2020-02-19 10:58:55 +01:00

64 lines
1.7 KiB
Plaintext

(typename $errno
(enum u32
$ok
$invalid_arg
$dont_want_to
$physically_unable
$picket_line))
(typename $excuse
(enum u8
$dog_ate
$traffic
$sleeping))
(typename $pair_ints
(struct
(field $first s32)
(field $second s32)))
(typename $pair_int_ptrs
(struct
(field $first (@witx const_pointer s32))
(field $second (@witx const_pointer s32))))
(typename $named_ptr (@witx pointer f32))
(typename $named_ptr_to_ptr (@witx pointer (@witx pointer f64)))
(typename $const_excuse_array (array (@witx const_pointer $excuse)))
(typename $excuse_array (array (@witx pointer $excuse)))
(module $foo
(@interface func (export "bar")
(param $an_int u32)
(param $an_float f32)
(result $error $errno))
(@interface func (export "baz")
(param $an_excuse $excuse)
(param $an_excuse_by_reference (@witx pointer $excuse))
(param $a_lamer_excuse (@witx const_pointer $excuse))
(param $two_layers_of_excuses (@witx pointer (@witx const_pointer $excuse)))
(result $error $errno))
(@interface func (export "bat")
(param $an_int u32)
(result $error $errno)
(result $doubled_it f32))
(@interface func (export "sum_of_pair")
(param $an_pair $pair_ints)
(result $error $errno)
(result $doubled s64))
(@interface func (export "sum_of_pair_of_ptrs")
(param $an_pair $pair_int_ptrs)
(result $error $errno)
(result $doubled s64))
(@interface func (export "reduce_excuses")
(param $excuses $const_excuse_array)
(result $error $errno)
(result $reduced $excuse)
)
(@interface func (export "populate_excuses")
(param $excuses $excuse_array)
(result $error $errno)
)
)