@@ -58,6 +58,16 @@ struct Swarm {
5858 global_ty : bool ,
5959 global_drop : bool ,
6060 get_global_export : bool ,
61+ table_type_new : bool ,
62+ table_type_drop : bool ,
63+ table_new : bool ,
64+ table_get : bool ,
65+ table_set : bool ,
66+ table_grow : bool ,
67+ table_size : bool ,
68+ table_ty : bool ,
69+ table_drop : bool ,
70+ get_table_export : bool ,
6171}
6272
6373/// A call to one of Wasmtime's public APIs.
@@ -120,6 +130,44 @@ pub enum ApiCall {
120130 instance : usize ,
121131 nth : usize ,
122132 } ,
133+ TableTypeNew {
134+ id : usize ,
135+ nullable : bool ,
136+ } ,
137+ TableTypeDrop {
138+ id : usize ,
139+ } ,
140+ TableNew {
141+ id : usize ,
142+ table_ty : usize ,
143+ store : usize ,
144+ } ,
145+ TableGet {
146+ table : usize ,
147+ idx : u64 ,
148+ } ,
149+ TableSet {
150+ table : usize ,
151+ idx : u64 ,
152+ } ,
153+ TableGrow {
154+ table : usize ,
155+ delta : u32 ,
156+ } ,
157+ TableSize {
158+ table : usize ,
159+ } ,
160+ TableTy {
161+ table : usize ,
162+ } ,
163+ TableDrop {
164+ id : usize ,
165+ } ,
166+ GetTableExport {
167+ id : usize ,
168+ instance : usize ,
169+ nth : usize ,
170+ } ,
123171}
124172use ApiCall :: * ;
125173
@@ -143,6 +191,13 @@ struct Scope {
143191 /// associated `store_id`.
144192 globals : BTreeMap < usize , usize > , // global_id -> store_id
145193
194+ /// Table types that are currently live.
195+ table_types : BTreeSet < usize > ,
196+
197+ /// Tables that are currently live. Maps from `table_id` to the table's
198+ /// associated `store_id`.
199+ tables : BTreeMap < usize , usize > , // table_id -> store_id
200+
146201 config : Config ,
147202}
148203
@@ -176,6 +231,8 @@ impl<'a> Arbitrary<'a> for ApiCalls {
176231 instances : BTreeMap :: default ( ) ,
177232 global_types : BTreeSet :: default ( ) ,
178233 globals : BTreeMap :: default ( ) ,
234+ table_types : BTreeSet :: default ( ) ,
235+ tables : BTreeMap :: default ( ) ,
179236 config : config. clone ( ) ,
180237 } ;
181238
@@ -213,6 +270,7 @@ impl<'a> Arbitrary<'a> for ApiCalls {
213270 scope. stores . remove ( & id) ;
214271 scope. instances . retain ( |_, store_id| * store_id != id) ;
215272 scope. globals . retain ( |_, store_id| * store_id != id) ;
273+ scope. tables . retain ( |_, store_id| * store_id != id) ;
216274 Ok ( StoreDrop { id } )
217275 } ) ;
218276 }
@@ -334,6 +392,94 @@ impl<'a> Arbitrary<'a> for ApiCalls {
334392 Ok ( GetGlobalExport { id, instance, nth } )
335393 } ) ;
336394 }
395+ if swarm. table_type_new {
396+ choices. push ( |input, scope| {
397+ let id = scope. next_id ( ) ;
398+ let nullable = bool:: arbitrary ( input) ?;
399+ scope. table_types . insert ( id) ;
400+ Ok ( TableTypeNew { id, nullable } )
401+ } ) ;
402+ }
403+ if swarm. table_type_drop && !scope. table_types . is_empty ( ) {
404+ choices. push ( |input, scope| {
405+ let types: Vec < _ > = scope. table_types . iter ( ) . collect ( ) ;
406+ let id = * * input. choose ( & types) ?;
407+ scope. table_types . remove ( & id) ;
408+ Ok ( TableTypeDrop { id } )
409+ } ) ;
410+ }
411+ if swarm. table_new && !scope. table_types . is_empty ( ) && !scope. stores . is_empty ( ) {
412+ choices. push ( |input, scope| {
413+ let types: Vec < _ > = scope. table_types . iter ( ) . collect ( ) ;
414+ let table_ty = * * input. choose ( & types) ?;
415+ let stores: Vec < _ > = scope. stores . iter ( ) . collect ( ) ;
416+ let store = * * input. choose ( & stores) ?;
417+ let id = scope. next_id ( ) ;
418+ scope. tables . insert ( id, store) ;
419+ Ok ( TableNew {
420+ id,
421+ table_ty,
422+ store,
423+ } )
424+ } ) ;
425+ }
426+ if swarm. table_get && !scope. tables . is_empty ( ) {
427+ choices. push ( |input, scope| {
428+ let tables: Vec < _ > = scope. tables . keys ( ) . collect ( ) ;
429+ let table = * * input. choose ( & tables) ?;
430+ let idx = u64:: arbitrary ( input) ?;
431+ Ok ( TableGet { table, idx } )
432+ } ) ;
433+ }
434+ if swarm. table_set && !scope. tables . is_empty ( ) {
435+ choices. push ( |input, scope| {
436+ let tables: Vec < _ > = scope. tables . keys ( ) . collect ( ) ;
437+ let table = * * input. choose ( & tables) ?;
438+ let idx = u64:: arbitrary ( input) ?;
439+ Ok ( TableSet { table, idx } )
440+ } ) ;
441+ }
442+ if swarm. table_grow && !scope. tables . is_empty ( ) {
443+ choices. push ( |input, scope| {
444+ let tables: Vec < _ > = scope. tables . keys ( ) . collect ( ) ;
445+ let table = * * input. choose ( & tables) ?;
446+ let delta = u32:: arbitrary ( input) ?;
447+ Ok ( TableGrow { table, delta } )
448+ } ) ;
449+ }
450+ if swarm. table_size && !scope. tables . is_empty ( ) {
451+ choices. push ( |input, scope| {
452+ let tables: Vec < _ > = scope. tables . keys ( ) . collect ( ) ;
453+ let table = * * input. choose ( & tables) ?;
454+ Ok ( TableSize { table } )
455+ } ) ;
456+ }
457+ if swarm. table_ty && !scope. tables . is_empty ( ) {
458+ choices. push ( |input, scope| {
459+ let tables: Vec < _ > = scope. tables . keys ( ) . collect ( ) ;
460+ let table = * * input. choose ( & tables) ?;
461+ Ok ( TableTy { table } )
462+ } ) ;
463+ }
464+ if swarm. table_drop && !scope. tables . is_empty ( ) {
465+ choices. push ( |input, scope| {
466+ let tables: Vec < _ > = scope. tables . keys ( ) . collect ( ) ;
467+ let id = * * input. choose ( & tables) ?;
468+ scope. tables . remove ( & id) ;
469+ Ok ( TableDrop { id } )
470+ } ) ;
471+ }
472+ if swarm. get_table_export && !scope. instances . is_empty ( ) {
473+ choices. push ( |input, scope| {
474+ let instances: Vec < _ > = scope. instances . keys ( ) . collect ( ) ;
475+ let instance = * * input. choose ( & instances) ?;
476+ let nth = usize:: arbitrary ( input) ?;
477+ let id = scope. next_id ( ) ;
478+ let store = * scope. instances . get ( & instance) . unwrap ( ) ;
479+ scope. tables . insert ( id, store) ;
480+ Ok ( GetTableExport { id, instance, nth } )
481+ } ) ;
482+ }
337483
338484 if choices. is_empty ( ) {
339485 break ;
0 commit comments