Skip to content

Commit f8b61d8

Browse files
authored
Rollup merge of #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 c821063 + 4fa9e08 commit f8b61d8

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

library/core/tests/atomic.rs

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

62+
#[test]
63+
#[cfg(any(not(target_arch = "arm"), target_os = "linux"))] // Missing intrinsic in compiler-builtins
64+
fn uint_min() {
65+
let x = AtomicUsize::new(0xf731);
66+
assert_eq!(x.fetch_min(0x137f, SeqCst), 0xf731);
67+
assert_eq!(x.load(SeqCst), 0x137f);
68+
assert_eq!(x.fetch_min(0xf731, SeqCst), 0x137f);
69+
assert_eq!(x.load(SeqCst), 0x137f);
70+
}
71+
72+
#[test]
73+
#[cfg(any(not(target_arch = "arm"), target_os = "linux"))] // Missing intrinsic in compiler-builtins
74+
fn uint_max() {
75+
let x = AtomicUsize::new(0x137f);
76+
assert_eq!(x.fetch_max(0xf731, SeqCst), 0x137f);
77+
assert_eq!(x.load(SeqCst), 0xf731);
78+
assert_eq!(x.fetch_max(0x137f, SeqCst), 0xf731);
79+
assert_eq!(x.load(SeqCst), 0xf731);
80+
}
81+
6282
#[test]
6383
fn int_and() {
6484
let x = AtomicIsize::new(0xf731);
@@ -87,6 +107,26 @@ fn int_xor() {
87107
assert_eq!(x.load(SeqCst), 0xf731 ^ 0x137f);
88108
}
89109

110+
#[test]
111+
#[cfg(any(not(target_arch = "arm"), target_os = "linux"))] // Missing intrinsic in compiler-builtins
112+
fn int_min() {
113+
let x = AtomicIsize::new(0xf731);
114+
assert_eq!(x.fetch_min(0x137f, SeqCst), 0xf731);
115+
assert_eq!(x.load(SeqCst), 0x137f);
116+
assert_eq!(x.fetch_min(0xf731, SeqCst), 0x137f);
117+
assert_eq!(x.load(SeqCst), 0x137f);
118+
}
119+
120+
#[test]
121+
#[cfg(any(not(target_arch = "arm"), target_os = "linux"))] // Missing intrinsic in compiler-builtins
122+
fn int_max() {
123+
let x = AtomicIsize::new(0x137f);
124+
assert_eq!(x.fetch_max(0xf731, SeqCst), 0x137f);
125+
assert_eq!(x.load(SeqCst), 0xf731);
126+
assert_eq!(x.fetch_max(0x137f, SeqCst), 0xf731);
127+
assert_eq!(x.load(SeqCst), 0xf731);
128+
}
129+
90130
static S_FALSE: AtomicBool = AtomicBool::new(false);
91131
static S_TRUE: AtomicBool = AtomicBool::new(true);
92132
static S_INT: AtomicIsize = AtomicIsize::new(0);

0 commit comments

Comments
 (0)