Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mandragorian committed Aug 2, 2024
1 parent 1df484c commit 9ec55eb
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ LL | libc::pthread_mutex_lock(&mut m2 as *mut _);
note: inside `main`
--> $DIR/libc_pthread_mutex_move.rs:LL:CC
|
LL | check();
| ^^^^^^^
LL | check();
| ^^^^^^^

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ LL | libc::pthread_mutex_lock(&mut m2 as *mut _);
note: inside `main`
--> $DIR/libc_pthread_mutex_move.rs:LL:CC
|
LL | check();
| ^^^^^^^
LL | check();
| ^^^^^^^

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

Expand Down
26 changes: 23 additions & 3 deletions tests/fail-dep/concurrency/libc_pthread_mutex_move.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ignore-target-windows: No pthreads on Windows
//@revisions: lock trylock unlock init
//@[unlock_register]only-target-linux: recursive initializers are non-standard.
//@revisions: lock trylock unlock_register unlock_detect init

fn main() {
check();
Expand Down Expand Up @@ -40,13 +41,32 @@ fn check() {
}
}

#[cfg(unlock)]
#[cfg(unlock_register)]
fn check() {
unsafe {
let mut m: libc::pthread_mutex_t = libc::PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
libc::pthread_mutex_unlock(&mut m as *mut _);

let mut m2 = m;
libc::pthread_mutex_unlock(&mut m2 as *mut _); //~[unlock] ERROR: pthread_mutex_t can't be moved after first use
libc::pthread_mutex_unlock(&mut m2 as *mut _); //~[unlock_register] ERROR: pthread_mutex_t can't be moved after first use
}
}

#[cfg(unlock_detect)]
fn check() {
unsafe {
let mut mutexattr: libc::pthread_mutexattr_t = std::mem::zeroed();
assert_eq!(
libc::pthread_mutexattr_settype(
&mut mutexattr as *mut _,
libc::PTHREAD_MUTEX_RECURSIVE
),
0,
);
let mut m: libc::pthread_mutex_t = std::mem::zeroed();
assert_eq!(libc::pthread_mutex_init(&mut m as *mut _, &mutexattr as *const _), 0);

let mut m2 = m;
libc::pthread_mutex_unlock(&mut m2 as *mut _); //~[unlock_detect] ERROR: pthread_mutex_t can't be moved after first use
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ LL | libc::pthread_mutex_trylock(&mut m2 as *mut _);
note: inside `main`
--> $DIR/libc_pthread_mutex_move.rs:LL:CC
|
LL | check();
| ^^^^^^^
LL | check();
| ^^^^^^^

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ LL | libc::pthread_mutex_unlock(&mut m2 as *mut _);
note: inside `main`
--> $DIR/libc_pthread_mutex_move.rs:LL:CC
|
LL | check();
| ^^^^^^^
LL | check();
| ^^^^^^^

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error: Undefined Behavior: pthread_mutex_t can't be moved after first use
--> $DIR/libc_pthread_mutex_move.rs:LL:CC
|
LL | libc::pthread_mutex_unlock(&mut m2 as *mut _);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pthread_mutex_t can't be moved after first use
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: BACKTRACE:
= note: inside `check` at $DIR/libc_pthread_mutex_move.rs:LL:CC
note: inside `main`
--> $DIR/libc_pthread_mutex_move.rs:LL:CC
|
LL | check();
| ^^^^^^^

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to 1 previous error

0 comments on commit 9ec55eb

Please sign in to comment.