From 2fb3f257618a756605f9d89a994326ba71fe5f32 Mon Sep 17 00:00:00 2001 From: ClementTsang Date: Fri, 24 Mar 2023 01:08:23 -0400 Subject: [PATCH] add test --- src/apple/macos/system.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/apple/macos/system.rs b/src/apple/macos/system.rs index 1fbe13fc0..bf1fb233d 100644 --- a/src/apple/macos/system.rs +++ b/src/apple/macos/system.rs @@ -137,3 +137,29 @@ impl SystemTimeInfo { } } } + +#[cfg(test)] +mod test { + + use super::*; + + /// Regression test for . + #[test] + fn test_getting_time_interval() { + if !crate::System::IS_SUPPORTED || cfg!(feature = "apple-sandbox") { + return; + } + + let port = unsafe { libc::mach_host_self() }; + let mut info = SystemTimeInfo::new(port).unwrap(); + info.get_time_interval(port); + + std::thread::sleep(crate::System::MINIMUM_CPU_UPDATE_INTERVAL.saturating_mul(2)); + + let val = info.get_time_interval(port); + assert!( + val > crate::System::MINIMUM_CPU_UPDATE_INTERVAL.as_secs_f64() * 1_000_000_000.0 + / info.timebase_to_ns + ); + } +}