From 756410e5b4c12fcc570bfa37ef92607ac26b320b Mon Sep 17 00:00:00 2001 From: Samy Solhi Date: Wed, 9 Nov 2022 15:06:22 +0100 Subject: [PATCH] Added some tests --- src/print.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/print.rs b/src/print.rs index 2f4d185..d4651ba 100644 --- a/src/print.rs +++ b/src/print.rs @@ -1,3 +1,5 @@ +#![allow(dead_code)] +#![allow(unused_variables)] use crate::decode::Instruction; const RISCV_LUI: u8 = 0x37; @@ -254,4 +256,26 @@ pub fn print(ins: Instruction, pc: i32) -> String { //TODO pc should be u64 _ => "Unknown".to_string() // Error } +} + + +#[cfg(test)] +mod Test { + use crate::{print, decode}; + + #[test] + fn test1() { + let sub = decode::decode(0b01000001000010001000111000110011); + let add = decode::decode(0b00000001000010001000111000110011); + let xor = decode::decode(0b00000001000010001100111000110011); + let slr = decode::decode(0b00000001000010001101111000110011); + let sra = decode::decode(0b01000001000010001101111000110011); + + assert_eq!("sub r28, r17, r16", print::print(sub, 0)); + assert_eq!("xor r28, r17, r16", print::print(xor, 0)); + assert_eq!("srl r28, r17, r16", print::print(slr, 0)); + assert_eq!("sra r28, r17, r16", print::print(sra, 0)); + assert_eq!("add r28, r17, r16", print::print(add, 0)); + + } } \ No newline at end of file