-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorrectness.cc
More file actions
133 lines (102 loc) · 3.38 KB
/
correctness.cc
File metadata and controls
133 lines (102 loc) · 3.38 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <iostream>
#include <cstdint>
#include <string>
#include "test.h"
class CorrectnessTest : public Test {
private:
const uint64_t SIMPLE_TEST_MAX = 512;
const uint64_t LARGE_TEST_MAX = 1024 * 64;
void regular_test(uint64_t max)
{
uint64_t i;
// Test a single key
EXPECT(not_found, store.get(1));
store.put(1, "SE");
EXPECT("SE", store.get(1));
EXPECT(true, store.del(1));
EXPECT(not_found, store.get(1));
EXPECT(false, store.del(1));
phase();
// Test multiple key-value pairs
for (i = 0; i < max; ++i) {
store.put(i, std::string(i+1, 's'));
EXPECT(std::string(i+1, 's'), store.get(i));
}
phase();
// Test after all insertions
for (i = 0; i < max; ++i)
EXPECT(std::string(i+1, 's'), store.get(i));
phase();
if(max > 600){
int a = 0;
}
// Test scan
std::list<std::pair<uint64_t, std::string> > list_ans;
std::list<std::pair<uint64_t, std::string> > list_stu;
for (i = 0; i < max / 2; ++i) {
list_ans.emplace_back(std::make_pair(i, std::string(i+1, 's')));
}
store.scan(0, max / 2 - 1, list_stu);
EXPECT(list_ans.size(), list_stu.size());
auto ap = list_ans.begin();
auto sp = list_stu.begin();
int counter = 0;
while(ap != list_ans.end()) {
if (sp == list_stu.end()) {
EXPECT((*ap).first, -1);
EXPECT((*ap).second, not_found);
ap++;
}
else {
counter++;
EXPECT((*ap).first, (*sp).first);
EXPECT((*ap).second, (*sp).second);
// if((*ap).second != (*sp).second){
// std::cout << "num: " << counter << std::endl;
// std::cout << "key" << (*ap).first << std::endl;
// std::cout << (*ap).second.length() << std::endl;
// std::cout << (*sp).second.length() << std::endl;
// }
ap++;
sp++;
}
}
phase();
// Test deletions
for (i = 0; i < max; i+=2)
EXPECT(true, store.del(i));
for (i = 0; i < max; ++i)
EXPECT((i & 1) ? std::string(i+1, 's') : not_found,
store.get(i));
for (i = 1; i < max; ++i)
EXPECT(i & 1, store.del(i));
phase();
report();
}
public:
CorrectnessTest(const std::string &dir, bool v=true) : Test(dir, v)
{
}
void start_test(void *args = NULL) override
{
std::cout << "KVStore Correctness Test" << std::endl;
store.reset();
std::cout << "[Simple Test]" << std::endl;
regular_test(SIMPLE_TEST_MAX);
store.reset();
std::cout << "[Large Test]" << std::endl;
regular_test(LARGE_TEST_MAX);
}
};
int main(int argc, char *argv[])
{
bool verbose = (argc == 2 && std::string(argv[1]) == "-v");
std::cout << "Usage: " << argv[0] << " [-v]" << std::endl;
std::cout << " -v: print extra info for failed tests [currently ";
std::cout << (verbose ? "ON" : "OFF")<< "]" << std::endl;
std::cout << std::endl;
std::cout.flush();
CorrectnessTest test("./data", verbose);
test.start_test();
return 0;
}