Skip to content

Commit 4c7b0ba

Browse files
committed
weak memory tests: add more info on where they come from
1 parent 3ad5863 commit 4c7b0ba

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

tests/pass/0weak_memory_consistency.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
// To mitigate this, each test is ran enough times such that the chance
1515
// of spurious success is very low. These tests never spuriously fail.
1616

17-
// Test cases and their consistent outcomes are from
18-
// http://svr-pes20-cppmem.cl.cam.ac.uk/cppmem/
19-
// Based on
20-
// M. Batty, S. Owens, S. Sarkar, P. Sewell and T. Weber,
21-
// "Mathematizing C++ concurrency", ACM SIGPLAN Notices, vol. 46, no. 1, pp. 55-66, 2011.
22-
// Available: https://ss265.host.cs.st-andrews.ac.uk/papers/n3132.pdf.
23-
2417
use std::sync::atomic::Ordering::*;
2518
use std::sync::atomic::{AtomicBool, AtomicI32, Ordering, fence};
2619
use std::thread::spawn;
@@ -56,6 +49,7 @@ fn spin_until_bool(loc: &AtomicBool, ord: Ordering, val: bool) -> bool {
5649
val
5750
}
5851

52+
/// Test matching https://www.doc.ic.ac.uk/~afd/homepages/papers/pdfs/2017/POPL.pdf, Figure 7
5953
fn test_corr() {
6054
let x = static_atomic(0);
6155
let y = static_atomic(0);
@@ -75,19 +69,25 @@ fn test_corr() {
7569
let j3 = spawn(move || { // | |
7670
spin_until_i32(&y, Acquire, 1); // <---------+ |
7771
x.load(Relaxed) // <----------------------------------------------+
78-
// The two reads on x are ordered by hb, so they cannot observe values
79-
// differently from the modification order. If the first read observed
80-
// 2, then the second read must observe 2 as well.
8172
});
8273

8374
j1.join().unwrap();
8475
let r2 = j2.join().unwrap();
8576
let r3 = j3.join().unwrap();
77+
// The two reads on x are ordered by hb, so they cannot observe values
78+
// differently from the modification order. If the first read observed
79+
// 2, then the second read must observe 2 as well.
8680
if r2 == 2 {
8781
assert_eq!(r3, 2);
8882
}
8983
}
9084

85+
/// This test case is from:
86+
/// http://svr-pes20-cppmem.cl.cam.ac.uk/cppmem/, "WRC"
87+
/// Based on
88+
/// M. Batty, S. Owens, S. Sarkar, P. Sewell and T. Weber,
89+
/// "Mathematizing C++ concurrency", ACM SIGPLAN Notices, vol. 46, no. 1, pp. 55-66, 2011.
90+
/// Available: https://www.cl.cam.ac.uk/~pes20/cpp/popl085ap-sewell.pdf.
9191
fn test_wrc() {
9292
let x = static_atomic(0);
9393
let y = static_atomic(0);
@@ -114,6 +114,8 @@ fn test_wrc() {
114114
assert_eq!(r3, 1);
115115
}
116116

117+
/// Another test from http://svr-pes20-cppmem.cl.cam.ac.uk/cppmem/:
118+
/// MP (na_rel+acq_na)
117119
fn test_message_passing() {
118120
let mut var = 0u32;
119121
let ptr = &mut var as *mut u32;
@@ -139,7 +141,8 @@ fn test_message_passing() {
139141
assert_eq!(r2, 1);
140142
}
141143

142-
// LB+acq_rel+acq_rel
144+
/// Another test from http://svr-pes20-cppmem.cl.cam.ac.uk/cppmem/:
145+
/// LB+acq_rel+acq_rel
143146
fn test_load_buffering_acq_rel() {
144147
let x = static_atomic(0);
145148
let y = static_atomic(0);

0 commit comments

Comments
 (0)