MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / write_static_api_tests

Function write_static_api_tests

fuzz/build.rs:40–179  ·  view source on GitHub ↗
(out: &mut String)

Source from the content-addressed store, hash-verified

38 }
39
40 fn write_static_api_tests(out: &mut String) -> Result<()> {
41 println!("cargo:rerun-if-env-changed=WASMTIME_FUZZ_SEED");
42 let seed = if let Ok(seed) = env::var("WASMTIME_FUZZ_SEED") {
43 seed.parse::<u64>()
44 .with_context(|| format_err!("expected u64 in WASMTIME_FUZZ_SEED"))?
45 } else {
46 rand::random()
47 };
48
49 eprintln!(
50 "using seed {seed} (set WASMTIME_FUZZ_SEED={seed} in your environment to reproduce)"
51 );
52
53 let mut rng = StdRng::seed_from_u64(seed);
54
55 const TYPE_COUNT: usize = 50;
56 const TEST_CASE_COUNT: usize = 100;
57
58 let mut type_fuel = 1000;
59 let mut types = Vec::new();
60 let mut rust_type_names = Vec::new();
61 let name_counter = &mut 0;
62 let mut declarations = TokenStream::new();
63 let mut tests = TokenStream::new();
64
65 // First generate a set of type to select from.
66 for _ in 0..TYPE_COUNT {
67 let ty = generate(&mut rng, |u| {
68 // Only discount fuel if the generation was successful,
69 // otherwise we'll get more random data and try again.
70 let mut fuel = type_fuel;
71 let ret = Type::generate(u, MAX_TYPE_DEPTH, &mut fuel);
72 if ret.is_ok() {
73 type_fuel = fuel;
74 }
75 ret
76 })?;
77
78 let rust_ty_name =
79 wasmtime_test_util::component_fuzz::rust_type(&ty, name_counter, &mut declarations);
80 types.push(ty);
81 rust_type_names.push(rust_ty_name);
82 }
83
84 fn hash_key(ty: &Type) -> usize {
85 let ty: *const Type = ty;
86 ty.addr()
87 }
88
89 let type_to_name_map = types
90 .iter()
91 .map(hash_key)
92 .zip(rust_type_names.iter().cloned())
93 .collect::<HashMap<_, _>>();
94
95 // Next generate a set of static API test cases driven by the above
96 // types.
97 for index in 0..TEST_CASE_COUNT {

Callers 1

Calls 13

rust_typeFunction · 0.85
hash_keyFunction · 0.85
OkFunction · 0.85
with_contextMethod · 0.80
is_okMethod · 0.80
generateFunction · 0.70
newFunction · 0.50
pushMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
extendMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected