Skip to content

Commit

Permalink
add elf parser test
Browse files Browse the repository at this point in the history
  • Loading branch information
svv232 committed Nov 18, 2024
1 parent 4bc0b20 commit 3fdda8e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions o1vm/tests/test_riscv_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ use o1vm::interpreters::riscv32i::{
PAGE_SIZE,
};

#[test]
// This test is used to check that the elf loader is working correctly.
// We must export the code used in this test in a function that can be called by
// the o1vm at load time.
fn test_correctly_parsing_elf() {
let curr_dir = std::env::current_dir().unwrap();
let path = curr_dir.join(std::path::PathBuf::from(
"resources/programs/riscv32i/fibonacci",
));
let state = o1vm::elf_loader::parse_riscv32i(&path).unwrap();
// This is the output we get by running objdump -d fibonacci
assert_eq!(state.pc, 69932);

assert_eq!(state.memory.len(), 1);
assert_eq!(state.memory[0].index, 17);
}

#[test]
// Checking an instruction can be converted into a string.
// It is mostly because we would want to use it to debug or write better error
Expand Down

0 comments on commit 3fdda8e

Please sign in to comment.