Skip to content

Commit

Permalink
update tests for miri
Browse files Browse the repository at this point in the history
  • Loading branch information
s5suzuki committed Jan 23, 2025
1 parent 7759f74 commit 2411f2b
Show file tree
Hide file tree
Showing 53 changed files with 160 additions and 247 deletions.
51 changes: 24 additions & 27 deletions autd3-core/src/defined/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,41 +53,38 @@ mod inner {

#[cfg(feature = "dynamic_freq")]
mod inner {
use std::sync::Once;
use std::sync::LazyLock;

use super::Freq;
use crate::defined::Hz;

static mut VAL: Freq<u32> = Freq { freq: 40000 };
static FREQ: Once = Once::new();
static LAZY_FREQ: LazyLock<Freq<u32>> =
LazyLock::new(|| match std::env::var("AUTD3_ULTRASOUND_FREQ") {
Ok(freq) => match freq.parse::<u32>() {
Ok(freq) => {
tracing::info!("Set ultrasound frequency to {} Hz.", freq);
freq * Hz
}
Err(_) => {
tracing::error!(
"Invalid ultrasound frequency ({} Hz), fallback to 40 kHz.",
freq
);
Freq { freq: 40000 }
}
},
Err(_) => {
tracing::warn!(
"Environment variable AUTD3_ULTRASOUND_FREQ is not set, fallback to 40 kHz."
);
Freq { freq: 40000 }
}
});

#[inline]
/// The frequency of ultrasound
pub fn ultrasound_freq() -> Freq<u32> {
unsafe {
FREQ.call_once(|| {
VAL = match std::env::var("AUTD3_ULTRASOUND_FREQ") {
Ok(freq) => match freq.parse::<u32>() {
Ok(freq) => {
tracing::info!("Set ultrasound frequency to {} Hz.", freq);
freq * Hz
}
Err(_) => {
tracing::error!(
"Invalid ultrasound frequency ({} Hz), fallback to 40 kHz.",
freq
);
Freq { freq: 40000 }
}
},
Err(_) => {
tracing::warn!("Environment variable AUTD3_ULTRASOUND_FREQ is not set, fallback to 40 kHz.");
Freq { freq: 40000 }
}
};
});
VAL
}
*LAZY_FREQ
}

#[doc(hidden)]
Expand Down
4 changes: 2 additions & 2 deletions autd3-driver/src/datagram/gain/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub mod tests {
].into_iter().collect(),
vec![true, false],
2)]
fn boxed_gain(
fn boxed_gain_unsafe(
#[case] expect: HashMap<usize, Vec<Drive>>,
#[case] enabled: Vec<bool>,
#[case] n: u16,
Expand Down Expand Up @@ -211,7 +211,7 @@ pub mod tests {
}

#[test]
fn boxed_gain_dbg() {
fn boxed_gain_dbg_unsafe() {
let g = TestGain::null();
assert_eq!(format!("{:?}", g), format!("{:?}", g.into_boxed()));
}
Expand Down
2 changes: 1 addition & 1 deletion autd3-driver/src/datagram/modulation/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub mod tests {
use crate::datagram::modulation::tests::TestModulation;

#[test]
fn test() {
fn boxed_modulation_unsafe() {
let m = TestModulation {
sampling_config: SamplingConfig::DIV_10,
};
Expand Down
3 changes: 0 additions & 3 deletions autd3-firmware-emulator/src/cpu/emulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ mod tests {
use rand::Rng;

#[test]
#[cfg_attr(miri, ignore)]
fn cpu_idx() {
let mut rng = rand::thread_rng();
let idx = rng.gen();
Expand All @@ -265,7 +264,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn num_transducers() {
let cpu = CPUEmulator::new(0, 249);
assert_eq!(249, cpu.num_transducers());
Expand All @@ -281,7 +279,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn should_update() {
let mut cpu = CPUEmulator::new(0, 249);
assert!(!cpu.should_update());
Expand Down
1 change: 0 additions & 1 deletion autd3-firmware-emulator/src/cpu/operation/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ mod tests {
use super::*;

#[test]
#[cfg_attr(miri, ignore)]
fn clear_memory_layout() {
assert_eq!(2, std::mem::size_of::<Clear>());
assert_eq!(0, std::mem::offset_of!(Clear, tag));
Expand Down
1 change: 0 additions & 1 deletion autd3-firmware-emulator/src/cpu/operation/cpu_gpio_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ mod tests {
use super::*;

#[test]
#[cfg_attr(miri, ignore)]
fn debug_out_idx_memory_layout() {
assert_eq!(2, std::mem::size_of::<CpuGPIOOut>());
assert_eq!(0, std::mem::offset_of!(CpuGPIOOut, tag));
Expand Down
1 change: 0 additions & 1 deletion autd3-firmware-emulator/src/cpu/operation/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ mod tests {
use super::*;

#[test]
#[cfg_attr(miri, ignore)]
fn debug_out_idx_memory_layout() {
assert_eq!(40, std::mem::size_of::<DebugOutIdx>());
assert_eq!(0, std::mem::offset_of!(DebugOutIdx, tag));
Expand Down
1 change: 0 additions & 1 deletion autd3-firmware-emulator/src/cpu/operation/force_fan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ mod tests {
use super::*;

#[test]
#[cfg_attr(miri, ignore)]
fn configure_force_fan_memory_layout() {
assert_eq!(2, std::mem::size_of::<ForceFan>());
assert_eq!(0, std::mem::offset_of!(ForceFan, tag));
Expand Down
1 change: 0 additions & 1 deletion autd3-firmware-emulator/src/cpu/operation/gain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ mod tests {
use super::*;

#[test]
#[cfg_attr(miri, ignore)]
fn gain_memory_layout() {
assert_eq!(4, std::mem::size_of::<Gain>());
assert_eq!(0, std::mem::offset_of!(Gain, tag));
Expand Down
1 change: 0 additions & 1 deletion autd3-firmware-emulator/src/cpu/operation/gpio_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ mod tests {
use super::*;

#[test]
#[cfg_attr(miri, ignore)]
fn emulate_gpio_in_memory_layout() {
assert_eq!(2, std::mem::size_of::<GPIOIn>());
assert_eq!(0, std::mem::offset_of!(GPIOIn, tag));
Expand Down
1 change: 0 additions & 1 deletion autd3-firmware-emulator/src/cpu/operation/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ mod tests {
use super::*;

#[test]
#[cfg_attr(miri, ignore)]
fn firminfo_memory_layout() {
assert_eq!(2, std::mem::size_of::<FirmInfo>());
assert_eq!(0, std::mem::offset_of!(FirmInfo, tag));
Expand Down
1 change: 0 additions & 1 deletion autd3-firmware-emulator/src/cpu/operation/modulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ mod tests {
use super::*;

#[test]
#[cfg_attr(miri, ignore)]
fn modulation_memory_layout() {
assert_eq!(16, std::mem::size_of::<ModulationHead>());
assert_eq!(0, std::mem::offset_of!(ModulationHead, tag));
Expand Down
1 change: 0 additions & 1 deletion autd3-firmware-emulator/src/cpu/operation/phase_corr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ mod tests {
use super::*;

#[test]
#[cfg_attr(miri, ignore)]
fn pwe_memory_layout() {
assert_eq!(2, std::mem::size_of::<PhaseCorr>());
assert_eq!(0, std::mem::offset_of!(PhaseCorr, tag));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ mod tests {
use super::*;

#[test]
#[cfg_attr(miri, ignore)]
fn pwe_memory_layout() {
assert_eq!(2, std::mem::size_of::<Pwe>());
assert_eq!(0, std::mem::offset_of!(Pwe, tag));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ mod tests {
use super::*;

#[test]
#[cfg_attr(miri, ignore)]
fn configure_reads_fpga_state_memory_layout() {
assert_eq!(2, std::mem::size_of::<ReadsFPGAState>());
assert_eq!(0, std::mem::offset_of!(ReadsFPGAState, tag));
Expand Down
1 change: 0 additions & 1 deletion autd3-firmware-emulator/src/cpu/operation/silecer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ mod tests {
use super::*;

#[test]
#[cfg_attr(miri, ignore)]
fn silencer_memory_layout() {
assert_eq!(6, std::mem::size_of::<ConfigSilencer>());
assert_eq!(0, std::mem::offset_of!(ConfigSilencer, tag));
Expand Down
1 change: 0 additions & 1 deletion autd3-firmware-emulator/src/cpu/operation/stm/foci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ mod tests {
use super::*;

#[test]
#[cfg_attr(miri, ignore)]
fn foci_stm_memory_layout() {
assert_eq!(24, std::mem::size_of::<FociSTMHead>());
assert_eq!(0, std::mem::offset_of!(FociSTMHead, tag));
Expand Down
1 change: 0 additions & 1 deletion autd3-firmware-emulator/src/cpu/operation/stm/gain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ mod tests {
use super::*;

#[test]
#[cfg_attr(miri, ignore)]
fn gain_stm_memory_layout() {
assert_eq!(16, std::mem::size_of::<GainSTMHead>());
assert_eq!(0, std::mem::offset_of!(GainSTMHead, tag));
Expand Down
1 change: 0 additions & 1 deletion autd3-firmware-emulator/src/cpu/operation/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ mod tests {
use super::*;

#[test]
#[cfg_attr(miri, ignore)]
fn sync_memory_layout() {
assert_eq!(2, std::mem::size_of::<Sync>());
assert_eq!(0, std::mem::offset_of!(Sync, tag));
Expand Down
1 change: 0 additions & 1 deletion autd3-firmware-emulator/src/fpga/emulator/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ mod tests {

#[test]
#[should_panic]
#[cfg_attr(miri, ignore)]
fn read_panic() {
let fpga = FPGAEmulator::new(249);
let addr = (BRAM_SELECT_MOD as u16) << 14;
Expand Down
1 change: 0 additions & 1 deletion autd3-firmware-emulator/src/fpga/emulator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ mod tests {
use super::*;

#[test]
#[cfg_attr(miri, ignore)]
fn thermo() {
let mut fpga = FPGAEmulator::new(249);
assert!(!fpga.is_thermo_asserted());
Expand Down
1 change: 0 additions & 1 deletion autd3-firmware-emulator/src/fpga/emulator/pwe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn test_to_pulse_width() {
let fpga = FPGAEmulator::new(249);
itertools::iproduct!(0x00..=0xFF, 0x00..=0xFF).for_each(|(a, b)| {
Expand Down
4 changes: 1 addition & 3 deletions autd3-firmware-emulator/src/fpga/emulator/silencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl SilencerEmulator<EmitIntensity> {

impl FPGAEmulator {
pub fn silencer_update_rate(&self) -> FixedUpdateRate {
unsafe /* ignore miri */ {
unsafe {
FixedUpdateRate {
intensity: NonZeroU16::new_unchecked(
self.mem.controller_bram.borrow()[ADDR_SILENCER_UPDATE_RATE_INTENSITY],
Expand Down Expand Up @@ -299,7 +299,6 @@ mod tests {
#[case(vec![255; 256], 256, true, 0, vec![255; 256])]
#[case([(0..=254).rev().collect::<Vec<_>>(), vec![0]].concat(), 256, false, 255, vec![0; 256])]
#[case(vec![0; 256], 256, true, 255, vec![0; 256])]
#[cfg_attr(miri, ignore)]
fn apply_silencer_fixed_update_rate(
#[case] expect: Vec<u8>,
#[case] value: u16,
Expand Down Expand Up @@ -359,7 +358,6 @@ mod tests {
#[case::phase_11(vec![187, 195, 202, 210, 218, 225, 233, 240, 248, 0, 0], 10, true, 180, vec![0; 11])]
#[case::intensity_12(vec![0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5], 10, false, 0, vec![5; 11])]
#[case::phase_12(vec![0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5], 10, true, 0, vec![5; 11])]
#[cfg_attr(miri, ignore)]
fn apply_silencer_fixed_completion_steps(
#[case] expect: Vec<u8>,
#[case] value: u8,
Expand Down
8 changes: 0 additions & 8 deletions autd3-firmware-emulator/src/fpga/emulator/swapchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ mod tests {
const FREQ_DIV: u16 = 1;

#[test]
#[cfg_attr(miri, ignore)]
fn transition_same_segment() {
let mut fpga = FPGAEmulator::new(249);

Expand All @@ -229,7 +228,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn transition_infinite() {
let mut fpga = FPGAEmulator::new(249);

Expand All @@ -256,7 +254,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn transition_finite() {
let mut fpga = FPGAEmulator::new(249);

Expand All @@ -282,7 +279,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn transition_sync_idx() {
let mut fpga = FPGAEmulator::new(249);

Expand Down Expand Up @@ -336,7 +332,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn transition_sys_time() {
let mut fpga = FPGAEmulator::new(249);

Expand Down Expand Up @@ -391,7 +386,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn transition_gpio() {
let mut fpga = FPGAEmulator::new(249);

Expand Down Expand Up @@ -451,7 +445,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn transition_gpio_over() {
let mut fpga = FPGAEmulator::new(249);

Expand Down Expand Up @@ -496,7 +489,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)]
fn transition_ext() {
let mut fpga = FPGAEmulator::new(249);

Expand Down
2 changes: 1 addition & 1 deletion autd3-firmware-emulator/tests/op/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use autd3_firmware_emulator::CPUEmulator;
use zerocopy::FromZeros;

#[test]
fn send_clear() -> anyhow::Result<()> {
fn send_clear_unsafe() -> anyhow::Result<()> {
let geometry = create_geometry(1);
let mut cpu = CPUEmulator::new(0, geometry.num_transducers());
let mut tx = vec![TxMessage::new_zeroed(); 1];
Expand Down
1 change: 0 additions & 1 deletion autd3-firmware-emulator/tests/op/cpu_gpio_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use zerocopy::FromZeros;
#[case(0b00100000, true, false)]
#[case(0b10000000, false, true)]
#[case(0b00000000, false, false)]
#[cfg_attr(miri, ignore)]
fn send_cpu_gpio_out(
#[case] expect: u8,
#[case] pa5: bool,
Expand Down
1 change: 0 additions & 1 deletion autd3-firmware-emulator/tests/op/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use zerocopy::FromZeros;
#[case([DBG_NONE, DBG_BASE_SIG, DBG_THERMO, DBG_FORCE_FAN], [0, 0, 0, 0], [DebugType::None, DebugType::BaseSignal, DebugType::Thermo, DebugType::ForceFan])]
#[case([DBG_SYNC, DBG_MOD_SEGMENT, DBG_MOD_IDX, DBG_STM_SEGMENT], [0, 0, 0x01, 0], [DebugType::Sync, DebugType::ModSegment, DebugType::ModIdx(0x01), DebugType::StmSegment])]
#[case([DBG_STM_IDX, DBG_IS_STM_MODE, DBG_SYS_TIME_EQ, DBG_DIRECT], [0x02, 0, 1<<9, 1], [DebugType::StmIdx(0x02), DebugType::IsStmMode, DebugType::SysTimeEq(DcSysTime::ZERO + std::time::Duration::from_nanos(50000)), DebugType::Direct(true)])]
#[cfg_attr(miri, ignore)]
fn send_debug_output_idx(
#[case] expect_types: [u8; 4],
#[case] expect_values: [u64; 4],
Expand Down
3 changes: 1 addition & 2 deletions autd3-firmware-emulator/tests/op/gain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Gain for TestGain {
}

#[test]
fn send_gain() -> anyhow::Result<()> {
fn send_gain_unsafe() -> anyhow::Result<()> {
let mut rng = rand::thread_rng();

let geometry = create_geometry(1);
Expand Down Expand Up @@ -151,7 +151,6 @@ fn send_gain() -> anyhow::Result<()> {
}

#[test]
#[cfg_attr(miri, ignore)]
fn send_gain_invalid_segment_transition() -> anyhow::Result<()> {
let geometry = create_geometry(1);
let mut cpu = CPUEmulator::new(0, geometry.num_transducers());
Expand Down
Loading

0 comments on commit 2411f2b

Please sign in to comment.