zephyr::raw

Function sys_heap_stress

source
pub unsafe extern "C" fn sys_heap_stress(
    alloc_fn: Option<unsafe extern "C" fn(_: *mut c_void, _: usize) -> *mut c_void>,
    free_fn: Option<unsafe extern "C" fn(_: *mut c_void, _: *mut c_void)>,
    arg: *mut c_void,
    total_bytes: usize,
    op_count: u32,
    scratch_mem: *mut c_void,
    scratch_bytes: usize,
    target_percent: i32,
    result: *mut z_heap_stress_result,
)
Expand description

@brief sys_heap stress test rig

Test rig for heap allocation validation. This will loop for @a op_count cycles, in each iteration making a random choice to allocate or free a pointer of randomized (power law) size based on heuristics designed to keep the heap in a state where it is near @a target_percent full. Allocation and free operations are provided by the caller as callbacks (i.e. this can in theory test any heap). Results, including counts of frees and successful/unsuccessful allocations, are returned via the @a result struct.

@param alloc_fn Callback to perform an allocation. Passes back the @a arg parameter as a context handle. @param free_fn Callback to perform a free of a pointer returned from @a alloc. Passes back the @a arg parameter as a context handle. @param arg Context handle to pass back to the callbacks @param total_bytes Size of the byte array the heap was initialized in @param op_count How many iterations to test @param scratch_mem A pointer to scratch memory to be used by the test. Should be about 1/2 the size of the heap for tests that need to stress fragmentation. @param scratch_bytes Size of the memory pointed to by @a scratch_mem @param target_percent Percentage fill value (1-100) to which the random allocation choices will seek. High values will result in significant allocation failures and a very fragmented heap. @param result Struct into which to store test results.