1
1
// ignore-windows: Concurrency on Windows is not supported yet.
2
2
// compile-flags: -Zmiri-ignore-leaks -Zmiri-disable-stacked-borrows
3
3
4
- // Weak memory emulation tests. All of the following test if
5
- // our weak memory emulation produces any inconsistent execution outcomes
4
+ // The following tests check whether our weak memory emulation produces
5
+ // any inconsistent execution outcomes
6
6
//
7
7
// Due to the random nature of choosing valid stores, it is always
8
8
// possible that our tests spuriously succeeds: even though our weak
12
12
//
13
13
// To mitigate this, each test is ran enough times such that the chance
14
14
// of spurious success is very low. These tests never supriously fail.
15
- //
16
- // Note that we can't effectively test whether our weak memory emulation
17
- // can produce *all* consistent execution outcomes. This may be possible
18
- // if Miri's scheduler is sufficiently random and explores all possible
19
- // interleavings of our small test cases after a reasonable number of runs.
20
- // However, since Miri's scheduler is not even pre-emptive, there will
21
- // always be possible interleavings (and possible execution outcomes),
22
- // that can never be observed regardless of how weak memory emulation is
23
- // implemented.
24
15
25
16
// Test cases and their consistent outcomes are from
26
17
// http://svr-pes20-cppmem.cl.cam.ac.uk/cppmem/
27
18
// Based on
28
19
// M. Batty, S. Owens, S. Sarkar, P. Sewell and T. Weber,
29
20
// "Mathematizing C++ concurrency", ACM SIGPLAN Notices, vol. 46, no. 1, pp. 55-66, 2011.
30
21
// Available: https://ss265.host.cs.st-andrews.ac.uk/papers/n3132.pdf.
31
- #![ feature( atomic_from_mut) ]
32
22
23
+ use std:: sync:: atomic:: AtomicUsize ;
33
24
use std:: sync:: atomic:: Ordering :: * ;
34
- use std:: sync:: atomic:: { AtomicU16 , AtomicU32 , AtomicUsize } ;
35
25
use std:: thread:: { spawn, yield_now} ;
36
26
37
27
#[ derive( Copy , Clone ) ]
@@ -41,7 +31,7 @@ unsafe impl<T> Send for EvilSend<T> {}
41
31
unsafe impl < T > Sync for EvilSend < T > { }
42
32
43
33
// We can't create static items because we need to run each test
44
- // multiple tests
34
+ // multiple times
45
35
fn static_atomic ( val : usize ) -> & ' static AtomicUsize {
46
36
let ret = Box :: leak ( Box :: new ( AtomicUsize :: new ( val) ) ) ;
47
37
// A workaround to put the initialisation value in the store buffer
@@ -190,26 +180,6 @@ fn test_mixed_access() {
190
180
assert_eq ! ( r2, 2 ) ;
191
181
}
192
182
193
- // Strictly speaking, atomic accesses that imperfectly overlap with existing
194
- // atomic objects are UB. Nonetheless we'd like to provide a sane value when
195
- // the access is not racy.
196
- fn test_imperfectly_overlapping_access ( ) {
197
- let mut qword = AtomicU32 :: new ( 42 ) ;
198
- assert_eq ! ( qword. load( Relaxed ) , 42 ) ;
199
- qword. store ( u32:: to_be ( 0xabbafafa ) , Relaxed ) ;
200
-
201
- let qword_mut = qword. get_mut ( ) ;
202
-
203
- let dwords_mut = unsafe { std:: mem:: transmute :: < & mut u32 , & mut [ u16 ; 2 ] > ( qword_mut) } ;
204
-
205
- let ( hi_mut, lo_mut) = dwords_mut. split_at_mut ( 1 ) ;
206
-
207
- let ( hi, lo) = ( AtomicU16 :: from_mut ( & mut hi_mut[ 0 ] ) , AtomicU16 :: from_mut ( & mut lo_mut[ 0 ] ) ) ;
208
-
209
- assert_eq ! ( u16 :: from_be( hi. load( Relaxed ) ) , 0xabba ) ;
210
- assert_eq ! ( u16 :: from_be( lo. load( Relaxed ) ) , 0xfafa ) ;
211
- }
212
-
213
183
// The following two tests are taken from Repairing Sequential Consistency in C/C++11
214
184
// by Lahav et al.
215
185
// https://plv.mpi-sws.org/scfix/paper.pdf
@@ -236,7 +206,6 @@ fn test_sc_store_buffering() {
236
206
}
237
207
238
208
pub fn main ( ) {
239
- test_imperfectly_overlapping_access ( ) ;
240
209
// TODO: does this make chances of spurious success
241
210
// "sufficiently low"? This also takes a long time to run,
242
211
// prehaps each function should be its own test case so they
0 commit comments