diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0746ff7..e6b0a50 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,6 +7,8 @@ stages: unit-test-job: stage: test script: + - echo "Compiling c files" + - cd test && make build && cd .. - echo "Running unit tests..." - cargo test diff --git a/src/simulator/loader.rs b/src/simulator/loader.rs index 82be5e7..7185c29 100644 --- a/src/simulator/loader.rs +++ b/src/simulator/loader.rs @@ -602,13 +602,15 @@ fn get_address_point(instructions: &[u8], address: usize, is_32bits: bool) -> Op } } +/// Tests has been made for C program compiled with RISC-V GCC 12.2.0, target: riscv64-unknown-elf +/// +/// It may not pass in the future if future gcc version modify order of the binary or something else #[cfg(test)] mod test { - use crate::simulator::{loader::Loader, machine::Machine}; + use crate::simulator::{loader::{Loader, SectionHeader}, machine::Machine}; #[test] - #[ignore = "CI gitlab a modifié"] fn test_parse_elf() { let mut machine = Machine::init_machine(); let loader = Loader::load_and_parse("./test/riscv_instructions/simple_arithmetics/unsigned_addition").expect("IO Error"); @@ -629,4 +631,20 @@ mod test { println!("{:#x?}", loader.sections); } + #[test] + fn test_parse_section() { + let mut machine = Machine::init_machine(); + let loader = Loader::load_and_parse("./test/riscv_instructions/simple_arithmetics/unsigned_addition").expect("IO Error"); + loader.load_into_machine(&mut machine, 0).expect("Parsing error"); + assert_eq!(9, loader.sections.len()); + let n = loader.sections.iter().filter(|p| { p.does_flag_contains_key(crate::simulator::loader::FlagValue::ShfAlloc)}).collect::>().len(); + assert_eq!(3, n); + assert_eq!(loader.sections[1].virt_addr, 0x4000); + assert_eq!(loader.sections[1].image_offset, 0x1000); + assert!(loader.sections[1].does_flag_contains_key(crate::simulator::loader::FlagValue::ShfAlloc)); + assert_eq!(loader.sections[2].virt_addr, 0x400_000); + assert_eq!(loader.sections[2].image_offset, 0x2000); + assert!(loader.sections[2].does_flag_contains_key(crate::simulator::loader::FlagValue::ShfAlloc)); + } + } \ No newline at end of file