mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 17:24:06 +00:00
cf6d6050f7
* The WASI targets deal with the `main` symbol a bit differently than native so some `codegen` and `assembly` tests have been ignored. * All `ignore-emscripten` directives have been updated to `ignore-wasm32` to be more clear that all wasm targets are ignored and it's not just Emscripten. * Most `ignore-wasm32-bare` directives are now gone. * Some ignore directives for wasm were switched to `needs-unwind` instead. * Many `ignore-wasm32*` directives are removed as the tests work with WASI as opposed to `wasm32-unknown-unknown`.
95 lines
2.8 KiB
Rust
95 lines
2.8 KiB
Rust
//@ run-pass
|
|
//@ ignore-wasm32 no processes
|
|
//@ ignore-sgx no processes
|
|
|
|
use std::process::{Command, Stdio};
|
|
use std::env;
|
|
use std::sync::{Mutex, RwLock};
|
|
use std::time::Duration;
|
|
use std::thread;
|
|
|
|
fn test_mutex() {
|
|
let m = Mutex::new(0);
|
|
let _g = m.lock().unwrap();
|
|
let _g2 = m.lock().unwrap();
|
|
}
|
|
|
|
fn test_try_mutex() {
|
|
let m = Mutex::new(0);
|
|
let _g = m.lock().unwrap();
|
|
let _g2 = m.try_lock().unwrap();
|
|
}
|
|
|
|
fn test_rwlock_ww() {
|
|
let m = RwLock::new(0);
|
|
let _g = m.write().unwrap();
|
|
let _g2 = m.write().unwrap();
|
|
}
|
|
|
|
fn test_try_rwlock_ww() {
|
|
let m = RwLock::new(0);
|
|
let _g = m.write().unwrap();
|
|
let _g2 = m.try_write().unwrap();
|
|
}
|
|
|
|
fn test_rwlock_rw() {
|
|
let m = RwLock::new(0);
|
|
let _g = m.read().unwrap();
|
|
let _g2 = m.write().unwrap();
|
|
}
|
|
|
|
fn test_try_rwlock_rw() {
|
|
let m = RwLock::new(0);
|
|
let _g = m.read().unwrap();
|
|
let _g2 = m.try_write().unwrap();
|
|
}
|
|
|
|
fn test_rwlock_wr() {
|
|
let m = RwLock::new(0);
|
|
let _g = m.write().unwrap();
|
|
let _g2 = m.read().unwrap();
|
|
}
|
|
|
|
fn test_try_rwlock_wr() {
|
|
let m = RwLock::new(0);
|
|
let _g = m.write().unwrap();
|
|
let _g2 = m.try_read().unwrap();
|
|
}
|
|
|
|
fn main() {
|
|
let args: Vec<String> = env::args().collect();
|
|
if args.len() > 1 {
|
|
match &*args[1] {
|
|
"mutex" => test_mutex(),
|
|
"try_mutex" => test_try_mutex(),
|
|
"rwlock_ww" => test_rwlock_ww(),
|
|
"try_rwlock_ww" => test_try_rwlock_ww(),
|
|
"rwlock_rw" => test_rwlock_rw(),
|
|
"try_rwlock_rw" => test_try_rwlock_rw(),
|
|
"rwlock_wr" => test_rwlock_wr(),
|
|
"try_rwlock_wr" => test_try_rwlock_wr(),
|
|
_ => unreachable!(),
|
|
}
|
|
// If we reach this point then the test failed
|
|
println!("TEST FAILED: {}", args[1]);
|
|
} else {
|
|
let mut v = vec![];
|
|
v.push(Command::new(&args[0]).arg("mutex").stderr(Stdio::null()).spawn().unwrap());
|
|
v.push(Command::new(&args[0]).arg("try_mutex").stderr(Stdio::null()).spawn().unwrap());
|
|
v.push(Command::new(&args[0]).arg("rwlock_ww").stderr(Stdio::null()).spawn().unwrap());
|
|
v.push(Command::new(&args[0]).arg("try_rwlock_ww").stderr(Stdio::null()).spawn().unwrap());
|
|
v.push(Command::new(&args[0]).arg("rwlock_rw").stderr(Stdio::null()).spawn().unwrap());
|
|
v.push(Command::new(&args[0]).arg("try_rwlock_rw").stderr(Stdio::null()).spawn().unwrap());
|
|
v.push(Command::new(&args[0]).arg("rwlock_wr").stderr(Stdio::null()).spawn().unwrap());
|
|
v.push(Command::new(&args[0]).arg("try_rwlock_wr").stderr(Stdio::null()).spawn().unwrap());
|
|
|
|
thread::sleep(Duration::new(1, 0));
|
|
|
|
// Make sure all subprocesses either panicked or were killed because they deadlocked
|
|
for mut c in v {
|
|
c.kill().ok();
|
|
assert!(!c.wait().unwrap().success());
|
|
}
|
|
}
|
|
}
|