-
Notifications
You must be signed in to change notification settings - Fork 0
/
history_test.cpp
75 lines (61 loc) · 1.62 KB
/
history_test.cpp
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
#include "history.hpp"
struct history_test {
struct element {
intptr_t ver;
intptr_t tid;
intptr_t sum;
element(intptr_t v, intptr_t t) : ver(v), tid(t), sum(v+t) { }
element() = default;
};
bool valid(element e) {
return e.ver + e.tid == e.sum && 0 <= e.tid && e.tid < thread_count;
}
int thread_count;
int history_size;
int reps;
history<element, raw_locked_history> hist;
std::unique_ptr<VAR_T(bool)[]> done;
typedef raw_history::version_t version_t;
history_test(int t, int h, int r) : thread_count(t), hist(h, t), history_size(h), reps(r), done(new VAR_T(bool)[r*h]) { }
void check_single_ver(version_t ver) {
element value;
bool ok = hist.get(ver, &value);
if (ok) {
assert(valid(value));
assert(value.ver == ver);
} else {
version_t current_ver = hist.get_version();
// LOG << "current ver " << current_ver;
assert(current_ver - ver >= history_size);
}
}
void before() {
for(int i=1;i<reps*history_size;i++)
VAR(done[i]) = false;
}
void thread(int thread_idx) {
for(version_t i=hist.get_version()+1; i<reps*history_size; i++) {
element value(i, thread_idx);
bool ok = hist.publish(thread_idx, i, &value);
if (ok) {
assert(!VAR(done[i])); // We need not worry about races on done[i] -- they cause the test to fail.
VAR(done[i]) = true;
}
// LOG << "checking " << i;
check_single_ver(i);
}
}
void after() {
for(int i=1;i<reps*history_size;i++)
assert(VAR(done[i]));
}
};
RELACY_FIXTURE(history_fixture, history_test, 5, 5, 2);
int main()
{
#ifdef RELACY
rl::simulate<history_fixture>();
#else
run_test<history_test>(2, 500, 20000);
#endif
}