From 8bf7a452f3a773217993e38374717a4e46220dba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Thu, 9 Mar 2023 13:07:50 +0100 Subject: [PATCH] Added macro to get new thread easily and started writing test --- src/kernel/thread.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/kernel/thread.rs b/src/kernel/thread.rs index 1b8b41d..b07058b 100644 --- a/src/kernel/thread.rs +++ b/src/kernel/thread.rs @@ -103,10 +103,26 @@ fn start_thread_execution() { #[cfg(test)] mod test { - use super::Thread; + use super::{Thread, ThreadContext}; - fn get_new_thread() -> Thread { - Thread::new("test_thread") + macro_rules! get_new_thread { + () => { Thread::new("test_thread") }; + ($a:literal) => { + Thread::new(&$a.to_string()) + }; + } + + #[test] + fn test_macro() { + let t = get_new_thread!("hello"); + assert_eq!(t.get_name(), "hello"); + let t = get_new_thread!(1); + assert_eq!(t.get_name(), "1"); + } + + #[test] + fn check_init() { + let t = get_new_thread!(); } } \ No newline at end of file