Debian Codegraph @

debian/rust-vendor/crc-fast/src/test/mod.rs

raw
1 // Copyright 2025 Don MacAskill. Licensed under MIT or Apache-2.0.
2
3 //! This module provides tests and utilities for the CRC library.
4
5 #![cfg(test)]
6 #![allow(dead_code)]
7
8 pub(crate) mod consts;
9 pub(crate) mod enums;
10 mod future_proof_tests;
11 mod structs;
12
13 use proptest::test_runner::Config as ProptestConfig;
14
15 /// Returns a proptest config that works under Miri by disabling file-based failure persistence.
16 /// Miri runs with isolation enabled by default, which blocks getcwd() calls that proptest
17 /// uses for its failure persistence feature.
18 pub(crate) fn miri_compatible_proptest_config() -> ProptestConfig {
19 let mut config = ProptestConfig::with_cases(100);
20
21 if cfg!(miri) {
22 // don't let Miri spend too much time on these
23 config.cases = 1;
24
25 // disable file-based failure persistence to avoid getcwd() calls
26 config.failure_persistence = None;
27
28 return config;
29 }
30
31 config
32 }
33
34 /// Creates a new aligned data vector from the input slice for testing.
35 pub(crate) fn create_aligned_data(input: &[u8]) -> Vec<u8> {
36 // Size of our target alignment structure
37 let align_size = std::mem::size_of::<[[u64; 4]; 2]>(); // 64 bytes
38
39 // Create a zero-filled vector with padding to ensure we can find a properly aligned position
40 let mut padded = vec![0; input.len() + align_size];
41
42 // Find the first address that satisfies our alignment
43 let start_addr = padded.as_ptr() as usize;
44 let align_offset = (align_size - (start_addr % align_size)) % align_size;
45
46 // Copy the input into the aligned position
47 let aligned_start = &mut padded[align_offset..];
48 aligned_start[..input.len()].copy_from_slice(input);
49
50 // Return the exact slice we need
51 aligned_start[..input.len()].to_vec()
52 }