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