Add test of recursive mutex using libc FFI

This commit is contained in:
David Cook 2020-02-21 19:10:20 -06:00
parent c773ca8614
commit 5cc091bc6e

View file

@ -8,6 +8,7 @@ fn main() {
test_mutex();
#[cfg(not(target_os = "windows"))] // TODO: implement RwLock on Windows
{
test_mutex_libc_recursive();
test_rwlock_stdlib();
test_rwlock_libc_init();
test_rwlock_libc_static_initializer();
@ -24,6 +25,28 @@ fn test_mutex() {
drop(m);
}
#[cfg(not(target_os = "windows"))]
fn test_mutex_libc_recursive() {
unsafe {
let mut attr: libc::pthread_mutexattr_t = std::mem::zeroed();
assert_eq!(libc::pthread_mutexattr_init(&mut attr as *mut _), 0);
assert_eq!(libc::pthread_mutexattr_settype(&mut attr as *mut _, libc::PTHREAD_MUTEX_RECURSIVE), 0);
let mut mutex: libc::pthread_mutex_t = std::mem::zeroed();
assert_eq!(libc::pthread_mutex_init(&mut mutex as *mut _, &mut attr as *mut _), 0);
assert_eq!(libc::pthread_mutex_lock(&mut mutex as *mut _), 0);
assert_eq!(libc::pthread_mutex_trylock(&mut mutex as *mut _), 0);
assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), 0);
assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), 0);
assert_eq!(libc::pthread_mutex_trylock(&mut mutex as *mut _), 0);
assert_eq!(libc::pthread_mutex_lock(&mut mutex as *mut _), 0);
assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), 0);
assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), 0);
assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), libc::EPERM);
assert_eq!(libc::pthread_mutex_destroy(&mut mutex as *mut _), 0);
assert_eq!(libc::pthread_mutexattr_destroy(&mut attr as *mut _), 0);
}
}
#[cfg(not(target_os = "windows"))]
fn test_rwlock_stdlib() {
let rw = RwLock::new(0);