From 6945128f720da30ef460ac0ee1a031d3eeb0fb26 Mon Sep 17 00:00:00 2001 From: Moysan Gabriel Date: Wed, 8 Feb 2023 12:37:21 +0100 Subject: [PATCH] test create mem check --- src/simulator/mem_cmp.rs | 54 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/src/simulator/mem_cmp.rs b/src/simulator/mem_cmp.rs index 02a3602..00a60eb 100644 --- a/src/simulator/mem_cmp.rs +++ b/src/simulator/mem_cmp.rs @@ -73,6 +73,13 @@ impl Section{ Section{addr:addr, len:len, content:content} } + + + fn print_Section(s: &Section){ + println!("ADDR :: {}", s.addr); + println!("LEN :: {}", s.len); + println!("CONTENT :: {:?}", s.content); + } } /* @@ -86,12 +93,18 @@ struct Mem_Checker{ impl Mem_Checker{ - fn from(path: &String) /*-> Mem_Checker*/{ + + fn from(path: &String) -> Mem_Checker { let file = fs::File::open("test_file_section.txt").expect("Wrong filename"); let reader = io::BufReader::new(file); + let mut pc: usize = 0; let mut sp: usize = 0; + let mut sections: Vec
= Vec::new(); + + let mut tmp_addr_str: String = String::new(); + let mut tmp_len_str: String = String::new(); for (i,line) in reader.lines().enumerate() { @@ -107,8 +120,38 @@ impl Mem_Checker{ } else { //Lecture des sections + if current_line.contains(' ') { + //lecture ligne ADDR LEN + let next_word_index = current_line.find(' ').unwrap(); + tmp_addr_str = String::from(¤t_line[0..next_word_index]); + tmp_len_str = String::from(¤t_line[next_word_index+1..]); + } + else { + //lecture ligne CONTENT + let section_f = SectionFormat{ + addr: tmp_addr_str.clone(), + len: tmp_len_str.clone(), + content: current_line, + }; + sections.push(Section::from(§ion_f)); + } + } } + + Mem_Checker{pc:pc, sp:sp, sections:sections} + } + + + fn print_Mem_Checker(m_c: &Mem_Checker){ + println!("PC :: {}", m_c.pc); + println!("SP :: {}", m_c.sp); + + for(i,s) in m_c.sections.iter().enumerate() { + println!("\nSection {}\n", i); + Section::print_Section(&s); + } + } } @@ -121,7 +164,7 @@ fn string_hex_to_usize(s: &String) -> usize{ let base: usize = 16; for (i,c )in s.chars().enumerate(){ - print!("Current char :: {} :: Current pow :: {} ::", c, max_pow - (i as u32)); + //println!("Current char :: {} :: Current pow :: {} ::", c, max_pow - (i as u32)); let tmp: usize = (one_hex_to_dec(c) as usize); ret_value += base.pow(max_pow - (i as u32))*tmp; } @@ -185,6 +228,13 @@ fn test_show_sections_file(){ mod tests { use super::*; + #[test] + fn test_create_Mem_Chercker(){ + let path: String = "osef".to_string(); + let m_c = Mem_Checker::from(&path); + Mem_Checker::print_Mem_Checker(&m_c); + } + #[test] fn test_string_hex_to_usize(){