Skip to content

Commit

Permalink
tests: Clean up helper macros
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Sep 28, 2024
1 parent 3b19e14 commit d587a5f
Showing 1 changed file with 13 additions and 79 deletions.
92 changes: 13 additions & 79 deletions src/tests/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,11 +1427,23 @@ macro_rules! __test_atomic_ptr {
};
}

macro_rules! __test_atomic_int_load_store_pub {
macro_rules! __test_atomic_int_pub {
($atomic_type:ty, $int_type:ident) => {
__test_atomic_pub_common!($atomic_type, $int_type);
use std::{boxed::Box, mem};
#[test]
fn fetch_update() {
let a = <$atomic_type>::new(7);
test_compare_exchange_ordering(|set, fetch| a.fetch_update(set, fetch, |x| Some(x)));
for &(success, failure) in &test_helper::COMPARE_EXCHANGE_ORDERINGS {
let a = <$atomic_type>::new(7);
assert_eq!(a.fetch_update(success, failure, |_| None), Err(7));
assert_eq!(a.fetch_update(success, failure, |x| Some(x + 1)), Ok(7));
assert_eq!(a.fetch_update(success, failure, |x| Some(x + 1)), Ok(8));
assert_eq!(a.load(Ordering::SeqCst), 9);
}
}
#[test]
fn impls() {
#[cfg(not(portable_atomic_no_const_transmute))]
const _: $int_type = {
Expand All @@ -1456,22 +1468,6 @@ macro_rules! __test_atomic_int_load_store_pub {
drop(Box::from_raw(ptr));
}
}
};
}
macro_rules! __test_atomic_int_pub {
($atomic_type:ty, $int_type:ident) => {
#[test]
fn fetch_update() {
let a = <$atomic_type>::new(7);
test_compare_exchange_ordering(|set, fetch| a.fetch_update(set, fetch, |x| Some(x)));
for &(success, failure) in &test_helper::COMPARE_EXCHANGE_ORDERINGS {
let a = <$atomic_type>::new(7);
assert_eq!(a.fetch_update(success, failure, |_| None), Err(7));
assert_eq!(a.fetch_update(success, failure, |x| Some(x + 1)), Ok(7));
assert_eq!(a.fetch_update(success, failure, |x| Some(x + 1)), Ok(8));
assert_eq!(a.load(Ordering::SeqCst), 9);
}
}
::quickcheck::quickcheck! {
fn quickcheck_fetch_update(x: $int_type, y: $int_type) -> bool {
let z = loop {
Expand Down Expand Up @@ -1823,20 +1819,6 @@ macro_rules! test_atomic_int_load_store {
}
};
}
macro_rules! test_atomic_bool_load_store {
() => {
#[allow(
clippy::alloc_instead_of_core,
clippy::std_instead_of_alloc,
clippy::std_instead_of_core,
clippy::undocumented_unsafe_blocks
)]
mod test_atomic_bool {
use super::*;
__test_atomic_bool_load_store!(AtomicBool);
}
};
}
macro_rules! test_atomic_ptr_load_store {
() => {
#[allow(
Expand Down Expand Up @@ -1869,21 +1851,6 @@ macro_rules! test_atomic_int_single_thread {
}
};
}
macro_rules! test_atomic_bool_single_thread {
() => {
#[allow(
clippy::alloc_instead_of_core,
clippy::std_instead_of_alloc,
clippy::std_instead_of_core,
clippy::undocumented_unsafe_blocks
)]
mod test_atomic_bool {
use super::*;
__test_atomic_bool_load_store!(AtomicBool, single_thread);
__test_atomic_bool!(AtomicBool, single_thread);
}
};
}
macro_rules! test_atomic_ptr_single_thread {
() => {
#[allow(
Expand Down Expand Up @@ -1917,21 +1884,6 @@ macro_rules! test_atomic_int {
}
};
}
macro_rules! test_atomic_bool {
() => {
#[allow(
clippy::alloc_instead_of_core,
clippy::std_instead_of_alloc,
clippy::std_instead_of_core,
clippy::undocumented_unsafe_blocks
)]
mod test_atomic_bool {
use super::*;
__test_atomic_bool_load_store!(AtomicBool);
__test_atomic_bool!(AtomicBool);
}
};
}
macro_rules! test_atomic_ptr {
() => {
#[allow(
Expand Down Expand Up @@ -1962,29 +1914,11 @@ macro_rules! test_atomic_int_pub {
use super::*;
__test_atomic_int_load_store!([<Atomic $int_type:camel>], $int_type);
__test_atomic_int!([<Atomic $int_type:camel>], $int_type);
__test_atomic_int_load_store_pub!([<Atomic $int_type:camel>], $int_type);
__test_atomic_int_pub!([<Atomic $int_type:camel>], $int_type);
}
}
};
}
macro_rules! test_atomic_int_load_store_pub {
($int_type:ident) => {
paste::paste! {
#[allow(
clippy::alloc_instead_of_core,
clippy::std_instead_of_alloc,
clippy::std_instead_of_core,
clippy::undocumented_unsafe_blocks
)]
mod [<test_atomic_ $int_type>] {
use super::*;
__test_atomic_int_load_store!([<Atomic $int_type:camel>], $int_type);
__test_atomic_int_load_store_pub!([<Atomic $int_type:camel>], $int_type);
}
}
};
}
#[cfg(feature = "float")]
macro_rules! test_atomic_float_pub {
($float_type:ident) => {
Expand Down

0 comments on commit d587a5f

Please sign in to comment.