|
1 | 1 | //@ignore-target-windows: No libc on Windows
|
2 | 2 | //@compile-flags: -Zmiri-disable-isolation
|
3 | 3 | #![feature(io_error_more)]
|
4 |
| -#![feature(rustc_private)] |
5 | 4 |
|
6 | 5 | use std::fs::{remove_file, File};
|
7 | 6 | use std::os::unix::io::AsRawFd;
|
@@ -161,122 +160,6 @@ fn test_sync_file_range() {
|
161 | 160 | assert_eq!(result_2, 0);
|
162 | 161 | }
|
163 | 162 |
|
164 |
| -fn test_mutex_libc_init_recursive() { |
165 |
| - unsafe { |
166 |
| - let mut attr: libc::pthread_mutexattr_t = std::mem::zeroed(); |
167 |
| - assert_eq!(libc::pthread_mutexattr_init(&mut attr as *mut _), 0); |
168 |
| - assert_eq!( |
169 |
| - libc::pthread_mutexattr_settype(&mut attr as *mut _, libc::PTHREAD_MUTEX_RECURSIVE), |
170 |
| - 0, |
171 |
| - ); |
172 |
| - let mut mutex: libc::pthread_mutex_t = std::mem::zeroed(); |
173 |
| - assert_eq!(libc::pthread_mutex_init(&mut mutex as *mut _, &mut attr as *mut _), 0); |
174 |
| - assert_eq!(libc::pthread_mutex_lock(&mut mutex as *mut _), 0); |
175 |
| - assert_eq!(libc::pthread_mutex_trylock(&mut mutex as *mut _), 0); |
176 |
| - assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), 0); |
177 |
| - assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), 0); |
178 |
| - assert_eq!(libc::pthread_mutex_trylock(&mut mutex as *mut _), 0); |
179 |
| - assert_eq!(libc::pthread_mutex_lock(&mut mutex as *mut _), 0); |
180 |
| - assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), 0); |
181 |
| - assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), 0); |
182 |
| - assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), libc::EPERM); |
183 |
| - assert_eq!(libc::pthread_mutex_destroy(&mut mutex as *mut _), 0); |
184 |
| - assert_eq!(libc::pthread_mutexattr_destroy(&mut attr as *mut _), 0); |
185 |
| - } |
186 |
| -} |
187 |
| - |
188 |
| -fn test_mutex_libc_init_normal() { |
189 |
| - unsafe { |
190 |
| - let mut mutexattr: libc::pthread_mutexattr_t = std::mem::zeroed(); |
191 |
| - assert_eq!( |
192 |
| - libc::pthread_mutexattr_settype(&mut mutexattr as *mut _, 0x12345678), |
193 |
| - libc::EINVAL, |
194 |
| - ); |
195 |
| - assert_eq!( |
196 |
| - libc::pthread_mutexattr_settype(&mut mutexattr as *mut _, libc::PTHREAD_MUTEX_NORMAL), |
197 |
| - 0, |
198 |
| - ); |
199 |
| - let mut mutex: libc::pthread_mutex_t = std::mem::zeroed(); |
200 |
| - assert_eq!(libc::pthread_mutex_init(&mut mutex as *mut _, &mutexattr as *const _), 0); |
201 |
| - assert_eq!(libc::pthread_mutex_lock(&mut mutex as *mut _), 0); |
202 |
| - assert_eq!(libc::pthread_mutex_trylock(&mut mutex as *mut _), libc::EBUSY); |
203 |
| - assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), 0); |
204 |
| - assert_eq!(libc::pthread_mutex_trylock(&mut mutex as *mut _), 0); |
205 |
| - assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), 0); |
206 |
| - assert_eq!(libc::pthread_mutex_destroy(&mut mutex as *mut _), 0); |
207 |
| - } |
208 |
| -} |
209 |
| - |
210 |
| -fn test_mutex_libc_init_errorcheck() { |
211 |
| - unsafe { |
212 |
| - let mut mutexattr: libc::pthread_mutexattr_t = std::mem::zeroed(); |
213 |
| - assert_eq!( |
214 |
| - libc::pthread_mutexattr_settype( |
215 |
| - &mut mutexattr as *mut _, |
216 |
| - libc::PTHREAD_MUTEX_ERRORCHECK, |
217 |
| - ), |
218 |
| - 0, |
219 |
| - ); |
220 |
| - let mut mutex: libc::pthread_mutex_t = std::mem::zeroed(); |
221 |
| - assert_eq!(libc::pthread_mutex_init(&mut mutex as *mut _, &mutexattr as *const _), 0); |
222 |
| - assert_eq!(libc::pthread_mutex_lock(&mut mutex as *mut _), 0); |
223 |
| - assert_eq!(libc::pthread_mutex_trylock(&mut mutex as *mut _), libc::EBUSY); |
224 |
| - assert_eq!(libc::pthread_mutex_lock(&mut mutex as *mut _), libc::EDEADLK); |
225 |
| - assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), 0); |
226 |
| - assert_eq!(libc::pthread_mutex_trylock(&mut mutex as *mut _), 0); |
227 |
| - assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), 0); |
228 |
| - assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), libc::EPERM); |
229 |
| - assert_eq!(libc::pthread_mutex_destroy(&mut mutex as *mut _), 0); |
230 |
| - } |
231 |
| -} |
232 |
| - |
233 |
| -// Only linux provides PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP, |
234 |
| -// libc for macOS just has the default PTHREAD_MUTEX_INITIALIZER. |
235 |
| -#[cfg(target_os = "linux")] |
236 |
| -fn test_mutex_libc_static_initializer_recursive() { |
237 |
| - let mutex = std::cell::UnsafeCell::new(libc::PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP); |
238 |
| - unsafe { |
239 |
| - assert_eq!(libc::pthread_mutex_lock(mutex.get()), 0); |
240 |
| - assert_eq!(libc::pthread_mutex_trylock(mutex.get()), 0); |
241 |
| - assert_eq!(libc::pthread_mutex_unlock(mutex.get()), 0); |
242 |
| - assert_eq!(libc::pthread_mutex_unlock(mutex.get()), 0); |
243 |
| - assert_eq!(libc::pthread_mutex_trylock(mutex.get()), 0); |
244 |
| - assert_eq!(libc::pthread_mutex_lock(mutex.get()), 0); |
245 |
| - assert_eq!(libc::pthread_mutex_unlock(mutex.get()), 0); |
246 |
| - assert_eq!(libc::pthread_mutex_unlock(mutex.get()), 0); |
247 |
| - assert_eq!(libc::pthread_mutex_unlock(mutex.get()), libc::EPERM); |
248 |
| - assert_eq!(libc::pthread_mutex_destroy(mutex.get()), 0); |
249 |
| - } |
250 |
| -} |
251 |
| - |
252 |
| -// Testing the behavior of std::sync::RwLock does not fully exercise the pthread rwlock shims, we |
253 |
| -// need to go a layer deeper and test the behavior of the libc functions, because |
254 |
| -// std::sys::unix::rwlock::RWLock itself keeps track of write_locked and num_readers. |
255 |
| -fn test_rwlock_libc_static_initializer() { |
256 |
| - let rw = std::cell::UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER); |
257 |
| - unsafe { |
258 |
| - assert_eq!(libc::pthread_rwlock_rdlock(rw.get()), 0); |
259 |
| - assert_eq!(libc::pthread_rwlock_rdlock(rw.get()), 0); |
260 |
| - assert_eq!(libc::pthread_rwlock_unlock(rw.get()), 0); |
261 |
| - assert_eq!(libc::pthread_rwlock_tryrdlock(rw.get()), 0); |
262 |
| - assert_eq!(libc::pthread_rwlock_unlock(rw.get()), 0); |
263 |
| - assert_eq!(libc::pthread_rwlock_trywrlock(rw.get()), libc::EBUSY); |
264 |
| - assert_eq!(libc::pthread_rwlock_unlock(rw.get()), 0); |
265 |
| - |
266 |
| - assert_eq!(libc::pthread_rwlock_wrlock(rw.get()), 0); |
267 |
| - assert_eq!(libc::pthread_rwlock_tryrdlock(rw.get()), libc::EBUSY); |
268 |
| - assert_eq!(libc::pthread_rwlock_trywrlock(rw.get()), libc::EBUSY); |
269 |
| - assert_eq!(libc::pthread_rwlock_unlock(rw.get()), 0); |
270 |
| - |
271 |
| - assert_eq!(libc::pthread_rwlock_trywrlock(rw.get()), 0); |
272 |
| - assert_eq!(libc::pthread_rwlock_tryrdlock(rw.get()), libc::EBUSY); |
273 |
| - assert_eq!(libc::pthread_rwlock_trywrlock(rw.get()), libc::EBUSY); |
274 |
| - assert_eq!(libc::pthread_rwlock_unlock(rw.get()), 0); |
275 |
| - |
276 |
| - assert_eq!(libc::pthread_rwlock_destroy(rw.get()), 0); |
277 |
| - } |
278 |
| -} |
279 |
| - |
280 | 163 | /// Tests whether each thread has its own `__errno_location`.
|
281 | 164 | fn test_thread_local_errno() {
|
282 | 165 | #[cfg(target_os = "linux")]
|
@@ -413,14 +296,6 @@ fn main() {
|
413 | 296 | #[cfg(any(target_os = "linux"))]
|
414 | 297 | test_sync_file_range();
|
415 | 298 |
|
416 |
| - test_mutex_libc_init_recursive(); |
417 |
| - test_mutex_libc_init_normal(); |
418 |
| - test_mutex_libc_init_errorcheck(); |
419 |
| - test_rwlock_libc_static_initializer(); |
420 |
| - |
421 |
| - #[cfg(any(target_os = "linux"))] |
422 |
| - test_mutex_libc_static_initializer_recursive(); |
423 |
| - |
424 | 299 | test_thread_local_errno();
|
425 | 300 |
|
426 | 301 | #[cfg(any(target_os = "linux"))]
|
|
0 commit comments