1 #![cfg(arc_try_new)]
2
3 use wasmtime::{Config, Engine, Ref, RefType, Result, Store, Table, TableType};
4 use wasmtime_fuzzing::oom::OomTest;
5
6 #[test]
table_new() -> Result<()>7 fn table_new() -> Result<()> {
8 let mut config = Config::new();
9 config.enable_compiler(false);
10 config.concurrency_support(false);
11 let engine = Engine::new(&config)?;
12
13 OomTest::new()
14 // `IndexMap::reserve` will try to allocate double space, but if that
15 // fails, will attempt to allocate the minimal space necessary.
16 .allow_alloc_after_oom(true)
17 .test(|| {
18 let mut store = Store::try_new(&engine, ())?;
19 let ty = TableType::new(RefType::FUNCREF, 1, None);
20 let _table = wasmtime::Table::new(&mut store, ty, Ref::Func(None))?;
21 Ok(())
22 })
23 }
24
25 #[test]
table_grow() -> Result<()>26 fn table_grow() -> Result<()> {
27 let mut config = Config::new();
28 config.enable_compiler(false);
29 config.concurrency_support(false);
30 let engine = Engine::new(&config)?;
31
32 OomTest::new().allow_alloc_after_oom(true).test(|| {
33 let mut store = Store::try_new(&engine, ())?;
34 let ty = TableType::new(RefType::FUNCREF, 1, None);
35 let table = Table::new(&mut store, ty, Ref::Func(None))?;
36 let _old_size = table.grow(&mut store, 4, Ref::Func(None))?;
37 Ok(())
38 })
39 }
40
41 #[test]
table_set() -> Result<()>42 fn table_set() -> Result<()> {
43 let mut config = Config::new();
44 config.enable_compiler(false);
45 config.concurrency_support(false);
46 let engine = Engine::new(&config)?;
47
48 OomTest::new().allow_alloc_after_oom(true).test(|| {
49 let mut store = Store::try_new(&engine, ())?;
50 let ty = TableType::new(RefType::FUNCREF, 1, None);
51 let table = Table::new(&mut store, ty, Ref::Func(None))?;
52 table.set(&mut store, 0, Ref::Func(None))?;
53 Ok(())
54 })
55 }
56
57 #[test]
table_copy() -> Result<()>58 fn table_copy() -> Result<()> {
59 let mut config = Config::new();
60 config.enable_compiler(false);
61 config.concurrency_support(false);
62 let engine = Engine::new(&config)?;
63
64 OomTest::new().allow_alloc_after_oom(true).test(|| {
65 let mut store = Store::try_new(&engine, ())?;
66 let ty = TableType::new(RefType::FUNCREF, 4, None);
67 let table = Table::new(&mut store, ty, Ref::Func(None))?;
68 Table::copy(&mut store, &table, 0, &table, 2, 2)?;
69 Ok(())
70 })
71 }
72
73 #[test]
table_fill() -> Result<()>74 fn table_fill() -> Result<()> {
75 let mut config = Config::new();
76 config.enable_compiler(false);
77 config.concurrency_support(false);
78 let engine = Engine::new(&config)?;
79
80 OomTest::new().allow_alloc_after_oom(true).test(|| {
81 let mut store = Store::try_new(&engine, ())?;
82 let ty = TableType::new(RefType::FUNCREF, 4, None);
83 let table = Table::new(&mut store, ty, Ref::Func(None))?;
84 table.fill(&mut store, 0, Ref::Func(None), 4)?;
85 Ok(())
86 })
87 }
88
89 #[test]
table_get() -> Result<()>90 fn table_get() -> Result<()> {
91 let mut config = Config::new();
92 config.enable_compiler(false);
93 config.concurrency_support(false);
94 let engine = Engine::new(&config)?;
95
96 OomTest::new().allow_alloc_after_oom(true).test(|| {
97 let mut store = Store::try_new(&engine, ())?;
98 let ty = TableType::new(RefType::FUNCREF, 1, None);
99 let table = Table::new(&mut store, ty, Ref::Func(None))?;
100 let val = table.get(&mut store, 0);
101 assert!(val.is_some());
102 Ok(())
103 })
104 }
105
106 #[test]
table_ty() -> Result<()>107 fn table_ty() -> Result<()> {
108 let mut config = Config::new();
109 config.enable_compiler(false);
110 config.concurrency_support(false);
111 let engine = Engine::new(&config)?;
112
113 OomTest::new().allow_alloc_after_oom(true).test(|| {
114 let mut store = Store::try_new(&engine, ())?;
115 let ty = TableType::new(RefType::FUNCREF, 1, None);
116 let table = Table::new(&mut store, ty, Ref::Func(None))?;
117 let _ty = table.ty(&store);
118 Ok(())
119 })
120 }
121
122 #[test]
table_size() -> Result<()>123 fn table_size() -> Result<()> {
124 let mut config = Config::new();
125 config.enable_compiler(false);
126 config.concurrency_support(false);
127 let engine = Engine::new(&config)?;
128
129 OomTest::new().allow_alloc_after_oom(true).test(|| {
130 let mut store = Store::try_new(&engine, ())?;
131 let ty = TableType::new(RefType::FUNCREF, 2, None);
132 let table = Table::new(&mut store, ty, Ref::Func(None))?;
133 assert_eq!(table.size(&store), 2);
134 Ok(())
135 })
136 }
137