Adding test to loader, update ci (hope it work)
This commit is contained in:
parent
aef8d219d0
commit
fc3237c4ad
@ -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
|
||||||
|
|
||||||
|
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user