Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Support arbitrary CLI flags in `*.wast` tests (#15152)

Alex Crichtonbd3a789abc0c
diff --git a/Cargo.lock b/Cargo.lock
index 7bf3654c22..be78a54316 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5123,6 +5123,7 @@ version = "52.0.0-dev"
dependencies = [
"arbitrary",
"arbtest",
+ "clap",
"env_logger 0.11.5",
"indexmap 2.14.0",
"proc-macro2",
@@ -5135,6 +5136,7 @@ dependencies = [
"wasmparser 0.263.0",
"wasmprinter",
"wasmtime",
+ "wasmtime-cli-flags",
"wasmtime-environ",
"wasmtime-internal-component-util",
"wat",
diff --git a/Cargo.toml b/Cargo.toml
index 2269376f48..16f8fae9d5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -632,6 +632,7 @@ run = [
"wasmtime/runtime",
"wasmtime/wave",
"dep:tokio",
+ "wasmtime-cli-flags/runtime",
"wasmtime-cli-flags/async",
"wasmtime-wasi-http?/p2",
]
@@ -654,6 +655,7 @@ wizer = [
"dep:wasmtime-wasi",
"dep:tokio",
"wasmtime/wave",
+ "wasmtime-cli-flags/runtime",
]
[[test]]
diff --git a/crates/cli-flags/Cargo.toml b/crates/cli-flags/Cargo.toml
index 4187b908bb..88854388aa 100644
--- a/crates/cli-flags/Cargo.toml
+++ b/crates/cli-flags/Cargo.toml
@@ -36,6 +36,7 @@ toml = ["dep:toml", "serde"]
# ----------------------------------------
# Forwarding features to the `wasmtime` crate, and additionally being able to
# configure various options gated behind these features.
+runtime = ["wasmtime/runtime"]
async = ["wasmtime/async"]
pooling-allocator = ["wasmtime/pooling-allocator"]
component-model = ["wasmtime/component-model"]
diff --git a/crates/cli-flags/src/lib.rs b/crates/cli-flags/src/lib.rs
index 65cecf0fdc..06101fbc40 100644
--- a/crates/cli-flags/src/lib.rs
+++ b/crates/cli-flags/src/lib.rs
@@ -528,6 +528,11 @@ wasmtime_option_group! {
pub extended_const: Option<bool>,
/// Configure support for the exceptions proposal.
pub exceptions: Option<bool>,
+ /// Configure support for the legacy exceptions proposal.
+ ///
+ /// This only exists for Wasmtime's own testing of the spec test suite
+ /// and may be removed at any time.
+ pub legacy_exceptions: Option<bool>,
/// Whether or not any GC infrastructure in Wasmtime is enabled or not.
pub gc_support: Option<bool>,
/// Component model support for fixed-length lists: this corresponds
@@ -783,6 +788,12 @@ pub struct CommonOptions {
#[cfg_attr(feature = "serde", serde(skip))]
configured: bool,
+ /// Whether to ignore `WASMTIME_*` environment variables, which are
+ /// otherwise read as options in addition to those specified here.
+ #[cfg_attr(feature = "clap", arg(skip))]
+ #[cfg_attr(feature = "serde", serde(skip))]
+ pub ignore_env: bool,
+
#[cfg_attr(feature = "clap", arg(skip))]
#[cfg_attr(feature = "serde", serde(rename = "optimize", default))]
pub opts: OptimizeOptions,
@@ -823,6 +834,101 @@ pub struct CommonOptions {
pub config: Option<PathBuf>,
}
+type F = WasmFeatures;
+
+/// The options in [`WasmOptions`] that enable or disable a [`WasmFeatures`]
+/// flag.
+///
+/// Each entry is the flag, the option, and the option's name if it's not the
+/// flag's name in lowercase with dashes (`CM_ASYNC` is `cm-async`).
+static WASM_FEATURE_OPTIONS: &[(WasmFeatures, fn(&WasmOptions) -> Option<bool>, Option<&str>)] = &[
+ (F::SIMD, |w| w.simd, None),
+ (F::RELAXED_SIMD, |w| w.relaxed_simd, None),
+ (F::BULK_MEMORY, |w| w.bulk_memory, None),
+ (F::MULTI_VALUE, |w| w.multi_value, None),
+ (F::TAIL_CALL, |w| w.tail_call, None),
+ (F::MULTI_MEMORY, |w| w.multi_memory, None),
+ (F::MEMORY64, |w| w.memory64, None),
+ (F::CUSTOM_PAGE_SIZES, |w| w.custom_page_sizes, None),
+ (F::WIDE_ARITHMETIC, |w| w.wide_arithmetic, None),
+ (F::COMPACT_IMPORTS, |w| w.compact_imports, None),
+ (F::EXTENDED_CONST, |w| w.extended_const, None),
+ (F::THREADS, |w| w.threads, None),
+ (
+ F::SHARED_EVERYTHING_THREADS,
+ |w| w.shared_everything_threads,
+ None,
+ ),
+ (F::GC, |w| w.gc, None),
+ (F::GC_TYPES, |w| w.gc_support, Some("gc-support")),
+ (F::REFERENCE_TYPES, |w| w.reference_types, None),
+ (F::FUNCTION_REFERENCES, |w| w.function_references, None),
+ (F::EXCEPTIONS, |w| w.exceptions, None),
+ (F::LEGACY_EXCEPTIONS, |w| w.legacy_exceptions, None),
+ (F::STACK_SWITCHING, |w| w.stack_switching, None),
+ (F::COMPONENT_MODEL, |w| w.component_model, None),
+ (
+ F::CM_ASYNC,
+ |w| w.component_model_async,
+ Some("component-model-async"),
+ ),
+ (
+ F::CM_MORE_ASYNC_BUILTINS,
+ |w| w.component_model_more_async_builtins,
+ Some("component-model-more-async-builtins"),
+ ),
+ (
+ F::CM_ASYNC_STACKFUL,
+ |w| w.component_model_async_stackful,
+ Some("component-model-async-stackful"),
+ ),
+ (
+ F::CM_THREADING,
+ |w| w.component_model_threading,
+ Some("component-model-threading"),
+ ),
+ (
+ F::CM_ERROR_CONTEXT,
+ |w| w.component_model_error_context,
+ Some("component-model-error-context"),
+ ),
+ (
+ F::CM_MAP,
+ |w| w.component_model_map,
+ Some("component-model-map"),
+ ),
+ (
+ F::CM_FIXED_LENGTH_LISTS,
+ |w| w.component_model_fixed_length_lists,
+ Some("component-model-fixed-length-lists"),
+ ),
+ (
+ F::CM_IMPLEMENTS,
+ |w| w.component_model_implements,
+ Some("component-model-implements"),
+ ),
+ (
+ F::CM_CANON_NAMES,
+ |w| w.component_model_canonical_names,
+ Some("component-model-canonical-names"),
+ ),
+ (
+ F::CM_ACCESSORS,
+ |w| w.component_model_accessors,
+ Some("component-model-accessors"),
+ ),
+ (
+ F::CM64,
+ |w| w.component_model_memory64,
+ Some("component-model-memory64"),
+ ),
+ (
+ F::CM_GC,
+ |w| w.component_model_gc,
+ Some("component-model-gc"),
+ ),
+];
+
macro_rules! match_feature {
(
[$feat:tt : $config:expr]
@@ -855,6 +961,7 @@ impl CommonOptions {
wasi_raw: Vec::new(),
record_raw: Vec::new(),
configured: true,
+ ignore_env: false,
opts: Default::default(),
codegen: Default::default(),
debug: Default::default(),
@@ -890,12 +997,66 @@ impl CommonOptions {
);
}
}
- self.opts.configure_with(&self.opts_raw)?;
- self.codegen.configure_with(&self.codegen_raw)?;
- self.debug.configure_with(&self.debug_raw)?;
- self.wasm.configure_with(&self.wasm_raw)?;
- self.wasi.configure_with(&self.wasi_raw)?;
- self.record.configure_with(&self.record_raw)?;
+ self.opts.configure_with(&self.opts_raw, !self.ignore_env)?;
+ self.codegen
+ .configure_with(&self.codegen_raw, !self.ignore_env)?;
+ self.debug
+ .configure_with(&self.debug_raw, !self.ignore_env)?;
+ self.wasm.configure_with(&self.wasm_raw, !self.ignore_env)?;
+ self.wasi.configure_with(&self.wasi_raw, !self.ignore_env)?;
+ self.record
+ .configure_with(&self.record_raw, !self.ignore_env)?;
+ Ok(())
+ }
+
+ /// Layers `other` on top of `self`.
+ ///
+ /// Each option that `other` specifies overrides the one in `self`, and
+ /// options that `other` doesn't specify are left as they are in `self`.
+ pub fn merge(&mut self, other: &mut CommonOptions) -> Result<()> {
+ self.configure()?;
+ other.configure()?;
+ let CommonOptions {
+ // Processed into the fields below by `configure`.
+ opts_raw: _,
+ codegen_raw: _,
+ debug_raw: _,
+ wasm_raw: _,
+ wasi_raw: _,
+ record_raw: _,
+ configured: _,
+ ignore_env: _,
+ config: _,
+
+ opts,
+ codegen,
+ debug,
+ wasm,
+ wasi,
+ record,
+ target,
+ } = other;
+ for opt in opts.to_options() {
+ self.opts.configure(&opt);
+ }
+ for opt in codegen.to_options() {
+ self.codegen.configure(&opt);
+ }
+ for opt in debug.to_options() {
+ self.debug.configure(&opt);
+ }
+ for opt in wasm.to_options() {
+ self.wasm.configure(&opt);
+ }
+ for opt in wasi.to_options() {
+ self.wasi.configure(&opt);
+ }
+ for opt in record.to_options() {
+ self.record.configure(&opt);
+ }
+ if target.is_some() {
+ self.target = target.clone();
+ }
Ok(())
}
@@ -932,9 +1093,21 @@ impl CommonOptions {
Ok(())
}
+ /// Returns a fresh new [`Config`] which reflects all configuration settings
+ /// in `self`.
pub fn config(&mut self, pooling_allocator_default: Option<bool>) -> Result<Config> {
- self.configure()?;
let mut config = Config::new();
+ self.apply_config(&mut config, pooling_allocator_default)?;
+ Ok(config)
+ }
+
+ /// Applies the options in `self` to an existing `config`.
+ pub fn apply_config(
+ &mut self,
+ config: &mut Config,
+ pooling_allocator_default: Option<bool>,
+ ) -> Result<()> {
+ self.configure()?;
match_feature! {
["cranelift" : self.codegen.compiler]
@@ -984,7 +1157,7 @@ impl CommonOptions {
true => err,
}
- self.enable_wasm_features(&mut config)?;
+ self.enable_wasm_features(config)?;
#[cfg(feature = "cranelift")]
for (name, value) in self.codegen.cranelift.iter() {
@@ -1284,10 +1457,6 @@ impl CommonOptions {
true => err,
}
- if let Some(enable) = self.wasm.gc_support {
- config.gc_support(enable);
- }
-
if let Some(enable) = self.wasm.concurrency_support {
config.concurrency_support(enable);
}
@@ -1305,98 +1474,80 @@ impl CommonOptions {
_ => err,
}
- Ok(config)
+ Ok(())
}
- pub fn enable_wasm_features(&self, config: &mut Config) -> Result<()> {
- let all = self.wasm.all_proposals;
-
- if let Some(enable) = self.wasm.simd.or(all) {
- config.wasm_simd(enable);
- }
- if let Some(enable) = self.wasm.relaxed_simd.or(all) {
- config.wasm_relaxed_simd(enable);
- }
- if let Some(enable) = self.wasm.bulk_memory.or(all) {
- config.wasm_bulk_memory(enable);
- }
- if let Some(enable) = self.wasm.multi_value.or(all) {
- config.wasm_multi_value(enable);
- }
- if let Some(enable) = self.wasm.tail_call.or(all) {
- config.wasm_tail_call(enable);
- }
- if let Some(enable) = self.wasm.multi_memory.or(all) {
- config.wasm_multi_memory(enable);
- }
- if let Some(enable) = self.wasm.memory64.or(all) {
- config.wasm_memory64(enable);
+ /// Applies the per-`Store` options in `self` to `store`.
+ ///
+ /// Note that [`CommonOptions::config`] or [`CommonOptions::apply_config`]
+ /// should be called before this to ensure options are processed internally
+ /// correctly.
+ #[cfg(feature = "runtime")]
+ pub fn configure_store<T>(&self, store: &mut wasmtime::Store<T>) -> Result<()> {
+ debug_assert!(self.configured, "`config` or `apply_config` not called");
+ #[cfg(feature = "component-model")]
+ {
+ if let Some(fuel) = self.wasi.hostcall_fuel {
+ store.set_hostcall_fuel(fuel);
+ }
+ if let Some(max) = self.wasi.max_component_handles {
+ store.set_max_component_handles(max);
+ }
}
- if let Some(enable) = self.wasm.stack_switching {
- config.wasm_stack_switching(enable);
+ #[cfg(feature = "async")]
+ if let Some(max) = self.wasi.max_fibers {
+ store.set_max_fibers(max);
}
- if let Some(enable) = self.wasm.custom_page_sizes.or(all) {
- config.wasm_custom_page_sizes(enable);
+ if let Some(fuel) = self.wasm.fuel {
+ store.set_fuel(fuel)?;
}
- if let Some(enable) = self.wasm.wide_arithmetic.or(all) {
- config.wasm_wide_arithmetic(enable);
+ Ok(())
+ }
+
+ fn enable_wasm_features(&self, config: &mut Config) -> Result<()> {
+ let all = self.wasm.all_proposals;
+ for (feature, option, _) in WASM_FEATURE_OPTIONS {
+ let mut value = option(&self.wasm);
+ // Exempt legacy exceptions from `-Wall-proposals`.
+ if *feature != F::LEGACY_EXCEPTIONS {
+ value = value.or(all);
+ }
+ if let Some(enable) = value {
+ config.wasm_features(*feature, enable);
+ }
}
- // Not included in `all_proposals`: off by default until fuzzed.
- if let Some(enable) = self.wasm.branch_hinting {
+
+ // Branch hinting is a setting of the compiler rather than a
+ // `WasmFeatures` flag.
+ if let Some(enable) = self.wasm.branch_hinting.or(all) {
config.wasm_branch_hinting(enable);
}
- // Not included in `all_proposals`: off by default until fuzzed.
- if let Some(enable) = self.wasm.compact_imports {
- config.wasm_compact_imports(enable);
- }
- if let Some(enable) = self.wasm.extended_const.or(all) {
- config.wasm_extended_const(enable);
- }
- macro_rules! handle_conditionally_compiled {
- ($(($feature:tt, $field:tt, $method:tt))*) => ($(
- if let Some(enable) = self.wasm.$field.or(all) {
- #[cfg(feature = $feature)]
- config.$method(enable);
- #[cfg(not(feature = $feature))]
- if enable && all.is_none() {
- bail!("support for {} was disabled at compile-time", $feature);
- }
- }
- )*)
- }
-
- handle_conditionally_compiled! {
- ("component-model", component_model, wasm_component_model)
- ("component-model-async", component_model_async, wasm_component_model_async)
- ("component-model-async", component_model_more_async_builtins, wasm_component_model_more_async_builtins)
- ("component-model-async", component_model_async_stackful, wasm_component_model_async_stackful)
- ("component-model-async", component_model_threading, wasm_component_model_threading)
- ("component-model", component_model_error_context, wasm_component_model_error_context)
- ("component-model", component_model_map, wasm_component_model_map)
- ("component-model", component_model_fixed_length_lists, wasm_component_model_fixed_length_lists)
- ("component-model", component_model_implements, wasm_component_model_implements)
- ("component-model", component_model_canonical_names, wasm_component_model_canonical_names)
- ("component-model", component_model_accessors, wasm_component_model_accessors)
- ("component-model", component_model_memory64, wasm_component_model_memory64)
- ("threads", threads, wasm_threads)
- ("gc", gc, wasm_gc)
- ("gc", reference_types, wasm_reference_types)
- ("gc", function_references, wasm_function_references)
- ("gc", exceptions, wasm_exceptions)
- ("stack-switching", stack_switching, wasm_stack_switching)
- }
-
- if let Some(enable) = self.wasm.component_model_gc {
- #[cfg(all(feature = "component-model", feature = "gc"))]
- config.wasm_component_model_gc(enable);
- #[cfg(not(all(feature = "component-model", feature = "gc")))]
- if enable && all.is_none() {
- bail!("support for `component-model-gc` was disabled at compile time")
+ Ok(())
+ }
+
+ /// Returns the names of the specified options that enable or disable a
+ /// WebAssembly feature, such as `simd` for `-W simd=y`.
+ ///
+ /// This includes `all-proposals` for `-W all-proposals`.
+ pub fn wasm_features_specified(&self) -> Vec<String> {
+ let mut ret = Vec::new();
+ for (feature, option, name) in WASM_FEATURE_OPTIONS {
+ if option(&self.wasm).is_none() {
+ continue;
}
+ ret.push(match name {
+ Some(name) => name.to_string(),
+ None => {
+ let (name, _) = feature.iter_names().next().unwrap();
+ name.to_lowercase().replace('_', "-")
+ }
+ });
}
-
- Ok(())
+ if self.wasm.all_proposals.is_some() {
+ ret.push("all-proposals".to_string());
+ }
+ ret
}
#[cfg(feature = "toml")]
@@ -1565,6 +1716,7 @@ impl CommonOptions {
component_model_threading: Some(features.contains(WasmFeatures::CM_THREADING)),
custom_page_sizes: Some(features.contains(WasmFeatures::CUSTOM_PAGE_SIZES)),
exceptions: Some(features.contains(WasmFeatures::EXCEPTIONS)),
+ legacy_exceptions: Some(features.contains(WasmFeatures::LEGACY_EXCEPTIONS)),
extended_const: Some(features.contains(WasmFeatures::EXTENDED_CONST)),
function_references: Some(features.contains(WasmFeatures::FUNCTION_REFERENCES)),
gc: Some(features.contains(WasmFeatures::GC)),
@@ -1620,6 +1772,7 @@ impl CommonOptions {
// CLI flags are represented above, they have default values here.
configured: true,
+ ignore_env: false,
codegen_raw: Default::default(),
debug_raw: Default::default(),
opts_raw: Default::default(),
@@ -1784,6 +1937,7 @@ impl fmt::Display for CommonOptions {
record_raw,
record,
configured,
+ ignore_env: _,
target,
config,
} = self;
diff --git a/crates/cli-flags/src/opt.rs b/crates/cli-flags/src/opt.rs
index bfebb1beaf..df1d3674f3 100644
--- a/crates/cli-flags/src/opt.rs
+++ b/crates/cli-flags/src/opt.rs
@@ -129,8 +129,16 @@ macro_rules! wasmtime_option_group {
}
impl $opts {
- fn configure_with(&mut self, opts: &[$crate::opt::CommaSeparated<$option>]) -> Result<()> {
- let env_opts = <$option as $crate::opt::WasmtimeOption>::parse_env()?;
+ fn configure_with(
+ &mut self,
+ opts: &[$crate::opt::CommaSeparated<$option>],
+ env: bool,
+ ) -> Result<()> {
+ let env_opts = if env {
+ <$option as $crate::opt::WasmtimeOption>::parse_env()?
+ } else {
+ Vec::new()
+ };
for opt in env_opts.iter().chain(opts.iter().flat_map(|o| o.0.iter())) {
self.configure(opt);
}
diff --git a/crates/fuzzing/Cargo.toml b/crates/fuzzing/Cargo.toml
index 7cc54edaa4..67f2c56f8f 100644
--- a/crates/fuzzing/Cargo.toml
+++ b/crates/fuzzing/Cargo.toml
@@ -36,7 +36,7 @@ wasm-smith = { workspace = true, features = ['serde'] }
wasm-mutate = { workspace = true }
wasmi = { version = "1.0.8", default-features = false, features = ["std", "simd"] }
futures = { workspace = true }
-wasmtime-test-util = { workspace = true, features = ['wast', 'component-fuzz', 'component'] }
+wasmtime-test-util = { workspace = true, features = ['wast', 'wasmtime-wast', 'component-fuzz', 'component'] }
serde_json = { workspace = true }
serde = { workspace = true }
diff --git a/crates/fuzzing/src/generators/config.rs b/crates/fuzzing/src/generators/config.rs
index 61b86ddd9e..dba59aaecc 100644
--- a/crates/fuzzing/src/generators/config.rs
+++ b/crates/fuzzing/src/generators/config.rs
@@ -119,108 +119,20 @@ impl Config {
/// Updates this configuration to be able to run the `test` specified.
///
- /// This primarily updates `self.module_config` to ensure that it enables
- /// all features and proposals necessary to execute the `test` specified.
- /// This will additionally update limits in the pooling allocator to be able
- /// to execute all tests.
+ /// This updates limits in the pooling allocator, and other settings, to be
+ /// able to execute all tests. The test's features and `flags` are applied
+ /// separately, see `oracles::wast_test`.
pub fn make_wast_test_compliant(&mut self, test: &WastTest) -> WastConfig {
- let wasmtime_test_util::wast::TestConfig {
- bulk_memory,
- memory64,
- custom_page_sizes,
- multi_memory,
- threads,
- shared_everything_threads,
- gc,
- function_references,
- relaxed_simd,
- reference_types,
- tail_call,
- extended_const,
- wide_arithmetic,
- branch_hinting,
- compact_imports,
- component_model_async,
- component_model_more_async_builtins,
- component_model_async_stackful,
- component_model_threading,
- component_model_error_context,
- component_model_gc,
- component_model_map,
- component_model_memory64,
- component_model_fixed_length_lists,
- component_model_implements,
- component_model_canonical_names,
- component_model_accessors,
- simd,
- exceptions,
- legacy_exceptions: _,
- custom_descriptors: _,
-
- hogs_memory: _,
- consume_fuel,
- nan_canonicalization: _,
- gc_types: _,
- stack_switching,
- spec_test: _,
- } = test.config;
-
- // Enable/disable some proposals that aren't configurable in wasm-smith
- // but are configurable in Wasmtime.
- self.module_config.function_references_enabled =
- function_references.or(gc).unwrap_or(false);
- self.module_config.component_model_async = component_model_async.unwrap_or(false);
- self.module_config.component_model_more_async_builtins =
- component_model_more_async_builtins.unwrap_or(false);
- self.module_config.component_model_async_stackful =
- component_model_async_stackful.unwrap_or(false);
- self.module_config.component_model_threading = component_model_threading.unwrap_or(false);
- self.module_config.component_model_error_context =
- component_model_error_context.unwrap_or(false);
- self.module_config.component_model_gc = component_model_gc.unwrap_or(false);
- self.module_config.component_model_map = component_model_map.unwrap_or(false);
- self.module_config.component_model_memory64 = component_model_memory64.unwrap_or(false);
- self.module_config.component_model_fixed_length_lists =
- component_model_fixed_length_lists.unwrap_or(false);
- self.module_config.component_model_implements = component_model_implements.unwrap_or(false);
- self.module_config.component_model_canonical_names =
- component_model_canonical_names.unwrap_or(false);
- self.module_config.component_model_accessors = component_model_accessors.unwrap_or(false);
- self.module_config.stack_switching = stack_switching.unwrap_or(false);
- self.wasmtime.branch_hinting = branch_hinting.unwrap_or(false);
- if consume_fuel.unwrap_or(false) {
- self.wasmtime.consume_fuel = true;
- }
-
- // Enable/disable proposals that wasm-smith has knobs for which will be
- // read when creating `wasmtime::Config`.
- let config = &mut self.module_config.config;
- config.bulk_memory_enabled = bulk_memory.unwrap_or(false);
- config.multi_value_enabled = true;
- config.wide_arithmetic_enabled = wide_arithmetic.unwrap_or(false);
- config.compact_imports_enabled = compact_imports.unwrap_or(false);
- config.memory64_enabled = memory64.unwrap_or(false);
- config.relaxed_simd_enabled = relaxed_simd.unwrap_or(false);
- config.simd_enabled = config.relaxed_simd_enabled || simd.unwrap_or(false);
- config.tail_call_enabled = tail_call.unwrap_or(false);
- config.custom_page_sizes_enabled = custom_page_sizes.unwrap_or(false);
- config.threads_enabled = threads.unwrap_or(false);
- config.shared_everything_threads_enabled = shared_everything_threads.unwrap_or(false);
- config.gc_enabled = gc.unwrap_or(false);
- config.reference_types_enabled = config.gc_enabled
- || self.module_config.function_references_enabled
- || self.module_config.component_model_async
- || reference_types.unwrap_or(false);
- config.extended_const_enabled = extended_const.unwrap_or(false);
- config.exceptions_enabled =
- self.module_config.stack_switching || exceptions.unwrap_or(false);
- if multi_memory.unwrap_or(false) {
- config.max_memories = limits::MEMORIES_PER_MODULE as usize;
- } else {
- config.max_memories = 1;
- }
-
- if self.module_config.stack_switching {
+ // Features, flags, etc, within `test` will all get overlaid on top of
+ // `self` by default. This means that we don't have to fully reflect all
+ // of `test` into `self`, for example all individual wasm features. We
+ // do reflect some minor things, though, when they affect other options
+ // that are otherwise configured.
+ //
+ // For example `threads_enabled` here feeds into memory configuration
+ // and whether that's respected.
+ self.module_config.config.threads_enabled = test.config.threads();
+ if test.config.stack_switching() {
self.wasmtime.inlining = Some(Inlining::No);
}
@@ -285,13 +197,6 @@ impl Config {
// which is used afterwards to test if the `test` here is expected to
// fail or not.
WastConfig {
- collector: match self.wasmtime.collector {
- Collector::Null => wasmtime_test_util::wast::Collector::Null,
- Collector::DeferredReferenceCounting => {
- wasmtime_test_util::wast::Collector::DeferredReferenceCounting
- }
- Collector::Copying => wasmtime_test_util::wast::Collector::Copying,
- },
pooling: matches!(
self.wasmtime.strategy,
InstanceAllocationStrategy::Pooling(_)
@@ -310,6 +215,15 @@ impl Config {
/// Converts this to a `wasmtime::Config` object
pub fn to_wasmtime(&self) -> wasmtime::Config {
+ self.to_wasmtime_with(&mut self.to_common_options())
+ }
+
+ /// Converts this to the `wasmtime` CLI options that it represents.
+ ///
+ /// Note that some of this configuration, such as async settings, isn't
+ /// representable as CLI options and is only applied by
+ /// [`Config::to_wasmtime_with`].
+ pub fn to_common_options(&self) -> wasmtime_cli_flags::CommonOptions {
crate::init_fuzzing();
let mut cfg = wasmtime_cli_flags::CommonOptions::default();
@@ -468,8 +382,19 @@ impl Config {
memory_config.configure(&mut cfg);
}
- log::debug!("creating wasmtime config with CLI options:\n{cfg}");
- let mut cfg = cfg.config(None).expect("failed to create wasmtime::Config");
+ cfg
+ }
+
+ /// Creates a `wasmtime::Config` from `opts`, which are typically from
+ /// [`Config::to_common_options`] with further adjustments.
+ pub fn to_wasmtime_with(
+ &self,
+ opts: &mut wasmtime_cli_flags::CommonOptions,
+ ) -> wasmtime::Config {
+ log::debug!("creating wasmtime config with CLI options:\n{opts}");
+ let mut cfg = opts
+ .config(None)
+ .expect("failed to create wasmtime::Config");
if self.wasmtime.async_config != AsyncConfig::Disabled {
log::debug!("async config in use {:?}", self.wasmtime.async_config);
diff --git a/crates/fuzzing/src/oracles.rs b/crates/fuzzing/src/oracles.rs
index 661cb7c201..3dcae7a8ba 100644
--- a/crates/fuzzing/src/oracles.rs
+++ b/crates/fuzzing/src/oracles.rs
@@ -693,9 +693,17 @@ pub fn wast_test(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<()> {
wasmtime_wast::Async::Yes
};
log::debug!("async: {async_:?}");
- let engine = Engine::new(&fuzz_config.to_wasmtime()).unwrap();
+ // The test's configuration is layered on top of the fuzz configuration toe
+ // ensure that any explicitly specified configuration overrides whatever the
+ // fuzz-generated input selected.
+ let mut opts = fuzz_config.to_common_options();
+ test.config
+ .apply(&mut opts)
+ .expect("invalid `flags` in wast test");
+ let engine = Engine::new(&fuzz_config.to_wasmtime_with(&mut opts)).unwrap();
let mut wast_context = WastContext::new(&engine, async_, move |store| {
fuzz_config.configure_store_epoch_and_fuel(store);
+ opts.configure_store(store).unwrap();
});
wast_context.ignore_error_messages(test.config.spec_test.unwrap_or(false));
wast_context
diff --git a/crates/test-macros/src/wasmtime_test.rs b/crates/test-macros/src/wasmtime_test.rs
index 7f6bc58e34..3f2c463682 100644
--- a/crates/test-macros/src/wasmtime_test.rs
+++ b/crates/test-macros/src/wasmtime_test.rs
@@ -339,19 +339,10 @@ fn expand(test_config: &TestConfig, func: Fn) -> Result<TokenStream> {
return;
}
let _ = env_logger::try_init();
- let mut config = Config::new();
- wasmtime_test_util::wasmtime_wast::apply_test_config(
- &mut config,
- &#flags,
- );
- wasmtime_test_util::wasmtime_wast::apply_wast_config(
- &mut config,
- &wasmtime_test_util::wast::WastConfig {
- compiler,
- pooling: false,
- collector: wasmtime_test_util::wast::Collector::#collector_ident,
- },
- );
+ let mut opts = compiler.common_options();
+ opts.codegen.collector = Some(wasmtime::Collector::#collector_ident);
+ #flags.apply(&mut opts).unwrap();
+ let mut config: Config = opts.config(None).unwrap();
let result = #func_name(&mut config) #await_;
if compiler.should_fail(&#flags) {
assert!(result.is_err());
diff --git a/crates/test-util/Cargo.toml b/crates/test-util/Cargo.toml
index b0073ef039..4951d8d08c 100644
--- a/crates/test-util/Cargo.toml
+++ b/crates/test-util/Cargo.toml
@@ -25,6 +25,8 @@ target-lexicon = { workspace = true, optional = true }
env_logger = { workspace = true, optional = true }
wasmtime = { workspace = true, optional = true }
indexmap = { workspace = true, optional = true, features = ['std'] }
+wasmtime-cli-flags = { workspace = true, optional = true, features = ['clap'] }
+clap = { workspace = true, optional = true }
# NB: this crate is compiled both in as a dependency of a proc-macro and as a
# dependency of tests themselves. That means dependencies of this crate are
# compiled twice. Try to ensure "big" dependencies are optional and feature
@@ -43,16 +45,30 @@ wast = [
'dep:toml',
'dep:serde_derive',
]
+# Building `wasmtime_cli_flags::CommonOptions` and `wasmtime::Config` for tests.
wasmtime-wast = [
'wast',
'dep:wasmtime',
+ 'dep:wasmtime-cli-flags',
+ 'dep:clap',
+ 'dep:target-lexicon',
'wasmtime/cranelift',
'wasmtime/winch',
'wasmtime/gc-drc',
'wasmtime/gc-null',
'wasmtime/threads',
'wasmtime/component-model-async',
- 'dep:target-lexicon',
+ 'wasmtime-cli-flags/runtime',
+ 'wasmtime-cli-flags/cranelift',
+ 'wasmtime-cli-flags/gc-drc',
+ 'wasmtime-cli-flags/gc-null',
+ 'wasmtime-cli-flags/threads',
+ 'wasmtime-cli-flags/component-model',
+ 'wasmtime-cli-flags/component-model-async',
+ 'wasmtime-cli-flags/async',
+ 'wasmtime-cli-flags/stack-switching',
+ 'wasmtime-cli-flags/pooling-allocator',
+ 'wasmtime-cli-flags/memory-protection-keys',
]
component = [
'arbitrary/derive',
diff --git a/crates/test-util/src/wasmtime_wast.rs b/crates/test-util/src/wasmtime_wast.rs
index 995600ba37..4fb59b87eb 100644
--- a/crates/test-util/src/wasmtime_wast.rs
+++ b/crates/test-util/src/wasmtime_wast.rs
@@ -1,152 +1,188 @@
-use crate::wast;
-use wasmtime::Config;
+//! Translation of test configuration in [`crate::wast`] into Wasmtime
+//! configuration.
+//!
+//! Everything is expressed as [`CommonOptions`], the same options the
+//! `wasmtime` CLI accepts. Harnesses follow the same steps:
+//!
+//! 1. Start from [`Compiler::common_options`], or their own options.
+//! 2. Make their own adjustments, such as memory limits.
+//! 3. Apply the test with [`TestConfig::apply`], last so the test has the
+//! final say.
+//! 4. Create a [`wasmtime::Config`] with [`CommonOptions::config`] and
+//! configure each [`wasmtime::Store`] with
+//! [`CommonOptions::configure_store`].
-/// Helper method to apply `wast_config` to `config`.
-pub fn apply_wast_config(config: &mut Config, wast_config: &wast::WastConfig) {
- use wasmtime_environ::TripleExt;
- use wast::{Collector, Compiler};
+use crate::wast::{Compiler, TestConfig};
+use wasmtime::{Result, bail, format_err};
+use wasmtime_cli_flags::CommonOptions;
- config.strategy(match wast_config.compiler {
- Compiler::CraneliftNative | Compiler::CraneliftPulley => wasmtime::Strategy::Cranelift,
- Compiler::Winch => wasmtime::Strategy::Winch,
- });
- if let Compiler::CraneliftPulley = wast_config.compiler {
- config
- .target(&target_lexicon::Triple::pulley_host().to_string())
- .unwrap();
+impl TestConfig {
+ /// Applies this test's configuration on top of `opts`.
+ ///
+ /// This sets the test's WebAssembly features and then applies its own
+ /// `flags`, which override anything already in `opts`.
+ ///
+ /// Returns an error if the flags set a WebAssembly feature, which must use
+ /// the boolean options of `TestConfig` instead, or an option that the
+ /// harness owns because it's described by [`crate::wast::WastConfig`]: the compiler,
+ /// the target, or the pooling allocator.
+ pub fn apply(&self, opts: &mut CommonOptions) -> Result<()> {
+ self.apply_features(opts);
+ let mut flags = self.flags()?;
+ opts.merge(&mut flags)?;
+
+ // Reject `flags` that are supposed to be configured elsewhere in the
+ // harness for testing wasts and such. This ensures that `should_fail`
+ // calculations have all relevant info to make a decision since `flags`
+ // aren't factored in at all there.
+ if let Some(name) = flags.wasm_features_specified().first() {
+ bail!("`flags` cannot set the wasm feature `-W {name}`, use `;;!` feature options");
+ }
+ if flags.codegen.compiler.is_some() {
+ bail!("`flags` cannot set `-C compiler`, it's chosen by the harness");
+ }
+ if flags.target.is_some() {
+ bail!("`flags` cannot set `--target`, it's chosen by the harness");
+ }
+ if flags.opts.pooling_allocator.is_some() {
+ bail!("`flags` cannot set `-O pooling-allocator`, it's chosen by the harness");
+ }
+ Ok(())
}
- config.collector(match wast_config.collector {
- Collector::Auto => wasmtime::Collector::Auto,
- Collector::Null => wasmtime::Collector::Null,
- Collector::DeferredReferenceCounting => wasmtime::Collector::DeferredReferenceCounting,
- Collector::Copying => wasmtime::Collector::Copying,
- });
-}
-/// Helper method to apply `test_config` to `config`.
-pub fn apply_test_config(config: &mut Config, test_config: &wast::TestConfig) {
- let wast::TestConfig {
- bulk_memory,
- memory64,
- custom_page_sizes,
- multi_memory,
- threads,
- shared_everything_threads,
- gc,
- function_references,
- relaxed_simd,
- reference_types,
- tail_call,
- extended_const,
- wide_arithmetic,
- branch_hinting,
- compact_imports,
- component_model_async,
- component_model_more_async_builtins,
- component_model_async_stackful,
- component_model_threading,
- component_model_error_context,
- component_model_gc,
- component_model_map,
- component_model_memory64,
- component_model_fixed_length_lists,
- component_model_implements,
- component_model_canonical_names,
- component_model_accessors,
- nan_canonicalization,
- consume_fuel,
- simd,
- exceptions,
- legacy_exceptions,
- stack_switching,
- custom_descriptors,
- gc_types,
+ /// Sets the WebAssembly features in `opts` to those of this test.
+ ///
+ /// Every feature is set explicitly, and features the test doesn't list
+ /// are disabled. This ensures tests are annotated with the features they
+ /// need, even after a feature becomes enabled by default. Features that
+ /// enabled features depend on, such as `function_references` for `gc`,
+ /// are enabled too.
+ fn apply_features(&self, opts: &mut CommonOptions) {
+ let TestConfig {
+ bulk_memory,
+ memory64,
+ custom_page_sizes,
+ multi_memory,
+ threads,
+ shared_everything_threads,
+ gc,
+ function_references,
+ relaxed_simd,
+ reference_types,
+ tail_call,
+ extended_const,
+ wide_arithmetic,
+ compact_imports,
+ component_model_async,
+ component_model_more_async_builtins,
+ component_model_async_stackful,
+ component_model_threading,
+ component_model_error_context,
+ component_model_gc,
+ component_model_map,
+ component_model_memory64,
+ component_model_fixed_length_lists,
+ component_model_implements,
+ component_model_canonical_names,
+ component_model_accessors,
+ simd,
+ exceptions,
+ legacy_exceptions,
+ stack_switching,
+ // Not implemented in Wasmtime yet.
+ custom_descriptors: _,
+
+ // Not features.
+ hogs_memory: _,
+ spec_test: _,
+ flags: _,
+ } = *self;
+
+ let on = |feature: Option<bool>| feature.unwrap_or(false);
+
+ // Enable the features that enabled features depend on, so tests only
+ // need to list the feature they're testing.
+ let gc = on(gc);
+ let function_references = gc || on(function_references);
+ let reference_types =
+ function_references || on(component_model_async) || on(reference_types);
+ let relaxed_simd = on(relaxed_simd);
+ let simd = relaxed_simd || on(simd);
+ let stack_switching = on(stack_switching);
+ let exceptions = stack_switching || on(exceptions);
+
+ let w = &mut opts.wasm;
+ w.bulk_memory = Some(on(bulk_memory));
+ w.memory64 = Some(on(memory64));
+ w.custom_page_sizes = Some(on(custom_page_sizes));
+ w.multi_memory = Some(on(multi_memory));
+ w.threads = Some(on(threads));
+ w.shared_everything_threads = Some(on(shared_everything_threads));
+ w.gc = Some(gc);
+ w.function_references = Some(function_references);
+ w.relaxed_simd = Some(relaxed_simd);
+ w.reference_types = Some(reference_types);
+ w.tail_call = Some(on(tail_call));
+ w.extended_const = Some(on(extended_const));
+ w.wide_arithmetic = Some(on(wide_arithmetic));
+ w.compact_imports = Some(on(compact_imports));
+ w.component_model_async = Some(on(component_model_async));
+ w.component_model_more_async_builtins = Some(on(component_model_more_async_builtins));
+ w.component_model_async_stackful = Some(on(component_model_async_stackful));
+ w.component_model_threading = Some(on(component_model_threading));
+ w.component_model_error_context = Some(on(component_model_error_context));
+ w.component_model_gc = Some(on(component_model_gc));
+ w.component_model_map = Some(on(component_model_map));
+ w.component_model_memory64 = Some(on(component_model_memory64));
+ w.component_model_fixed_length_lists = Some(on(component_model_fixed_length_lists));
+ w.component_model_implements = Some(on(component_model_implements));
+ w.component_model_canonical_names = Some(on(component_model_canonical_names));
+ w.component_model_accessors = Some(on(component_model_accessors));
+ w.simd = Some(simd);
+ w.exceptions = Some(exceptions);
+ w.legacy_exceptions = Some(on(legacy_exceptions));
+ w.stack_switching = Some(stack_switching);
- hogs_memory: _,
- spec_test: _,
- } = *test_config;
- // Note that all of these proposals/features are currently default-off to
- // ensure that we annotate all tests accurately with what features they
- // need, even in the future when features are stabilized.
- let bulk_memory = bulk_memory.unwrap_or(false);
- let memory64 = memory64.unwrap_or(false);
- let custom_page_sizes = custom_page_sizes.unwrap_or(false);
- let multi_memory = multi_memory.unwrap_or(false);
- let threads = threads.unwrap_or(false);
- let shared_everything_threads = shared_everything_threads.unwrap_or(false);
- let gc = gc.unwrap_or(false);
- let tail_call = tail_call.unwrap_or(false);
- let extended_const = extended_const.unwrap_or(false);
- let wide_arithmetic = wide_arithmetic.unwrap_or(false);
- let branch_hinting = branch_hinting.unwrap_or(false);
- let compact_imports = compact_imports.unwrap_or(false);
- let component_model_async = component_model_async.unwrap_or(false);
- let component_model_more_async_builtins = component_model_more_async_builtins.unwrap_or(false);
- let component_model_async_stackful = component_model_async_stackful.unwrap_or(false);
- let component_model_threading = component_model_threading.unwrap_or(false);
- let component_model_error_context = component_model_error_context.unwrap_or(false);
- let component_model_gc = component_model_gc.unwrap_or(false);
- let component_model_map = component_model_map.unwrap_or(false);
- let component_model_memory64 = component_model_memory64.unwrap_or(false);
- let component_model_fixed_length_lists = component_model_fixed_length_lists.unwrap_or(false);
- let component_model_implements = component_model_implements.unwrap_or(false);
- let component_model_canonical_names = component_model_canonical_names.unwrap_or(false);
- let component_model_accessors = component_model_accessors.unwrap_or(false);
- let nan_canonicalization = nan_canonicalization.unwrap_or(false);
- let relaxed_simd = relaxed_simd.unwrap_or(false);
- let legacy_exceptions = legacy_exceptions.unwrap_or(false);
- let stack_switching = stack_switching.unwrap_or(false);
+ // Multi-value is part of the baseline that all tests assume.
+ w.multi_value = Some(true);
- // Some proposals in wasm depend on previous proposals. For example the gc
- // proposal depends on function-references which depends on reference-types.
- // To avoid needing to enable all of them at once implicitly enable
- // downstream proposals once the end proposal is enabled (e.g. when enabling
- // gc that also enables function-references and reference-types).
- let function_references = gc || function_references.unwrap_or(false);
- let reference_types =
- function_references || component_model_async || reference_types.unwrap_or(false);
- let simd = relaxed_simd || simd.unwrap_or(false);
+ // GC infrastructure in Wasmtime is needed for any GC reference.
+ w.gc_support = Some(gc || exceptions || reference_types);
+ }
+
+ /// Parses this test's `flags`. Options that the flags don't specify are
+ /// unset.
+ fn flags(&self) -> Result<CommonOptions> {
+ use clap::Parser;
+
+ let mut args = vec!["wasmtime"];
+ if let Some(flags) = &self.flags {
+ args.extend(flags.to_vec());
+ }
+ let mut flags = CommonOptions::try_parse_from(&args)
+ .map_err(|e| format_err!("failed to parse `flags`: {e}"))?;
+ // Tests are configured by their `flags`, not the environment.
+ flags.ignore_env = true;
+ Ok(flags)
+ }
+}
- let exceptions = stack_switching || exceptions.unwrap_or(false);
- let gc_types = gc || exceptions || reference_types || gc_types.unwrap_or(false);
+impl Compiler {
+ /// Returns the options to run tests with this compiler.
+ pub fn common_options(&self) -> CommonOptions {
+ use wasmtime_environ::TripleExt;
- // Not implemented in Wasmtime yet.
- let _custom_descriptors = custom_descriptors.unwrap_or(false);
+ let mut opts = CommonOptions::new();
+ // Tests shouldn't read or write the global compilation cache.
+ opts.codegen.cache = Some(false);
- config
- .wasm_bulk_memory(bulk_memory)
- .wasm_multi_memory(multi_memory)
- .wasm_threads(threads)
- .wasm_shared_everything_threads(shared_everything_threads)
- .wasm_memory64(memory64)
- .wasm_function_references(function_references)
- .wasm_gc(gc)
- .wasm_reference_types(reference_types)
- .wasm_relaxed_simd(relaxed_simd)
- .wasm_simd(simd)
- .wasm_tail_call(tail_call)
- .wasm_custom_page_sizes(custom_page_sizes)
- .wasm_extended_const(extended_const)
- .wasm_wide_arithmetic(wide_arithmetic)
- .wasm_branch_hinting(branch_hinting)
- .wasm_compact_imports(compact_imports)
- .wasm_component_model_async(component_model_async)
- .wasm_component_model_more_async_builtins(component_model_more_async_builtins)
- .wasm_component_model_async_stackful(component_model_async_stackful)
- .wasm_component_model_threading(component_model_threading)
- .wasm_component_model_error_context(component_model_error_context)
- .wasm_component_model_gc(component_model_gc)
- .wasm_component_model_map(component_model_map)
- .wasm_component_model_memory64(component_model_memory64)
- .wasm_component_model_fixed_length_lists(component_model_fixed_length_lists)
- .wasm_component_model_implements(component_model_implements)
- .wasm_component_model_canonical_names(component_model_canonical_names)
- .wasm_component_model_accessors(component_model_accessors)
- .wasm_exceptions(exceptions)
- .wasm_stack_switching(stack_switching)
- .gc_support(gc_types)
- .cranelift_nan_canonicalization(nan_canonicalization)
- .consume_fuel(consume_fuel.unwrap_or(false));
- #[expect(deprecated, reason = "forwarding legacy-exceptions")]
- config.wasm_legacy_exceptions(legacy_exceptions);
+ opts.codegen.compiler = Some(match self {
+ Compiler::CraneliftNative | Compiler::CraneliftPulley => wasmtime::Strategy::Cranelift,
+ Compiler::Winch => wasmtime::Strategy::Winch,
+ });
+ if let Compiler::CraneliftPulley = self {
+ opts.target = Some(target_lexicon::Triple::pulley_host().to_string());
+ }
+ opts
+ }
}
diff --git a/crates/test-util/src/wast.rs b/crates/test-util/src/wast.rs
index 2e198071d6..52e95896a6 100644
--- a/crates/test-util/src/wast.rs
+++ b/crates/test-util/src/wast.rs
@@ -355,11 +355,8 @@ macro_rules! foreach_config_option {
tail_call
extended_const
wide_arithmetic
- branch_hinting
compact_imports
hogs_memory
- consume_fuel
- nan_canonicalization
component_model_async
component_model_more_async_builtins
component_model_async_stackful
@@ -373,7 +370,6 @@ macro_rules! foreach_config_option {
component_model_canonical_names
component_model_accessors
simd
- gc_types
exceptions
legacy_exceptions
stack_switching
@@ -385,12 +381,25 @@ macro_rules! foreach_config_option {
macro_rules! define_test_config {
($($option:ident)*) => {
- /// Per-test configuration which is written down in the test file itself for
- /// `misc_testsuite/**/*.wast` or in `spec_test_config` above for spec tests.
+ /// Per-test configuration which is written down in the test file itself
+ /// for `misc_testsuite/**/*.wast` or in `spec_test_config` above for
+ /// spec tests.
#[derive(Debug, PartialEq, Default, Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct TestConfig {
+ // Boolean options for each wasm feature.
$(pub $option: Option<bool>,)*
+
+ /// Mostly arbitrary Wasmtime CLI flags to configure the engine and
+ /// store with.
+ ///
+ /// Flags which affect wasm features, plus some major decisions like
+ /// `-Ccompiler`, are rejected here. This field is opaque to
+ /// `should_fail` calculations below, so nothing specified here can
+ /// affect that result. Hence why major decisions like `-Ccompiler`
+ /// are rejected as they must be representable in such a way that
+ /// `should_fail` can test for.
+ pub flags: Option<TestFlags>,
}
impl TestConfig {
@@ -405,6 +414,38 @@ macro_rules! define_test_config {
foreach_config_option!(define_test_config);
+/// The `flags` key of a [`TestConfig`]: either one string of
+/// whitespace-separated flags or a list of flags.
+#[derive(PartialEq, Deserialize, Clone)]
+#[serde(untagged)]
+pub enum TestFlags {
+ SpaceSeparated(String),
+ List(Vec<String>),
+}
+
+// The `Debug` output of `TestConfig` is embedded as Rust source by
+// `crates/fuzzing/build.rs` and `#[wasmtime_test]`, so this prints a Rust
+// expression.
+impl fmt::Debug for TestFlags {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "wasmtime_test_util::wast::TestFlags::List(vec![")?;
+ for flag in self.to_vec() {
+ write!(f, "{flag:?}.to_string(),")?;
+ }
+ write!(f, "])")
+ }
+}
+
+impl TestFlags {
+ /// Returns each individual flag.
+ pub fn to_vec(&self) -> Vec<&str> {
+ match self {
+ TestFlags::SpaceSeparated(s) => s.split_whitespace().collect(),
+ TestFlags::List(s) => s.iter().map(|s| s.as_str()).collect(),
+ }
+ }
+}
+
impl TestConfig {
/// Returns an iterator over each option.
pub fn options_mut(&mut self) -> impl Iterator<Item = (&'static str, &mut Option<bool>)> {
@@ -426,8 +467,6 @@ pub struct WastConfig {
pub compiler: Compiler,
/// Whether or not the pooling allocator is enabled.
pub pooling: bool,
- /// What garbage collector is being used.
- pub collector: Collector,
}
/// Different compilers that can be tested in Wasmtime.
@@ -531,12 +570,6 @@ pub enum Collector {
}
impl WastTest {
- /// Returns whether this test exercises the GC types and might want to use
- /// multiple different garbage collectors.
- pub fn test_uses_gc_types(&self) -> bool {
- self.config.gc() || self.config.function_references()
- }
-
/// Returns the optional spec proposal that this test is associated with.
pub fn spec_proposal(&self) -> Option<&str> {
spec_proposal_from_path(&self.path)
diff --git a/src/commands/wast.rs b/src/commands/wast.rs
index 272a85906c..7f26e2da53 100644
--- a/src/commands/wast.rs
+++ b/src/commands/wast.rs
@@ -57,6 +57,7 @@ impl WastCommand {
let async_ = optional_flag_with_default(self.async_, true);
let mut config = self.common.config(None)?;
config.shared_memory(true);
+ let common = self.common.clone();
let generate_dwarf = optional_flag_with_default(self.generate_dwarf, true);
// When DWARF is being generated go ahead and enable backtrace details
@@ -73,10 +74,8 @@ impl WastCommand {
wasmtime_wast::Async::No
},
move |store| {
- if let Some(fuel) = self.common.wasm.fuel {
- store.set_fuel(fuel).unwrap();
- }
- if let Some(true) = self.common.wasm.epoch_interruption {
+ common.configure_store(store).unwrap();
+ if let Some(true) = common.wasm.epoch_interruption {
store.epoch_deadline_trap();
store.set_epoch_deadline(1);
}
diff --git a/src/common.rs b/src/common.rs
index d86dd1415b..e180948ff4 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -525,24 +525,10 @@ impl RunCommon {
table.set_max_capacity(max);
}
}
- if let Some(fuel) = self.common.wasi.hostcall_fuel {
- store.set_hostcall_fuel(fuel);
- }
- if let Some(max) = self.common.wasi.max_component_handles {
- store.set_max_component_handles(max);
- }
- if let Some(max) = self.common.wasi.max_fibers {
- store.set_max_fibers(max);
- }
+ self.common.configure_store(store)?;
*limits(store.data_mut()) = self.store_limits();
store.limiter(move |t| limits(t));
-
- // If fuel has been configured, we want to add the configured
- // fuel amount to this store.
- if let Some(fuel) = self.common.wasm.fuel {
- store.set_fuel(fuel)?;
- }
Ok(())
}
}
diff --git a/tests/all/func.rs b/tests/all/func.rs
index 6a215d41d8..3a6219ccc4 100644
--- a/tests/all/func.rs
+++ b/tests/all/func.rs
@@ -1528,7 +1528,7 @@ fn typed_funcs_count_params_correctly_in_error_messages(
Ok(())
}
-#[wasmtime_test(wasm_features(reference_types, gc_types))]
+#[wasmtime_test(wasm_features(reference_types))]
#[cfg_attr(miri, ignore)]
fn calls_with_funcref_and_externref(config: &mut Config) -> wasmtime::Result<()> {
let engine = Engine::new(&config)?;
diff --git a/tests/misc_testsuite/branch-hinting-invalid.wast b/tests/misc_testsuite/branch-hinting-invalid.wast
index d8a0a9ef95..a3e57e9b69 100644
--- a/tests/misc_testsuite/branch-hinting-invalid.wast
+++ b/tests/misc_testsuite/branch-hinting-invalid.wast
@@ -1,4 +1,4 @@
-;;! branch_hinting = true
+;;! flags = "-W branch-hinting"
;; A malformed `metadata.code.branch_hint` section must be ignored, not rejected:
;; the section is advisory and unvalidated, so a decode error discards it and
diff --git a/tests/misc_testsuite/branch-hinting.wast b/tests/misc_testsuite/branch-hinting.wast
index 054d1eba90..b7e93c88cb 100644
--- a/tests/misc_testsuite/branch-hinting.wast
+++ b/tests/misc_testsuite/branch-hinting.wast
@@ -1,4 +1,4 @@
-;;! branch_hinting = true
+;;! flags = "-W branch-hinting"
;; Branch hints are advisory: with the proposal enabled a hinted module must
;; still produce the same results it would without hints. Both functions return
diff --git a/tests/misc_testsuite/canonicalize-nan-scalar.wast b/tests/misc_testsuite/canonicalize-nan-scalar.wast
index 8b019cdec8..2bc0fc4929 100644
--- a/tests/misc_testsuite/canonicalize-nan-scalar.wast
+++ b/tests/misc_testsuite/canonicalize-nan-scalar.wast
@@ -1,4 +1,4 @@
-;;! nan_canonicalization = true
+;;! flags = "-W nan-canonicalization"
;; Scalar counterpart to simd/canonicalize-nan.wast.
diff --git a/tests/misc_testsuite/component-model/async/subtask-drop-exited.wast b/tests/misc_testsuite/component-model/async/subtask-drop-exited.wast
index a71a41f5c8..5b8553c31d 100644
--- a/tests/misc_testsuite/component-model/async/subtask-drop-exited.wast
+++ b/tests/misc_testsuite/component-model/async/subtask-drop-exited.wast
@@ -1,6 +1,5 @@
;;! component_model_async = true
;;! reference_types = true
-;;! gc_types = true
(component
(component $C
diff --git a/tests/misc_testsuite/component-model/gc/empty.wast b/tests/misc_testsuite/component-model/gc/empty.wast
index 4a96753ab5..d2006615f6 100644
--- a/tests/misc_testsuite/component-model/gc/empty.wast
+++ b/tests/misc_testsuite/component-model/gc/empty.wast
@@ -1,7 +1,6 @@
;;! component_model_gc = true
;;! gc = true
;;! reference_types = true
-;;! gc_types = true
;;! multi_memory = true
;; GC calling GC.
diff --git a/tests/misc_testsuite/fuel/bulk-ops.wast b/tests/misc_testsuite/fuel/bulk-ops.wast
index ae9afd07b1..9cd4427325 100644
--- a/tests/misc_testsuite/fuel/bulk-ops.wast
+++ b/tests/misc_testsuite/fuel/bulk-ops.wast
@@ -1,7 +1,7 @@
;;! bulk_memory = true
;;! reference_types = true
;;! memory64 = true
-;;! consume_fuel = true
+;;! flags = "-W fuel=1000000000"
;; Fuel charged by bulk memory and table operations, on top of the usual cost
;; per operator. Like `costs.wast`, each test sets the fuel to 1000,
diff --git a/tests/misc_testsuite/fuel/costs-gc.wast b/tests/misc_testsuite/fuel/costs-gc.wast
index f8fe76bef1..b0172cfa89 100644
--- a/tests/misc_testsuite/fuel/costs-gc.wast
+++ b/tests/misc_testsuite/fuel/costs-gc.wast
@@ -2,7 +2,7 @@
;;! gc = true
;;! function_references = true
;;! exceptions = true
-;;! consume_fuel = true
+;;! flags = "-W fuel=1000000000"
;; Like `costs.wast`, but for the tests that need GC or typed function
;; references. Each test sets the store's fuel to 1000, instantiates a module
diff --git a/tests/misc_testsuite/fuel/costs.wast b/tests/misc_testsuite/fuel/costs.wast
index 50ecb28b45..87af64b1b5 100644
--- a/tests/misc_testsuite/fuel/costs.wast
+++ b/tests/misc_testsuite/fuel/costs.wast
@@ -1,7 +1,7 @@
;;! bulk_memory = true
;;! reference_types = true
;;! exceptions = true
-;;! consume_fuel = true
+;;! flags = "-W fuel=1000000000"
;; Each test sets the store's fuel to 1000, instantiates a module (usually
;; running its start function), and checks exactly how much fuel is left.
diff --git a/tests/misc_testsuite/fuel/execution.wast b/tests/misc_testsuite/fuel/execution.wast
index 7116292ff8..273bc13bdd 100644
--- a/tests/misc_testsuite/fuel/execution.wast
+++ b/tests/misc_testsuite/fuel/execution.wast
@@ -1,7 +1,7 @@
;;! reference_types = true
;;! exceptions = true
;;! extended_const = true
-;;! consume_fuel = true
+;;! flags = "-W fuel=1000000000"
(module $Fuel
(import "wasmtime" "set-fuel" (func $set (param i64)))
diff --git a/tests/misc_testsuite/fuel/gc.wast b/tests/misc_testsuite/fuel/gc.wast
index 9faf17b2cc..ead711b392 100644
--- a/tests/misc_testsuite/fuel/gc.wast
+++ b/tests/misc_testsuite/fuel/gc.wast
@@ -1,6 +1,6 @@
;;! bulk_memory = true
;;! gc = true
-;;! consume_fuel = true
+;;! flags = "-W fuel=1000000000"
(module $Fuel
(import "wasmtime" "set-fuel" (func $set (param i64)))
diff --git a/tests/misc_testsuite/fuel/iloop.wast b/tests/misc_testsuite/fuel/iloop.wast
index 7956c41dc0..a60e8de9e4 100644
--- a/tests/misc_testsuite/fuel/iloop.wast
+++ b/tests/misc_testsuite/fuel/iloop.wast
@@ -1,4 +1,4 @@
-;;! consume_fuel = true
+;;! flags = "-W fuel=1000000000"
;; Infinite loops and exponential call trees run out of fuel.
(module $Fuel
diff --git a/tests/misc_testsuite/simd/canonicalize-nan.wast b/tests/misc_testsuite/simd/canonicalize-nan.wast
index 3cb4609479..3f41be9738 100644
--- a/tests/misc_testsuite/simd/canonicalize-nan.wast
+++ b/tests/misc_testsuite/simd/canonicalize-nan.wast
@@ -1,5 +1,5 @@
-;;! nan_canonicalization = true
;;! simd = true
+;;! flags = "-W nan-canonicalization"
;; This *.wast test should be run with `cranelift_nan_canonicalization` set to
;; `true` in `wast.rs`
diff --git a/tests/misc_testsuite/stack-switching/fuel.wast b/tests/misc_testsuite/stack-switching/fuel.wast
index ca5c350894..65101bbcf2 100644
--- a/tests/misc_testsuite/stack-switching/fuel.wast
+++ b/tests/misc_testsuite/stack-switching/fuel.wast
@@ -1,7 +1,7 @@
;;! bulk_memory = true
;;! function_references = true
;;! stack_switching = true
-;;! consume_fuel = true
+;;! flags = "-W fuel=1000000000"
;; Fuel used inside a continuation is accounted for.
(module $Fuel
diff --git a/tests/misc_testsuite/winch/fuel_stack_alignment.wast b/tests/misc_testsuite/winch/fuel_stack_alignment.wast
index 72bec44922..356173fb63 100644
--- a/tests/misc_testsuite/winch/fuel_stack_alignment.wast
+++ b/tests/misc_testsuite/winch/fuel_stack_alignment.wast
@@ -1,4 +1,4 @@
-;;! consume_fuel = true
+;;! flags = "-W fuel=1000000000"
;; Regression test for #9554: a fuel check must keep the stack aligned when it
;; calls the out-of-fuel builtin. A fuzz-generated module.
diff --git a/tests/misc_testsuite/winch/gc-refs.wast b/tests/misc_testsuite/winch/gc-refs.wast
index d9ba79a13a..4a39d98427 100644
--- a/tests/misc_testsuite/winch/gc-refs.wast
+++ b/tests/misc_testsuite/winch/gc-refs.wast
@@ -1,5 +1,4 @@
;;! reference_types = true
-;;! gc_types = true
;; Winch reference-value support: externref flows through params, results,
;; locals, and globals, and survives calls (stack maps). Global reads and
diff --git a/tests/wast.rs b/tests/wast.rs
index a0b0c5590d..a0e07e8d47 100644
--- a/tests/wast.rs
+++ b/tests/wast.rs
@@ -1,10 +1,7 @@
use libtest_mimic::{Arguments, FormatSetting, Trial};
use std::sync::{Condvar, LazyLock, Mutex};
-use wasmtime::{
- Config, Enabled, Engine, InstanceAllocationStrategy, PoolingAllocationConfig, bail,
- error::Context as _,
-};
-use wasmtime_test_util::wast::{Collector, Compiler, WastConfig, WastTest, limits};
+use wasmtime::{Enabled, Engine, bail, error::Context as _};
+use wasmtime_test_util::wast::{Compiler, WastConfig, WastTest, limits};
use wasmtime_wast::{Async, SpectestConfig, WastContext};
fn main() {
@@ -61,7 +58,6 @@ fn main() {
let config = WastConfig {
compiler: *compiler,
pooling: false,
- collector: Collector::Auto,
};
let name = format!("{compiler:?}/{name}");
@@ -87,7 +83,7 @@ fn main() {
// function which actually executes the `wast` test suite given the `strategy`
// to compile it.
fn run_wast(test: &WastTest, config: WastConfig) -> wasmtime::Result<()> {
- let test_config = test.config.clone();
+ let test_config = &test.config;
// Determine whether this test is expected to fail or pass. Regardless the
// test is executed and the result of the execution is asserted to match
@@ -113,14 +109,15 @@ fn run_wast(test: &WastTest, config: WastConfig) -> wasmtime::Result<()> {
_ => false,
};
- let mut cfg = Config::new();
- cfg.shared_memory(true);
- wasmtime_test_util::wasmtime_wast::apply_test_config(&mut cfg, &test_config);
- wasmtime_test_util::wasmtime_wast::apply_wast_config(&mut cfg, &config);
+ let mut opts = config.compiler.common_options();
+ opts.wasm.shared_memory = Some(true);
if is_cranelift {
- cfg.cranelift_debug_verifier(true);
- cfg.cranelift_wasmtime_debug_checks(true);
+ opts.codegen.cranelift_debug_verifier = Some(true);
+ opts.codegen.cranelift.push((
+ "wasmtime_debug_checks".to_string(),
+ Some("true".to_string()),
+ ));
}
// By default we'll allocate huge chunks (6gb) of the address space for each
@@ -152,11 +149,10 @@ fn run_wast(test: &WastTest, config: WastConfig) -> wasmtime::Result<()> {
// Don't use 4gb address space reservations when not hogging memory, and
// also don't reserve lots of memory after dynamic memories for growth
// (makes growth slower).
- cfg.memory_reservation(2 * u64::from(wasmtime_environ::Memory::DEFAULT_PAGE_SIZE));
- cfg.memory_reservation_for_growth(0);
-
- let small_guard = 64 * 1024;
- cfg.memory_guard_size(small_guard);
+ opts.opts.memory_reservation =
+ Some(2 * u64::from(wasmtime_environ::Memory::DEFAULT_PAGE_SIZE));
+ opts.opts.memory_reservation_for_growth = Some(0);
+ opts.opts.memory_guard_size = Some(64 * 1024);
}
let _pooling_lock = if config.pooling {
@@ -179,34 +175,41 @@ fn run_wast(test: &WastTest, config: WastConfig) -> wasmtime::Result<()> {
// impact.
let max_memory_size = limits::MEMORY_SIZE;
if multi_memory {
- cfg.memory_reservation(max_memory_size as u64);
- cfg.memory_reservation_for_growth(0);
- cfg.memory_guard_size(0);
+ opts.opts.memory_reservation = Some(max_memory_size as u64);
+ opts.opts.memory_reservation_for_growth = Some(0);
+ opts.opts.memory_guard_size = Some(0);
}
- let mut pool = PoolingAllocationConfig::default();
- pool.total_memories(limits::MEMORIES * 2)
- .max_memory_protection_keys(2)
- .max_memory_size(max_memory_size)
- .max_memories_per_module(if multi_memory {
- limits::MEMORIES_PER_MODULE
- } else {
- 1
- })
- .max_tables_per_module(limits::TABLES_PER_MODULE);
+ let o = &mut opts.opts;
+ o.pooling_allocator = Some(true);
+ o.pooling_total_memories = Some(limits::MEMORIES * 2);
+ o.pooling_max_memory_size = Some(max_memory_size);
+ o.pooling_max_memories_per_module = Some(if multi_memory {
+ limits::MEMORIES_PER_MODULE
+ } else {
+ 1
+ });
+ o.pooling_max_tables_per_module = Some(limits::TABLES_PER_MODULE);
// When testing, we may choose to start with MPK force-enabled to ensure
// we use that functionality.
- if std::env::var("WASMTIME_TEST_FORCE_MPK").is_ok() {
- pool.memory_protection_keys(Enabled::Yes);
- }
+ o.pooling_memory_protection_keys =
+ Some(if std::env::var("WASMTIME_TEST_FORCE_MPK").is_ok() {
+ Enabled::Yes
+ } else {
+ Enabled::No
+ });
+ o.pooling_max_memory_protection_keys = Some(2);
- cfg.allocation_strategy(InstanceAllocationStrategy::Pooling(pool));
Some(lock_pooling())
} else {
None
};
+ // The test's configuration goes last so the test has the final say.
+ test_config.apply(&mut opts)?;
+ let mut cfg = opts.config(None)?;
+
let mut engines = vec![(Engine::new(&cfg), "default")];
// For tests that use relaxed-simd test both the default engine and the
@@ -221,11 +224,9 @@ fn run_wast(test: &WastTest, config: WastConfig) -> wasmtime::Result<()> {
for (engine, desc) in engines {
let result = engine.and_then(|engine| {
- let consume_fuel = test.config.consume_fuel();
+ let opts = opts.clone();
let mut wast_context = WastContext::new(&engine, Async::Yes, move |store| {
- if consume_fuel {
- store.set_fuel(u64::MAX).unwrap();
- }
+ opts.configure_store(store).unwrap();
});
wast_context.generate_dwarf(true);
wast_context.register_spectest(&SpectestConfig {