From dc7d0ee366e36c36e227e3477756664cc587f3d2 Mon Sep 17 00:00:00 2001 From: Jett Rink Date: Fri, 23 Jun 2023 18:07:58 +0000 Subject: [PATCH] tests: add helper function to fake Kernel Add helper functions to fake Kernel that allow unit test to make better decision about code flow. Change-Id: I7977af0af2860a4a125e608d8feb3d37b58ddfb0 --- unittest/src/fake/kernel.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/unittest/src/fake/kernel.rs b/unittest/src/fake/kernel.rs index 5239bd78..1eaa1337 100644 --- a/unittest/src/fake/kernel.rs +++ b/unittest/src/fake/kernel.rs @@ -108,6 +108,20 @@ impl Kernel { pub fn take_syscall_log(&self) -> Vec { with_kernel_data(|kernel_data| std::mem::take(&mut kernel_data.unwrap().syscall_log)) } + + /// Returns true if the specified driver installed. + pub fn is_driver_present(driver_num: u32) -> bool { + with_kernel_data(|kernel_data| { + kernel_data.map_or(false, |kernel| kernel.drivers.contains_key(&driver_num)) + }) + } + + /// Returns true if there are any pending upcalls. + pub fn is_upcall_pending() -> bool { + with_kernel_data(|kernel_data| { + kernel_data.map_or(false, |kernel| !kernel.upcall_queue.is_empty()) + }) + } } impl Drop for Kernel {