Skip to content

Commit 9503c41

Browse files
committed
also test pthread_condattr_getclock
1 parent 86d7dff commit 9503c41

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/tools/miri/src/shims/unix/sync.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
727727
) -> InterpResult<'tcx, Scalar<Provenance>> {
728728
let this = self.eval_context_mut();
729729

730+
// Does not exist on macOS!
731+
if !matches!(&*this.tcx.sess.target.os, "linux") {
732+
throw_unsup_format!(
733+
"`pthread_condattr_init` is not supported on {}",
734+
this.tcx.sess.target.os
735+
);
736+
}
737+
730738
let clock_id = this.read_scalar(clock_id_op)?.to_i32()?;
731739
if clock_id == this.eval_libc_i32("CLOCK_REALTIME")
732740
|| clock_id == this.eval_libc_i32("CLOCK_MONOTONIC")
@@ -747,6 +755,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
747755
) -> InterpResult<'tcx, Scalar<Provenance>> {
748756
let this = self.eval_context_mut();
749757

758+
// Does not exist on macOS!
759+
if !matches!(&*this.tcx.sess.target.os, "linux") {
760+
throw_unsup_format!(
761+
"`pthread_condattr_init` is not supported on {}",
762+
this.tcx.sess.target.os
763+
);
764+
}
765+
750766
let clock_id = condattr_get_clock_id(this, attr_op)?;
751767
this.write_scalar(Scalar::from_i32(clock_id), &this.deref_pointer(clk_id_op)?)?;
752768

src/tools/miri/tests/pass-dep/shims/libc-rsfs.stdout

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/tools/miri/tests/pass-dep/shims/pthread-sync.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fn main() {
1919
check_rwlock_write();
2020
check_rwlock_read_no_deadlock();
2121
check_cond();
22+
check_condattr();
2223
}
2324

2425
fn test_mutex_libc_init_recursive() {
@@ -261,6 +262,31 @@ fn check_cond() {
261262
}
262263
}
263264

265+
fn check_condattr() {
266+
unsafe {
267+
// Just smoke-testing that these functions can be called.
268+
let mut attr: MaybeUninit<libc::pthread_condattr_t> = MaybeUninit::uninit();
269+
assert_eq!(libc::pthread_condattr_init(attr.as_mut_ptr()), 0);
270+
271+
#[cfg(not(target_os = "macos"))] // setclock-getclock do not exist on macOS
272+
{
273+
let clock_id = libc::CLOCK_MONOTONIC;
274+
assert_eq!(libc::pthread_condattr_setclock(attr.as_mut_ptr(), clock_id), 0);
275+
let mut check_clock_id = MaybeUninit::<libc::clockid_t>::uninit();
276+
assert_eq!(
277+
libc::pthread_condattr_getclock(attr.as_mut_ptr(), check_clock_id.as_mut_ptr()),
278+
0
279+
);
280+
assert_eq!(check_clock_id.assume_init(), clock_id);
281+
}
282+
283+
let mut cond: MaybeUninit<libc::pthread_cond_t> = MaybeUninit::uninit();
284+
assert_eq!(libc::pthread_cond_init(cond.as_mut_ptr(), attr.as_ptr()), 0);
285+
assert_eq!(libc::pthread_condattr_destroy(attr.as_mut_ptr()), 0);
286+
assert_eq!(libc::pthread_cond_destroy(cond.as_mut_ptr()), 0);
287+
}
288+
}
289+
264290
// std::sync::RwLock does not even used pthread_rwlock any more.
265291
// Do some smoke testing of the API surface.
266292
fn test_rwlock_libc_static_initializer() {

0 commit comments

Comments
 (0)