1 | mod idx { |
2 | use crate::{ |
3 | cfg, |
4 | page::{self, slot}, |
5 | Pack, Tid, |
6 | }; |
7 | use proptest::prelude::*; |
8 | |
9 | proptest! { |
10 | #[test] |
11 | #[cfg_attr (loom, ignore)] |
12 | fn tid_roundtrips(tid in 0usize..Tid::<cfg::DefaultConfig>::BITS) { |
13 | let tid = Tid::<cfg::DefaultConfig>::from_usize(tid); |
14 | let packed = tid.pack(0); |
15 | assert_eq!(tid, Tid::from_packed(packed)); |
16 | } |
17 | |
18 | #[test] |
19 | #[cfg_attr (loom, ignore)] |
20 | fn idx_roundtrips( |
21 | tid in 0usize..Tid::<cfg::DefaultConfig>::BITS, |
22 | gen in 0usize..slot::Generation::<cfg::DefaultConfig>::BITS, |
23 | addr in 0usize..page::Addr::<cfg::DefaultConfig>::BITS, |
24 | ) { |
25 | let tid = Tid::<cfg::DefaultConfig>::from_usize(tid); |
26 | let gen = slot::Generation::<cfg::DefaultConfig>::from_usize(gen); |
27 | let addr = page::Addr::<cfg::DefaultConfig>::from_usize(addr); |
28 | let packed = tid.pack(gen.pack(addr.pack(0))); |
29 | assert_eq!(addr, page::Addr::from_packed(packed)); |
30 | assert_eq!(gen, slot::Generation::from_packed(packed)); |
31 | assert_eq!(tid, Tid::from_packed(packed)); |
32 | } |
33 | } |
34 | } |
35 | |
36 | pub(crate) mod util { |
37 | #[cfg (loom)] |
38 | use std::sync::atomic::{AtomicUsize, Ordering}; |
39 | pub(crate) struct TinyConfig; |
40 | |
41 | impl crate::Config for TinyConfig { |
42 | const INITIAL_PAGE_SIZE: usize = 4; |
43 | } |
44 | |
45 | #[cfg (loom)] |
46 | pub(crate) fn run_model(name: &'static str, f: impl Fn() + Sync + Send + 'static) { |
47 | run_builder(name, loom::model::Builder::new(), f) |
48 | } |
49 | |
50 | #[cfg (loom)] |
51 | pub(crate) fn run_builder( |
52 | name: &'static str, |
53 | builder: loom::model::Builder, |
54 | f: impl Fn() + Sync + Send + 'static, |
55 | ) { |
56 | let iters = AtomicUsize::new(1); |
57 | builder.check(move || { |
58 | test_println!( |
59 | " \n------------ running test {}; iteration {} ------------ \n" , |
60 | name, |
61 | iters.fetch_add(1, Ordering::SeqCst) |
62 | ); |
63 | f() |
64 | }); |
65 | } |
66 | } |
67 | |
68 | #[cfg (not(loom))] |
69 | mod custom_config; |
70 | #[cfg (loom)] |
71 | mod loom_pool; |
72 | #[cfg (loom)] |
73 | mod loom_slab; |
74 | #[cfg (not(loom))] |
75 | mod properties; |
76 | |