| 805 | arbtest::arbtest(|u| run(u)).budget_ms(1_000); |
| 806 | |
| 807 | fn run(u: &mut Unstructured<'_>) -> Result<()> { |
| 808 | let mut funcs = Vec::new(); |
| 809 | |
| 810 | // Build up a random set of functions with random indices. |
| 811 | for _ in 0..u.int_in_range(1..=200)? { |
| 812 | #[cfg(feature = "component-model")] |
| 813 | let choice = u.int_in_range(0..=6)?; |
| 814 | #[cfg(not(feature = "component-model"))] |
| 815 | let choice = u.int_in_range(0..=4)?; |
| 816 | |
| 817 | let key = match choice { |
| 818 | 0 => FuncKey::DefinedWasmFunction(idx(u, 10)?, idx(u, 200)?), |
| 819 | 1 => FuncKey::ArrayToWasmTrampoline(idx(u, 10)?, idx(u, 200)?), |
| 820 | 2 => FuncKey::WasmToArrayTrampoline(idx(u, 100)?), |
| 821 | 3 => FuncKey::WasmToBuiltinTrampoline(u.arbitrary()?), |
| 822 | 4 => FuncKey::PulleyHostCall(u.arbitrary()?), |
| 823 | #[cfg(feature = "component-model")] |
| 824 | 5 => FuncKey::ComponentTrampoline(u.arbitrary()?, idx(u, 50)?), |
| 825 | #[cfg(feature = "component-model")] |
| 826 | 6 => FuncKey::ResourceDropTrampoline, |
| 827 | _ => unreachable!(), |
| 828 | }; |
| 829 | funcs.push(key); |
| 830 | } |
| 831 | |
| 832 | // Sort/dedup our list of `funcs` to satisfy the requirement of |
| 833 | // `CompiledFunctionsTableBuilder::push_func`. |
| 834 | funcs.sort(); |
| 835 | funcs.dedup(); |
| 836 | |
| 837 | let mut builder = CompiledFunctionsTableBuilder::new(); |
| 838 | let mut size = 0; |
| 839 | let mut expected = Vec::new(); |
| 840 | for key in funcs { |
| 841 | let length = u.int_in_range(1..=10)?; |
| 842 | for _ in 0..length { |
| 843 | expected.push(key); |
| 844 | } |
| 845 | // println!("push {key:?} - {length}"); |
| 846 | builder.push_func( |
| 847 | key, |
| 848 | FunctionLoc { |
| 849 | start: size, |
| 850 | length, |
| 851 | }, |
| 852 | FilePos::none(), |
| 853 | ); |
| 854 | size += length; |
| 855 | } |
| 856 | let index = builder.finish(); |
| 857 | |
| 858 | let mut expected = expected.iter(); |
| 859 | for i in 0..size { |
| 860 | // println!("lookup {i}"); |
| 861 | let actual = index.func_by_text_offset(i).unwrap(); |
| 862 | assert_eq!(Some(&actual), expected.next()); |
| 863 | } |
| 864 | |