Added debug attributes to structs pertaining to thread in order to allow for applying assertions upon Thread
This commit is contained in:
parent
8bf7a452f3
commit
bfef7254d8
@ -1,5 +1,5 @@
|
||||
|
||||
#[derive(PartialEq)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct Process {
|
||||
pub num_thread: usize,
|
||||
}
|
@ -52,7 +52,7 @@ impl<'a> System<'a> {
|
||||
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum ObjectType {
|
||||
SemaphoreType,
|
||||
LockType,
|
||||
|
@ -3,14 +3,14 @@ use crate::{simulator::machine::{NUM_INT_REGS, NUM_FP_REGS, STACK_REG}};
|
||||
|
||||
const STACK_FENCEPOST: u32 = 0xdeadbeef;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct ThreadContext {
|
||||
pub int_registers: [i64; NUM_INT_REGS],
|
||||
pub float_registers: [f32; NUM_FP_REGS],
|
||||
pc: i64,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct Thread {
|
||||
name: String,
|
||||
pub process: Option<Process>,
|
||||
@ -103,7 +103,7 @@ fn start_thread_execution() {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
use super::{Thread, ThreadContext};
|
||||
use super::{Thread, ThreadContext, NUM_INT_REGS, NUM_FP_REGS, ObjectType};
|
||||
|
||||
macro_rules! get_new_thread {
|
||||
() => { Thread::new("test_thread") };
|
||||
@ -112,6 +112,23 @@ mod test {
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! expected_initial_state {
|
||||
() => { expected_initial_state!("test_thread") };
|
||||
($a:literal) => { {
|
||||
let mut x = Thread::new($a);
|
||||
x.name = $a.to_string();
|
||||
x.process = Option::None;
|
||||
x.thread_context = ThreadContext {
|
||||
int_registers: [0; NUM_INT_REGS],
|
||||
float_registers: [0f32; NUM_FP_REGS],
|
||||
pc: 0
|
||||
};
|
||||
x.stack_pointer = 0;
|
||||
x.object_type = ObjectType::ThreadType;
|
||||
x }
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_macro() {
|
||||
let t = get_new_thread!("hello");
|
||||
@ -123,6 +140,8 @@ mod test {
|
||||
#[test]
|
||||
fn check_init() {
|
||||
let t = get_new_thread!();
|
||||
let expected_state = expected_initial_state!();
|
||||
assert_eq!(t, expected_state)
|
||||
}
|
||||
|
||||
}
|
BIN
test_programs/userlib/libnachos.o
Normal file
BIN
test_programs/userlib/libnachos.o
Normal file
Binary file not shown.
BIN
test_programs/userlib/sys.o
Normal file
BIN
test_programs/userlib/sys.o
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user