Skip to content

Commit d31934b

Browse files
committed
Clean up mutex_simple test
1 parent ce3fa1e commit d31934b

File tree

4 files changed

+14
-29
lines changed

4 files changed

+14
-29
lines changed

tests/genmc/pass/intercept/mutex_simple.reps1.stderr

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/genmc/pass/intercept/mutex_simple.reps2.stderr

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/genmc/pass/intercept/mutex_simple.rs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
//@revisions: reps1 reps2 reps3
21
//@compile-flags: -Zmiri-genmc -Zmiri-disable-stacked-borrows -Zmiri-genmc-verbose
32
//@normalize-stderr-test: "Verification took .*s" -> "Verification took [TIME]s"
43

54
// Test various features of the `std::sync::Mutex` API with GenMC.
6-
// The test variants use a different number of iterations for the part that increments the counter protected by the mutex.
7-
// More repetitions leads to more possible executions, representing all ways that the threads entering the critical sections can be ordered.
5+
// Miri running with GenMC intercepts the Mutex functions `lock`, `try_lock` and `unlock`, instead of running their actual implementation.
6+
// This interception should not break any functionality.
87
//
98
// FIXME(genmc): Once the actual implementation of mutexes can be used in GenMC mode and there is a setting to disable Mutex interception: Add test revision without interception.
109
//
1110
// Miri provides annotations to GenMC for the condition required to unblock a thread blocked on a Mutex lock call.
12-
// This allows massively reduces the number of blocked executions we need to explore (in this test to zero blocked execution).
13-
// We use verbose output to test that there are no blocked executions, only completed executions.
11+
// This massively reduces the number of blocked executions we need to explore (in this test we require zero blocked execution).
12+
// We use verbose output to test that there are no blocked executions introduces by future changes, only completed executions.
1413

1514
#![no_main]
1615
#![feature(abort_unwind)]
@@ -22,13 +21,7 @@ use std::sync::Mutex;
2221

2322
use crate::genmc::*;
2423

25-
const REPS: u64 = if cfg!(reps3) {
26-
3
27-
} else if cfg!(reps2) {
28-
2
29-
} else {
30-
1
31-
};
24+
const REPS: u64 = 3;
3225

3326
static LOCK: Mutex<[u64; 32]> = Mutex::new([1234; 32]);
3427

@@ -47,13 +40,17 @@ fn main_() {
4740
guard[1] = 10;
4841
assert!(guard[0] == 0 && guard[1] == 10); // Check if changes are accepted
4942

50-
assert!(LOCK.try_lock().is_err()); // Trying to lock should fail if the lock is already held
43+
// Trying to lock should fail if the lock is already held
44+
assert!(LOCK.try_lock().is_err());
5145

52-
drop(guard); // Dropping the guard should unlock the mutex correctly.
46+
// Dropping the guard should unlock the mutex correctly.
47+
drop(guard);
5348
{
54-
assert!(LOCK.try_lock().is_ok()); // Trying to lock now should *not* fail since the lock is not held.
49+
// Trying to lock now should succeed since the lock is unlocked.
50+
assert!(LOCK.try_lock().is_ok());
5551
}
5652

53+
// Spawn multiple threads interacting with the same mutex.
5754
unsafe {
5855
let ids = [
5956
spawn_pthread_closure(|| {
@@ -71,12 +68,6 @@ fn main_() {
7168
];
7269
join_pthreads(ids);
7370
}
74-
75-
let guard = LOCK.lock().unwrap();
76-
assert!(guard[0] == REPS * 6); // Due to locking, all increments should be visible in every execution.
77-
assert!(guard[1] == 10); // All other values should be unchanged.
78-
for &v in guard.iter().skip(2) {
79-
assert!(v == 1234);
80-
}
81-
drop(guard);
71+
// Due to locking, all increments should be visible in every execution GenMC explores.
72+
assert!(LOCK.lock().unwrap()[0] == REPS * 6);
8273
}
File renamed without changes.

0 commit comments

Comments
 (0)