Skip to content

Commit b96fe1f

Browse files
authored
Rollup merge of rust-lang#82093 - bjorn3:more_atomic_tests, r=kennytm
Add tests for Atomic*::fetch_{min,max} This ensures that all atomic operations except for fences are tested. This has been useful to test my work on using atomic instructions for atomic operations in cg_clif instead of a global lock.
2 parents 94f339b + d1a541e commit b96fe1f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

library/core/tests/atomic.rs

+36
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ fn uint_xor() {
5959
assert_eq!(x.load(SeqCst), 0xf731 ^ 0x137f);
6060
}
6161

62+
#[test]
63+
fn uint_min() {
64+
let x = AtomicUsize::new(0xf731);
65+
assert_eq!(x.fetch_min(0x137f, SeqCst), 0xf731);
66+
assert_eq!(x.load(SeqCst), 0x137f);
67+
assert_eq!(x.fetch_min(0xf731, SeqCst), 0x137f);
68+
assert_eq!(x.load(SeqCst), 0x137f);
69+
}
70+
71+
#[test]
72+
fn uint_max() {
73+
let x = AtomicUsize::new(0x137f);
74+
assert_eq!(x.fetch_max(0xf731, SeqCst), 0x137f);
75+
assert_eq!(x.load(SeqCst), 0xf731);
76+
assert_eq!(x.fetch_max(0x137f, SeqCst), 0xf731);
77+
assert_eq!(x.load(SeqCst), 0xf731);
78+
}
79+
6280
#[test]
6381
fn int_and() {
6482
let x = AtomicIsize::new(0xf731);
@@ -87,6 +105,24 @@ fn int_xor() {
87105
assert_eq!(x.load(SeqCst), 0xf731 ^ 0x137f);
88106
}
89107

108+
#[test]
109+
fn int_min() {
110+
let x = AtomicIsize::new(0xf731);
111+
assert_eq!(x.fetch_min(0x137f, SeqCst), 0xf731);
112+
assert_eq!(x.load(SeqCst), 0x137f);
113+
assert_eq!(x.fetch_min(0xf731, SeqCst), 0x137f);
114+
assert_eq!(x.load(SeqCst), 0x137f);
115+
}
116+
117+
#[test]
118+
fn int_max() {
119+
let x = AtomicIsize::new(0x137f);
120+
assert_eq!(x.fetch_max(0xf731, SeqCst), 0x137f);
121+
assert_eq!(x.load(SeqCst), 0xf731);
122+
assert_eq!(x.fetch_max(0x137f, SeqCst), 0xf731);
123+
assert_eq!(x.load(SeqCst), 0xf731);
124+
}
125+
90126
static S_FALSE: AtomicBool = AtomicBool::new(false);
91127
static S_TRUE: AtomicBool = AtomicBool::new(true);
92128
static S_INT: AtomicIsize = AtomicIsize::new(0);

0 commit comments

Comments
 (0)