1 #[cfg(feature = "thread")]
2 use rustix
::thread
::nanosleep
;
3 use rustix
::time
::{clock_gettime, ClockId, Timespec}
;
5 /// Attempt to test that the monotonic clock is monotonic. Time may or may not
6 /// advance, but it shouldn't regress.
8 fn test_monotonic_clock() {
9 let a
= clock_gettime(ClockId
::Monotonic
);
10 let b
= clock_gettime(ClockId
::Monotonic
);
11 if b
.tv_sec
== a
.tv_sec
{
12 assert
!(b
.tv_nsec
>= a
.tv_nsec
);
14 assert
!(b
.tv_sec
> a
.tv_sec
);
18 /// With the "thread" feature, we can sleep so that we're guaranteed that time
20 #[cfg(feature = "thread")]
22 fn test_monotonic_clock_with_sleep_1s() {
23 let a
= clock_gettime(ClockId
::Monotonic
);
24 let _rem
= nanosleep(&Timespec
{
28 let b
= clock_gettime(ClockId
::Monotonic
);
29 assert
!(b
.tv_sec
> a
.tv_sec
);
32 /// With the "thread" feature, we can sleep so that we're guaranteed that time
34 #[cfg(feature = "thread")]
36 fn test_monotonic_clock_with_sleep_1ms() {
37 let a
= clock_gettime(ClockId
::Monotonic
);
38 let _rem
= nanosleep(&Timespec
{
42 let b
= clock_gettime(ClockId
::Monotonic
);
43 assert
!(b
.tv_sec
>= a
.tv_sec
);
44 assert
!(b
.tv_sec
!= a
.tv_sec
|| b
.tv_nsec
> a
.tv_nsec
);