diff --git a/Cargo.toml b/Cargo.toml index eeae42f..41a0fea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,6 @@ edition = "2021" [features] default = [] c-library = [] + +[dev-dependencies] +sequential-test = "0.2.4" diff --git a/src/task_manager.rs b/src/task_manager.rs index 792069a..dec6c15 100644 --- a/src/task_manager.rs +++ b/src/task_manager.rs @@ -227,28 +227,44 @@ impl TaskManager { } } - /// Starts task manager work. + /// One step of task manager's work. // TODO: Support priorities. // TODO: Delete tasks from task vector if they are pending - pub fn start_task_manager() -> ! { - loop { - if unsafe { !TASK_MANAGER.tasks.is_empty() } { - let waker = task_waker(); - - let task = unsafe { &mut TASK_MANAGER.tasks[TASK_MANAGER.task_to_execute_index] }; - let mut task_future_pin = Pin::new(task); - let _ = task_future_pin - .as_mut() - .poll(&mut Context::from_waker(&waker)); - - unsafe { - if TASK_MANAGER.task_to_execute_index + 1 < TASK_MANAGER.tasks.len() { - TASK_MANAGER.task_to_execute_index += 1; - } else { - TASK_MANAGER.task_to_execute_index = 0; - } + fn task_manager_step() { + if unsafe { !TASK_MANAGER.tasks.is_empty() } { + let waker = task_waker(); + + let task = unsafe { &mut TASK_MANAGER.tasks[TASK_MANAGER.task_to_execute_index] }; + let mut task_future_pin = Pin::new(task); + let _ = task_future_pin + .as_mut() + .poll(&mut Context::from_waker(&waker)); + + unsafe { + if TASK_MANAGER.task_to_execute_index + 1 < TASK_MANAGER.tasks.len() { + TASK_MANAGER.task_to_execute_index += 1; + } else { + TASK_MANAGER.task_to_execute_index = 0; } } } } + + /// Starts task manager work. + pub fn start_task_manager() -> ! { + loop { + TaskManager::task_manager_step(); + } + } + + /// Starts task manager work. Returns after 1000 steps only for testing task_manager_step. + pub fn test_start_task_manager() { + for _n in 1..=1000 { + TaskManager::task_manager_step(); + } + // This is bad idea + unsafe { + TASK_MANAGER.tasks_number = 0; + } + } } diff --git a/tests/unit_tests.rs b/tests/unit_tests.rs index 892b53b..298f230 100644 --- a/tests/unit_tests.rs +++ b/tests/unit_tests.rs @@ -2,26 +2,18 @@ mod unit_tests { use ma_rtos::task_manager::TaskManager; use ma_rtos::timer::Timer; + use sequential_test::sequential; use std::sync::atomic::{AtomicU32, Ordering}; - use std::thread::{sleep, spawn}; - use std::time::Duration; - // TODO: fix tests for task manager. They can't be run in parallel because of static task manager // TODO: refactor unit tests. They should check less. Separate tests for setup, loop and stop functions. // TODO: refactor unit tests. Task manager and timer tests should be in different files in one directory. - // #[test] - // /// Tests if task manager without tasks works during 1 second without panic. - // fn test_empty_task_manager() { - // TaskExecutor::drop_task_executor(); - // - // let fun_thread = spawn(|| { - // TaskExecutor::start_task_manager(); - // }); - // sleep(Duration::from_secs(1)); - // - // assert_eq!(fun_thread.is_finished(), false); - // } + #[test] + #[sequential] + /// Tests if task manager without tasks works during some time. + fn test_empty_task_manager() { + TaskManager::test_start_task_manager(); + } /// Counter for task for test_one_finite_task_task_manager. static TEST_ONE_FINITE_TASK_TASK_MANAGER_COUNTER: AtomicU32 = AtomicU32::new(1); @@ -40,261 +32,231 @@ mod unit_tests { return false; } #[test] - /// Tests if task manager with one finite task works correctly during 1 second without panic. + #[sequential] + /// Tests if task manager with one finite task works correctly during some time without panic. fn test_one_finite_task_task_manager() { - let fun_thread = spawn(|| { - TaskManager::add_task( - test_one_finite_task_task_manager_setup_fn, - test_one_finite_task_task_manager_loop_fn, - test_one_finite_task_task_manager_stop_condition_fn, - ); - TaskManager::start_task_manager() - }); - sleep(Duration::from_secs(1)); + TaskManager::add_task( + test_one_finite_task_task_manager_setup_fn, + test_one_finite_task_task_manager_loop_fn, + test_one_finite_task_task_manager_stop_condition_fn, + ); + TaskManager::test_start_task_manager(); - assert_eq!(fun_thread.is_finished(), false); assert_eq!( unsafe { TEST_ONE_FINITE_TASK_TASK_MANAGER_COUNTER.as_ptr().read() }, 50 ); } - // - // /// Counter for task for test_one_infinite_task_task_manager. - // static TEST_ONE_INFINITE_TASK_TASK_MANAGER_COUNTER: AtomicU32 = AtomicU32::new(1); - // /// Setup function for task for test_one_infinite_task_task_manager. - // fn test_one_infinite_task_task_manager_setup_fn() {} - // /// Loop function for task for test_one_infinite_task_task_manager. - // fn test_one_infinite_task_task_manager_loop_fn() { - // TEST_ONE_INFINITE_TASK_TASK_MANAGER_COUNTER.fetch_add(1, Ordering::Relaxed); - // } - // /// Stop function for task for test_one_infinite_task_task_manager. - // fn test_one_infinite_task_task_manager_stop_condition_fn() -> bool { - // return false; - // } - // #[test] - // /// Tests if task manager with one infinite task works correctly during 1 second without panic. - // fn test_one_infinite_task_task_manager() { - // TaskExecutor::drop_task_executor(); - // - // let fun_thread = spawn(|| { - // TaskExecutor::add_task( - // test_one_infinite_task_task_manager_setup_fn, - // test_one_infinite_task_task_manager_loop_fn, - // test_one_infinite_task_task_manager_stop_condition_fn, - // ); - // TaskExecutor::start_task_manager() - // }); - // sleep(Duration::from_secs(1)); - // - // assert_eq!(fun_thread.is_finished(), false); - // } - // - // /// Counter for task for test_two_finite_tasks_task_manager. - // static TEST_TWO_FINITE_TASK_TASK_MANAGER_COUNTER1: AtomicU32 = AtomicU32::new(1); - // /// Setup function for task for test_two_finite_tasks_task_manager. - // fn test_two_finite_tasks_task_manager_setup_fn1() {} - // /// Loop function for task for test_two_finite_tasks_task_manager. - // fn test_two_finite_tasks_task_manager_loop_fn1() { - // TEST_TWO_FINITE_TASK_TASK_MANAGER_COUNTER1.fetch_add(1, Ordering::Relaxed); - // } - // /// Stop function for task for test_two_finite_tasks_task_manager. - // fn test_two_finite_tasks_task_manager_stop_condition_fn1() -> bool { - // let value = unsafe { TEST_TWO_FINITE_TASK_TASK_MANAGER_COUNTER1.as_ptr().read() }; - // if value % 50 == 0 { - // return true; - // } - // return false; - // } - // /// Counter for task for test_two_finite_tasks_task_manager. - // static TEST_TWO_FINITE_TASK_TASK_MANAGER_COUNTER2: AtomicU32 = AtomicU32::new(1); - // /// Setup function for task for test_two_finite_tasks_task_manager. - // fn test_two_finite_tasks_task_manager_setup_fn2() {} - // /// Loop function for task for test_two_finite_tasks_task_manager. - // fn test_two_finite_tasks_task_manager_loop_fn2() { - // TEST_TWO_FINITE_TASK_TASK_MANAGER_COUNTER2.fetch_add(1, Ordering::Relaxed); - // } - // /// Stop function for task for test_two_finite_tasks_task_manager. - // fn test_two_finite_tasks_task_manager_stop_condition_fn2() -> bool { - // let value = unsafe { TEST_TWO_FINITE_TASK_TASK_MANAGER_COUNTER2.as_ptr().read() }; - // if value % 25 == 0 { - // return true; - // } - // return false; - // } - // #[test] - // /// Tests if task manager with two finite tasks works correctly during 1 second without panic. - // fn test_two_finite_tasks_task_manager() { - // TaskExecutor::drop_task_executor(); - // - // let fun_thread = spawn(|| { - // TaskExecutor::add_task( - // test_two_finite_tasks_task_manager_setup_fn1, - // test_two_finite_tasks_task_manager_loop_fn1, - // test_two_finite_tasks_task_manager_stop_condition_fn1, - // ); - // TaskExecutor::add_task( - // test_two_finite_tasks_task_manager_setup_fn2, - // test_two_finite_tasks_task_manager_loop_fn2, - // test_two_finite_tasks_task_manager_stop_condition_fn2, - // ); - // TaskExecutor::start_task_manager() - // }); - // sleep(Duration::from_secs(1)); - // - // assert_eq!(fun_thread.is_finished(), false); - // assert_eq!( - // unsafe { TEST_TWO_FINITE_TASK_TASK_MANAGER_COUNTER1.as_ptr().read() }, - // 50 - // ); - // assert_eq!( - // unsafe { TEST_TWO_FINITE_TASK_TASK_MANAGER_COUNTER2.as_ptr().read() }, - // 25 - // ); - // } - // - // /// Counter for task for test_two_different_tasks_task_manager. - // static TEST_TWO_DIFFERENT_TASK_TASK_MANAGER_COUNTER1: AtomicU32 = AtomicU32::new(1); - // /// Setup function for task for test_two_different_tasks_task_manager. - // fn test_two_different_tasks_task_manager_setup_fn1() {} - // /// Loop function for task for test_two_different_tasks_task_manager. - // fn test_two_different_tasks_task_manager_loop_fn1() { - // TEST_TWO_DIFFERENT_TASK_TASK_MANAGER_COUNTER1.fetch_add(1, Ordering::Relaxed); - // } - // /// Stop function for task for test_two_different_tasks_task_manager. - // fn test_two_different_tasks_task_manager_stop_condition_fn1() -> bool { - // let value = unsafe { - // TEST_TWO_DIFFERENT_TASK_TASK_MANAGER_COUNTER1 - // .as_ptr() - // .read() - // }; - // if value % 50 == 0 { - // return true; - // } - // return false; - // } - // /// Counter for task for test_two_different_tasks_task_manager. - // static TEST_TWO_DIFFERENT_TASK_TASK_MANAGER_COUNTER2: AtomicU32 = AtomicU32::new(1); - // /// Setup function for task for test_two_different_tasks_task_manager. - // fn test_two_different_tasks_task_manager_setup_fn2() {} - // /// Loop function for task for test_two_different_tasks_task_manager. - // fn test_two_different_tasks_task_manager_loop_fn2() { - // TEST_TWO_DIFFERENT_TASK_TASK_MANAGER_COUNTER2.fetch_add(1, Ordering::Relaxed); - // } - // /// Stop function for task for test_two_different_tasks_task_manager. - // fn test_two_different_tasks_task_manager_stop_condition_fn2() -> bool { - // return false; - // } - // #[test] - // /// Tests if task manager with two different (finite and infinite) tasks works correctly during 1 second without panic. - // fn test_two_different_tasks_task_manager() { - // TaskExecutor::drop_task_executor(); - // - // let fun_thread = spawn(|| { - // TaskExecutor::add_task( - // test_two_different_tasks_task_manager_setup_fn1, - // test_two_different_tasks_task_manager_loop_fn1, - // test_two_different_tasks_task_manager_stop_condition_fn1, - // ); - // TaskExecutor::add_task( - // test_two_different_tasks_task_manager_setup_fn2, - // test_two_different_tasks_task_manager_loop_fn2, - // test_two_different_tasks_task_manager_stop_condition_fn2, - // ); - // TaskExecutor::start_task_manager() - // }); - // sleep(Duration::from_secs(1)); - // - // assert_eq!(fun_thread.is_finished(), false); - // assert_eq!( - // unsafe { - // TEST_TWO_DIFFERENT_TASK_TASK_MANAGER_COUNTER1 - // .as_ptr() - // .read() - // }, - // 50 - // ); - // } - // - // /// Counter for task for test_two_infinite_tasks_task_manager. - // static TEST_TWO_INFINITE_TASK_TASK_MANAGER_COUNTER1: AtomicU32 = AtomicU32::new(1); - // /// Setup function for task for test_two_infinite_tasks_task_manager. - // fn test_two_infinite_tasks_task_manager_setup_fn1() {} - // /// Loop function for task for test_two_infinite_tasks_task_manager. - // fn test_two_infinite_tasks_task_manager_loop_fn1() { - // TEST_TWO_INFINITE_TASK_TASK_MANAGER_COUNTER1.fetch_add(1, Ordering::Relaxed); - // } - // /// Stop function for task for test_two_infinite_tasks_task_manager. - // fn test_two_infinite_tasks_task_manager_stop_condition_fn1() -> bool { - // return false; - // } - // /// Counter for task for test_two_infinite_tasks_task_manager. - // static TEST_TWO_INFINITE_TASK_TASK_MANAGER_COUNTER2: AtomicU32 = AtomicU32::new(1); - // /// Setup function for task for test_two_infinite_tasks_task_manager. - // fn test_two_infinite_tasks_task_manager_setup_fn2() {} - // /// Loop function for task for test_two_infinite_tasks_task_manager. - // fn test_two_infinite_tasks_task_manager_loop_fn2() { - // TEST_TWO_INFINITE_TASK_TASK_MANAGER_COUNTER2.fetch_add(1, Ordering::Relaxed); - // } - // /// Stop function for task for test_two_infinite_tasks_task_manager. - // fn test_two_infinite_tasks_task_manager_stop_condition_fn2() -> bool { - // return false; - // } - // #[test] - // /// Tests if task manager with two infinite tasks works correctly during 1 second without panic. - // fn test_two_infinite_tasks_task_manager() { - // TaskExecutor::drop_task_executor(); - // - // let fun_thread = spawn(|| { - // TaskExecutor::add_task( - // test_two_infinite_tasks_task_manager_setup_fn1, - // test_two_infinite_tasks_task_manager_loop_fn1, - // test_two_infinite_tasks_task_manager_stop_condition_fn1, - // ); - // TaskExecutor::add_task( - // test_two_infinite_tasks_task_manager_setup_fn2, - // test_two_infinite_tasks_task_manager_loop_fn2, - // test_two_infinite_tasks_task_manager_stop_condition_fn2, - // ); - // TaskExecutor::start_task_manager() - // }); - // sleep(Duration::from_secs(1)); - // - // assert_eq!(fun_thread.is_finished(), false); - // } - // - // /// Counter for task for test_setup_task_manager. - // static TEST_SETUP_TASK_MANAGER_COUNTER: AtomicU32 = AtomicU32::new(1); - // /// Setup function for task for test_setup_task_manager. - // fn test_setup_task_manager_setup_fn() { - // TEST_SETUP_TASK_MANAGER_COUNTER.store(42, Ordering::Relaxed); - // } - // /// Loop function for task for test_setup_task_manager. - // fn test_setup_task_manager_loop_fn() {} - // /// Stop function for task for test_setup_task_manager. - // fn test_setup_task_manager_stop_condition_fn() -> bool { - // return false; - // } - // #[test] - // /// Tests if task manager works correctly with setup function during 1 second without panic. - // fn test_setup_task_manager() { - // TaskExecutor::drop_task_executor(); - // - // let fun_thread = spawn(|| { - // TaskExecutor::add_task( - // test_setup_task_manager_setup_fn, - // test_setup_task_manager_loop_fn, - // test_setup_task_manager_stop_condition_fn, - // ); - // TaskExecutor::start_task_manager() - // }); - // sleep(Duration::from_secs(1)); - // - // assert_eq!(fun_thread.is_finished(), false); - // assert_eq!( - // unsafe { TEST_SETUP_TASK_MANAGER_COUNTER.as_ptr().read() }, - // 42 - // ); - // } + + /// Counter for task for test_one_infinite_task_task_manager. + static TEST_ONE_INFINITE_TASK_TASK_MANAGER_COUNTER: AtomicU32 = AtomicU32::new(1); + /// Setup function for task for test_one_infinite_task_task_manager. + fn test_one_infinite_task_task_manager_setup_fn() {} + /// Loop function for task for test_one_infinite_task_task_manager. + fn test_one_infinite_task_task_manager_loop_fn() { + TEST_ONE_INFINITE_TASK_TASK_MANAGER_COUNTER.fetch_add(1, Ordering::Relaxed); + } + /// Stop function for task for test_one_infinite_task_task_manager. + fn test_one_infinite_task_task_manager_stop_condition_fn() -> bool { + return false; + } + #[test] + #[sequential] + /// Tests if task manager with one infinite task works correctly during some time without panic. + fn test_one_infinite_task_task_manager() { + TaskManager::add_task( + test_one_infinite_task_task_manager_setup_fn, + test_one_infinite_task_task_manager_loop_fn, + test_one_infinite_task_task_manager_stop_condition_fn, + ); + TaskManager::test_start_task_manager(); + } + + /// Counter for task for test_two_finite_tasks_task_manager. + static TEST_TWO_FINITE_TASK_TASK_MANAGER_COUNTER1: AtomicU32 = AtomicU32::new(1); + /// Setup function for task for test_two_finite_tasks_task_manager. + fn test_two_finite_tasks_task_manager_setup_fn1() {} + /// Loop function for task for test_two_finite_tasks_task_manager. + fn test_two_finite_tasks_task_manager_loop_fn1() { + TEST_TWO_FINITE_TASK_TASK_MANAGER_COUNTER1.fetch_add(1, Ordering::Relaxed); + } + /// Stop function for task for test_two_finite_tasks_task_manager. + fn test_two_finite_tasks_task_manager_stop_condition_fn1() -> bool { + let value = unsafe { TEST_TWO_FINITE_TASK_TASK_MANAGER_COUNTER1.as_ptr().read() }; + if value % 50 == 0 { + return true; + } + return false; + } + /// Counter for task for test_two_finite_tasks_task_manager. + static TEST_TWO_FINITE_TASK_TASK_MANAGER_COUNTER2: AtomicU32 = AtomicU32::new(1); + /// Setup function for task for test_two_finite_tasks_task_manager. + fn test_two_finite_tasks_task_manager_setup_fn2() {} + /// Loop function for task for test_two_finite_tasks_task_manager. + fn test_two_finite_tasks_task_manager_loop_fn2() { + TEST_TWO_FINITE_TASK_TASK_MANAGER_COUNTER2.fetch_add(1, Ordering::Relaxed); + } + /// Stop function for task for test_two_finite_tasks_task_manager. + fn test_two_finite_tasks_task_manager_stop_condition_fn2() -> bool { + let value = unsafe { TEST_TWO_FINITE_TASK_TASK_MANAGER_COUNTER2.as_ptr().read() }; + if value % 25 == 0 { + return true; + } + return false; + } + #[test] + #[sequential] + /// Tests if task manager with two finite tasks works correctly during some time without panic. + fn test_two_finite_tasks_task_manager() { + TaskManager::add_task( + test_two_finite_tasks_task_manager_setup_fn1, + test_two_finite_tasks_task_manager_loop_fn1, + test_two_finite_tasks_task_manager_stop_condition_fn1, + ); + TaskManager::add_task( + test_two_finite_tasks_task_manager_setup_fn2, + test_two_finite_tasks_task_manager_loop_fn2, + test_two_finite_tasks_task_manager_stop_condition_fn2, + ); + TaskManager::test_start_task_manager(); + + assert_eq!( + unsafe { TEST_TWO_FINITE_TASK_TASK_MANAGER_COUNTER1.as_ptr().read() }, + 50 + ); + assert_eq!( + unsafe { TEST_TWO_FINITE_TASK_TASK_MANAGER_COUNTER2.as_ptr().read() }, + 25 + ); + } + + /// Counter for task for test_two_different_tasks_task_manager. + static TEST_TWO_DIFFERENT_TASK_TASK_MANAGER_COUNTER1: AtomicU32 = AtomicU32::new(1); + /// Setup function for task for test_two_different_tasks_task_manager. + fn test_two_different_tasks_task_manager_setup_fn1() {} + /// Loop function for task for test_two_different_tasks_task_manager. + fn test_two_different_tasks_task_manager_loop_fn1() { + TEST_TWO_DIFFERENT_TASK_TASK_MANAGER_COUNTER1.fetch_add(1, Ordering::Relaxed); + } + /// Stop function for task for test_two_different_tasks_task_manager. + fn test_two_different_tasks_task_manager_stop_condition_fn1() -> bool { + let value = unsafe { + TEST_TWO_DIFFERENT_TASK_TASK_MANAGER_COUNTER1 + .as_ptr() + .read() + }; + if value % 50 == 0 { + return true; + } + return false; + } + /// Counter for task for test_two_different_tasks_task_manager. + static TEST_TWO_DIFFERENT_TASK_TASK_MANAGER_COUNTER2: AtomicU32 = AtomicU32::new(1); + /// Setup function for task for test_two_different_tasks_task_manager. + fn test_two_different_tasks_task_manager_setup_fn2() {} + /// Loop function for task for test_two_different_tasks_task_manager. + fn test_two_different_tasks_task_manager_loop_fn2() { + TEST_TWO_DIFFERENT_TASK_TASK_MANAGER_COUNTER2.fetch_add(1, Ordering::Relaxed); + } + /// Stop function for task for test_two_different_tasks_task_manager. + fn test_two_different_tasks_task_manager_stop_condition_fn2() -> bool { + return false; + } + #[test] + #[sequential] + /// Tests if task manager with two different (finite and infinite) tasks works correctly during some time without panic. + fn test_two_different_tasks_task_manager() { + TaskManager::add_task( + test_two_different_tasks_task_manager_setup_fn1, + test_two_different_tasks_task_manager_loop_fn1, + test_two_different_tasks_task_manager_stop_condition_fn1, + ); + TaskManager::add_task( + test_two_different_tasks_task_manager_setup_fn2, + test_two_different_tasks_task_manager_loop_fn2, + test_two_different_tasks_task_manager_stop_condition_fn2, + ); + TaskManager::test_start_task_manager(); + + assert_eq!( + unsafe { + TEST_TWO_DIFFERENT_TASK_TASK_MANAGER_COUNTER1 + .as_ptr() + .read() + }, + 50 + ); + } + + /// Counter for task for test_two_infinite_tasks_task_manager. + static TEST_TWO_INFINITE_TASK_TASK_MANAGER_COUNTER1: AtomicU32 = AtomicU32::new(1); + /// Setup function for task for test_two_infinite_tasks_task_manager. + fn test_two_infinite_tasks_task_manager_setup_fn1() {} + /// Loop function for task for test_two_infinite_tasks_task_manager. + fn test_two_infinite_tasks_task_manager_loop_fn1() { + TEST_TWO_INFINITE_TASK_TASK_MANAGER_COUNTER1.fetch_add(1, Ordering::Relaxed); + } + /// Stop function for task for test_two_infinite_tasks_task_manager. + fn test_two_infinite_tasks_task_manager_stop_condition_fn1() -> bool { + return false; + } + /// Counter for task for test_two_infinite_tasks_task_manager. + static TEST_TWO_INFINITE_TASK_TASK_MANAGER_COUNTER2: AtomicU32 = AtomicU32::new(1); + /// Setup function for task for test_two_infinite_tasks_task_manager. + fn test_two_infinite_tasks_task_manager_setup_fn2() {} + /// Loop function for task for test_two_infinite_tasks_task_manager. + fn test_two_infinite_tasks_task_manager_loop_fn2() { + TEST_TWO_INFINITE_TASK_TASK_MANAGER_COUNTER2.fetch_add(1, Ordering::Relaxed); + } + /// Stop function for task for test_two_infinite_tasks_task_manager. + fn test_two_infinite_tasks_task_manager_stop_condition_fn2() -> bool { + return false; + } + #[test] + #[sequential] + /// Tests if task manager with two infinite tasks works correctly during some without panic. + fn test_two_infinite_tasks_task_manager() { + TaskManager::add_task( + test_two_infinite_tasks_task_manager_setup_fn1, + test_two_infinite_tasks_task_manager_loop_fn1, + test_two_infinite_tasks_task_manager_stop_condition_fn1, + ); + TaskManager::add_task( + test_two_infinite_tasks_task_manager_setup_fn2, + test_two_infinite_tasks_task_manager_loop_fn2, + test_two_infinite_tasks_task_manager_stop_condition_fn2, + ); + TaskManager::test_start_task_manager(); + } + + /// Counter for task for test_setup_task_manager. + static TEST_SETUP_TASK_MANAGER_COUNTER: AtomicU32 = AtomicU32::new(1); + /// Setup function for task for test_setup_task_manager. + fn test_setup_task_manager_setup_fn() { + TEST_SETUP_TASK_MANAGER_COUNTER.store(42, Ordering::Relaxed); + } + /// Loop function for task for test_setup_task_manager. + fn test_setup_task_manager_loop_fn() {} + /// Stop function for task for test_setup_task_manager. + fn test_setup_task_manager_stop_condition_fn() -> bool { + return false; + } + #[test] + #[sequential] + /// Tests if task manager works correctly with setup function during some time without panic. + fn test_setup_task_manager() { + TaskManager::add_task( + test_setup_task_manager_setup_fn, + test_setup_task_manager_loop_fn, + test_setup_task_manager_stop_condition_fn, + ); + TaskManager::test_start_task_manager(); + + assert_eq!( + unsafe { TEST_SETUP_TASK_MANAGER_COUNTER.as_ptr().read() }, + 42 + ); + } #[test] /// Tests setup timer function and getting tick counter (bad unit test).