Add tests, improve test coverage

This commit is contained in:
David Cook 2020-04-05 14:55:57 -05:00
parent f9dc942cfd
commit 134d6a2faa
6 changed files with 78 additions and 1 deletions

View file

@ -0,0 +1,16 @@
// ignore-windows: No libc on Windows
#![feature(rustc_private)]
extern crate libc;
fn main() {
unsafe {
let mut mutexattr: libc::pthread_mutexattr_t = std::mem::zeroed();
assert_eq!(libc::pthread_mutexattr_settype(&mut mutexattr as *mut _, libc::PTHREAD_MUTEX_NORMAL), 0);
let mut mutex: libc::pthread_mutex_t = std::mem::zeroed();
assert_eq!(libc::pthread_mutex_init(&mut mutex as *mut _, &mutexattr as *const _), 0);
assert_eq!(libc::pthread_mutex_lock(&mut mutex as *mut _), 0);
libc::pthread_mutex_destroy(&mut mutex as *mut _); //~ ERROR destroyed a locked mutex
}
}

View file

@ -0,0 +1,17 @@
// ignore-windows: No libc on Windows
#![feature(rustc_private)]
extern crate libc;
fn main() {
unsafe {
let mut mutexattr: libc::pthread_mutexattr_t = std::mem::zeroed();
assert_eq!(libc::pthread_mutexattr_settype(&mut mutexattr as *mut _, libc::PTHREAD_MUTEX_NORMAL), 0);
let mut mutex: libc::pthread_mutex_t = std::mem::zeroed();
assert_eq!(libc::pthread_mutex_init(&mut mutex as *mut _, &mutexattr as *const _), 0);
assert_eq!(libc::pthread_mutex_lock(&mut mutex as *mut _), 0);
assert_eq!(libc::pthread_mutex_unlock(&mut mutex as *mut _), 0);
libc::pthread_mutex_unlock(&mut mutex as *mut _); //~ ERROR was not locked
}
}

View file

@ -0,0 +1,13 @@
// ignore-windows: No libc on Windows
#![feature(rustc_private)]
extern crate libc;
fn main() {
let rw = std::cell::UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER);
unsafe {
assert_eq!(libc::pthread_rwlock_rdlock(rw.get()), 0);
libc::pthread_rwlock_destroy(rw.get()); //~ ERROR destroyed a locked rwlock
}
}

View file

@ -0,0 +1,13 @@
// ignore-windows: No libc on Windows
#![feature(rustc_private)]
extern crate libc;
fn main() {
let rw = std::cell::UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER);
unsafe {
assert_eq!(libc::pthread_rwlock_wrlock(rw.get()), 0);
libc::pthread_rwlock_destroy(rw.get()); //~ ERROR destroyed a locked rwlock
}
}

View file

@ -0,0 +1,12 @@
// ignore-windows: No libc on Windows
#![feature(rustc_private)]
extern crate libc;
fn main() {
let rw = std::cell::UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER);
unsafe {
libc::pthread_rwlock_unlock(rw.get()); //~ ERROR was not locked
}
}

View file

@ -15,7 +15,7 @@ fn tmp() -> PathBuf {
#[cfg(not(target_os = "macos"))]
fn test_posix_fadvise() {
use std::convert::TryInto;
use std::fs::{File, remove_file};
use std::fs::{remove_file, File};
use std::io::Write;
use std::os::unix::io::AsRawFd;
@ -66,6 +66,7 @@ fn test_mutex_libc_init_recursive() {
fn test_mutex_libc_init_normal() {
unsafe {
let mut mutexattr: libc::pthread_mutexattr_t = std::mem::zeroed();
assert_eq!(libc::pthread_mutexattr_settype(&mut mutexattr as *mut _, 0x12345678), libc::EINVAL);
assert_eq!(libc::pthread_mutexattr_settype(&mut mutexattr as *mut _, libc::PTHREAD_MUTEX_NORMAL), 0);
let mut mutex: libc::pthread_mutex_t = std::mem::zeroed();
assert_eq!(libc::pthread_mutex_init(&mut mutex as *mut _, &mutexattr as *const _), 0);
@ -133,6 +134,11 @@ fn test_rwlock_libc_static_initializer() {
assert_eq!(libc::pthread_rwlock_trywrlock(rw.get()), libc::EBUSY);
assert_eq!(libc::pthread_rwlock_unlock(rw.get()), 0);
assert_eq!(libc::pthread_rwlock_trywrlock(rw.get()), 0);
assert_eq!(libc::pthread_rwlock_tryrdlock(rw.get()), libc::EBUSY);
assert_eq!(libc::pthread_rwlock_trywrlock(rw.get()), libc::EBUSY);
assert_eq!(libc::pthread_rwlock_unlock(rw.get()), 0);
assert_eq!(libc::pthread_rwlock_destroy(rw.get()), 0);
}
}