Skip to content

Commit a4b2fc0

Browse files
committed
Adjust pthread tests
1 parent f0d9157 commit a4b2fc0

File tree

3 files changed

+24
-38
lines changed

3 files changed

+24
-38
lines changed

tests/run-pass/concurrency/libc_pthread_cond.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,47 @@
11
// ignore-windows: No libc on Windows
22
// ignore-macos: pthread_condattr_setclock is not supported on MacOS.
3-
// compile-flags: -Zmiri-disable-isolation
3+
// compile-flags: -Zmiri-disable-isolation -Zmiri-check-number-validity
44

55
#![feature(rustc_private)]
66

77
/// Test that conditional variable timeouts are working properly with both
88
/// monotonic and system clocks.
99
extern crate libc;
1010

11-
use std::mem;
11+
use std::mem::MaybeUninit;
1212
use std::time::Instant;
1313

1414
fn test_timed_wait_timeout(clock_id: i32) {
1515
unsafe {
16-
let mut attr: libc::pthread_condattr_t = mem::zeroed();
17-
assert_eq!(libc::pthread_condattr_init(&mut attr as *mut _), 0);
18-
assert_eq!(libc::pthread_condattr_setclock(&mut attr as *mut _, clock_id), 0);
16+
let mut attr: MaybeUninit<libc::pthread_condattr_t> = MaybeUninit::uninit();
17+
assert_eq!(libc::pthread_condattr_init(attr.as_mut_ptr()), 0);
18+
assert_eq!(libc::pthread_condattr_setclock(attr.as_mut_ptr(), clock_id), 0);
1919

20-
let mut cond: libc::pthread_cond_t = mem::zeroed();
21-
assert_eq!(libc::pthread_cond_init(&mut cond as *mut _, &attr as *const _), 0);
22-
assert_eq!(libc::pthread_condattr_destroy(&mut attr as *mut _), 0);
20+
let mut cond: MaybeUninit<libc::pthread_cond_t> = MaybeUninit::uninit();
21+
assert_eq!(libc::pthread_cond_init(cond.as_mut_ptr(), attr.as_ptr()), 0);
22+
assert_eq!(libc::pthread_condattr_destroy(attr.as_mut_ptr()), 0);
2323

24-
let mut mutex: libc::pthread_mutex_t = mem::zeroed();
24+
let mut mutex: libc::pthread_mutex_t = libc::PTHREAD_MUTEX_INITIALIZER;
2525

26-
let mut now: libc::timespec = mem::zeroed();
27-
assert_eq!(libc::clock_gettime(clock_id, &mut now), 0);
26+
let mut now_mu: MaybeUninit<libc::timespec> = MaybeUninit::uninit();
27+
assert_eq!(libc::clock_gettime(clock_id, now_mu.as_mut_ptr()), 0);
28+
let now = now_mu.assume_init();
2829
// Waiting for a second... mostly because waiting less requires mich more tricky arithmetic.
2930
// FIXME: wait less.
3031
let timeout = libc::timespec { tv_sec: now.tv_sec + 1, tv_nsec: now.tv_nsec };
3132

3233
assert_eq!(libc::pthread_mutex_lock(&mut mutex as *mut _), 0);
3334
let current_time = Instant::now();
3435
assert_eq!(
35-
libc::pthread_cond_timedwait(&mut cond as *mut _, &mut mutex as *mut _, &timeout),
36+
libc::pthread_cond_timedwait(cond.as_mut_ptr(), &mut mutex as *mut _, &timeout),
3637
libc::ETIMEDOUT
3738
);
3839
let elapsed_time = current_time.elapsed().as_millis();
3940
assert!(900 <= elapsed_time && elapsed_time <= 1300);
4041

4142
// Test calling `pthread_cond_timedwait` again with an already elapsed timeout.
4243
assert_eq!(
43-
libc::pthread_cond_timedwait(&mut cond as *mut _, &mut mutex as *mut _, &timeout),
44+
libc::pthread_cond_timedwait(cond.as_mut_ptr(), &mut mutex as *mut _, &timeout),
4445
libc::ETIMEDOUT
4546
);
4647

@@ -49,7 +50,7 @@ fn test_timed_wait_timeout(clock_id: i32) {
4950
let invalid_timeout_1 = libc::timespec { tv_sec: now.tv_sec + 1, tv_nsec: 1_000_000_000 };
5051
assert_eq!(
5152
libc::pthread_cond_timedwait(
52-
&mut cond as *mut _,
53+
cond.as_mut_ptr(),
5354
&mut mutex as *mut _,
5455
&invalid_timeout_1
5556
),
@@ -58,7 +59,7 @@ fn test_timed_wait_timeout(clock_id: i32) {
5859
let invalid_timeout_2 = libc::timespec { tv_sec: now.tv_sec + 1, tv_nsec: -1 };
5960
assert_eq!(
6061
libc::pthread_cond_timedwait(
61-
&mut cond as *mut _,
62+
cond.as_mut_ptr(),
6263
&mut mutex as *mut _,
6364
&invalid_timeout_2
6465
),
@@ -68,7 +69,7 @@ fn test_timed_wait_timeout(clock_id: i32) {
6869
let invalid_timeout_3 = libc::timespec { tv_sec: -1, tv_nsec: 0 };
6970
assert_eq!(
7071
libc::pthread_cond_timedwait(
71-
&mut cond as *mut _,
72+
cond.as_mut_ptr(),
7273
&mut mutex as *mut _,
7374
&invalid_timeout_3
7475
),
@@ -77,7 +78,7 @@ fn test_timed_wait_timeout(clock_id: i32) {
7778

7879
assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), 0);
7980
assert_eq!(libc::pthread_mutex_destroy(&mut mutex as *mut _), 0);
80-
assert_eq!(libc::pthread_cond_destroy(&mut cond as *mut _), 0);
81+
assert_eq!(libc::pthread_cond_destroy(cond.as_mut_ptr()), 0);
8182
}
8283
}
8384

tests/run-pass/concurrency/pthread_condattr_init.rs

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/run-pass/concurrency/sync.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
2-
// compile-flags: -Zmiri-disable-isolation
2+
// compile-flags: -Zmiri-disable-isolation -Zmiri-check-number-validity
33

44
use std::sync::mpsc::{channel, sync_channel};
55
use std::sync::{Arc, Barrier, Condvar, Mutex, Once, RwLock};
@@ -340,6 +340,10 @@ fn park_unpark() {
340340
assert!((200..1000).contains(&start.elapsed().as_millis()));
341341
}
342342

343+
fn check_condvar() {
344+
let _ = std::sync::Condvar::new();
345+
}
346+
343347
fn main() {
344348
check_barriers();
345349
check_conditional_variables_notify_one();
@@ -357,4 +361,5 @@ fn main() {
357361
check_rwlock_unlock_bug2();
358362
park_timeout();
359363
park_unpark();
364+
check_condvar();
360365
}

0 commit comments

Comments
 (0)