|
1 | 1 | #![cfg(arc_try_new)] |
2 | 2 |
|
3 | | -use wasmtime::component::{Component, Linker}; |
4 | | -use wasmtime::{Config, Engine, Result, Store}; |
| 3 | +use wasmtime::component::{Component, Linker, ResourceType}; |
| 4 | +use wasmtime::{Config, Engine, Module, Result, Store}; |
5 | 5 | use wasmtime_fuzzing::oom::OomTest; |
6 | 6 |
|
7 | 7 | #[tokio::test] |
@@ -147,3 +147,103 @@ fn component_linker_substituted_component_type() -> Result<()> { |
147 | 147 | Ok(()) |
148 | 148 | }) |
149 | 149 | } |
| 150 | + |
| 151 | +#[test] |
| 152 | +fn component_linker_define_unknown_imports_as_traps() -> Result<()> { |
| 153 | + let component_bytes = { |
| 154 | + let mut config = Config::new(); |
| 155 | + config.concurrency_support(false); |
| 156 | + let engine = Engine::new(&config)?; |
| 157 | + Component::new( |
| 158 | + &engine, |
| 159 | + r#" |
| 160 | + (component |
| 161 | + (import "f" (func)) |
| 162 | + ) |
| 163 | + "#, |
| 164 | + )? |
| 165 | + .serialize()? |
| 166 | + }; |
| 167 | + let mut config = Config::new(); |
| 168 | + config.enable_compiler(false); |
| 169 | + config.concurrency_support(false); |
| 170 | + let engine = Engine::new(&config)?; |
| 171 | + let component = unsafe { Component::deserialize(&engine, &component_bytes)? }; |
| 172 | + |
| 173 | + // Error propagation via anyhow allocates after OOM. |
| 174 | + OomTest::new().allow_alloc_after_oom(true).test(|| { |
| 175 | + let mut linker = Linker::<()>::new(&engine); |
| 176 | + linker.define_unknown_imports_as_traps(&component)?; |
| 177 | + Ok(()) |
| 178 | + }) |
| 179 | +} |
| 180 | + |
| 181 | +#[test] |
| 182 | +fn component_linker_instance_func_wrap() -> Result<()> { |
| 183 | + let mut config = Config::new(); |
| 184 | + config.concurrency_support(false); |
| 185 | + let engine = Engine::new(&config)?; |
| 186 | + |
| 187 | + // Error propagation via anyhow allocates after OOM. |
| 188 | + OomTest::new().allow_alloc_after_oom(true).test(|| { |
| 189 | + let mut linker = Linker::<()>::new(&engine); |
| 190 | + linker |
| 191 | + .root() |
| 192 | + .func_wrap("f", |_cx: wasmtime::StoreContextMut<'_, ()>, (): ()| Ok(()))?; |
| 193 | + Ok(()) |
| 194 | + }) |
| 195 | +} |
| 196 | + |
| 197 | +#[test] |
| 198 | +fn component_linker_instance_func_new() -> Result<()> { |
| 199 | + let mut config = Config::new(); |
| 200 | + config.concurrency_support(false); |
| 201 | + let engine = Engine::new(&config)?; |
| 202 | + |
| 203 | + // Error propagation via anyhow allocates after OOM. |
| 204 | + OomTest::new().allow_alloc_after_oom(true).test(|| { |
| 205 | + let mut linker = Linker::<()>::new(&engine); |
| 206 | + linker |
| 207 | + .root() |
| 208 | + .func_new("f", |_cx, _func_ty, _params, _results| Ok(()))?; |
| 209 | + Ok(()) |
| 210 | + }) |
| 211 | +} |
| 212 | + |
| 213 | +#[test] |
| 214 | +fn component_linker_instance_module() -> Result<()> { |
| 215 | + let module_bytes = { |
| 216 | + let mut config = Config::new(); |
| 217 | + config.concurrency_support(false); |
| 218 | + let engine = Engine::new(&config)?; |
| 219 | + Module::new(&engine, "(module)")?.serialize()? |
| 220 | + }; |
| 221 | + let mut config = Config::new(); |
| 222 | + config.enable_compiler(false); |
| 223 | + config.concurrency_support(false); |
| 224 | + let engine = Engine::new(&config)?; |
| 225 | + let module = unsafe { Module::deserialize(&engine, &module_bytes)? }; |
| 226 | + |
| 227 | + // Error propagation via anyhow allocates after OOM. |
| 228 | + OomTest::new().allow_alloc_after_oom(true).test(|| { |
| 229 | + let mut linker = Linker::<()>::new(&engine); |
| 230 | + linker.root().module("m", &module)?; |
| 231 | + Ok(()) |
| 232 | + }) |
| 233 | +} |
| 234 | + |
| 235 | +#[test] |
| 236 | +fn component_linker_instance_resource() -> Result<()> { |
| 237 | + let mut config = Config::new(); |
| 238 | + config.concurrency_support(false); |
| 239 | + let engine = Engine::new(&config)?; |
| 240 | + |
| 241 | + // Error propagation from HostFunc::wrap allocates via anyhow. |
| 242 | + OomTest::new().allow_alloc_after_oom(true).test(|| { |
| 243 | + let mut linker = Linker::<()>::new(&engine); |
| 244 | + linker |
| 245 | + .root() |
| 246 | + .resource("r", ResourceType::host::<()>(), |_, _| Ok(()))?; |
| 247 | + Ok(()) |
| 248 | + }) |
| 249 | +} |
0 commit comments