Adding test to loader, update ci (hope it work)

This commit is contained in:
Quentin Legot 2023-04-04 11:50:29 +02:00
parent aef8d219d0
commit fc3237c4ad
2 changed files with 22 additions and 2 deletions

View File

@ -7,6 +7,8 @@ stages:
unit-test-job: unit-test-job:
stage: test stage: test
script: script:
- echo "Compiling c files"
- cd test && make build && cd ..
- echo "Running unit tests..." - echo "Running unit tests..."
- cargo test - cargo test

View File

@ -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)] #[cfg(test)]
mod test { mod test {
use crate::simulator::{loader::Loader, machine::Machine}; use crate::simulator::{loader::{Loader, SectionHeader}, machine::Machine};
#[test] #[test]
#[ignore = "CI gitlab a modifié"]
fn test_parse_elf() { fn test_parse_elf() {
let mut machine = Machine::init_machine(); let mut machine = Machine::init_machine();
let loader = Loader::load_and_parse("./test/riscv_instructions/simple_arithmetics/unsigned_addition").expect("IO Error"); 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); 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::<Vec<&SectionHeader>>().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));
}
} }