proptest/arbitrary/_alloc/
sync.rs1use crate::std_facade::Arc;
13use core::sync::atomic::*;
14
15use crate::arbitrary::*;
16use crate::strategy::statics::static_map;
17use crate::strategy::*;
18
19wrap_from!(Arc);
20
21macro_rules! atomic {
22 ($($type: ident, $base: ty);+) => {
23 $(arbitrary!($type, SMapped<$base, Self>;
24 static_map(any::<$base>(), $type::new)
25 );)+
26 };
27}
28
29atomic!(AtomicBool, bool; AtomicIsize, isize; AtomicUsize, usize);
31
32#[cfg(feature = "unstable")]
33atomic!(AtomicI8, i8; AtomicI16, i16; AtomicI32, i32;
34 AtomicU8, u8; AtomicU16, u16; AtomicU32, u32);
35
36#[cfg(all(feature = "unstable", feature = "atomic64bit"))]
37atomic!(AtomicI64, i64; AtomicU64, u64);
38
39arbitrary!(Ordering,
40 TupleUnion<(WA<Just<Self>>, WA<Just<Self>>, WA<Just<Self>>,
41 WA<Just<Self>>, WA<Just<Self>>)>;
42 prop_oneof![
43 Just(Ordering::Relaxed),
44 Just(Ordering::Release),
45 Just(Ordering::Acquire),
46 Just(Ordering::AcqRel),
47 Just(Ordering::SeqCst)
48 ]
49);
50
51#[cfg(test)]
52mod test {
53 no_panic_test!(
54 arc => Arc<u8>,
55 atomic_bool => AtomicBool,
56 atomic_isize => AtomicIsize,
57 atomic_usize => AtomicUsize,
58 ordering => Ordering
59 );
60
61 #[cfg(feature = "unstable")]
62 no_panic_test!(
63 atomic_i8 => AtomicI8,
64 atomic_i16 => AtomicI16,
65 atomic_i32 => AtomicI32,
66 atomic_u8 => AtomicU8,
67 atomic_u16 => AtomicU16,
68 atomic_u32 => AtomicU32
69 );
70
71 #[cfg(all(feature = "unstable", feature = "atomic64bit"))]
72 no_panic_test!(
73 atomic_i64 => AtomicI64,
74 atomic_u64 => AtomicU64
75 );
76}