aboutsummaryrefslogtreecommitdiff
path: root/test/long_mode/mod.rs
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2022-04-24 17:39:21 -0700
committeriximeow <me@iximeow.net>2022-04-24 19:22:52 -0700
commit2097524c851b15e89091fd3775817a06f0eeae4f (patch)
treee3c175856fcde170db91474ec580b549f97f8ad7 /test/long_mode/mod.rs
parente80b5622ec956a92f24ce6487fb0d76e9c541515 (diff)
fix a few issues preventing no-std builds from ... building
this includes a `Makefile` that exercises the various crate configs. most annoyingly, several doc comments needed to grow `#[cfg(feature="fmt")]` blocks so docs continue to build with that feature enabled or disabled. carved out a way to run exhaustive tests; they should be written as `#[ignore]`, and then the makefile will run even ignored tests on the expectation that this will run the exhaustive (but slower) suite. exhaustive tests are not yet written. they'll probably involve spanning 4 byte sequences from 0 to 2^32-1.
Diffstat (limited to 'test/long_mode/mod.rs')
-rw-r--r--test/long_mode/mod.rs49
1 files changed, 37 insertions, 12 deletions
diff --git a/test/long_mode/mod.rs b/test/long_mode/mod.rs
index 97e9a74..2a11b79 100644
--- a/test/long_mode/mod.rs
+++ b/test/long_mode/mod.rs
@@ -2,6 +2,7 @@ extern crate rand;
mod regspec;
mod operand;
+#[cfg(feature="fmt")]
mod display;
mod evex_generated;
mod reuse_test;
@@ -18,7 +19,17 @@ fn test_invalid(data: &[u8]) {
fn test_invalid_under(decoder: &InstDecoder, data: &[u8]) {
let mut reader = yaxpeax_arch::U8Reader::new(data);
if let Ok(inst) = decoder.decode(&mut reader) {
- panic!("decoded {:?} from {:02x?} under decoder {}", inst.opcode(), data, decoder);
+ // realistically, the chances an error only shows up under non-fmt builds seems unlikely,
+ // but try to report *something* in such cases.
+ cfg_if::cfg_if! {
+ if #[cfg(feature="fmt")] {
+ panic!("decoded {:?} from {:02x?} under decoder {}", inst.opcode(), data, decoder);
+ } else {
+ // don't warn about the unused inst here
+ let _ = inst;
+ panic!("decoded instruction <non-fmt build> from {:02x?} under decoder <non-fmt build>", data);
+ }
+ }
} else {
// this is fine
}
@@ -36,22 +47,36 @@ fn test_display_under(decoder: &InstDecoder, data: &[u8], expected: &'static str
let mut reader = yaxpeax_arch::U8Reader::new(data);
match decoder.decode(&mut reader) {
Ok(instr) => {
- let text = format!("{}", instr);
- assert!(
- text == expected,
- "display error for {}:\n decoded: {:?} under decoder {}\n displayed: {}\n expected: {}\n",
- hex,
- instr,
- decoder,
- text,
- expected
- );
+ cfg_if::cfg_if! {
+ if #[cfg(feature="fmt")] {
+ let text = format!("{}", instr);
+ assert!(
+ text == expected,
+ "display error for {}:\n decoded: {:?} under decoder {}\n displayed: {}\n expected: {}\n",
+ hex,
+ instr,
+ decoder,
+ text,
+ expected
+ );
+ } else {
+ eprintln!("non-fmt build cannot compare text equality")
+ }
+ }
// while we're at it, test that the instruction is as long, and no longer, than its
// input
assert_eq!((0u64.wrapping_offset(instr.len()).to_linear()) as usize, data.len(), "instruction length is incorrect, wanted instruction {}", expected);
},
Err(e) => {
- assert!(false, "decode error ({}) for {} under decoder {}:\n expected: {}\n", e, hex, decoder, expected);
+ cfg_if::cfg_if! {
+ if #[cfg(feature="fmt")] {
+ assert!(false, "decode error ({}) for {} under decoder {}:\n expected: {}\n", e, hex, decoder, expected);
+ } else {
+ // avoid the unused `e` warning
+ let _ = e;
+ assert!(false, "decode error (<non-fmt build>) for {} under decoder <non-fmt build>:\n expected: {}\n", hex, expected);
+ }
+ }
}
}
}