| 152 | } |
| 153 | |
| 154 | fn imports(store: &mut Store, modules: &HashMap<String, ModuleInstance>) -> Result<Imports> { |
| 155 | let mut imports = Imports::new(); |
| 156 | |
| 157 | let table = Table::new( |
| 158 | store, |
| 159 | TableType::new(WasmType::RefFunc, 10, Some(20)), |
| 160 | WasmValue::default_for(WasmType::RefFunc), |
| 161 | )?; |
| 162 | let memory = Memory::new(store, MemoryType::default().with_page_count_initial(1).with_page_count_max(Some(2)))?; |
| 163 | let global_i32 = |
| 164 | Global::new(store, tinywasm::types::GlobalType::new(WasmType::I32, false), WasmValue::I32(666))?; |
| 165 | let global_i64 = |
| 166 | Global::new(store, tinywasm::types::GlobalType::new(WasmType::I64, false), WasmValue::I64(666))?; |
| 167 | let global_f32 = |
| 168 | Global::new(store, tinywasm::types::GlobalType::new(WasmType::F32, false), WasmValue::F32(666.6))?; |
| 169 | let global_f64 = |
| 170 | Global::new(store, tinywasm::types::GlobalType::new(WasmType::F64, false), WasmValue::F64(666.6))?; |
| 171 | |
| 172 | imports |
| 173 | .define("spectest", "memory", memory) |
| 174 | .define("spectest", "table", table) |
| 175 | .define("spectest", "global_i32", global_i32) |
| 176 | .define("spectest", "global_i64", global_i64) |
| 177 | .define("spectest", "global_f32", global_f32) |
| 178 | .define("spectest", "global_f64", global_f64) |
| 179 | .define("spectest", "print", HostFunction::from(store, |_ctx: tinywasm::FuncContext, (): ()| Ok(()))) |
| 180 | .define("spectest", "print_i32", HostFunction::from(store, |_ctx: tinywasm::FuncContext, _arg: i32| Ok(()))) |
| 181 | .define("spectest", "print_i64", HostFunction::from(store, |_ctx: tinywasm::FuncContext, _arg: i64| Ok(()))) |
| 182 | .define("spectest", "print_f32", HostFunction::from(store, |_ctx: tinywasm::FuncContext, _arg: f32| Ok(()))) |
| 183 | .define("spectest", "print_f64", HostFunction::from(store, |_ctx: tinywasm::FuncContext, _arg: f64| Ok(()))) |
| 184 | .define( |
| 185 | "spectest", |
| 186 | "print_i32_f32", |
| 187 | HostFunction::from(store, |_ctx: tinywasm::FuncContext, _args: (i32, f32)| Ok(())), |
| 188 | ) |
| 189 | .define( |
| 190 | "spectest", |
| 191 | "print_f64_f64", |
| 192 | HostFunction::from(store, |_ctx: tinywasm::FuncContext, _args: (f64, f64)| Ok(())), |
| 193 | ); |
| 194 | |
| 195 | for (name, module) in modules { |
| 196 | imports.link_module(name, module.clone())?; |
| 197 | } |
| 198 | |
| 199 | Ok(imports) |
| 200 | } |
| 201 | |
| 202 | pub fn run_file(&mut self, file: TestFile<'_>) -> Result<()> { |
| 203 | let test_group = self.test_group(file.name(), file.parent()); |