| 1 |
#[cfg(any(freebsdlike, linux_android, target_os = "emscripten"))] |
| 2 |
use nix::time::clock_getcpuclockid; |
| 3 |
use nix::time::{clock_gettime, ClockId}; |
| 4 |
|
| 5 |
#[cfg(not(target_os = "redox"))] |
| 6 |
#[test] |
| 7 |
pub fn test_clock_getres() { |
| 8 |
nix::time::clock_getres(ClockId::CLOCK_REALTIME).expect("assertion failed"); |
| 9 |
} |
| 10 |
|
| 11 |
#[test] |
| 12 |
pub fn test_clock_gettime() { |
| 13 |
clock_gettime(ClockId::CLOCK_REALTIME).expect("assertion failed"); |
| 14 |
} |
| 15 |
|
| 16 |
#[cfg(any(freebsdlike, linux_android, target_os = "emscripten"))] |
| 17 |
#[test] |
| 18 |
pub fn test_clock_getcpuclockid() { |
| 19 |
let clock_id = clock_getcpuclockid(nix::unistd::Pid::this()).unwrap(); |
| 20 |
clock_gettime(clock_id).unwrap(); |
| 21 |
} |
| 22 |
|
| 23 |
#[cfg(not(target_os = "redox"))] |
| 24 |
#[test] |
| 25 |
pub fn test_clock_id_res() { |
| 26 |
ClockId::CLOCK_REALTIME.res().unwrap(); |
| 27 |
} |
| 28 |
|
| 29 |
#[test] |
| 30 |
pub fn test_clock_id_now() { |
| 31 |
ClockId::CLOCK_REALTIME.now().unwrap(); |
| 32 |
} |
| 33 |
|
| 34 |
#[cfg(any(freebsdlike, linux_android, target_os = "emscripten"))] |
| 35 |
#[test] |
| 36 |
pub fn test_clock_id_pid_cpu_clock_id() { |
| 37 |
ClockId::pid_cpu_clock_id(nix::unistd::Pid::this()) |
| 38 |
.map(ClockId::now) |
| 39 |
.unwrap() |
| 40 |
.unwrap(); |
| 41 |
} |
| 42 |
|
| 43 |
#[cfg(any( |
| 44 |
linux_android, |
| 45 |
solarish, |
| 46 |
freebsdlike, |
| 47 |
target_os = "netbsd", |
| 48 |
target_os = "hurd", |
| 49 |
target_os = "aix" |
| 50 |
))] |
| 51 |
#[test] |
| 52 |
pub fn test_clock_nanosleep() { |
| 53 |
use nix::{ |
| 54 |
sys::time::{TimeSpec, TimeValLike}, |
| 55 |
time::{clock_nanosleep, ClockNanosleepFlags}, |
| 56 |
}; |
| 57 |
|
| 58 |
let sleep_time = TimeSpec::microseconds(1); |
| 59 |
let res = clock_nanosleep( |
| 60 |
ClockId::CLOCK_MONOTONIC, |
| 61 |
ClockNanosleepFlags::empty(), |
| 62 |
&sleep_time, |
| 63 |
); |
| 64 |
let expected = TimeSpec::microseconds(0); |
| 65 |
assert_eq!(res, Ok(expected)); |
| 66 |
} |