Tests lock
Signed-off-by: Rémi Rativel <remi.rativel@etudiant.univ-rennes1.fr>
This commit is contained in:
parent
35b2949243
commit
32c1237c26
@ -301,7 +301,10 @@ impl ThreadManager {
|
||||
Some(thread) => {
|
||||
lock.owner = Some(thread);
|
||||
match &lock.owner {
|
||||
Some(x) => self.ready_to_run(Rc::clone(x)),
|
||||
Some(x) => {
|
||||
self.ready_to_run(Rc::clone(x));
|
||||
lock.free = true;
|
||||
},
|
||||
None => ()
|
||||
}
|
||||
},
|
||||
@ -369,6 +372,7 @@ mod test {
|
||||
use std::{rc::Rc, cell::RefCell};
|
||||
|
||||
use crate::{simulator::{machine::Machine, loader}, kernel::{system::System, thread::Thread, process::Process, thread_manager::ThreadManager, synch::Semaphore}};
|
||||
use crate::kernel::synch::Lock;
|
||||
|
||||
#[test]
|
||||
fn test_thread_context() {
|
||||
@ -398,6 +402,31 @@ mod test {
|
||||
machine.run(system);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lock(){
|
||||
let mut machine = Machine::new(true);
|
||||
let mut thread_manager = ThreadManager::new(true);
|
||||
let lock = Lock::new();
|
||||
let lock_id = thread_manager.get_obj_addrs().add_lock(lock);
|
||||
let thread = Rc::new(RefCell::new(Thread::new("test_lock")));
|
||||
thread_manager.ready_to_run(Rc::clone(&thread));
|
||||
thread_manager.set_g_current_thread(Some(thread));
|
||||
|
||||
thread_manager.lock_acquire(lock_id, &mut machine).expect("lock acquire return an error: ");
|
||||
{
|
||||
let lock = thread_manager.get_obj_addrs().search_lock(lock_id).unwrap();
|
||||
assert!(!lock.free);
|
||||
assert!(lock.waiting_queue.is_empty());
|
||||
}
|
||||
|
||||
thread_manager.lock_release(lock_id, &mut machine).expect("lock release return an error: ");
|
||||
{
|
||||
let lock = thread_manager.get_obj_addrs().search_lock(lock_id).unwrap();
|
||||
assert!(!lock.free);
|
||||
assert!(lock.waiting_queue.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_semaphore_single() {
|
||||
// Init
|
||||
|
Loading…
Reference in New Issue
Block a user