Improve test in thread_manager, increase memory size to make it fit

This commit is contained in:
Quentin Legot 2023-04-04 22:01:49 +02:00
parent a001e45c3f
commit 0fd2815a59
4 changed files with 20 additions and 13 deletions

View File

@ -1,5 +1,3 @@
use libc::printf;
use crate::simulator::{machine::{ExceptionType, Machine}, error::{MachineOk, MachineError}}; use crate::simulator::{machine::{ExceptionType, Machine}, error::{MachineOk, MachineError}};

View File

@ -200,13 +200,15 @@ impl ThreadManager {
mod test { mod test {
use std::{rc::Rc, cell::RefCell}; use std::{rc::Rc, cell::RefCell};
use crate::{simulator::{machine::Machine, loader}, kernel::{system::System, thread::Thread, process::Process}}; use crate::{simulator::{machine::Machine, loader}, kernel::{system::System, thread::{Thread, self}, process::Process}};
#[test] #[test]
#[ignore = "Pas encore terminé, contient des bugs"] #[ignore = "Pas encore terminé, contient des bugs"]
fn test_thread_context() { fn test_thread_context() {
let mut machine = Machine::init_machine(); let mut machine = Machine::init_machine();
let (loader, ptr) = loader::Loader::new("./test/riscv_instructions/simple_arithmetics/unsigned_addition", &mut machine, 0).expect("IO Error"); let (loader, ptr1) = loader::Loader::new("./test/riscv_instructions/simple_arithmetics/unsigned_addition", &mut machine, 0).expect("IO Error");
println!("{}", ptr1);
let (loader2, ptr2) = loader::Loader::new("./test/riscv_instructions/syscall_tests/halt", &mut machine, ptr1 as usize).expect("IO Error");
let start_pc = loader.elf_header.entrypoint; let start_pc = loader.elf_header.entrypoint;
let system = &mut System::default(); let system = &mut System::default();
@ -214,17 +216,24 @@ mod test {
let thread1 = Rc::new(RefCell::new(thread1)); let thread1 = Rc::new(RefCell::new(thread1));
system.get_thread_manager().get_g_alive().push(Rc::clone(&thread1)); system.get_thread_manager().get_g_alive().push(Rc::clone(&thread1));
let owner = Process { num_thread: 0 }; let thread2 = Thread::new("th2");
system.get_thread_manager().start_thread(Rc::clone(&thread1), owner, start_pc, ptr, -1); let thread2 = Rc::new(RefCell::new(thread2));
debug_assert_eq!(thread1.borrow_mut().thread_context.pc, start_pc); system.get_thread_manager().get_g_alive().push(Rc::clone(&thread1));
let to_run = system.get_thread_manager().find_next_to_run().unwrap(); let owner2 = Process { num_thread: 0 };
debug_assert_eq!(to_run, Rc::clone(&thread1)); system.get_thread_manager().start_thread(Rc::clone(&thread2), owner2, ptr1 + loader2.elf_header.entrypoint, ptr2 , -1);
let owner1 = Process { num_thread: 0 };
system.get_thread_manager().start_thread(Rc::clone(&thread1), owner1, loader.elf_header.entrypoint, ptr1, -1);
debug_assert_eq!(thread1.borrow_mut().thread_context.pc, start_pc);
debug_assert!(system.get_thread_manager().get_g_alive().contains(&Rc::clone(&thread1))); debug_assert!(system.get_thread_manager().get_g_alive().contains(&Rc::clone(&thread1)));
let to_run = system.get_thread_manager().find_next_to_run().unwrap();
debug_assert_eq!(to_run, Rc::clone(&thread2));
system.get_thread_manager().switch_to(&mut machine, Rc::clone(&to_run)); system.get_thread_manager().switch_to(&mut machine, Rc::clone(&to_run));
debug_assert_eq!(system.get_thread_manager().g_current_thread, Option::Some(Rc::clone(&thread1))); debug_assert_eq!(system.get_thread_manager().g_current_thread, Option::Some(Rc::clone(&thread2)));
debug_assert_eq!(machine.pc, start_pc); debug_assert_eq!(machine.pc, ptr1 + loader2.elf_header.entrypoint);
machine.run(); machine.run();
} }

View File

@ -490,7 +490,7 @@ impl Loader {
} }
} }
} }
Ok(start_index as u64 + end_index) Ok(start_index as u64 + end_index + 4)
} }
/// Load the binary file and store it inside an array and try to parse it, /// Load the binary file and store it inside an array and try to parse it,

View File

@ -75,7 +75,7 @@ pub const NUM_PHY_PAGE : u64 = 400;
/// Must be 2^x /// Must be 2^x
pub const PAGE_SIZE : u64 = 128; pub const PAGE_SIZE : u64 = 128;
/// Must be a multiple of PAGE_SIZE /// Must be a multiple of PAGE_SIZE
pub const MEM_SIZE : usize = (PAGE_SIZE*NUM_PHY_PAGE*100) as usize; pub const MEM_SIZE : usize = (PAGE_SIZE*NUM_PHY_PAGE*100_000) as usize;
/// RISC-V Simulator /// RISC-V Simulator
pub struct Machine { pub struct Machine {