From af84ff7ca6e634e51d2cadb490962e15947048c7 Mon Sep 17 00:00:00 2001 From: Noratrieb <48135649+Noratrieb@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:05:22 +0100 Subject: [PATCH] add exhaustive_decode_no_panic better than a fuzzer! --- src/inst.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/inst.rs b/src/inst.rs index 0d73d34..ba5581e 100644 --- a/src/inst.rs +++ b/src/inst.rs @@ -1120,3 +1120,26 @@ impl Inst { Ok(inst) } } + +#[cfg(test)] +mod tests { + use std::io::Write; + + #[test] + fn exhaustive_decode_no_panic() { + if std::env::var("SLOW_TESTS").is_err() { + return; + } + + for i in 0..u32::MAX { + if (i % (2 << 25)) == 0 { + let percent = i as f32 / (u32::MAX as f32); + let done = (100.0 * percent) as usize; + print!("\r{}{}", "#".repeat(done), "-".repeat(100 - done)); + std::io::stdout().flush().unwrap(); + } + let _ = super::Inst::decode(i); + } + let _ = super::Inst::decode(u32::MAX); + } +}