From 0fd2815a59fe500a66685b34915ac5df11098a92 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 4 Apr 2023 22:01:49 +0200 Subject: [PATCH] Improve test in thread_manager, increase memory size to make it fit --- src/kernel/exception.rs | 2 -- src/kernel/thread_manager.rs | 27 ++++++++++++++++++--------- src/simulator/loader.rs | 2 +- src/simulator/machine.rs | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/kernel/exception.rs b/src/kernel/exception.rs index 24555fe..5a96b44 100644 --- a/src/kernel/exception.rs +++ b/src/kernel/exception.rs @@ -1,5 +1,3 @@ -use libc::printf; - use crate::simulator::{machine::{ExceptionType, Machine}, error::{MachineOk, MachineError}}; diff --git a/src/kernel/thread_manager.rs b/src/kernel/thread_manager.rs index e5b0e14..ad123f3 100644 --- a/src/kernel/thread_manager.rs +++ b/src/kernel/thread_manager.rs @@ -200,13 +200,15 @@ impl ThreadManager { mod test { 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] #[ignore = "Pas encore terminé, contient des bugs"] fn test_thread_context() { 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 system = &mut System::default(); @@ -214,17 +216,24 @@ mod test { let thread1 = Rc::new(RefCell::new(thread1)); system.get_thread_manager().get_g_alive().push(Rc::clone(&thread1)); - let owner = Process { num_thread: 0 }; - system.get_thread_manager().start_thread(Rc::clone(&thread1), owner, start_pc, ptr, -1); - debug_assert_eq!(thread1.borrow_mut().thread_context.pc, start_pc); + let thread2 = Thread::new("th2"); + let thread2 = Rc::new(RefCell::new(thread2)); + system.get_thread_manager().get_g_alive().push(Rc::clone(&thread1)); - let to_run = system.get_thread_manager().find_next_to_run().unwrap(); - debug_assert_eq!(to_run, Rc::clone(&thread1)); + let owner2 = Process { num_thread: 0 }; + 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))); + 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)); - debug_assert_eq!(system.get_thread_manager().g_current_thread, Option::Some(Rc::clone(&thread1))); - debug_assert_eq!(machine.pc, start_pc); + debug_assert_eq!(system.get_thread_manager().g_current_thread, Option::Some(Rc::clone(&thread2))); + debug_assert_eq!(machine.pc, ptr1 + loader2.elf_header.entrypoint); machine.run(); } diff --git a/src/simulator/loader.rs b/src/simulator/loader.rs index 7185c29..6916705 100644 --- a/src/simulator/loader.rs +++ b/src/simulator/loader.rs @@ -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, diff --git a/src/simulator/machine.rs b/src/simulator/machine.rs index a5dc3e4..cf320a5 100644 --- a/src/simulator/machine.rs +++ b/src/simulator/machine.rs @@ -75,7 +75,7 @@ pub const NUM_PHY_PAGE : u64 = 400; /// Must be 2^x pub const PAGE_SIZE : u64 = 128; /// 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 pub struct Machine {