From 2533883ea788be2cd874c369c52a7f17a5ed000e Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 15 Mar 2023 15:12:47 +0100 Subject: [PATCH] machine tests ok --- src/simulator/machine.rs | 24 +++++++++++++----------- src/simulator/mem_cmp.rs | 6 +++--- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/simulator/machine.rs b/src/simulator/machine.rs index 1425292..0b0888b 100644 --- a/src/simulator/machine.rs +++ b/src/simulator/machine.rs @@ -39,7 +39,7 @@ pub const NUM_PHY_PAGE : u64 = 400; //doit etre une puissance de deux pub const PAGE_SIZE : u64 = 128; //doit etre un multiple de PAGE_SIZE -pub const MEM_SIZE : usize = (PAGE_SIZE*NUM_PHY_PAGE) as usize; +pub const MEM_SIZE : usize = (PAGE_SIZE*NUM_PHY_PAGE*100) as usize; pub trait RegisterNum: Add + Sub + PartialEq + Copy {} @@ -257,10 +257,10 @@ impl Machine { panic!("ERROR : number max of instructions rushed"); } let mut val: [u8; 4] = [0; 4]; - for (i, mut _item) in val.iter_mut().enumerate() { - _item = &mut machine.main_memory[machine.pc as usize + i]; + for i in 0..4 { + val[i] = machine.main_memory[machine.pc as usize + i]; } - + let val = u32::from_be_bytes(val) as u64; let inst : Instruction = decode(val); Self::print_machine_status(machine); @@ -763,6 +763,8 @@ mod test { let memory_before = mem_cmp::MemChecker::from("test/machine/memoryComp.txt").unwrap(); let memory_after = mem_cmp::MemChecker::from("test/machine/memoryCompEnd.txt").unwrap(); mem_cmp::MemChecker::fill_memory_from_mem_checker(&memory_before, &mut m); + Machine::_print_memory(&mut m, 0x4000, 0x4200); + Machine::_print_memory(&mut m, 4000, 4200); Machine::run(&mut m); let expected_trace = fs::read_to_string("test/machine/reg_traceComp.txt").unwrap(); @@ -772,7 +774,7 @@ mod test { } #[test] - #[ignore] + //#[ignore] fn test_div() { let mut m = Machine::init_machine(); let memory_before = mem_cmp::MemChecker::from("test/machine/memoryDiv.txt").unwrap(); @@ -787,7 +789,7 @@ mod test { } #[test] - #[ignore] + //#[ignore] fn test_if() { let mut m = Machine::init_machine(); let memory_before = mem_cmp::MemChecker::from("test/machine/memoryIf.txt").unwrap(); @@ -802,7 +804,7 @@ mod test { } #[test] - #[ignore] + //#[ignore] fn test_jump() { let mut m = Machine::init_machine(); let memory_before = mem_cmp::MemChecker::from("test/machine/memoryJump.txt").unwrap(); @@ -817,7 +819,7 @@ mod test { } #[test] - #[ignore] + //#[ignore] fn test_mul() { let mut m = Machine::init_machine(); let memory_before = mem_cmp::MemChecker::from("test/machine/memoryMult.txt").unwrap(); @@ -832,7 +834,7 @@ mod test { } #[test] - #[ignore] + //#[ignore] fn test_ret() { let mut m = Machine::init_machine(); let memory_before = mem_cmp::MemChecker::from("test/machine/memoryRet.txt").unwrap(); @@ -847,7 +849,7 @@ mod test { } #[test] - #[ignore] + //#[ignore] fn test_sub() { let mut m = Machine::init_machine(); let memory_before = mem_cmp::MemChecker::from("test/machine/memorySub.txt").unwrap(); @@ -862,7 +864,7 @@ mod test { } #[test] - #[ignore] + //#[ignore] fn test_switch() { let mut m = Machine::init_machine(); let memory_before = mem_cmp::MemChecker::from("test/machine/memorySwitch.txt").unwrap(); diff --git a/src/simulator/mem_cmp.rs b/src/simulator/mem_cmp.rs index 04aed6d..083e982 100644 --- a/src/simulator/mem_cmp.rs +++ b/src/simulator/mem_cmp.rs @@ -39,8 +39,8 @@ impl Section { /// Creates a memory section from a SectionFormat fn from(section: &SectionFormat) -> Section { - let addr = usize::from_str_radix(§ion.addr, 10).unwrap_or_default(); - let len = usize::from_str_radix(§ion.len, 10).unwrap_or_default(); + let addr = usize::from_str_radix(§ion.addr, 16).unwrap_or_default(); + let len = usize::from_str_radix(§ion.len, 16).unwrap_or_default(); let content: Vec = section.content.as_bytes().chunks(2).map(|x| { u8::from_str_radix(std::str::from_utf8(x).unwrap_or_default(), 16).unwrap_or_default() }).collect(); @@ -170,7 +170,7 @@ impl MemChecker{ for section in m_c.sections.iter() { for (i,b) in section.content.iter().enumerate() { - machine.main_memory[section.addr/8 + i] = *b; + machine.main_memory[section.addr + i] = *b; } } }