From ca4969d4da07faab68ab8be893602a41fca63724 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 2 Aug 2019 19:50:54 +0200 Subject: [PATCH] consolidate atomic tests --- tests/run-pass/atomic-access-bool.rs | 19 ------------ .../{atomic-compare_exchange.rs => atomic.rs} | 29 +++++++++++++++++-- 2 files changed, 26 insertions(+), 22 deletions(-) delete mode 100644 tests/run-pass/atomic-access-bool.rs rename tests/run-pass/{atomic-compare_exchange.rs => atomic.rs} (64%) diff --git a/tests/run-pass/atomic-access-bool.rs b/tests/run-pass/atomic-access-bool.rs deleted file mode 100644 index 68a5d7295f1..00000000000 --- a/tests/run-pass/atomic-access-bool.rs +++ /dev/null @@ -1,19 +0,0 @@ -use std::sync::atomic::{AtomicBool, Ordering::*}; - -static mut ATOMIC: AtomicBool = AtomicBool::new(false); - -fn main() { - unsafe { - assert_eq!(*ATOMIC.get_mut(), false); - ATOMIC.store(true, SeqCst); - assert_eq!(*ATOMIC.get_mut(), true); - ATOMIC.fetch_or(false, SeqCst); - assert_eq!(*ATOMIC.get_mut(), true); - ATOMIC.fetch_and(false, SeqCst); - assert_eq!(*ATOMIC.get_mut(), false); - ATOMIC.fetch_nand(true, SeqCst); - assert_eq!(*ATOMIC.get_mut(), true); - ATOMIC.fetch_xor(true, SeqCst); - assert_eq!(*ATOMIC.get_mut(), false); - } -} diff --git a/tests/run-pass/atomic-compare_exchange.rs b/tests/run-pass/atomic.rs similarity index 64% rename from tests/run-pass/atomic-compare_exchange.rs rename to tests/run-pass/atomic.rs index 575b53fb44b..ed9a9f45349 100644 --- a/tests/run-pass/atomic-compare_exchange.rs +++ b/tests/run-pass/atomic.rs @@ -1,8 +1,31 @@ -use std::sync::atomic::{AtomicIsize, Ordering::*}; - -static ATOMIC: AtomicIsize = AtomicIsize::new(0); +use std::sync::atomic::{AtomicBool, AtomicIsize, Ordering::*}; fn main() { + atomic_bool(); + atomic_isize(); +} + +fn atomic_bool() { + static mut ATOMIC: AtomicBool = AtomicBool::new(false); + + unsafe { + assert_eq!(*ATOMIC.get_mut(), false); + ATOMIC.store(true, SeqCst); + assert_eq!(*ATOMIC.get_mut(), true); + ATOMIC.fetch_or(false, SeqCst); + assert_eq!(*ATOMIC.get_mut(), true); + ATOMIC.fetch_and(false, SeqCst); + assert_eq!(*ATOMIC.get_mut(), false); + ATOMIC.fetch_nand(true, SeqCst); + assert_eq!(*ATOMIC.get_mut(), true); + ATOMIC.fetch_xor(true, SeqCst); + assert_eq!(*ATOMIC.get_mut(), false); + } +} + +fn atomic_isize() { + static ATOMIC: AtomicIsize = AtomicIsize::new(0); + // Make sure trans can emit all the intrinsics correctly assert_eq!(ATOMIC.compare_exchange(0, 1, Relaxed, Relaxed), Ok(0)); assert_eq!(ATOMIC.compare_exchange(0, 2, Acquire, Relaxed), Err(1));