aboutsummaryrefslogtreecommitdiff
path: root/tests/test.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test.rs')
-rw-r--r--tests/test.rs93
1 files changed, 47 insertions, 46 deletions
diff --git a/tests/test.rs b/tests/test.rs
index 5007464..bae941d 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -8,59 +8,30 @@ mod armv8;
use yaxpeax_arch::{Arch, Decoder, U8Reader};
use std::fmt::Write;
-#[test]
-#[ignore]
-fn test_armv7_does_not_panic() {
- let armv7 = <yaxpeax_arm::armv7::ARMv7 as Arch>::Decoder::default();
+fn test_range<A: Arch>(decoder: &A::Decoder, start: u64, end: u64)
+where
+ for <'a> U8Reader<'a>: yaxpeax_arch::Reader<<A as Arch>::Address, <A as Arch>::Word>,
+ <A as Arch>::Instruction: std::fmt::Display
+{
- for i in 0..=u32::MAX {
- let bytes = i.to_le_bytes();
- let res = armv7.decode(&mut U8Reader::new(&bytes));
- if let Ok(instr) = res {
- let s = instr.to_string();
- drop(s);
- }
- }
-}
-#[test]
-#[ignore]
-fn test_armv7_thumb_does_not_panic() {
- let mut armv7_t = <yaxpeax_arm::armv7::ARMv7 as Arch>::Decoder::default();
- armv7_t.set_thumb_mode(true);
+ let mut instr = A::Instruction::default();
+ let mut s = String::new();
- for i in 0..=u32::MAX {
+ 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 = armv7_t.decode(&mut U8Reader::new(&bytes));
- if let Ok(instr) = res {
- let s = instr.to_string();
- drop(s);
+ let res = decoder.decode_into(&mut instr, &mut U8Reader::new(&bytes));
+ if let Ok(()) = res {
+ s.clear();
+ write!(s, "{}", instr).unwrap();
}
}
}
-#[test]
-#[ignore]
-fn test_armv8_does_not_panic() {
- fn test_range(start: u64, end: u64) {
- let armv8 = <yaxpeax_arm::armv8::a64::ARMv8 as Arch>::Decoder::default();
-
- 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();
- }
- }
- }
-
+fn par_test_u32(test_range: fn(u64, u64)) {
const NR_THREADS: u64 = 512;
const RANGE_SIZE: u64 = (u32::MAX as u64 + 1) / NR_THREADS;
@@ -76,3 +47,33 @@ fn test_armv8_does_not_panic() {
handle.join().unwrap();
}
}
+
+#[test]
+#[ignore]
+fn test_armv7_does_not_panic() {
+ par_test_u32(|start, end| {
+ let armv7 = <yaxpeax_arm::armv7::ARMv7 as Arch>::Decoder::default();
+
+ test_range::<yaxpeax_arm::armv7::ARMv7>(&armv7, start, end);
+ });
+}
+#[test]
+#[ignore]
+fn test_armv7_thumb_does_not_panic() {
+ par_test_u32(|start, end| {
+ let mut armv7_t = <yaxpeax_arm::armv7::ARMv7 as Arch>::Decoder::default();
+ armv7_t.set_thumb_mode(true);
+
+ test_range::<yaxpeax_arm::armv7::ARMv7>(&armv7_t, start, end);
+ });
+}
+
+#[test]
+#[ignore]
+fn test_armv8_does_not_panic() {
+ par_test_u32(|start, end| {
+ let armv8 = <yaxpeax_arm::armv8::a64::ARMv8 as Arch>::Decoder::default();
+
+ test_range::<yaxpeax_arm::armv8::a64::ARMv8>(&armv8, start, end);
+ });
+}