Added debug attributes to structs pertaining to thread in order to allow for applying assertions upon Thread

This commit is contained in:
François Autin 2023-03-09 13:24:04 +01:00
parent 71ccd0c16e
commit 6e6b97911a
No known key found for this signature in database
GPG Key ID: 343F5D382E1DD77C
5 changed files with 24 additions and 5 deletions

View File

@ -1,5 +1,5 @@
#[derive(PartialEq)] #[derive(PartialEq, Debug)]
pub struct Process { pub struct Process {
pub num_thread: usize, pub num_thread: usize,
} }

View File

@ -52,7 +52,7 @@ impl<'a> System<'a> {
} }
#[derive(PartialEq)] #[derive(PartialEq, Debug)]
pub enum ObjectType { pub enum ObjectType {
SemaphoreType, SemaphoreType,
LockType, LockType,

View File

@ -3,14 +3,14 @@ use crate::{simulator::machine::{NUM_INT_REGS, NUM_FP_REGS, STACK_REG}};
const STACK_FENCEPOST: u32 = 0xdeadbeef; const STACK_FENCEPOST: u32 = 0xdeadbeef;
#[derive(PartialEq)] #[derive(PartialEq, Debug)]
pub struct ThreadContext { pub struct ThreadContext {
pub int_registers: [i64; NUM_INT_REGS], pub int_registers: [i64; NUM_INT_REGS],
pub float_registers: [f32; NUM_FP_REGS], pub float_registers: [f32; NUM_FP_REGS],
pc: i64, pc: i64,
} }
#[derive(PartialEq)] #[derive(PartialEq, Debug)]
pub struct Thread { pub struct Thread {
name: String, name: String,
pub process: Option<Process>, pub process: Option<Process>,
@ -103,7 +103,7 @@ fn start_thread_execution() {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::{Thread, ThreadContext}; use super::{Thread, ThreadContext, NUM_INT_REGS, NUM_FP_REGS, ObjectType};
macro_rules! get_new_thread { macro_rules! get_new_thread {
() => { Thread::new("test_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] #[test]
fn test_macro() { fn test_macro() {
let t = get_new_thread!("hello"); let t = get_new_thread!("hello");
@ -123,6 +140,8 @@ mod test {
#[test] #[test]
fn check_init() { fn check_init() {
let t = get_new_thread!(); let t = get_new_thread!();
let expected_state = expected_initial_state!();
assert_eq!(t, expected_state)
} }
} }

Binary file not shown.

BIN
test_programs/userlib/sys.o Normal file

Binary file not shown.