aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2024-03-17 10:41:03 -0700
committeriximeow <me@iximeow.net>2024-03-17 10:41:13 -0700
commit6a9170db63f70be95adc2c80c342ed713a4546e7 (patch)
tree7c506ccae288b982c4b27a9ffb85b6197f2c4a83 /tests
parent96cac06673bfb2c9fb6ea2da4bee4f0ed0f9b055 (diff)
armv8 no-panic test is now multithreaded
Diffstat (limited to 'tests')
-rw-r--r--tests/test.rs40
1 files changed, 33 insertions, 7 deletions
diff --git a/tests/test.rs b/tests/test.rs
index 7311616..5007464 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -6,6 +6,7 @@ mod armv7;
mod armv8;
use yaxpeax_arch::{Arch, Decoder, U8Reader};
+use std::fmt::Write;
#[test]
#[ignore]
@@ -36,17 +37,42 @@ fn test_armv7_thumb_does_not_panic() {
}
}
}
+
#[test]
#[ignore]
fn test_armv8_does_not_panic() {
- let armv8 = <yaxpeax_arm::armv8::a64::ARMv8 as Arch>::Decoder::default();
+ fn test_range(start: u64, end: u64) {
+ let armv8 = <yaxpeax_arm::armv8::a64::ARMv8 as Arch>::Decoder::default();
- for i in 0..=u32::MAX {
- let bytes = i.to_le_bytes();
- let res = armv8.decode(&mut U8Reader::new(&bytes));
- if let Ok(instr) = res {
- let s = instr.to_string();
- drop(s);
+ let mut instr = <yaxpeax_arm::armv8::a64::ARMv8 as yaxpeax_arch::Arch>::Instruction::default();
+ let mut s = String::new();
+
+ for i in start..=end {
+ if i & 0x01_ff_ff_ff == 0 {
+ eprintln!("case {:08x}", i);
+ }
+ let i = i as u32;
+ let bytes = i.to_le_bytes();
+ let res = armv8.decode_into(&mut instr, &mut U8Reader::new(&bytes));
+ if let Ok(()) = res {
+ s.clear();
+ write!(s, "{}", instr).unwrap();
+ }
}
}
+
+ const NR_THREADS: u64 = 512;
+
+ const RANGE_SIZE: u64 = (u32::MAX as u64 + 1) / NR_THREADS;
+
+ let mut handles = Vec::new();
+
+ for i in 0..NR_THREADS {
+ let handle = std::thread::spawn(move || test_range(i * RANGE_SIZE, (i + 1) * RANGE_SIZE));
+ handles.push(handle);
+ }
+
+ while let Some(handle) = handles.pop() {
+ handle.join().unwrap();
+ }
}