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