-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test ensuring a moved mutex deadlocks
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/tools/miri/tests/fail/concurrency/mutex-leak-move-deadlock.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//@error-in-other-file: deadlock | ||
//@normalize-stderr-test: "src/sys/.*\.rs" -> "$$FILE" | ||
//@normalize-stderr-test: "LL \| .*" -> "LL | $$CODE" | ||
//@normalize-stderr-test: "\| +\^+" -> "| ^" | ||
//@normalize-stderr-test: "\n *= note:.*" -> "" | ||
use std::mem; | ||
use std::sync::Mutex; | ||
|
||
fn main() { | ||
let m = Mutex::new(0); | ||
mem::forget(m.lock()); | ||
// Move the lock while it is "held" (really: leaked) | ||
let m2 = m; | ||
// Now try to acquire the lock again. | ||
let _guard = m2.lock(); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/tools/miri/tests/fail/concurrency/mutex-leak-move-deadlock.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
error: deadlock: the evaluated program deadlocked | ||
--> RUSTLIB/std/$FILE:LL:CC | ||
| | ||
LL | $CODE | ||
| ^ the evaluated program deadlocked | ||
| | ||
note: inside `main` | ||
--> tests/fail/concurrency/mutex-leak-move-deadlock.rs:LL:CC | ||
| | ||
LL | $CODE | ||
| ^ | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to 1 previous error | ||
|