From bfef7254d846121e14ae0ba8737941e11ed905c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Thu, 9 Mar 2023 13:24:04 +0100 Subject: [PATCH] Added debug attributes to structs pertaining to thread in order to allow for applying assertions upon Thread --- src/kernel/process.rs | 2 +- src/kernel/system.rs | 2 +- src/kernel/thread.rs | 25 ++++++++++++++++++++++--- test_programs/userlib/libnachos.o | Bin 0 -> 15488 bytes test_programs/userlib/sys.o | Bin 0 -> 3624 bytes 5 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 test_programs/userlib/libnachos.o create mode 100644 test_programs/userlib/sys.o diff --git a/src/kernel/process.rs b/src/kernel/process.rs index a56883e..f28b0fa 100644 --- a/src/kernel/process.rs +++ b/src/kernel/process.rs @@ -1,5 +1,5 @@ -#[derive(PartialEq)] +#[derive(PartialEq, Debug)] pub struct Process { pub num_thread: usize, } \ No newline at end of file diff --git a/src/kernel/system.rs b/src/kernel/system.rs index 319be5c..bad8652 100644 --- a/src/kernel/system.rs +++ b/src/kernel/system.rs @@ -52,7 +52,7 @@ impl<'a> System<'a> { } -#[derive(PartialEq)] +#[derive(PartialEq, Debug)] pub enum ObjectType { SemaphoreType, LockType, diff --git a/src/kernel/thread.rs b/src/kernel/thread.rs index b07058b..d4aedbc 100644 --- a/src/kernel/thread.rs +++ b/src/kernel/thread.rs @@ -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, @@ -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) } } \ No newline at end of file diff --git a/test_programs/userlib/libnachos.o b/test_programs/userlib/libnachos.o new file mode 100644 index 0000000000000000000000000000000000000000..26f4ccaceb20d8eedc82ca547f5f92ffa2644878 GIT binary patch literal 15488 zcmcJV4RBP~b;s}SKIsvVLH5cuDI``|0W!wwuC)3}NV6`oA+8#$4r#tp{ zp8vh)N@uTj38|CE?0fh9-v6F^?zx}uiLX7=_-rr`Q1%F@|5b~3mMYa(Z_*xJ5;~bs zMQVi#2Lf}E_`|_S^yOgK3xpzDPR|~x?I$)hPuKa0K3|0klsZ9qCi;{L)Aa~xL-9b6 z@`m<-1p@PtEf1?m-OGw>1S9d&^O5Me`M>g&N)PyIn0}#JZ+?wWwhDcf{yN=P_s?6K zX}>^)iILp^*$t4rAloHB7X6CUotur6dGnEV-h8J@tT?ig&# zFWA}#pQtQulkso)RPTIs&F*(-U+NcgvR@!xXuD9gx0G{C5ohWTIv!!tBhGL7nFR9c zdx}xjfT{ES^-CMS*0vX2=1L!spD#qmS!S%5KTp3xj~VxxMK z+Hm-U9ZT8vQD6Ga;TocR)c!o?MBlXI?V|2Ko#1le)i{m{GY)`~F>;i#(d& z3TS?trTJ|(?H8&@#T5F*Y-Gz6&70nAq;6^!^UUHrrItO=-0^FkbCTaSaiMm(ix`dX z%}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