summaryrefslogtreecommitdiffstats
path: root/third_party/rust/wasm-smith/tests
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/wasm-smith/tests')
-rw-r--r--third_party/rust/wasm-smith/tests/common/mod.rs52
-rw-r--r--third_party/rust/wasm-smith/tests/component.rs8
-rw-r--r--third_party/rust/wasm-smith/tests/core.rs55
-rw-r--r--third_party/rust/wasm-smith/tests/exports.rs32
4 files changed, 53 insertions, 94 deletions
diff --git a/third_party/rust/wasm-smith/tests/common/mod.rs b/third_party/rust/wasm-smith/tests/common/mod.rs
index cc24eed278..8a238776d6 100644
--- a/third_party/rust/wasm-smith/tests/common/mod.rs
+++ b/third_party/rust/wasm-smith/tests/common/mod.rs
@@ -2,30 +2,34 @@ use wasm_smith::Config;
use wasmparser::{types::Types, Validator, WasmFeatures};
pub fn parser_features_from_config(config: &Config) -> WasmFeatures {
- WasmFeatures {
- mutable_global: true,
- saturating_float_to_int: config.saturating_float_to_int_enabled,
- sign_extension: config.sign_extension_ops_enabled,
- reference_types: config.reference_types_enabled,
- multi_value: config.multi_value_enabled,
- bulk_memory: config.bulk_memory_enabled,
- simd: config.simd_enabled,
- relaxed_simd: config.relaxed_simd_enabled,
- multi_memory: config.max_memories > 1,
- exceptions: config.exceptions_enabled,
- memory64: config.memory64_enabled,
- tail_call: config.tail_call_enabled,
- function_references: config.gc_enabled,
- gc: config.gc_enabled,
-
- threads: false,
- floats: true,
- extended_const: false,
- component_model: false,
- memory_control: false,
- component_model_values: false,
- component_model_nested_names: false,
- }
+ let mut features = WasmFeatures::MUTABLE_GLOBAL | WasmFeatures::FLOATS;
+ features.set(
+ WasmFeatures::SATURATING_FLOAT_TO_INT,
+ config.saturating_float_to_int_enabled,
+ );
+ features.set(
+ WasmFeatures::SIGN_EXTENSION,
+ config.sign_extension_ops_enabled,
+ );
+ features.set(
+ WasmFeatures::REFERENCE_TYPES,
+ config.reference_types_enabled,
+ );
+ features.set(WasmFeatures::MULTI_VALUE, config.multi_value_enabled);
+ features.set(WasmFeatures::BULK_MEMORY, config.bulk_memory_enabled);
+ features.set(WasmFeatures::SIMD, config.simd_enabled);
+ features.set(WasmFeatures::RELAXED_SIMD, config.relaxed_simd_enabled);
+ features.set(WasmFeatures::MULTI_MEMORY, config.max_memories > 1);
+ features.set(WasmFeatures::EXCEPTIONS, config.exceptions_enabled);
+ features.set(WasmFeatures::MEMORY64, config.memory64_enabled);
+ features.set(WasmFeatures::TAIL_CALL, config.tail_call_enabled);
+ features.set(WasmFeatures::FUNCTION_REFERENCES, config.gc_enabled);
+ features.set(WasmFeatures::GC, config.gc_enabled);
+ features.set(
+ WasmFeatures::CUSTOM_PAGE_SIZES,
+ config.custom_page_sizes_enabled,
+ );
+ features
}
pub fn validate(validator: &mut Validator, bytes: &[u8]) -> Types {
diff --git a/third_party/rust/wasm-smith/tests/component.rs b/third_party/rust/wasm-smith/tests/component.rs
index 7d5a40159c..89fdebffaa 100644
--- a/third_party/rust/wasm-smith/tests/component.rs
+++ b/third_party/rust/wasm-smith/tests/component.rs
@@ -18,11 +18,9 @@ fn smoke_test_component() {
ok_count += 1;
let component = component.to_bytes();
- let mut validator =
- wasmparser::Validator::new_with_features(wasmparser::WasmFeatures {
- component_model: true,
- ..Default::default()
- });
+ let mut validator = wasmparser::Validator::new_with_features(
+ wasmparser::WasmFeatures::default() | wasmparser::WasmFeatures::COMPONENT_MODEL,
+ );
if let Err(e) = validator.validate_all(&component) {
std::fs::write("component.wasm", &component).unwrap();
panic!(
diff --git a/third_party/rust/wasm-smith/tests/core.rs b/third_party/rust/wasm-smith/tests/core.rs
index 7286952dc6..9b18fcdeaf 100644
--- a/third_party/rust/wasm-smith/tests/core.rs
+++ b/third_party/rust/wasm-smith/tests/core.rs
@@ -3,6 +3,9 @@ use rand::{rngs::SmallRng, RngCore, SeedableRng};
use wasm_smith::{Config, Module};
use wasmparser::{Validator, WasmFeatures};
+mod common;
+use common::{parser_features_from_config, validate};
+
#[test]
fn smoke_test_module() {
let mut rng = SmallRng::seed_from_u64(0);
@@ -66,7 +69,7 @@ fn multi_value_disabled() {
if let Ok(module) = Module::new(cfg, &mut u) {
let wasm_bytes = module.to_bytes();
let mut features = wasm_features();
- features.multi_value = false;
+ features.remove(WasmFeatures::MULTI_VALUE);
let mut validator = Validator::new_with_features(features);
validate(&mut validator, &wasm_bytes);
}
@@ -140,53 +143,5 @@ fn smoke_test_wasm_gc() {
}
fn wasm_features() -> WasmFeatures {
- WasmFeatures {
- multi_memory: true,
- relaxed_simd: true,
- memory64: true,
- exceptions: true,
- tail_call: true,
- function_references: true,
- gc: true,
- ..WasmFeatures::default()
- }
-}
-
-fn parser_features_from_config(config: &Config) -> WasmFeatures {
- WasmFeatures {
- mutable_global: true,
- saturating_float_to_int: config.saturating_float_to_int_enabled,
- sign_extension: config.sign_extension_ops_enabled,
- reference_types: config.reference_types_enabled,
- multi_value: config.multi_value_enabled,
- bulk_memory: config.bulk_memory_enabled,
- simd: config.simd_enabled,
- relaxed_simd: config.relaxed_simd_enabled,
- multi_memory: config.max_memories > 1,
- exceptions: config.exceptions_enabled,
- memory64: config.memory64_enabled,
- tail_call: config.tail_call_enabled,
-
- threads: false,
- floats: true,
- extended_const: false,
- component_model: false,
- function_references: false,
- memory_control: false,
- gc: false,
- component_model_values: false,
- component_model_nested_names: false,
- }
-}
-
-fn validate(validator: &mut Validator, bytes: &[u8]) {
- let err = match validator.validate_all(bytes) {
- Ok(_) => return,
- Err(e) => e,
- };
- drop(std::fs::write("test.wasm", &bytes));
- if let Ok(text) = wasmprinter::print_bytes(bytes) {
- drop(std::fs::write("test.wat", &text));
- }
- panic!("wasm failed to validate: {}", err);
+ WasmFeatures::all()
}
diff --git a/third_party/rust/wasm-smith/tests/exports.rs b/third_party/rust/wasm-smith/tests/exports.rs
index ff1dac0cbe..6d3e4451a2 100644
--- a/third_party/rust/wasm-smith/tests/exports.rs
+++ b/third_party/rust/wasm-smith/tests/exports.rs
@@ -1,3 +1,5 @@
+#![cfg(feature = "wasmparser")]
+
use arbitrary::{Arbitrary, Unstructured};
use rand::{rngs::SmallRng, RngCore, SeedableRng};
use wasm_smith::{Config, Module};
@@ -18,9 +20,9 @@ enum ExportType {
fn smoke_test_single_export() {
let test = r#"
(module
- (func (export "foo") (param i32) (result i64)
- unreachable
- )
+ (func (export "foo") (param i32) (result i64)
+ unreachable
+ )
)
"#;
smoke_test_exports(test, 11)
@@ -30,15 +32,15 @@ fn smoke_test_single_export() {
fn smoke_test_multiple_exports() {
let test = r#"
(module
- (func (export "a") (param i32) (result i64)
- unreachable
- )
- (func (export "b")
- unreachable
- )
- (func (export "c")
- unreachable
- )
+ (func (export "a") (param i32) (result i64)
+ unreachable
+ )
+ (func (export "b")
+ unreachable
+ )
+ (func (export "c")
+ unreachable
+ )
)
"#;
smoke_test_exports(test, 12)
@@ -48,9 +50,9 @@ fn smoke_test_multiple_exports() {
fn smoke_test_exported_global() {
let test = r#"
(module
- (func (export "a") (param i32 i32 f32 f64) (result f32)
- unreachable
- )
+ (func (export "a") (param i32 i32 f32 f64) (result f32)
+ unreachable
+ )
(global (export "glob") f64 f64.const 0)
)
"#;