Path: blob/main/cranelift/fuzzgen/src/config.rs
1692 views
use std::collections::HashMap;1use std::ops::RangeInclusive;23/// Holds the range of acceptable values to use during the generation of testcases4pub struct Config {5/// Maximum allowed test case inputs.6/// We build test case inputs from the rest of the bytes that the fuzzer provides us7/// so we allow the fuzzer to control this by feeding us more or less bytes.8/// The upper bound here is to prevent too many inputs that cause long test times9pub max_test_case_inputs: usize,10// Number of functions that we generate per testcase11pub testcase_funcs: RangeInclusive<usize>,12pub signature_params: RangeInclusive<usize>,13pub signature_rets: RangeInclusive<usize>,14pub instructions_per_block: RangeInclusive<usize>,15/// Number of variables that we allocate per function16/// This value does not include the signature params17pub vars_per_function: RangeInclusive<usize>,18/// Number of blocks that we generate per function.19/// This value does not include the entry block20pub blocks_per_function: RangeInclusive<usize>,21/// Number of params a block should take22/// This value does not apply to block0 which takes the function params23/// and is thus governed by `signature_params`24pub block_signature_params: RangeInclusive<usize>,25/// Max number of jump tables entries to generate26pub jump_table_entries: RangeInclusive<usize>,2728/// The Switch API specializes either individual blocks or contiguous ranges.29/// In `switch_cases` we decide to produce either a single block or a range.30/// The size of the range is controlled by `switch_max_range_size`.31pub switch_cases: RangeInclusive<usize>,32pub switch_max_range_size: RangeInclusive<usize>,3334/// Stack slots.35/// The combination of these two determines stack usage per function36pub static_stack_slots_per_function: RangeInclusive<usize>,37/// Size in bytes38pub static_stack_slot_size: RangeInclusive<usize>,39/// Stack slot alignment as a power of 240pub stack_slot_alignment_log2: RangeInclusive<usize>,41/// Allowed stack probe sizes42pub stack_probe_size_log2: RangeInclusive<usize>,4344/// Determines how often we generate a backwards branch45/// Backwards branches are prone to infinite loops, and thus cause timeouts.46pub backwards_branch_ratio: (usize, usize),4748/// How often should we allow integer division by zero traps.49///50/// Some instructions such as Srem and Udiv can cause a `int_divz` trap51/// under some inputs. We almost always insert a sequence of instructions52/// that avoids these issues. However we can allow some `int_divz` traps53/// by controlling this config.54pub allowed_int_divz_ratio: (usize, usize),5556/// How often should we allow fcvt related traps.57///58/// `Fcvt*` instructions fail under some inputs, most commonly NaN's.59/// We insert a checking sequence to guarantee that those inputs never make60/// it to the instruction, but sometimes we want to allow them.61pub allowed_fcvt_traps_ratio: (usize, usize),6263/// Some flags really impact compile performance, we still want to test64/// them, but probably at a lower rate, so that overall execution time isn't65/// impacted as much66pub compile_flag_ratio: HashMap<&'static str, (usize, usize)>,6768/// Range of values for the padding between basic blocks. Larger values will69/// generate larger functions.70pub bb_padding_log2_size: RangeInclusive<usize>,71}7273impl Default for Config {74fn default() -> Self {75Config {76max_test_case_inputs: 100,77testcase_funcs: 1..=8,78signature_params: 0..=16,79signature_rets: 0..=16,80instructions_per_block: 0..=64,81vars_per_function: 0..=16,82blocks_per_function: 0..=16,83block_signature_params: 0..=16,84jump_table_entries: 0..=16,85switch_cases: 0..=64,86// Ranges smaller than 2 don't make sense.87switch_max_range_size: 2..=32,88static_stack_slots_per_function: 0..=8,89static_stack_slot_size: 0..=128,90stack_slot_alignment_log2: 0..=10,91// We need the mix of sizes that allows us to:92// * not generates any stack probes93// * generate unrolled stack probes94// * generate loop stack probes95//96// This depends on the total amount of stack space that we have for this function97// (controlled by `static_stack_slots_per_function` and `static_stack_slot_size`)98//99// 1<<6 = 64 and 1<<14 = 16384100//101// This range allows us to generate all 3 cases within the current allowed102// stack size range.103stack_probe_size_log2: 6..=14,104// 0.1% allows us to explore this, while not causing enough timeouts to significantly105// impact execs/s106backwards_branch_ratio: (1, 1000),107allowed_int_divz_ratio: (1, 1_000_000),108allowed_fcvt_traps_ratio: (1, 1_000_000),109compile_flag_ratio: [("regalloc_checker", (1usize, 1000))].into_iter().collect(),110// Generate up to 4KiB of padding between basic blocks. Although we only111// explicitly generate up to 16 blocks, after SSA construction we can112// end up with way more blocks than that (Seeing 400 blocks is not uncommon).113// At 4KiB we end up at around 1.5MiB of padding per function, which seems reasonable.114bb_padding_log2_size: 0..=12,115}116}117}118119120