xref: /wasmtime-44.0.1/crates/fuzzing/wit/fuzz.wit (revision fee9be21)
1// For more information on what this is used for, see `fuzz_async.rs`
2
3package wasmtime-fuzz:fuzz;
4
5interface types {
6  variant command {
7    // invoke the imported `sync-ready` function
8    sync-ready-call,
9
10    // invoke the imported `async-ready` function, and assert it's ready
11    async-ready-call,
12
13    // invoke the imported `async-pending` function, assert it's not
14    // ready, and save it with the id provided.
15    async-pending-import-call(u32),
16    // cancel's a prior call of `async-pending` with the id specified
17    async-pending-import-cancel(u32),
18    // asserts that a prior call of `async-pending` with the id specified is
19    // ready.
20    async-pending-import-assert-ready(u32),
21    // complete a previous invocation of this component's `async-pending`
22    // export.
23    async-pending-export-complete(u32),
24    // assert a previous invocation of this component's `async-pending` export
25    // is cancelled.
26    async-pending-export-assert-cancelled(u32),
27
28    // make a future read/write combo with the `id` specified.
29    future-new(u32),
30    // take a future readable end through the `future-take` import.
31    future-take(u32),
32    // pass the future specified to this component's `future-receive` import.
33    future-give(u32),
34    // drop the future end identified
35    future-drop-readable(u32),
36    // ...
37    future-write-ready(future-payload),
38    future-read-ready(future-payload),
39    future-write-pending(future-payload),
40    future-read-pending(u32),
41    future-write-dropped(u32),
42    future-cancel-write(u32),
43    future-cancel-read(u32),
44    future-write-assert-complete(u32),
45    future-write-assert-dropped(u32),
46    future-read-assert-complete(future-payload),
47
48    // make a stream read/write combo with the `id` specified.
49    stream-new(u32),
50    // take a stream readable end through the `stream-take` import.
51    stream-take(u32),
52    // pass the stream specified to this component's `stream-receive` import.
53    stream-give(u32),
54    // drop the stream end identified
55    stream-drop-readable(u32),
56    stream-drop-writable(u32),
57    // ...
58    stream-write-ready(stream-ready-payload),
59    stream-read-ready(stream-ready-payload),
60    stream-write-pending(stream-write-payload),
61    stream-read-pending(stream-read-payload),
62    stream-write-dropped(stream-write-payload),
63    stream-read-dropped(stream-read-payload),
64    stream-cancel-write(u32),
65    stream-cancel-read(u32),
66    stream-write-assert-complete(stream-read-payload),
67    stream-write-assert-dropped(stream-read-payload),
68    stream-read-assert-complete(stream-write-payload),
69    stream-read-assert-dropped(u32),
70
71    ack,
72  }
73
74  record future-payload {
75    %future: u32,
76    item: u32,
77  }
78
79  record stream-ready-payload {
80    %stream: u32,
81    item: u32,
82    op-count: u32,
83    ready-count: u32,
84  }
85
86  record stream-write-payload {
87    %stream: u32,
88    item: u32,
89    count: u32,
90  }
91
92  record stream-read-payload {
93    %stream: u32,
94    count: u32,
95  }
96
97  enum scope {
98    caller,
99    callee,
100  }
101
102  get-commands: func(s: scope) -> stream<command>;
103}
104
105interface async-test {
106  use types.{command, scope};
107
108  // Initialization function. Invokes `task.return` but keeps running to receive
109  // commands. Commands come from the `get-commands` function which is passed
110  // the `scope` provided here.
111  //
112  // This invokes the imported `init` function with the `callee` scope.
113  init: async func(scope: scope);
114
115  sync-ready: func();
116
117  // Must return immediately.
118  async-ready: async func();
119
120  // Must not be ready when called. Status will be resolved through a later
121  // command using the `id` provided.
122  async-pending: async func(id: u32);
123
124  // Remove the future reader `id` from this component's state and return it.
125  future-take: func(id: u32) -> future<u32>;
126  // Receive a future from another component.
127  future-receive: func(id: u32, f: future<u32>);
128
129  // Remove the stream reader `id` from this component's state and return it.
130  stream-take: func(id: u32) -> stream<u32>;
131  // Receive a stream from another component.
132  stream-receive: func(id: u32, f: stream<u32>);
133
134}
135
136world fuzz-async {
137  import async-test;
138  export async-test;
139}
140