| 1 |
#![cfg(feature = "component-model")] |
| 2 |
|
| 3 |
use arbitrary::{Arbitrary, Unstructured}; |
| •4 |
use rand::{Rng, SeedableRng, rngs::SmallRng}; |
| 5 |
use wasm_smith::Component; |
| 6 |
|
| 7 |
#[test] |
| 8 |
#[ignore] // FIXME(#1000): need to update wasm-smith's support for components |
| 9 |
fn smoke_test_component() { |
| 10 |
const NUM_RUNS: usize = 4096; |
| 11 |
|
| 12 |
let mut rng = SmallRng::seed_from_u64(0); |
| 13 |
let mut buf = vec![0; 1024]; |
| 14 |
let mut ok_count = 0; |
| 15 |
|
| 16 |
for _ in 0..NUM_RUNS { |
| 17 |
rng.fill_bytes(&mut buf); |
| 18 |
let u = Unstructured::new(&buf); |
| 19 |
if let Ok(component) = Component::arbitrary_take_rest(u) { |
| 20 |
ok_count += 1; |
| 21 |
let component = component.to_bytes(); |
| 22 |
|
| 23 |
let mut validator = wasmparser::Validator::new_with_features( |
| 24 |
wasmparser::WasmFeatures::default() | wasmparser::WasmFeatures::COMPONENT_MODEL, |
| 25 |
); |
| 26 |
if let Err(e) = validator.validate_all(&component) { |
| 27 |
std::fs::write("component.wasm", &component).unwrap(); |
| 28 |
panic!( |
| 29 |
"generated component should be valid; failing binary written \ |
| 30 |
to `component.wasm`. Error: {e}" |
| 31 |
); |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
println!( |
| 37 |
"Generated {} / {} ({:.02}%) arbitrary components okay", |
| 38 |
ok_count, |
| 39 |
NUM_RUNS, |
| 40 |
ok_count as f64 / NUM_RUNS as f64 * 100.0 |
| 41 |
); |
| 42 |
} |