1b8a62b91Sopenharmony_ci#[cfg(not(any(
2b8a62b91Sopenharmony_ci    target_os = "dragonfly",
3b8a62b91Sopenharmony_ci    target_os = "emscripten",
4b8a62b91Sopenharmony_ci    target_os = "freebsd",
5b8a62b91Sopenharmony_ci    target_os = "haiku",
6b8a62b91Sopenharmony_ci    target_os = "ios",
7b8a62b91Sopenharmony_ci    target_os = "macos",
8b8a62b91Sopenharmony_ci    target_os = "openbsd",
9b8a62b91Sopenharmony_ci    target_os = "redox",
10b8a62b91Sopenharmony_ci    target_os = "wasi",
11b8a62b91Sopenharmony_ci)))]
12b8a62b91Sopenharmony_ciuse rustix::thread::{clock_nanosleep_absolute, clock_nanosleep_relative, ClockId};
13b8a62b91Sopenharmony_ci#[cfg(not(target_os = "redox"))]
14b8a62b91Sopenharmony_ciuse {
15b8a62b91Sopenharmony_ci    rustix::io,
16b8a62b91Sopenharmony_ci    rustix::thread::{nanosleep, NanosleepRelativeResult, Timespec},
17b8a62b91Sopenharmony_ci};
18b8a62b91Sopenharmony_ci
19b8a62b91Sopenharmony_ci#[cfg(not(target_os = "redox"))]
20b8a62b91Sopenharmony_ci#[test]
21b8a62b91Sopenharmony_cifn test_invalid_nanosleep() {
22b8a62b91Sopenharmony_ci    match nanosleep(&Timespec {
23b8a62b91Sopenharmony_ci        tv_sec: 0,
24b8a62b91Sopenharmony_ci        tv_nsec: 1_000_000_000,
25b8a62b91Sopenharmony_ci    }) {
26b8a62b91Sopenharmony_ci        NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
27b8a62b91Sopenharmony_ci        otherwise => panic!("unexpected resut: {:?}", otherwise),
28b8a62b91Sopenharmony_ci    }
29b8a62b91Sopenharmony_ci    match nanosleep(&Timespec {
30b8a62b91Sopenharmony_ci        tv_sec: 0,
31b8a62b91Sopenharmony_ci        tv_nsec: !0,
32b8a62b91Sopenharmony_ci    }) {
33b8a62b91Sopenharmony_ci        NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
34b8a62b91Sopenharmony_ci        otherwise => panic!("unexpected resut: {:?}", otherwise),
35b8a62b91Sopenharmony_ci    }
36b8a62b91Sopenharmony_ci    match nanosleep(&Timespec {
37b8a62b91Sopenharmony_ci        tv_sec: !0,
38b8a62b91Sopenharmony_ci        tv_nsec: 1_000_000_000,
39b8a62b91Sopenharmony_ci    }) {
40b8a62b91Sopenharmony_ci        NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
41b8a62b91Sopenharmony_ci        otherwise => panic!("unexpected resut: {:?}", otherwise),
42b8a62b91Sopenharmony_ci    }
43b8a62b91Sopenharmony_ci    match nanosleep(&Timespec {
44b8a62b91Sopenharmony_ci        tv_sec: !0,
45b8a62b91Sopenharmony_ci        tv_nsec: !0,
46b8a62b91Sopenharmony_ci    }) {
47b8a62b91Sopenharmony_ci        NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
48b8a62b91Sopenharmony_ci        otherwise => panic!("unexpected resut: {:?}", otherwise),
49b8a62b91Sopenharmony_ci    }
50b8a62b91Sopenharmony_ci}
51b8a62b91Sopenharmony_ci
52b8a62b91Sopenharmony_ci#[cfg(not(any(
53b8a62b91Sopenharmony_ci    target_os = "dragonfly",
54b8a62b91Sopenharmony_ci    target_os = "emscripten",
55b8a62b91Sopenharmony_ci    target_os = "freebsd",
56b8a62b91Sopenharmony_ci    target_os = "haiku",
57b8a62b91Sopenharmony_ci    target_os = "ios",
58b8a62b91Sopenharmony_ci    target_os = "macos",
59b8a62b91Sopenharmony_ci    target_os = "openbsd",
60b8a62b91Sopenharmony_ci    target_os = "redox",
61b8a62b91Sopenharmony_ci    target_os = "wasi",
62b8a62b91Sopenharmony_ci)))]
63b8a62b91Sopenharmony_ci#[test]
64b8a62b91Sopenharmony_cifn test_invalid_nanosleep_absolute() {
65b8a62b91Sopenharmony_ci    match clock_nanosleep_absolute(
66b8a62b91Sopenharmony_ci        ClockId::Monotonic,
67b8a62b91Sopenharmony_ci        &Timespec {
68b8a62b91Sopenharmony_ci            tv_sec: 0,
69b8a62b91Sopenharmony_ci            tv_nsec: 1000000000,
70b8a62b91Sopenharmony_ci        },
71b8a62b91Sopenharmony_ci    ) {
72b8a62b91Sopenharmony_ci        Err(io::Errno::INVAL) => (),
73b8a62b91Sopenharmony_ci        otherwise => panic!("unexpected resut: {:?}", otherwise),
74b8a62b91Sopenharmony_ci    }
75b8a62b91Sopenharmony_ci    match clock_nanosleep_absolute(
76b8a62b91Sopenharmony_ci        ClockId::Monotonic,
77b8a62b91Sopenharmony_ci        &Timespec {
78b8a62b91Sopenharmony_ci            tv_sec: 0,
79b8a62b91Sopenharmony_ci            tv_nsec: !0,
80b8a62b91Sopenharmony_ci        },
81b8a62b91Sopenharmony_ci    ) {
82b8a62b91Sopenharmony_ci        Err(io::Errno::INVAL) => (),
83b8a62b91Sopenharmony_ci        otherwise => panic!("unexpected resut: {:?}", otherwise),
84b8a62b91Sopenharmony_ci    }
85b8a62b91Sopenharmony_ci    match clock_nanosleep_absolute(
86b8a62b91Sopenharmony_ci        ClockId::Monotonic,
87b8a62b91Sopenharmony_ci        &Timespec {
88b8a62b91Sopenharmony_ci            tv_sec: !0,
89b8a62b91Sopenharmony_ci            tv_nsec: 1_000_000_000,
90b8a62b91Sopenharmony_ci        },
91b8a62b91Sopenharmony_ci    ) {
92b8a62b91Sopenharmony_ci        Err(io::Errno::INVAL) => (),
93b8a62b91Sopenharmony_ci        otherwise => panic!("unexpected resut: {:?}", otherwise),
94b8a62b91Sopenharmony_ci    }
95b8a62b91Sopenharmony_ci    match clock_nanosleep_absolute(
96b8a62b91Sopenharmony_ci        ClockId::Monotonic,
97b8a62b91Sopenharmony_ci        &Timespec {
98b8a62b91Sopenharmony_ci            tv_sec: !0,
99b8a62b91Sopenharmony_ci            tv_nsec: !0,
100b8a62b91Sopenharmony_ci        },
101b8a62b91Sopenharmony_ci    ) {
102b8a62b91Sopenharmony_ci        Err(io::Errno::INVAL) => (),
103b8a62b91Sopenharmony_ci        otherwise => panic!("unexpected resut: {:?}", otherwise),
104b8a62b91Sopenharmony_ci    }
105b8a62b91Sopenharmony_ci}
106b8a62b91Sopenharmony_ci
107b8a62b91Sopenharmony_ci#[cfg(not(any(
108b8a62b91Sopenharmony_ci    target_os = "dragonfly",
109b8a62b91Sopenharmony_ci    target_os = "emscripten",
110b8a62b91Sopenharmony_ci    target_os = "freebsd",
111b8a62b91Sopenharmony_ci    target_os = "haiku",
112b8a62b91Sopenharmony_ci    target_os = "ios",
113b8a62b91Sopenharmony_ci    target_os = "macos",
114b8a62b91Sopenharmony_ci    target_os = "openbsd",
115b8a62b91Sopenharmony_ci    target_os = "redox",
116b8a62b91Sopenharmony_ci    target_os = "wasi",
117b8a62b91Sopenharmony_ci)))]
118b8a62b91Sopenharmony_ci#[test]
119b8a62b91Sopenharmony_cifn test_invalid_nanosleep_relative() {
120b8a62b91Sopenharmony_ci    match clock_nanosleep_relative(
121b8a62b91Sopenharmony_ci        ClockId::Monotonic,
122b8a62b91Sopenharmony_ci        &Timespec {
123b8a62b91Sopenharmony_ci            tv_sec: 0,
124b8a62b91Sopenharmony_ci            tv_nsec: 1_000_000_000,
125b8a62b91Sopenharmony_ci        },
126b8a62b91Sopenharmony_ci    ) {
127b8a62b91Sopenharmony_ci        NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
128b8a62b91Sopenharmony_ci        otherwise => panic!("unexpected resut: {:?}", otherwise),
129b8a62b91Sopenharmony_ci    }
130b8a62b91Sopenharmony_ci    match clock_nanosleep_relative(
131b8a62b91Sopenharmony_ci        ClockId::Monotonic,
132b8a62b91Sopenharmony_ci        &Timespec {
133b8a62b91Sopenharmony_ci            tv_sec: 0,
134b8a62b91Sopenharmony_ci            tv_nsec: !0,
135b8a62b91Sopenharmony_ci        },
136b8a62b91Sopenharmony_ci    ) {
137b8a62b91Sopenharmony_ci        NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
138b8a62b91Sopenharmony_ci        otherwise => panic!("unexpected resut: {:?}", otherwise),
139b8a62b91Sopenharmony_ci    }
140b8a62b91Sopenharmony_ci    match clock_nanosleep_relative(
141b8a62b91Sopenharmony_ci        ClockId::Monotonic,
142b8a62b91Sopenharmony_ci        &Timespec {
143b8a62b91Sopenharmony_ci            tv_sec: !0,
144b8a62b91Sopenharmony_ci            tv_nsec: 1_000_000_000,
145b8a62b91Sopenharmony_ci        },
146b8a62b91Sopenharmony_ci    ) {
147b8a62b91Sopenharmony_ci        NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
148b8a62b91Sopenharmony_ci        otherwise => panic!("unexpected resut: {:?}", otherwise),
149b8a62b91Sopenharmony_ci    }
150b8a62b91Sopenharmony_ci    match clock_nanosleep_relative(
151b8a62b91Sopenharmony_ci        ClockId::Monotonic,
152b8a62b91Sopenharmony_ci        &Timespec {
153b8a62b91Sopenharmony_ci            tv_sec: !0,
154b8a62b91Sopenharmony_ci            tv_nsec: !0,
155b8a62b91Sopenharmony_ci        },
156b8a62b91Sopenharmony_ci    ) {
157b8a62b91Sopenharmony_ci        NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
158b8a62b91Sopenharmony_ci        otherwise => panic!("unexpected resut: {:?}", otherwise),
159b8a62b91Sopenharmony_ci    }
160b8a62b91Sopenharmony_ci}
161b8a62b91Sopenharmony_ci
162b8a62b91Sopenharmony_ci#[cfg(not(target_os = "redox"))]
163b8a62b91Sopenharmony_ci#[test]
164b8a62b91Sopenharmony_cifn test_zero_nanosleep() {
165b8a62b91Sopenharmony_ci    match nanosleep(&Timespec {
166b8a62b91Sopenharmony_ci        tv_sec: 0,
167b8a62b91Sopenharmony_ci        tv_nsec: 0,
168b8a62b91Sopenharmony_ci    }) {
169b8a62b91Sopenharmony_ci        NanosleepRelativeResult::Ok => (),
170b8a62b91Sopenharmony_ci        otherwise => panic!("unexpected resut: {:?}", otherwise),
171b8a62b91Sopenharmony_ci    }
172b8a62b91Sopenharmony_ci}
173b8a62b91Sopenharmony_ci
174b8a62b91Sopenharmony_ci#[cfg(not(any(
175b8a62b91Sopenharmony_ci    target_os = "dragonfly",
176b8a62b91Sopenharmony_ci    target_os = "emscripten",
177b8a62b91Sopenharmony_ci    target_os = "freebsd",
178b8a62b91Sopenharmony_ci    target_os = "haiku",
179b8a62b91Sopenharmony_ci    target_os = "ios",
180b8a62b91Sopenharmony_ci    target_os = "macos",
181b8a62b91Sopenharmony_ci    target_os = "openbsd",
182b8a62b91Sopenharmony_ci    target_os = "redox",
183b8a62b91Sopenharmony_ci    target_os = "wasi",
184b8a62b91Sopenharmony_ci)))]
185b8a62b91Sopenharmony_ci#[test]
186b8a62b91Sopenharmony_cifn test_zero_nanosleep_absolute() {
187b8a62b91Sopenharmony_ci    match clock_nanosleep_absolute(
188b8a62b91Sopenharmony_ci        ClockId::Monotonic,
189b8a62b91Sopenharmony_ci        &Timespec {
190b8a62b91Sopenharmony_ci            tv_sec: 0,
191b8a62b91Sopenharmony_ci            tv_nsec: 0,
192b8a62b91Sopenharmony_ci        },
193b8a62b91Sopenharmony_ci    ) {
194b8a62b91Sopenharmony_ci        Ok(()) => (),
195b8a62b91Sopenharmony_ci        otherwise => panic!("unexpected resut: {:?}", otherwise),
196b8a62b91Sopenharmony_ci    }
197b8a62b91Sopenharmony_ci}
198b8a62b91Sopenharmony_ci
199b8a62b91Sopenharmony_ci#[cfg(not(any(
200b8a62b91Sopenharmony_ci    target_os = "dragonfly",
201b8a62b91Sopenharmony_ci    target_os = "emscripten",
202b8a62b91Sopenharmony_ci    target_os = "freebsd",
203b8a62b91Sopenharmony_ci    target_os = "haiku",
204b8a62b91Sopenharmony_ci    target_os = "ios",
205b8a62b91Sopenharmony_ci    target_os = "macos",
206b8a62b91Sopenharmony_ci    target_os = "openbsd",
207b8a62b91Sopenharmony_ci    target_os = "redox",
208b8a62b91Sopenharmony_ci    target_os = "wasi",
209b8a62b91Sopenharmony_ci)))]
210b8a62b91Sopenharmony_ci#[test]
211b8a62b91Sopenharmony_cifn test_zero_nanosleep_relative() {
212b8a62b91Sopenharmony_ci    match clock_nanosleep_relative(
213b8a62b91Sopenharmony_ci        ClockId::Monotonic,
214b8a62b91Sopenharmony_ci        &Timespec {
215b8a62b91Sopenharmony_ci            tv_sec: 0,
216b8a62b91Sopenharmony_ci            tv_nsec: 0,
217b8a62b91Sopenharmony_ci        },
218b8a62b91Sopenharmony_ci    ) {
219b8a62b91Sopenharmony_ci        NanosleepRelativeResult::Ok => (),
220b8a62b91Sopenharmony_ci        otherwise => panic!("unexpected resut: {:?}", otherwise),
221b8a62b91Sopenharmony_ci    }
222b8a62b91Sopenharmony_ci}
223