Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/wiggle/tests/wasi.rs
1692 views
1
use wiggle::{GuestErrorType, GuestMemory, GuestPtr};
2
use wiggle_test::WasiCtx;
3
4
// This test file exists to make sure that the entire `wasi.witx` file can be
5
// handled by wiggle, producing code that compiles correctly.
6
// The trait impls here are never executed, and just exist to validate that the
7
// witx is exposed with the type signatures that we expect.
8
9
wiggle::from_witx!({
10
witx: ["tests/wasi.witx"],
11
});
12
13
// The only test in this file is to verify that the witx document provided by the
14
// proc macro in the `metadata` module is equal to the document on the disk.
15
#[test]
16
fn document_equivalent() {
17
let macro_doc = metadata::document();
18
let mut path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
19
path.push("tests");
20
path.push("wasi.witx");
21
let disk_doc = witx::load(&[path]).expect("load wasi.witx from disk");
22
23
assert_eq!(macro_doc, disk_doc);
24
}
25
26
type Result<T> = std::result::Result<T, types::Errno>;
27
28
impl GuestErrorType for types::Errno {
29
fn success() -> types::Errno {
30
types::Errno::Success
31
}
32
}
33
34
impl<'a> crate::wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx<'a> {
35
fn args_get(
36
&mut self,
37
_memory: &mut GuestMemory<'_>,
38
_argv: GuestPtr<GuestPtr<u8>>,
39
_argv_buf: GuestPtr<u8>,
40
) -> Result<()> {
41
unimplemented!("args_get")
42
}
43
44
fn args_sizes_get(
45
&mut self,
46
_memory: &mut GuestMemory<'_>,
47
) -> Result<(types::Size, types::Size)> {
48
unimplemented!("args_sizes_get")
49
}
50
51
fn environ_get(
52
&mut self,
53
_memory: &mut GuestMemory<'_>,
54
_environ: GuestPtr<GuestPtr<u8>>,
55
_environ_buf: GuestPtr<u8>,
56
) -> Result<()> {
57
unimplemented!("environ_get")
58
}
59
60
fn environ_sizes_get(
61
&mut self,
62
_memory: &mut GuestMemory<'_>,
63
) -> Result<(types::Size, types::Size)> {
64
unimplemented!("environ_sizes_get")
65
}
66
67
fn clock_res_get(
68
&mut self,
69
_memory: &mut GuestMemory<'_>,
70
_id: types::Clockid,
71
) -> Result<types::Timestamp> {
72
unimplemented!("clock_res_get")
73
}
74
75
fn clock_time_get(
76
&mut self,
77
_memory: &mut GuestMemory<'_>,
78
_id: types::Clockid,
79
_precision: types::Timestamp,
80
) -> Result<types::Timestamp> {
81
unimplemented!("clock_time_get")
82
}
83
84
fn fd_advise(
85
&mut self,
86
_memory: &mut GuestMemory<'_>,
87
_fd: types::Fd,
88
_offset: types::Filesize,
89
_len: types::Filesize,
90
_advice: types::Advice,
91
) -> Result<()> {
92
unimplemented!("fd_advise")
93
}
94
95
fn fd_allocate(
96
&mut self,
97
_memory: &mut GuestMemory<'_>,
98
_fd: types::Fd,
99
_offset: types::Filesize,
100
_len: types::Filesize,
101
) -> Result<()> {
102
unimplemented!("fd_allocate")
103
}
104
105
fn fd_close(&mut self, _memory: &mut GuestMemory<'_>, _fd: types::Fd) -> Result<()> {
106
unimplemented!("fd_close")
107
}
108
109
fn fd_datasync(&mut self, _memory: &mut GuestMemory<'_>, _fd: types::Fd) -> Result<()> {
110
unimplemented!("fd_datasync")
111
}
112
113
fn fd_fdstat_get(
114
&mut self,
115
_memory: &mut GuestMemory<'_>,
116
_fd: types::Fd,
117
) -> Result<types::Fdstat> {
118
unimplemented!("fd_fdstat_get")
119
}
120
121
fn fd_fdstat_set_flags(
122
&mut self,
123
_memory: &mut GuestMemory<'_>,
124
_fd: types::Fd,
125
_flags: types::Fdflags,
126
) -> Result<()> {
127
unimplemented!("fd_fdstat_set_flags")
128
}
129
130
fn fd_fdstat_set_rights(
131
&mut self,
132
_memory: &mut GuestMemory<'_>,
133
_fd: types::Fd,
134
_fs_rights_base: types::Rights,
135
_fs_rights_inherting: types::Rights,
136
) -> Result<()> {
137
unimplemented!("fd_fdstat_set_rights")
138
}
139
140
fn fd_filestat_get(
141
&mut self,
142
_memory: &mut GuestMemory<'_>,
143
_fd: types::Fd,
144
) -> Result<types::Filestat> {
145
unimplemented!("fd_filestat_get")
146
}
147
148
fn fd_filestat_set_size(
149
&mut self,
150
_memory: &mut GuestMemory<'_>,
151
_fd: types::Fd,
152
_size: types::Filesize,
153
) -> Result<()> {
154
unimplemented!("fd_filestat_set_size")
155
}
156
157
fn fd_filestat_set_times(
158
&mut self,
159
_memory: &mut GuestMemory<'_>,
160
_fd: types::Fd,
161
_atim: types::Timestamp,
162
_mtim: types::Timestamp,
163
_fst_flags: types::Fstflags,
164
) -> Result<()> {
165
unimplemented!("fd_filestat_set_times")
166
}
167
168
fn fd_pread(
169
&mut self,
170
_memory: &mut GuestMemory<'_>,
171
_fd: types::Fd,
172
_iovs: types::IovecArray,
173
_offset: types::Filesize,
174
) -> Result<types::Size> {
175
unimplemented!("fd_pread")
176
}
177
178
fn fd_prestat_get(
179
&mut self,
180
_memory: &mut GuestMemory<'_>,
181
_fd: types::Fd,
182
) -> Result<types::Prestat> {
183
unimplemented!("fd_prestat_get")
184
}
185
186
fn fd_prestat_dir_name(
187
&mut self,
188
_memory: &mut GuestMemory<'_>,
189
_fd: types::Fd,
190
_path: GuestPtr<u8>,
191
_path_len: types::Size,
192
) -> Result<()> {
193
unimplemented!("fd_prestat_dir_name")
194
}
195
196
fn fd_pwrite(
197
&mut self,
198
_memory: &mut GuestMemory<'_>,
199
_fd: types::Fd,
200
_ciovs: types::CiovecArray,
201
_offset: types::Filesize,
202
) -> Result<types::Size> {
203
unimplemented!("fd_pwrite")
204
}
205
206
fn fd_read(
207
&mut self,
208
_memory: &mut GuestMemory<'_>,
209
_fd: types::Fd,
210
_iovs: types::IovecArray,
211
) -> Result<types::Size> {
212
unimplemented!("fd_read")
213
}
214
215
fn fd_readdir(
216
&mut self,
217
_memory: &mut GuestMemory<'_>,
218
_fd: types::Fd,
219
_buf: GuestPtr<u8>,
220
_buf_len: types::Size,
221
_cookie: types::Dircookie,
222
) -> Result<types::Size> {
223
unimplemented!("fd_readdir")
224
}
225
226
fn fd_renumber(
227
&mut self,
228
_memory: &mut GuestMemory<'_>,
229
_fd: types::Fd,
230
_to: types::Fd,
231
) -> Result<()> {
232
unimplemented!("fd_renumber")
233
}
234
235
fn fd_seek(
236
&mut self,
237
_memory: &mut GuestMemory<'_>,
238
_fd: types::Fd,
239
_offset: types::Filedelta,
240
_whence: types::Whence,
241
) -> Result<types::Filesize> {
242
unimplemented!("fd_seek")
243
}
244
245
fn fd_sync(&mut self, _memory: &mut GuestMemory<'_>, _fd: types::Fd) -> Result<()> {
246
unimplemented!("fd_sync")
247
}
248
249
fn fd_tell(
250
&mut self,
251
_memory: &mut GuestMemory<'_>,
252
_fd: types::Fd,
253
) -> Result<types::Filesize> {
254
unimplemented!("fd_tell")
255
}
256
257
fn fd_write(
258
&mut self,
259
_memory: &mut GuestMemory<'_>,
260
_fd: types::Fd,
261
_ciovs: types::CiovecArray,
262
) -> Result<types::Size> {
263
unimplemented!("fd_write")
264
}
265
266
fn path_create_directory(
267
&mut self,
268
_memory: &mut GuestMemory<'_>,
269
_fd: types::Fd,
270
_path: GuestPtr<str>,
271
) -> Result<()> {
272
unimplemented!("path_create_directory")
273
}
274
275
fn path_filestat_get(
276
&mut self,
277
_memory: &mut GuestMemory<'_>,
278
_fd: types::Fd,
279
_flags: types::Lookupflags,
280
_path: GuestPtr<str>,
281
) -> Result<types::Filestat> {
282
unimplemented!("path_filestat_get")
283
}
284
285
fn path_filestat_set_times(
286
&mut self,
287
_memory: &mut GuestMemory<'_>,
288
_fd: types::Fd,
289
_flags: types::Lookupflags,
290
_path: GuestPtr<str>,
291
_atim: types::Timestamp,
292
_mtim: types::Timestamp,
293
_fst_flags: types::Fstflags,
294
) -> Result<()> {
295
unimplemented!("path_filestat_set_times")
296
}
297
298
fn path_link(
299
&mut self,
300
_memory: &mut GuestMemory<'_>,
301
_old_fd: types::Fd,
302
_old_flags: types::Lookupflags,
303
_old_path: GuestPtr<str>,
304
_new_fd: types::Fd,
305
_new_path: GuestPtr<str>,
306
) -> Result<()> {
307
unimplemented!("path_link")
308
}
309
310
fn path_open(
311
&mut self,
312
_memory: &mut GuestMemory<'_>,
313
_fd: types::Fd,
314
_dirflags: types::Lookupflags,
315
_path: GuestPtr<str>,
316
_oflags: types::Oflags,
317
_fs_rights_base: types::Rights,
318
_fs_rights_inherting: types::Rights,
319
_fdflags: types::Fdflags,
320
) -> Result<types::Fd> {
321
unimplemented!("path_open")
322
}
323
324
fn path_readlink(
325
&mut self,
326
_memory: &mut GuestMemory<'_>,
327
_fd: types::Fd,
328
_path: GuestPtr<str>,
329
_buf: GuestPtr<u8>,
330
_buf_len: types::Size,
331
) -> Result<types::Size> {
332
unimplemented!("path_readlink")
333
}
334
335
fn path_remove_directory(
336
&mut self,
337
_memory: &mut GuestMemory<'_>,
338
_fd: types::Fd,
339
_path: GuestPtr<str>,
340
) -> Result<()> {
341
unimplemented!("path_remove_directory")
342
}
343
344
fn path_rename(
345
&mut self,
346
_memory: &mut GuestMemory<'_>,
347
_fd: types::Fd,
348
_old_path: GuestPtr<str>,
349
_new_fd: types::Fd,
350
_new_path: GuestPtr<str>,
351
) -> Result<()> {
352
unimplemented!("path_rename")
353
}
354
355
fn path_symlink(
356
&mut self,
357
_memory: &mut GuestMemory<'_>,
358
_old_path: GuestPtr<str>,
359
_fd: types::Fd,
360
_new_path: GuestPtr<str>,
361
) -> Result<()> {
362
unimplemented!("path_symlink")
363
}
364
365
fn path_unlink_file(
366
&mut self,
367
_memory: &mut GuestMemory<'_>,
368
_fd: types::Fd,
369
_path: GuestPtr<str>,
370
) -> Result<()> {
371
unimplemented!("path_unlink_file")
372
}
373
374
fn poll_oneoff(
375
&mut self,
376
_memory: &mut GuestMemory<'_>,
377
_in_: GuestPtr<types::Subscription>,
378
_out: GuestPtr<types::Event>,
379
_nsubscriptions: types::Size,
380
) -> Result<types::Size> {
381
unimplemented!("poll_oneoff")
382
}
383
384
fn proc_exit(
385
&mut self,
386
_memory: &mut GuestMemory<'_>,
387
_rval: types::Exitcode,
388
) -> anyhow::Error {
389
unimplemented!("proc_exit")
390
}
391
392
fn proc_raise(&mut self, _memory: &mut GuestMemory<'_>, _sig: types::Signal) -> Result<()> {
393
unimplemented!("proc_raise")
394
}
395
396
fn sched_yield(&mut self, _memory: &mut GuestMemory<'_>) -> Result<()> {
397
unimplemented!("sched_yield")
398
}
399
400
fn random_get(
401
&mut self,
402
_memory: &mut GuestMemory<'_>,
403
_buf: GuestPtr<u8>,
404
_buf_len: types::Size,
405
) -> Result<()> {
406
unimplemented!("random_get")
407
}
408
409
fn sock_recv(
410
&mut self,
411
_memory: &mut GuestMemory<'_>,
412
_fd: types::Fd,
413
_ri_data: types::IovecArray,
414
_ri_flags: types::Riflags,
415
) -> Result<(types::Size, types::Roflags)> {
416
unimplemented!("sock_recv")
417
}
418
419
fn sock_send(
420
&mut self,
421
_memory: &mut GuestMemory<'_>,
422
_fd: types::Fd,
423
_si_data: types::CiovecArray,
424
_si_flags: types::Siflags,
425
) -> Result<types::Size> {
426
unimplemented!("sock_send")
427
}
428
429
fn sock_shutdown(
430
&mut self,
431
_memory: &mut GuestMemory<'_>,
432
_fd: types::Fd,
433
_how: types::Sdflags,
434
) -> Result<()> {
435
unimplemented!("sock_shutdown")
436
}
437
}
438
439