Skip to content

Commit

Permalink
Adjust x86_64 tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
WINSDK committed Apr 30, 2023
1 parent 0b35b97 commit 8a2f23c
Show file tree
Hide file tree
Showing 21 changed files with 144 additions and 2,641 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion decoder-x86_64/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "x86_64"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 0 additions & 2 deletions decoder-x86_64/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

pub mod long_mode;
pub mod protected_mode;

mod safer_unchecked;
mod tests;

use decoder::{Decoded, ToTokens};
use tokenizing::{ColorScheme, Colors};
Expand Down
7 changes: 4 additions & 3 deletions decoder-x86_64/src/long_mode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod display;
mod evex;
pub mod uarch;
mod vex;
mod tests;

pub use crate::MemoryAccessSize;

Expand Down Expand Up @@ -875,12 +876,12 @@ const REGISTER_CLASS_NAMES: &[&'static str] = &[
/// ```
/// use x86_64::long_mode::{self as amd64};
/// use x86_64::long_mode::{Opcode, Operand, RegisterClass};
/// use yaxpeax_arch::{Decoder, U8Reader};
/// use decoder::Reader;
///
/// let movsx_eax_cl = &[0x0f, 0xbe, 0xc1];
/// let decoder = amd64::InstDecoder::default();
/// let instruction = decoder
/// .decode(&mut U8Reader::new(movsx_eax_cl))
/// .decode(&mut Reader::new(movsx_eax_cl))
/// .expect("can decode");
///
/// assert_eq!(instruction.opcode(), Opcode::MOVSX);
Expand Down Expand Up @@ -2850,7 +2851,7 @@ impl Decoder {

/// helper to decode an instruction directly from a byte slice.
///
/// this lets callers avoid the work of setting up a [`yaxpeax_arch::U8Reader`] for the slice
/// this lets callers avoid the work of setting up a [`decoder::Reader`] for the slice
/// to decode.
pub fn decode_slice(&self, data: &[u8]) -> Result<Instruction, Error> {
let mut reader = Reader::new(data);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::fmt::Write;

use crate::long_mode::Decoder;
use decoder::ToTokens;
use yaxpeax_arch::{AddressBase, Decoder, LengthedInstruction};
use decoder::{ToTokens, Reader, Decodable, Decoded};

fn test_display(data: &[u8], expected: &'static str) {
let dekoder = Decoder::default();
Expand All @@ -12,7 +11,7 @@ fn test_display(data: &[u8], expected: &'static str) {
write!(hex, "{:02x}", b).unwrap();
}

let mut reader = yaxpeax_arch::U8Reader::new(data);
let mut reader = Reader::new(data);
match dekoder.decode(&mut reader) {
Ok(instr) => {
instr.tokenize(&mut stream);
Expand All @@ -30,7 +29,7 @@ fn test_display(data: &[u8], expected: &'static str) {
// 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,
(0u64.wrapping_add(instr.len() as u64)) as usize,
data.len(),
"instruction length is incorrect, wanted instruction {}",
expected
Expand All @@ -39,7 +38,7 @@ fn test_display(data: &[u8], expected: &'static str) {
Err(e) => {
assert!(
false,
"decode error ({}) for {} under decoder {}:\n expected: {}\n",
"decode error ({:?}) for {} under decoder {}:\n expected: {}\n",
e, hex, dekoder, expected
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use std::fmt::Write;

use crate::long_mode::Decoder;
use decoder::ToTokens;
use yaxpeax_arch::{AddressBase, Decoder, LengthedInstruction, U8Reader};
use decoder::{ToTokens, Reader, Decodable, Decoded};

#[allow(dead_code)]
fn test_invalid(data: &[u8]) {
test_invalid_under(&Decoder::default(), data);
}

fn test_invalid_under(decoder: &Decoder, data: &[u8]) {
let mut reader = U8Reader::new(data);
let mut reader = Reader::new(data);
if let Ok(inst) = decoder.decode(&mut reader) {
// realistically, the chances an error only shows up under non-fmt builds seems unlikely,
// but try to report *something* in such cases.
Expand All @@ -20,8 +19,6 @@ fn test_invalid_under(decoder: &Decoder, data: &[u8]) {
data,
decoder
);
} else {
// this is fine
}
}

Expand All @@ -36,7 +33,7 @@ fn test_display_under(dekoder: &Decoder, data: &[u8], expected: &'static str) {
for b in data {
write!(hex, "{:02x}", b).unwrap();
}
let mut reader = yaxpeax_arch::U8Reader::new(data);
let mut reader = Reader::new(data);
match dekoder.decode(&mut reader) {
Ok(instr) => {
instr.tokenize(&mut stream);
Expand All @@ -55,7 +52,7 @@ fn test_display_under(dekoder: &Decoder, data: &[u8], expected: &'static str) {
// 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,
(0u64.wrapping_add(instr.len() as u64)) as usize,
data.len(),
"instruction length is incorrect, wanted instruction {}",
expected
Expand All @@ -64,7 +61,7 @@ fn test_display_under(dekoder: &Decoder, data: &[u8], expected: &'static str) {
Err(e) => {
assert!(
false,
"decode error ({}) for {} under decoder {}:\n expected: {}\n",
"decode error ({:?}) for {} under decoder {}:\n expected: {}\n",
e, hex, dekoder, expected
);
}
Expand Down
Loading

0 comments on commit 8a2f23c

Please sign in to comment.