1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use std::sync::atomic::{AtomicUsize, Ordering};
#[macro_export]
macro_rules! _hit {
($ident:ident) => {{
#[cfg(test)]
{
extern "C" {
#[no_mangle]
static $ident: std::sync::atomic::AtomicUsize;
}
unsafe {
$ident.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
}
}
}};
}
pub use _hit as hit;
#[macro_export]
macro_rules! _check {
($ident:ident) => {
#[no_mangle]
static $ident: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
let _checker = $crate::mark::MarkChecker::new(&$ident);
};
}
pub use _check as check;
pub struct MarkChecker {
mark: &'static AtomicUsize,
value_on_entry: usize,
}
impl MarkChecker {
pub fn new(mark: &'static AtomicUsize) -> MarkChecker {
let value_on_entry = mark.load(Ordering::Relaxed);
MarkChecker { mark, value_on_entry }
}
}
impl Drop for MarkChecker {
fn drop(&mut self) {
if std::thread::panicking() {
return;
}
let value_on_exit = self.mark.load(Ordering::Relaxed);
assert!(value_on_exit > self.value_on_entry, "mark was not hit")
}
}