Skip to content

Commit

Permalink
psan: Conditional compile
Browse files Browse the repository at this point in the history
  • Loading branch information
zzz845zz committed Mar 8, 2023
1 parent 058c500 commit ae6aec2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 63 deletions.
2 changes: 0 additions & 2 deletions src/ds/queue_general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ pub(crate) mod test {

impl RootObj<EnqDeq> for TestRootObj<QueueGeneral<TestValue>> {
fn run(&self, enq_deq: &mut EnqDeq, handle: &Handle) {
#[cfg(not(feature = "pmcheck"))] // TODO: Remove
let testee = unsafe { TESTER.as_ref().unwrap().testee(true, handle) };

for seq in 0..NR_COUNT {
Expand All @@ -325,7 +324,6 @@ pub(crate) mod test {

assert!(res.is_some(), "tid:{}, seq:{seq}", handle.tid);

#[cfg(not(feature = "pmcheck"))] // TODO: Remove
testee.report(seq, res.unwrap());
}
}
Expand Down
38 changes: 0 additions & 38 deletions src/pepoch/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,45 +280,7 @@ impl<T> Pointable for T {
type Init = T;

unsafe fn init(init: Self::Init, pool: &PoolHandle) -> usize {
#[cfg(not(feature = "pmcheck"))]
let ptr = pool.alloc::<T>();
#[cfg(feature = "pmcheck")]
let ptr = {
let mut cnt = 0;
loop {
cnt += 1;

let ptr = pool.alloc::<T>();
let ptr_offset = ptr.into_offset();
let pshared = PShared::<T>::from_usize(ptr_offset);
let (_, _, _, _, pshared_offset, _) = decompose_tag::<T>(pshared.data);
if ptr_offset == pshared_offset {
break ptr;
}
pool.free(ptr);

if cnt > 1000 {
panic!(
"[PAtomic::init] Allocation align err!
\n\tType name: {:?}
\n\tType size: {:?}
\n\tInterpret as ptr offset: {:?}
\n\tInterpret as pshared offset: {:?}
\n\tInterpret as pshared: {:?}
\n\tPool start: {}
\n\t(Pool Start + offset) % 64: {}
",
core::any::type_name::<T>(),
mem::size_of::<T>(),
ptr_offset,
pshared_offset,
pshared,
pool.start(),
(pool.start() + ptr_offset) % 64,
)
}
}
};

let t = ptr.deref_mut(pool);
std::ptr::write(t as *mut T, init);
Expand Down
54 changes: 31 additions & 23 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ pub mod tests {
impl Testee<'_> {
#[inline]
pub fn report(&self, seq: usize, val: TestValue) {
#[cfg(not(feature = "pmcheck"))]
self.info.report(seq, val)
}
}
Expand Down Expand Up @@ -465,20 +466,23 @@ pub mod tests {
let tid = handle.tid;
let inner_tid = tid - 1;
let info = &self.infos[inner_tid];

#[cfg(not(feature = "pmcheck"))]
{
info.checked.store(Some(checked), Ordering::SeqCst);
if checked {
info.state.store(TestInfo::STATE_INIT, Ordering::SeqCst);
} else {
info.enable_killed();
}

info.checked.store(Some(checked), Ordering::SeqCst);
if checked {
info.state.store(TestInfo::STATE_INIT, Ordering::SeqCst);
} else {
info.enable_killed();
}

#[cfg(feature = "tcrash")]
if checked {
println!(
"[Testee {tid}] Crash may occur after seq {}.",
info.crash_seq
);
#[cfg(feature = "tcrash")]
if checked {
println!(
"[Testee {tid}] Crash may occur after seq {}.",
info.crash_seq
);
}
}

Testee { info }
Expand Down Expand Up @@ -564,16 +568,20 @@ pub mod tests {
.map(|i| results[i].load(Ordering::SeqCst))
.enumerate()
{
// `to_tid` must have returned value at `to_seq`
assert_ne!(result, TestInfo::RESULT_INIT, "tid:{to_tid}, seq:{to_seq}");

// `from_tid`'s `from_seq` must be issued exactly once
let (from_tid, from_seq) = TestValue::decompose(TestValue { data: result });
assert!(
!checked_map[from_tid][from_seq],
"From: (tid:{from_tid}, seq:{from_seq} / To: (tid:{to_tid}, seq:{to_seq}",
);
checked_map[from_tid][from_seq] = true;
#[cfg(not(feature = "pmcheck"))]
{
// `to_tid` must have returned value at `to_seq`
assert_ne!(result, TestInfo::RESULT_INIT, "tid:{to_tid}, seq:{to_seq}");

// `from_tid`'s `from_seq` must be issued exactly once
let (from_tid, from_seq) = TestValue::decompose(TestValue { data: result });
assert!(
!checked_map[from_tid][from_seq],
"From: (tid:{from_tid}, seq:{from_seq} / To: (tid:{to_tid}, seq:{to_seq}",
);

checked_map[from_tid][from_seq] = true;
}
}
}

Expand Down

0 comments on commit ae6aec2

Please sign in to comment.