1 //! Oracles. 2 //! 3 //! Oracles take a test case and determine whether we have a bug. For example, 4 //! one of the simplest oracles is to take a Wasm binary as our input test case, 5 //! validate and instantiate it, and (implicitly) check that no assertions 6 //! failed or segfaults happened. A more complicated oracle might compare the 7 //! result of executing a Wasm file with and without optimizations enabled, and 8 //! make sure that the two executions are observably identical. 9 //! 10 //! When an oracle finds a bug, it should report it to the fuzzing engine by 11 //! panicking. 12 13 pub mod component_api; 14 #[cfg(feature = "fuzz-spec-interpreter")] 15 pub mod diff_spec; 16 pub mod diff_wasmi; 17 pub mod diff_wasmtime; 18 pub mod dummy; 19 pub mod engine; 20 pub mod memory; 21 mod stacks; 22 23 use self::diff_wasmtime::WasmtimeInstance; 24 use self::engine::{DiffEngine, DiffInstance}; 25 use crate::block_on; 26 use crate::generators::GcOps; 27 use crate::generators::{self, CompilerStrategy, DiffValue, DiffValueType}; 28 use crate::single_module_fuzzer::KnownValid; 29 use arbitrary::Arbitrary; 30 pub use stacks::check_stacks; 31 use std::future::Future; 32 use std::pin::Pin; 33 use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering::SeqCst}; 34 use std::sync::{Arc, Condvar, Mutex}; 35 use std::task::{Context, Poll}; 36 use std::time::{Duration, Instant}; 37 use wasmtime::*; 38 use wasmtime_wast::WastContext; 39 40 #[cfg(not(any(windows, target_arch = "s390x", target_arch = "riscv64")))] 41 mod diff_v8; 42 43 static CNT: AtomicUsize = AtomicUsize::new(0); 44 45 /// Logs a wasm file to the filesystem to make it easy to figure out what wasm 46 /// was used when debugging. 47 pub fn log_wasm(wasm: &[u8]) { 48 super::init_fuzzing(); 49 50 if !log::log_enabled!(log::Level::Debug) { 51 return; 52 } 53 54 let i = CNT.fetch_add(1, SeqCst); 55 let name = format!("testcase{i}.wasm"); 56 std::fs::write(&name, wasm).expect("failed to write wasm file"); 57 log::debug!("wrote wasm file to `{name}`"); 58 let wat = format!("testcase{i}.wat"); 59 match wasmprinter::print_bytes(wasm) { 60 Ok(s) => std::fs::write(&wat, s).expect("failed to write wat file"), 61 // If wasmprinter failed remove a `*.wat` file, if any, to avoid 62 // confusing a preexisting one with this wasm which failed to get 63 // printed. 64 Err(e) => { 65 log::debug!("failed to print to wat: {e}"); 66 drop(std::fs::remove_file(&wat)) 67 } 68 } 69 } 70 71 /// The `T` in `Store<T>` for fuzzing stores, used to limit resource 72 /// consumption during fuzzing. 73 #[derive(Clone)] 74 pub struct StoreLimits(Arc<LimitsState>); 75 76 struct LimitsState { 77 /// Remaining memory, in bytes, left to allocate 78 remaining_memory: AtomicUsize, 79 /// Remaining amount of memory that's allowed to be copied via a growth. 80 remaining_copy_allowance: AtomicUsize, 81 /// Whether or not an allocation request has been denied 82 oom: AtomicBool, 83 } 84 85 /// Allow up to 1G which is well below the 2G limit on OSS-Fuzz and should allow 86 /// most interesting behavior. 87 const MAX_MEMORY: usize = 1 << 30; 88 89 /// Allow up to 4G of bytes to be copied (conservatively) which should enable 90 /// growth up to `MAX_MEMORY` or at least up to a relatively large amount. 91 const MAX_MEMORY_MOVED: usize = 4 << 30; 92 93 impl StoreLimits { 94 /// Creates the default set of limits for all fuzzing stores. 95 pub fn new() -> StoreLimits { 96 StoreLimits(Arc::new(LimitsState { 97 remaining_memory: AtomicUsize::new(MAX_MEMORY), 98 remaining_copy_allowance: AtomicUsize::new(MAX_MEMORY_MOVED), 99 oom: AtomicBool::new(false), 100 })) 101 } 102 103 fn alloc(&mut self, amt: usize) -> bool { 104 log::trace!("alloc {amt:#x} bytes"); 105 106 // Assume that on each allocation of memory that all previous 107 // allocations of memory are moved. This is pretty coarse but is used to 108 // help prevent against fuzz test cases that just move tons of bytes 109 // around continuously. This assumes that all previous memory was 110 // allocated in a single linear memory and growing by `amt` will require 111 // moving all the bytes to a new location. This isn't actually required 112 // all the time nor does it accurately reflect what happens all the 113 // time, but it's a coarse approximation that should be "good enough" 114 // for allowing interesting fuzz behaviors to happen while not timing 115 // out just copying bytes around. 116 let prev_size = MAX_MEMORY - self.0.remaining_memory.load(SeqCst); 117 if self 118 .0 119 .remaining_copy_allowance 120 .fetch_update(SeqCst, SeqCst, |remaining| remaining.checked_sub(prev_size)) 121 .is_err() 122 { 123 self.0.oom.store(true, SeqCst); 124 log::debug!("-> too many bytes moved, rejecting allocation"); 125 return false; 126 } 127 128 // If we're allowed to move the bytes, then also check if we're allowed 129 // to actually have this much residence at once. 130 match self 131 .0 132 .remaining_memory 133 .fetch_update(SeqCst, SeqCst, |remaining| remaining.checked_sub(amt)) 134 { 135 Ok(_) => true, 136 Err(_) => { 137 self.0.oom.store(true, SeqCst); 138 log::debug!("-> OOM hit"); 139 false 140 } 141 } 142 } 143 144 fn is_oom(&self) -> bool { 145 self.0.oom.load(SeqCst) 146 } 147 } 148 149 impl ResourceLimiter for StoreLimits { 150 fn memory_growing( 151 &mut self, 152 current: usize, 153 desired: usize, 154 _maximum: Option<usize>, 155 ) -> Result<bool> { 156 Ok(self.alloc(desired - current)) 157 } 158 159 fn table_growing( 160 &mut self, 161 current: usize, 162 desired: usize, 163 _maximum: Option<usize>, 164 ) -> Result<bool> { 165 let delta = (desired - current).saturating_mul(std::mem::size_of::<usize>()); 166 Ok(self.alloc(delta)) 167 } 168 } 169 170 /// Methods of timing out execution of a WebAssembly module 171 #[derive(Clone, Debug)] 172 pub enum Timeout { 173 /// No timeout is used, it should be guaranteed via some other means that 174 /// the input does not infinite loop. 175 None, 176 /// Fuel-based timeouts are used where the specified fuel is all that the 177 /// provided wasm module is allowed to consume. 178 Fuel(u64), 179 /// An epoch-interruption-based timeout is used with a sleeping 180 /// thread bumping the epoch counter after the specified duration. 181 Epoch(Duration), 182 } 183 184 /// Instantiate the Wasm buffer, and implicitly fail if we have an unexpected 185 /// panic or segfault or anything else that can be detected "passively". 186 /// 187 /// The engine will be configured using provided config. 188 pub fn instantiate( 189 wasm: &[u8], 190 known_valid: KnownValid, 191 config: &generators::Config, 192 timeout: Timeout, 193 ) { 194 let mut store = config.to_store(); 195 196 let module = match compile_module(store.engine(), wasm, known_valid, config) { 197 Some(module) => module, 198 None => return, 199 }; 200 201 let mut timeout_state = HelperThread::default(); 202 match timeout { 203 Timeout::Fuel(fuel) => store.set_fuel(fuel).unwrap(), 204 205 // If a timeout is requested then we spawn a helper thread to wait for 206 // the requested time and then send us a signal to get interrupted. We 207 // also arrange for the thread's sleep to get interrupted if we return 208 // early (or the wasm returns within the time limit), which allows the 209 // thread to get torn down. 210 // 211 // This prevents us from creating a huge number of sleeping threads if 212 // this function is executed in a loop, like it does on nightly fuzzing 213 // infrastructure. 214 Timeout::Epoch(timeout) => { 215 let engine = store.engine().clone(); 216 timeout_state.run_periodically(timeout, move || engine.increment_epoch()); 217 } 218 Timeout::None => {} 219 } 220 221 instantiate_with_dummy(&mut store, &module); 222 } 223 224 /// Represents supported commands to the `instantiate_many` function. 225 #[derive(Arbitrary, Debug)] 226 pub enum Command { 227 /// Instantiates a module. 228 /// 229 /// The value is the index of the module to instantiate. 230 /// 231 /// The module instantiated will be this value modulo the number of modules provided to `instantiate_many`. 232 Instantiate(usize), 233 /// Terminates a "running" instance. 234 /// 235 /// The value is the index of the instance to terminate. 236 /// 237 /// The instance terminated will be this value modulo the number of currently running 238 /// instances. 239 /// 240 /// If no instances are running, the command will be ignored. 241 Terminate(usize), 242 } 243 244 /// Instantiates many instances from the given modules. 245 /// 246 /// The engine will be configured using the provided config. 247 /// 248 /// The modules are expected to *not* have start functions as no timeouts are configured. 249 pub fn instantiate_many( 250 modules: &[Vec<u8>], 251 known_valid: KnownValid, 252 config: &generators::Config, 253 commands: &[Command], 254 ) { 255 log::debug!("instantiate_many: {commands:#?}"); 256 257 assert!(!config.module_config.config.allow_start_export); 258 259 let engine = Engine::new(&config.to_wasmtime()).unwrap(); 260 261 let modules = modules 262 .iter() 263 .enumerate() 264 .filter_map( 265 |(i, bytes)| match compile_module(&engine, bytes, known_valid, config) { 266 Some(m) => { 267 log::debug!("successfully compiled module {i}"); 268 Some(m) 269 } 270 None => { 271 log::debug!("failed to compile module {i}"); 272 None 273 } 274 }, 275 ) 276 .collect::<Vec<_>>(); 277 278 // If no modules were valid, we're done 279 if modules.is_empty() { 280 return; 281 } 282 283 // This stores every `Store` where a successful instantiation takes place 284 let mut stores = Vec::new(); 285 let limits = StoreLimits::new(); 286 287 for command in commands { 288 match command { 289 Command::Instantiate(index) => { 290 let index = *index % modules.len(); 291 log::info!("instantiating {index}"); 292 let module = &modules[index]; 293 let mut store = Store::new(&engine, limits.clone()); 294 config.configure_store(&mut store); 295 296 if instantiate_with_dummy(&mut store, module).is_some() { 297 stores.push(Some(store)); 298 } else { 299 log::warn!("instantiation failed"); 300 } 301 } 302 Command::Terminate(index) => { 303 if stores.is_empty() { 304 continue; 305 } 306 let index = *index % stores.len(); 307 308 log::info!("dropping {index}"); 309 stores.swap_remove(index); 310 } 311 } 312 } 313 } 314 315 fn compile_module( 316 engine: &Engine, 317 bytes: &[u8], 318 known_valid: KnownValid, 319 config: &generators::Config, 320 ) -> Option<Module> { 321 log_wasm(bytes); 322 323 fn is_pcc_error(e: &anyhow::Error) -> bool { 324 // NOTE: please keep this predicate in sync with the display format of CodegenError, 325 // defined in `wasmtime/cranelift/codegen/src/result.rs` 326 e.to_string().to_lowercase().contains("proof-carrying-code") 327 } 328 329 match config.compile(engine, bytes) { 330 Ok(module) => Some(module), 331 Err(e) if is_pcc_error(&e) => { 332 panic!("pcc error in input: {e:#?}"); 333 } 334 Err(_) if known_valid == KnownValid::No => None, 335 Err(e) => { 336 if let generators::InstanceAllocationStrategy::Pooling(c) = &config.wasmtime.strategy { 337 // When using the pooling allocator, accept failures to compile 338 // when arbitrary table element limits have been exceeded as 339 // there is currently no way to constrain the generated module 340 // table types. 341 let string = format!("{e:?}"); 342 if string.contains("minimum element size") { 343 return None; 344 } 345 346 // Allow modules-failing-to-compile which exceed the requested 347 // size for each instance. This is something that is difficult 348 // to control and ensure it always succeeds, so we simply have a 349 // "random" instance size limit and if a module doesn't fit we 350 // move on to the next fuzz input. 351 if string.contains("instance allocation for this module requires") { 352 return None; 353 } 354 355 // If the pooling allocator is more restrictive on the number of 356 // tables and memories than we allowed wasm-smith to generate 357 // then allow compilation errors along those lines. 358 if c.max_tables_per_module < (config.module_config.config.max_tables as u32) 359 && string.contains("defined tables count") 360 && string.contains("exceeds the per-instance limit") 361 { 362 return None; 363 } 364 365 if c.max_memories_per_module < (config.module_config.config.max_memories as u32) 366 && string.contains("defined memories count") 367 && string.contains("exceeds the per-instance limit") 368 { 369 return None; 370 } 371 } 372 373 panic!("failed to compile module: {e:?}"); 374 } 375 } 376 } 377 378 /// Create a Wasmtime [`Instance`] from a [`Module`] and fill in all imports 379 /// with dummy values (e.g., zeroed values, immediately-trapping functions). 380 /// Also, this function catches certain fuzz-related instantiation failures and 381 /// returns `None` instead of panicking. 382 /// 383 /// TODO: we should implement tracing versions of these dummy imports that 384 /// record a trace of the order that imported functions were called in and with 385 /// what values. Like the results of exported functions, calls to imports should 386 /// also yield the same values for each configuration, and we should assert 387 /// that. 388 pub fn instantiate_with_dummy(store: &mut Store<StoreLimits>, module: &Module) -> Option<Instance> { 389 // Creation of imports can fail due to resource limit constraints, and then 390 // instantiation can naturally fail for a number of reasons as well. Bundle 391 // the two steps together to match on the error below. 392 let linker = dummy::dummy_linker(store, module); 393 if let Err(e) = &linker { 394 log::warn!("failed to create dummy linker: {e:?}"); 395 } 396 let instance = linker.and_then(|l| l.instantiate(&mut *store, module)); 397 unwrap_instance(store, instance) 398 } 399 400 fn unwrap_instance( 401 store: &Store<StoreLimits>, 402 instance: anyhow::Result<Instance>, 403 ) -> Option<Instance> { 404 let e = match instance { 405 Ok(i) => return Some(i), 406 Err(e) => e, 407 }; 408 409 log::debug!("failed to instantiate: {e:?}"); 410 411 // If the instantiation hit OOM for some reason then that's ok, it's 412 // expected that fuzz-generated programs try to allocate lots of 413 // stuff. 414 if store.data().is_oom() { 415 return None; 416 } 417 418 // Allow traps which can happen normally with `unreachable` or a timeout or 419 // such. 420 if e.is::<Trap>() 421 // Also allow failures to instantiate as a result of hitting pooling 422 // limits. 423 || e.is::<wasmtime::PoolConcurrencyLimitError>() 424 // And GC heap OOMs. 425 || e.is::<wasmtime::GcHeapOutOfMemory<()>>() 426 // And thrown exceptions. 427 || e.is::<wasmtime::ThrownException>() 428 { 429 return None; 430 } 431 432 let string = e.to_string(); 433 434 // Currently we instantiate with a `Linker` which can't instantiate 435 // every single module under the sun due to using name-based resolution 436 // rather than positional-based resolution 437 if string.contains("incompatible import type") { 438 return None; 439 } 440 441 // Everything else should be a bug in the fuzzer or a bug in wasmtime 442 panic!("failed to instantiate: {e:?}"); 443 } 444 445 /// Evaluate the function identified by `name` in two different engine 446 /// instances--`lhs` and `rhs`. 447 /// 448 /// Returns `Ok(true)` if more evaluations can happen or `Ok(false)` if the 449 /// instances may have drifted apart and no more evaluations can happen. 450 /// 451 /// # Panics 452 /// 453 /// This will panic if the evaluation is different between engines (e.g., 454 /// results are different, hashed instance is different, one side traps, etc.). 455 pub fn differential( 456 lhs: &mut dyn DiffInstance, 457 lhs_engine: &dyn DiffEngine, 458 rhs: &mut WasmtimeInstance, 459 name: &str, 460 args: &[DiffValue], 461 result_tys: &[DiffValueType], 462 ) -> anyhow::Result<bool> { 463 log::debug!("Evaluating: `{name}` with {args:?}"); 464 let lhs_results = match lhs.evaluate(name, args, result_tys) { 465 Ok(Some(results)) => Ok(results), 466 Err(e) => Err(e), 467 // this engine couldn't execute this type signature, so discard this 468 // execution by returning success. 469 Ok(None) => return Ok(true), 470 }; 471 log::debug!(" -> lhs results on {}: {:?}", lhs.name(), &lhs_results); 472 473 let rhs_results = rhs 474 .evaluate(name, args, result_tys) 475 // wasmtime should be able to invoke any signature, so unwrap this result 476 .map(|results| results.unwrap()); 477 log::debug!(" -> rhs results on {}: {:?}", rhs.name(), &rhs_results); 478 479 // If Wasmtime hit its OOM condition, which is possible since it's set 480 // somewhat low while fuzzing, then don't return an error but return 481 // `false` indicating that differential fuzzing must stop. There's no 482 // guarantee the other engine has the same OOM limits as Wasmtime, and 483 // it's assumed that Wasmtime is configured to have a more conservative 484 // limit than the other engine. 485 if rhs.is_oom() { 486 return Ok(false); 487 } 488 489 match DiffEqResult::new(lhs_engine, lhs_results, rhs_results) { 490 DiffEqResult::Success(lhs, rhs) => assert_eq!(lhs, rhs), 491 DiffEqResult::Poisoned => return Ok(false), 492 DiffEqResult::Failed => {} 493 } 494 495 for (global, ty) in rhs.exported_globals() { 496 log::debug!("Comparing global `{global}`"); 497 let lhs = match lhs.get_global(&global, ty) { 498 Some(val) => val, 499 None => continue, 500 }; 501 let rhs = rhs.get_global(&global, ty).unwrap(); 502 assert_eq!(lhs, rhs); 503 } 504 for (memory, shared) in rhs.exported_memories() { 505 log::debug!("Comparing memory `{memory}`"); 506 let lhs = match lhs.get_memory(&memory, shared) { 507 Some(val) => val, 508 None => continue, 509 }; 510 let rhs = rhs.get_memory(&memory, shared).unwrap(); 511 if lhs == rhs { 512 continue; 513 } 514 eprintln!("differential memory is {} bytes long", lhs.len()); 515 eprintln!("wasmtime memory is {} bytes long", rhs.len()); 516 panic!("memories have differing values"); 517 } 518 519 Ok(true) 520 } 521 522 /// Result of comparing the result of two operations during differential 523 /// execution. 524 pub enum DiffEqResult<T, U> { 525 /// Both engines succeeded. 526 Success(T, U), 527 /// The result has reached the state where engines may have diverged and 528 /// results can no longer be compared. 529 Poisoned, 530 /// Both engines failed with the same error message, and internal state 531 /// should still match between the two engines. 532 Failed, 533 } 534 535 fn wasmtime_trap_is_non_deterministic(trap: &Trap) -> bool { 536 match trap { 537 // Allocations being too large for the GC are 538 // implementation-defined. 539 Trap::AllocationTooLarge | 540 // Stack size, and therefore when overflow happens, is 541 // implementation-defined. 542 Trap::StackOverflow => true, 543 _ => false, 544 } 545 } 546 547 fn wasmtime_error_is_non_deterministic(error: &wasmtime::Error) -> bool { 548 match error.downcast_ref::<Trap>() { 549 Some(trap) => wasmtime_trap_is_non_deterministic(trap), 550 551 // For general, unknown errors, we can't rely on this being 552 // a deterministic Wasm failure that both engines handled 553 // identically, leaving Wasm in identical states. We could 554 // just as easily be hitting engine-specific failures, like 555 // different implementation-defined limits. So simply poison 556 // this execution and move on to the next test. 557 None => true, 558 } 559 } 560 561 impl<T, U> DiffEqResult<T, U> { 562 /// Computes the differential result from executing in two different 563 /// engines. 564 pub fn new( 565 lhs_engine: &dyn DiffEngine, 566 lhs_result: Result<T>, 567 rhs_result: Result<U>, 568 ) -> DiffEqResult<T, U> { 569 match (lhs_result, rhs_result) { 570 (Ok(lhs_result), Ok(rhs_result)) => DiffEqResult::Success(lhs_result, rhs_result), 571 572 // Handle all non-deterministic errors by poisoning this execution's 573 // state, so that we simply move on to the next test. 574 (Err(lhs), _) if lhs_engine.is_non_deterministic_error(&lhs) => { 575 log::debug!("lhs failed non-deterministically: {lhs:?}"); 576 DiffEqResult::Poisoned 577 } 578 (_, Err(rhs)) if wasmtime_error_is_non_deterministic(&rhs) => { 579 log::debug!("rhs failed non-deterministically: {rhs:?}"); 580 DiffEqResult::Poisoned 581 } 582 583 // Both sides failed deterministically. Check that the trap and 584 // state at the time of failure is the same. 585 (Err(lhs), Err(rhs)) => { 586 let rhs = rhs 587 .downcast::<Trap>() 588 .expect("non-traps handled in earlier match arm"); 589 590 debug_assert!( 591 !lhs_engine.is_non_deterministic_error(&lhs), 592 "non-deterministic traps handled in earlier match arm", 593 ); 594 debug_assert!( 595 !wasmtime_trap_is_non_deterministic(&rhs), 596 "non-deterministic traps handled in earlier match arm", 597 ); 598 599 lhs_engine.assert_error_match(&lhs, &rhs); 600 DiffEqResult::Failed 601 } 602 603 // A real bug is found if only one side fails. 604 (Ok(_), Err(err)) => panic!("only the `rhs` failed for this input: {err:?}"), 605 (Err(err), Ok(_)) => panic!("only the `lhs` failed for this input: {err:?}"), 606 } 607 } 608 } 609 610 /// Invoke the given API calls. 611 pub fn make_api_calls(api: generators::api::ApiCalls) { 612 use crate::generators::api::ApiCall; 613 use std::collections::HashMap; 614 615 let mut store: Option<Store<StoreLimits>> = None; 616 let mut modules: HashMap<usize, Module> = Default::default(); 617 let mut instances: HashMap<usize, Instance> = Default::default(); 618 619 for call in api.calls { 620 match call { 621 ApiCall::StoreNew(config) => { 622 log::trace!("creating store"); 623 assert!(store.is_none()); 624 store = Some(config.to_store()); 625 } 626 627 ApiCall::ModuleNew { id, wasm } => { 628 log::debug!("creating module: {id}"); 629 log_wasm(&wasm); 630 let module = match Module::new(store.as_ref().unwrap().engine(), &wasm) { 631 Ok(m) => m, 632 Err(_) => continue, 633 }; 634 let old = modules.insert(id, module); 635 assert!(old.is_none()); 636 } 637 638 ApiCall::ModuleDrop { id } => { 639 log::trace!("dropping module: {id}"); 640 drop(modules.remove(&id)); 641 } 642 643 ApiCall::InstanceNew { id, module } => { 644 log::trace!("instantiating module {module} as {id}"); 645 let module = match modules.get(&module) { 646 Some(m) => m, 647 None => continue, 648 }; 649 650 let store = store.as_mut().unwrap(); 651 if let Some(instance) = instantiate_with_dummy(store, module) { 652 instances.insert(id, instance); 653 } 654 } 655 656 ApiCall::InstanceDrop { id } => { 657 log::trace!("dropping instance {id}"); 658 instances.remove(&id); 659 } 660 661 ApiCall::CallExportedFunc { instance, nth } => { 662 log::trace!("calling instance export {instance} / {nth}"); 663 let instance = match instances.get(&instance) { 664 Some(i) => i, 665 None => { 666 // Note that we aren't guaranteed to instantiate valid 667 // modules, see comments in `InstanceNew` for details on 668 // that. But the API call generator can't know if 669 // instantiation failed, so we might not actually have 670 // this instance. When that's the case, just skip the 671 // API call and keep going. 672 continue; 673 } 674 }; 675 let store = store.as_mut().unwrap(); 676 677 let funcs = instance 678 .exports(&mut *store) 679 .filter_map(|e| match e.into_extern() { 680 Extern::Func(f) => Some(f), 681 _ => None, 682 }) 683 .collect::<Vec<_>>(); 684 685 if funcs.is_empty() { 686 continue; 687 } 688 689 let nth = nth % funcs.len(); 690 let f = &funcs[nth]; 691 let ty = f.ty(&store); 692 if let Some(params) = ty 693 .params() 694 .map(|p| p.default_value()) 695 .collect::<Option<Vec<_>>>() 696 { 697 let mut results = vec![Val::I32(0); ty.results().len()]; 698 let _ = f.call(store, ¶ms, &mut results); 699 } 700 } 701 } 702 } 703 } 704 705 /// Executes the wast `test` with the `config` specified. 706 /// 707 /// Ensures that wast tests pass regardless of the `Config`. 708 pub fn wast_test(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<()> { 709 crate::init_fuzzing(); 710 711 let mut fuzz_config: generators::Config = u.arbitrary()?; 712 fuzz_config.module_config.shared_memory = true; 713 let test: generators::WastTest = u.arbitrary()?; 714 715 let test = &test.test; 716 717 if test.config.component_model_async() || u.arbitrary()? { 718 fuzz_config.enable_async(u)?; 719 } 720 721 // Discard tests that allocate a lot of memory as we don't want to OOM the 722 // fuzzer and we also limit memory growth which would cause the test to 723 // fail. 724 if test.config.hogs_memory.unwrap_or(false) { 725 return Err(arbitrary::Error::IncorrectFormat); 726 } 727 728 // Transform `fuzz_config` to be valid for `test` and make sure that this 729 // test is supposed to pass. 730 let wast_config = fuzz_config.make_wast_test_compliant(test); 731 if test.should_fail(&wast_config) { 732 return Err(arbitrary::Error::IncorrectFormat); 733 } 734 735 // Winch requires AVX and AVX2 for SIMD tests to pass so don't run the test 736 // if either isn't enabled. 737 if fuzz_config.wasmtime.compiler_strategy == CompilerStrategy::Winch 738 && test.config.simd() 739 && (fuzz_config 740 .wasmtime 741 .codegen_flag("has_avx") 742 .is_some_and(|value| value == "false") 743 || fuzz_config 744 .wasmtime 745 .codegen_flag("has_avx2") 746 .is_some_and(|value| value == "false")) 747 { 748 log::warn!( 749 "Skipping Wast test because Winch doesn't support SIMD tests with AVX or AVX2 disabled" 750 ); 751 return Err(arbitrary::Error::IncorrectFormat); 752 } 753 754 // Fuel and epochs don't play well with threads right now, so exclude any 755 // thread-spawning test if it looks like threads are spawned in that case. 756 if fuzz_config.wasmtime.consume_fuel || fuzz_config.wasmtime.epoch_interruption { 757 if test.contents.contains("(thread") { 758 return Err(arbitrary::Error::IncorrectFormat); 759 } 760 } 761 762 log::debug!("running {:?}", test.path); 763 let async_ = if fuzz_config.wasmtime.async_config == generators::AsyncConfig::Disabled { 764 wasmtime_wast::Async::No 765 } else { 766 wasmtime_wast::Async::Yes 767 }; 768 log::debug!("async: {async_:?}"); 769 let engine = Engine::new(&fuzz_config.to_wasmtime()).unwrap(); 770 let mut wast_context = WastContext::new(&engine, async_, move |store| { 771 fuzz_config.configure_store_epoch_and_fuel(store); 772 }); 773 wast_context 774 .register_spectest(&wasmtime_wast::SpectestConfig { 775 use_shared_memory: true, 776 suppress_prints: true, 777 }) 778 .unwrap(); 779 wast_context 780 .run_wast(test.path.to_str().unwrap(), test.contents.as_bytes()) 781 .unwrap(); 782 Ok(()) 783 } 784 785 /// Execute a series of `gc` operations. 786 /// 787 /// Returns the number of `gc` operations which occurred throughout the test 788 /// case -- used to test below that gc happens reasonably soon and eventually. 789 pub fn gc_ops(mut fuzz_config: generators::Config, mut ops: GcOps) -> Result<usize> { 790 let expected_drops = Arc::new(AtomicUsize::new(0)); 791 let num_dropped = Arc::new(AtomicUsize::new(0)); 792 793 let num_gcs = Arc::new(AtomicUsize::new(0)); 794 { 795 fuzz_config.wasmtime.consume_fuel = true; 796 let mut store = fuzz_config.to_store(); 797 store.set_fuel(1_000).unwrap(); 798 799 let wasm = ops.to_wasm_binary(); 800 log_wasm(&wasm); 801 let module = match compile_module(store.engine(), &wasm, KnownValid::No, &fuzz_config) { 802 Some(m) => m, 803 None => return Ok(0), 804 }; 805 806 let mut linker = Linker::new(store.engine()); 807 808 // To avoid timeouts, limit the number of explicit GCs we perform per 809 // test case. 810 const MAX_GCS: usize = 5; 811 812 let func_ty = FuncType::new( 813 store.engine(), 814 vec![], 815 vec![ValType::EXTERNREF, ValType::EXTERNREF, ValType::EXTERNREF], 816 ); 817 let func = Func::new(&mut store, func_ty, { 818 let num_dropped = num_dropped.clone(); 819 let expected_drops = expected_drops.clone(); 820 let num_gcs = num_gcs.clone(); 821 move |mut caller: Caller<'_, StoreLimits>, _params, results| { 822 log::info!("gc_ops: GC"); 823 if num_gcs.fetch_add(1, SeqCst) < MAX_GCS { 824 caller.gc(None); 825 } 826 827 let a = ExternRef::new( 828 &mut caller, 829 CountDrops::new(&expected_drops, num_dropped.clone()), 830 )?; 831 let b = ExternRef::new( 832 &mut caller, 833 CountDrops::new(&expected_drops, num_dropped.clone()), 834 )?; 835 let c = ExternRef::new( 836 &mut caller, 837 CountDrops::new(&expected_drops, num_dropped.clone()), 838 )?; 839 840 log::info!("gc_ops: gc() -> ({a:?}, {b:?}, {c:?})"); 841 results[0] = Some(a).into(); 842 results[1] = Some(b).into(); 843 results[2] = Some(c).into(); 844 Ok(()) 845 } 846 }); 847 linker.define(&store, "", "gc", func).unwrap(); 848 849 linker 850 .func_wrap("", "take_refs", { 851 let expected_drops = expected_drops.clone(); 852 move |caller: Caller<'_, StoreLimits>, 853 a: Option<Rooted<ExternRef>>, 854 b: Option<Rooted<ExternRef>>, 855 c: Option<Rooted<ExternRef>>| 856 -> Result<()> { 857 log::info!("gc_ops: take_refs({a:?}, {b:?}, {c:?})",); 858 859 // Do the assertion on each ref's inner data, even though it 860 // all points to the same atomic, so that if we happen to 861 // run into a use-after-free bug with one of these refs we 862 // are more likely to trigger a segfault. 863 if let Some(a) = a { 864 let a = a 865 .data(&caller)? 866 .unwrap() 867 .downcast_ref::<CountDrops>() 868 .unwrap(); 869 assert!(a.0.load(SeqCst) <= expected_drops.load(SeqCst)); 870 } 871 if let Some(b) = b { 872 let b = b 873 .data(&caller)? 874 .unwrap() 875 .downcast_ref::<CountDrops>() 876 .unwrap(); 877 assert!(b.0.load(SeqCst) <= expected_drops.load(SeqCst)); 878 } 879 if let Some(c) = c { 880 let c = c 881 .data(&caller)? 882 .unwrap() 883 .downcast_ref::<CountDrops>() 884 .unwrap(); 885 assert!(c.0.load(SeqCst) <= expected_drops.load(SeqCst)); 886 } 887 Ok(()) 888 } 889 }) 890 .unwrap(); 891 892 let func_ty = FuncType::new( 893 store.engine(), 894 vec![], 895 vec![ValType::EXTERNREF, ValType::EXTERNREF, ValType::EXTERNREF], 896 ); 897 let func = Func::new(&mut store, func_ty, { 898 let num_dropped = num_dropped.clone(); 899 let expected_drops = expected_drops.clone(); 900 move |mut caller, _params, results| { 901 log::info!("gc_ops: make_refs"); 902 903 let a = ExternRef::new( 904 &mut caller, 905 CountDrops::new(&expected_drops, num_dropped.clone()), 906 )?; 907 let b = ExternRef::new( 908 &mut caller, 909 CountDrops::new(&expected_drops, num_dropped.clone()), 910 )?; 911 let c = ExternRef::new( 912 &mut caller, 913 CountDrops::new(&expected_drops, num_dropped.clone()), 914 )?; 915 916 log::info!("gc_ops: make_refs() -> ({a:?}, {b:?}, {c:?})"); 917 918 results[0] = Some(a).into(); 919 results[1] = Some(b).into(); 920 results[2] = Some(c).into(); 921 922 Ok(()) 923 } 924 }); 925 linker.define(&store, "", "make_refs", func).unwrap(); 926 927 let func_ty = FuncType::new( 928 store.engine(), 929 vec![ValType::Ref(RefType::new(false, HeapType::Any))], 930 vec![], 931 ); 932 933 let func = Func::new(&mut store, func_ty, { 934 move |_caller: Caller<'_, StoreLimits>, _params, _results| { 935 log::info!("gc_ops: take_struct(<ref any>)"); 936 Ok(()) 937 } 938 }); 939 940 linker.define(&store, "", "take_struct", func).unwrap(); 941 942 for imp in module.imports() { 943 if imp.module() == "" { 944 let name = imp.name(); 945 if name.starts_with("take_struct_") { 946 if let wasmtime::ExternType::Func(ft) = imp.ty() { 947 let imp_name = name.to_string(); 948 let func = 949 Func::new(&mut store, ft.clone(), move |_caller, _params, _results| { 950 log::info!("gc_ops: {imp_name}(<typed structref>)"); 951 Ok(()) 952 }); 953 linker.define(&store, "", name, func).unwrap(); 954 } 955 } 956 } 957 } 958 959 let instance = linker.instantiate(&mut store, &module).unwrap(); 960 let run = instance.get_func(&mut store, "run").unwrap(); 961 962 { 963 let mut scope = RootScope::new(&mut store); 964 965 log::info!( 966 "gc_ops: begin allocating {} externref arguments", 967 ops.limits.num_globals 968 ); 969 let args: Vec<_> = (0..ops.limits.num_params) 970 .map(|_| { 971 Ok(Val::ExternRef(Some(ExternRef::new( 972 &mut scope, 973 CountDrops::new(&expected_drops, num_dropped.clone()), 974 )?))) 975 }) 976 .collect::<Result<_>>()?; 977 log::info!( 978 "gc_ops: end allocating {} externref arguments", 979 ops.limits.num_globals 980 ); 981 982 // The generated function should always return a trap. The only two 983 // valid traps are table-out-of-bounds which happens through `table.get` 984 // and `table.set` generated or an out-of-fuel trap. Otherwise any other 985 // error is unexpected and should fail fuzzing. 986 log::info!("gc_ops: calling into Wasm `run` function"); 987 let err = run.call(&mut scope, &args, &mut []).unwrap_err(); 988 if err.is::<GcHeapOutOfMemory<CountDrops>>() || err.is::<GcHeapOutOfMemory<()>>() { 989 // Accept GC OOM as an allowed outcome for this fuzzer. 990 } else { 991 let trap = err 992 .downcast::<Trap>() 993 .expect("if not GC oom, error should be a Wasm trap"); 994 match trap { 995 Trap::TableOutOfBounds | Trap::OutOfFuel | Trap::AllocationTooLarge => {} 996 _ => panic!("unexpected trap: {trap}"), 997 } 998 } 999 } 1000 1001 // Do a final GC after running the Wasm. 1002 store.gc(None); 1003 } 1004 1005 assert_eq!(num_dropped.load(SeqCst), expected_drops.load(SeqCst)); 1006 return Ok(num_gcs.load(SeqCst)); 1007 1008 struct CountDrops(Arc<AtomicUsize>); 1009 1010 impl CountDrops { 1011 fn new(expected_drops: &AtomicUsize, num_dropped: Arc<AtomicUsize>) -> Self { 1012 let expected = expected_drops.fetch_add(1, SeqCst); 1013 log::info!( 1014 "CountDrops::new: expected drops: {expected} -> {}", 1015 expected + 1 1016 ); 1017 Self(num_dropped) 1018 } 1019 } 1020 1021 impl Drop for CountDrops { 1022 fn drop(&mut self) { 1023 let drops = self.0.fetch_add(1, SeqCst); 1024 log::info!("CountDrops::drop: actual drops: {drops} -> {}", drops + 1); 1025 } 1026 } 1027 } 1028 1029 #[derive(Default)] 1030 struct HelperThread { 1031 state: Arc<HelperThreadState>, 1032 thread: Option<std::thread::JoinHandle<()>>, 1033 } 1034 1035 #[derive(Default)] 1036 struct HelperThreadState { 1037 should_exit: Mutex<bool>, 1038 should_exit_cvar: Condvar, 1039 } 1040 1041 impl HelperThread { 1042 fn run_periodically(&mut self, dur: Duration, mut closure: impl FnMut() + Send + 'static) { 1043 let state = self.state.clone(); 1044 self.thread = Some(std::thread::spawn(move || { 1045 // Using our mutex/condvar we wait here for the first of `dur` to 1046 // pass or the `HelperThread` instance to get dropped. 1047 let mut should_exit = state.should_exit.lock().unwrap(); 1048 while !*should_exit { 1049 let (lock, result) = state 1050 .should_exit_cvar 1051 .wait_timeout(should_exit, dur) 1052 .unwrap(); 1053 should_exit = lock; 1054 // If we timed out for sure then there's no need to continue 1055 // since we'll just abort on the next `checked_sub` anyway. 1056 if result.timed_out() { 1057 closure(); 1058 } 1059 } 1060 })); 1061 } 1062 } 1063 1064 impl Drop for HelperThread { 1065 fn drop(&mut self) { 1066 let thread = match self.thread.take() { 1067 Some(thread) => thread, 1068 None => return, 1069 }; 1070 // Signal our thread that it should exit and wake it up in case it's 1071 // sleeping. 1072 *self.state.should_exit.lock().unwrap() = true; 1073 self.state.should_exit_cvar.notify_one(); 1074 1075 // ... and then wait for the thread to exit to ensure we clean up 1076 // after ourselves. 1077 thread.join().unwrap(); 1078 } 1079 } 1080 1081 /// Instantiates a wasm module and runs its exports with dummy values, all in 1082 /// an async fashion. 1083 /// 1084 /// Attempts to stress yields in host functions to ensure that exiting and 1085 /// resuming a wasm function call works. 1086 pub fn call_async(wasm: &[u8], config: &generators::Config, mut poll_amts: &[u32]) { 1087 let mut store = config.to_store(); 1088 let module = match compile_module(store.engine(), wasm, KnownValid::Yes, config) { 1089 Some(module) => module, 1090 None => return, 1091 }; 1092 1093 // Configure a helper thread to periodically increment the epoch to 1094 // forcibly enable yields-via-epochs if epochs are in use. Note that this 1095 // is required because the wasm isn't otherwise guaranteed to necessarily 1096 // call any imports which will also increment the epoch. 1097 let mut helper_thread = HelperThread::default(); 1098 if let generators::AsyncConfig::YieldWithEpochs { dur, .. } = &config.wasmtime.async_config { 1099 let engine = store.engine().clone(); 1100 helper_thread.run_periodically(*dur, move || engine.increment_epoch()); 1101 } 1102 1103 // Generate a `Linker` where all function imports are custom-built to yield 1104 // periodically and additionally increment the epoch. 1105 let mut imports = Vec::new(); 1106 for import in module.imports() { 1107 let item = match import.ty() { 1108 ExternType::Func(ty) => { 1109 let poll_amt = take_poll_amt(&mut poll_amts); 1110 Func::new_async(&mut store, ty.clone(), move |caller, _, results| { 1111 let ty = ty.clone(); 1112 Box::new(async move { 1113 caller.engine().increment_epoch(); 1114 log::info!("yielding {poll_amt} times in import"); 1115 YieldN(poll_amt).await; 1116 for (ret_ty, result) in ty.results().zip(results) { 1117 *result = ret_ty.default_value().unwrap(); 1118 } 1119 Ok(()) 1120 }) 1121 }) 1122 .into() 1123 } 1124 other_ty => match other_ty.default_value(&mut store) { 1125 Ok(item) => item, 1126 Err(e) => { 1127 log::warn!("couldn't create import for {import:?}: {e:?}"); 1128 return; 1129 } 1130 }, 1131 }; 1132 imports.push(item); 1133 } 1134 1135 // Run the instantiation process, asynchronously, and if everything 1136 // succeeds then pull out the instance. 1137 // log::info!("starting instantiation"); 1138 let instance = block_on(Timeout { 1139 future: Instance::new_async(&mut store, &module, &imports), 1140 polls: take_poll_amt(&mut poll_amts), 1141 end: Instant::now() + Duration::from_millis(2_000), 1142 }); 1143 let instance = match instance { 1144 Ok(instantiation_result) => match unwrap_instance(&store, instantiation_result) { 1145 Some(instance) => instance, 1146 None => { 1147 log::info!("instantiation hit a nominal error"); 1148 return; // resource exhaustion or limits met 1149 } 1150 }, 1151 Err(_) => { 1152 log::info!("instantiation failed to complete"); 1153 return; // Timed out or ran out of polls 1154 } 1155 }; 1156 1157 // Run each export of the instance in the same manner as instantiation 1158 // above. Dummy values are passed in for argument values here: 1159 // 1160 // TODO: this should probably be more clever about passing in arguments for 1161 // example they might be used as pointers or something and always using 0 1162 // isn't too interesting. 1163 let funcs = instance 1164 .exports(&mut store) 1165 .filter_map(|e| { 1166 let name = e.name().to_string(); 1167 let func = e.into_extern().into_func()?; 1168 Some((name, func)) 1169 }) 1170 .collect::<Vec<_>>(); 1171 for (name, func) in funcs { 1172 let ty = func.ty(&store); 1173 let params = ty 1174 .params() 1175 .map(|ty| ty.default_value().unwrap()) 1176 .collect::<Vec<_>>(); 1177 let mut results = ty 1178 .results() 1179 .map(|ty| ty.default_value().unwrap()) 1180 .collect::<Vec<_>>(); 1181 1182 log::info!("invoking export {name:?}"); 1183 let future = func.call_async(&mut store, ¶ms, &mut results); 1184 match block_on(Timeout { 1185 future, 1186 polls: take_poll_amt(&mut poll_amts), 1187 end: Instant::now() + Duration::from_millis(2_000), 1188 }) { 1189 // On success or too many polls, try the next export. 1190 Ok(_) | Err(Exhausted::Polls) => {} 1191 1192 // If time ran out then stop the current test case as we might have 1193 // already sucked up a lot of time for this fuzz test case so don't 1194 // keep it going. 1195 Err(Exhausted::Time) => return, 1196 } 1197 } 1198 1199 fn take_poll_amt(polls: &mut &[u32]) -> u32 { 1200 match polls.split_first() { 1201 Some((a, rest)) => { 1202 *polls = rest; 1203 *a 1204 } 1205 None => 0, 1206 } 1207 } 1208 1209 /// Helper future to yield N times before resolving. 1210 struct YieldN(u32); 1211 1212 impl Future for YieldN { 1213 type Output = (); 1214 1215 fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> { 1216 if self.0 == 0 { 1217 Poll::Ready(()) 1218 } else { 1219 self.0 -= 1; 1220 cx.waker().wake_by_ref(); 1221 Poll::Pending 1222 } 1223 } 1224 } 1225 1226 /// Helper future for applying a timeout to `future` up to either when `end` 1227 /// is the current time or `polls` polls happen. 1228 /// 1229 /// Note that this helps to time out infinite loops in wasm, for example. 1230 struct Timeout<F> { 1231 future: F, 1232 /// If the future isn't ready by this time then the `Timeout<F>` future 1233 /// will return `None`. 1234 end: Instant, 1235 /// If the future doesn't resolve itself in this many calls to `poll` 1236 /// then the `Timeout<F>` future will return `None`. 1237 polls: u32, 1238 } 1239 1240 enum Exhausted { 1241 Time, 1242 Polls, 1243 } 1244 1245 impl<F: Future> Future for Timeout<F> { 1246 type Output = Result<F::Output, Exhausted>; 1247 1248 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { 1249 let (end, polls, future) = unsafe { 1250 let me = self.get_unchecked_mut(); 1251 (me.end, &mut me.polls, Pin::new_unchecked(&mut me.future)) 1252 }; 1253 match future.poll(cx) { 1254 Poll::Ready(val) => Poll::Ready(Ok(val)), 1255 Poll::Pending => { 1256 if Instant::now() >= end { 1257 log::warn!("future operation timed out"); 1258 return Poll::Ready(Err(Exhausted::Time)); 1259 } 1260 if *polls == 0 { 1261 log::warn!("future operation ran out of polls"); 1262 return Poll::Ready(Err(Exhausted::Polls)); 1263 } 1264 *polls -= 1; 1265 Poll::Pending 1266 } 1267 } 1268 } 1269 } 1270 } 1271 1272 #[cfg(test)] 1273 mod tests { 1274 use super::*; 1275 use crate::test::{gen_until_pass, test_n_times}; 1276 use wasmparser::{Validator, WasmFeatures}; 1277 1278 // Test that the `gc_ops` fuzzer eventually runs the gc function in the host. 1279 // We've historically had issues where this fuzzer accidentally wasn't fuzzing 1280 // anything for a long time so this is an attempt to prevent that from happening 1281 // again. 1282 #[test] 1283 fn gc_ops_eventually_gcs() { 1284 // Skip if we're under emulation because some fuzz configurations will do 1285 // large address space reservations that QEMU doesn't handle well. 1286 if std::env::var("WASMTIME_TEST_NO_HOG_MEMORY").is_ok() { 1287 return; 1288 } 1289 1290 let ok = gen_until_pass(|(config, test), _| { 1291 let result = gc_ops(config, test)?; 1292 Ok(result > 0) 1293 }); 1294 1295 if !ok { 1296 panic!("gc was never found"); 1297 } 1298 } 1299 1300 #[test] 1301 fn module_generation_uses_expected_proposals() { 1302 // Proposals that Wasmtime supports. Eventually a module should be 1303 // generated that needs these proposals. 1304 let mut expected = WasmFeatures::MUTABLE_GLOBAL 1305 | WasmFeatures::FLOATS 1306 | WasmFeatures::SIGN_EXTENSION 1307 | WasmFeatures::SATURATING_FLOAT_TO_INT 1308 | WasmFeatures::MULTI_VALUE 1309 | WasmFeatures::BULK_MEMORY 1310 | WasmFeatures::REFERENCE_TYPES 1311 | WasmFeatures::SIMD 1312 | WasmFeatures::MULTI_MEMORY 1313 | WasmFeatures::RELAXED_SIMD 1314 | WasmFeatures::TAIL_CALL 1315 | WasmFeatures::WIDE_ARITHMETIC 1316 | WasmFeatures::MEMORY64 1317 | WasmFeatures::FUNCTION_REFERENCES 1318 | WasmFeatures::GC 1319 | WasmFeatures::GC_TYPES 1320 | WasmFeatures::CUSTOM_PAGE_SIZES 1321 | WasmFeatures::EXTENDED_CONST 1322 | WasmFeatures::EXCEPTIONS; 1323 1324 // All other features that wasmparser supports, which is presumably a 1325 // superset of the features that wasm-smith supports, are listed here as 1326 // unexpected. This means, for example, that if wasm-smith updates to 1327 // include a new proposal by default that wasmtime implements then it 1328 // will be required to be listed above. 1329 let unexpected = WasmFeatures::all() ^ expected; 1330 1331 let ok = gen_until_pass(|config: generators::Config, u| { 1332 let wasm = config.generate(u, None)?.to_bytes(); 1333 1334 // Double-check the module is valid 1335 Validator::new_with_features(WasmFeatures::all()).validate_all(&wasm)?; 1336 1337 // If any of the unexpected features are removed then this module 1338 // should always be valid, otherwise something went wrong. 1339 for feature in unexpected.iter() { 1340 let ok = 1341 Validator::new_with_features(WasmFeatures::all() ^ feature).validate_all(&wasm); 1342 if ok.is_err() { 1343 anyhow::bail!("generated a module with {feature:?} but that wasn't expected"); 1344 } 1345 } 1346 1347 // If any of `expected` is removed and the module fails to validate, 1348 // then that means the module requires that feature. Remove that 1349 // from the set of features we're then expecting. 1350 for feature in expected.iter() { 1351 let ok = 1352 Validator::new_with_features(WasmFeatures::all() ^ feature).validate_all(&wasm); 1353 if ok.is_err() { 1354 expected ^= feature; 1355 } 1356 } 1357 1358 Ok(expected.is_empty()) 1359 }); 1360 1361 if !ok { 1362 panic!("never generated wasm module using {expected:?}"); 1363 } 1364 } 1365 1366 #[test] 1367 fn wast_smoke_test() { 1368 test_n_times(50, |(), u| super::wast_test(u)); 1369 } 1370 } 1371