Take a random assembly instruction and check its encoding and pretty-printing against a known-good disassembler. # Panics This function panics to express failure as expected by the `arbitrary` fuzzer infrastructure. It may fail during assembly, disassembly, or when comparing the disassembled strings.
(inst: &Inst<FuzzRegs>)
| 24 | /// fuzzer infrastructure. It may fail during assembly, disassembly, or when |
| 25 | /// comparing the disassembled strings. |
| 26 | pub fn roundtrip(inst: &Inst<FuzzRegs>) { |
| 27 | // Check that we can actually assemble this instruction. |
| 28 | let assembled = assemble(inst); |
| 29 | let expected = disassemble(&assembled, inst); |
| 30 | |
| 31 | // Check that our pretty-printed output matches the known-good output. Trim |
| 32 | // off the instruction offset first. |
| 33 | let expected = expected.split_once(' ').unwrap().1; |
| 34 | let actual = inst.to_string(); |
| 35 | if expected != actual && expected.trim() != fix_up(&actual) { |
| 36 | println!("> {inst}"); |
| 37 | println!(" debug: {inst:x?}"); |
| 38 | println!(" assembled: {}", pretty_print_hexadecimal(&assembled)); |
| 39 | println!(" expected (capstone): {expected}"); |
| 40 | println!(" actual (to_string): {actual}"); |
| 41 | assert_eq!(expected, &actual); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | /// Use this assembler to emit machine code into a byte buffer. |
| 46 | /// |