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