1 #![cfg_attr(miri, allow(dead_code, unused_imports))] 2 3 use wasmtime::Result; 4 5 mod arrays; 6 mod async_functions; 7 mod call_hook; 8 mod cli_tests; 9 mod code_too_large; 10 mod compile_time_builtins; 11 mod component_model; 12 mod coredump; 13 mod custom_code_memory; 14 mod debug; 15 mod defaults; 16 mod engine; 17 mod epoch_interruption; 18 mod eqref; 19 mod exceptions; 20 mod exnrefs; 21 mod externals; 22 mod fuel; 23 mod func; 24 mod funcref; 25 mod gc; 26 mod globals; 27 mod host_funcs; 28 mod i31ref; 29 mod iloop; 30 mod import_calling_export; 31 mod import_indexes; 32 mod instance; 33 mod intrinsics; 34 mod invoke_func_via_table; 35 mod limits; 36 mod linker; 37 mod memory; 38 mod memory_creator; 39 mod missing_async; 40 mod module; 41 mod module_serialize; 42 mod name; 43 mod native_debug; 44 mod noextern; 45 mod piped_tests; 46 mod pooling_allocator; 47 mod profiling; 48 mod pulley; 49 mod relocs; 50 mod stack_creator; 51 mod stack_overflow; 52 mod store; 53 mod structs; 54 mod table; 55 #[cfg(all(feature = "stack-switching", unix, target_arch = "x86_64"))] 56 mod tags; 57 mod threads; 58 mod traps; 59 mod types; 60 mod wait_notify; 61 mod winch_engine_features; 62 63 /// A helper to compile a module in a new store with reference types enabled. 64 pub(crate) fn ref_types_module( 65 use_epochs: bool, 66 source: &str, 67 ) -> wasmtime::Result<(wasmtime::Store<()>, wasmtime::Module)> { 68 use wasmtime::*; 69 70 let _ = env_logger::try_init(); 71 72 let mut config = Config::new(); 73 config.wasm_reference_types(true); 74 75 config.wasm_tail_call(true); 76 77 if use_epochs { 78 config.epoch_interruption(true); 79 } 80 81 let engine = Engine::new(&config)?; 82 let mut store = Store::new(&engine, ()); 83 if use_epochs { 84 store.set_epoch_deadline(1); 85 } 86 87 let module = Module::new(&engine, source)?; 88 89 Ok((store, module)) 90 } 91 92 /// A helper determining whether the pooling allocator tests should be skipped. 93 pub(crate) fn skip_pooling_allocator_tests() -> bool { 94 // There are a couple of issues when running the pooling allocator tests under QEMU: 95 // - high memory usage that may exceed the limits imposed by the environment (e.g. CI) 96 // - https://github.com/bytecodealliance/wasmtime/pull/2518#issuecomment-747280133 97 std::env::var("WASMTIME_TEST_NO_HOG_MEMORY").is_ok() 98 } 99 100 /// Get the default pooling allocator configuration for tests, which is a 101 /// smaller pool than the normal default. 102 pub(crate) fn small_pool_config() -> wasmtime::PoolingAllocationConfig { 103 let mut config = wasmtime::PoolingAllocationConfig::new(); 104 105 config.total_memories(1); 106 config.max_memory_size(1 << 16); 107 config.total_tables(1); 108 config.table_elements(10); 109 110 // When testing, we may choose to start with MPK force-enabled to ensure 111 // we use that functionality. 112 if std::env::var("WASMTIME_TEST_FORCE_MPK").is_ok() { 113 config.memory_protection_keys(wasmtime::Enabled::No); 114 } 115 116 config.total_stacks(1); 117 118 config 119 } 120 121 pub(crate) fn gc_store() -> Result<wasmtime::Store<()>> { 122 let _ = env_logger::try_init(); 123 124 let mut config = wasmtime::Config::new(); 125 config.wasm_function_references(true); 126 config.wasm_gc(true); 127 128 let engine = wasmtime::Engine::new(&config)?; 129 Ok(wasmtime::Store::new(&engine, ())) 130 } 131 132 trait ErrorExt { 133 fn assert_contains(&self, msg: &str); 134 } 135 136 impl ErrorExt for wasmtime::Error { 137 fn assert_contains(&self, msg: &str) { 138 if self.chain().any(|e| e.to_string().contains(msg)) { 139 return; 140 } 141 142 panic!("failed to find:\n{msg}\n\nwithin error message:\n{self:?}") 143 } 144 } 145