-
Notifications
You must be signed in to change notification settings - Fork 1
/
correctness.cc
89 lines (72 loc) · 1.89 KB
/
correctness.cc
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
#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;
//const uint64_t LARGE_TEST_MAX =5000;
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();//1
// 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();//2
// Test after all insertions
for (i = 0; i <max; ++i)
{
EXPECT(std::string(i+1, 's'), store.get(i));
}
phase();//3
// Test deletions
for (i = 0; i < max; i+=2)
EXPECT(true, store.del(i));
phase();//4
for (i = 0; i < max; ++i)
EXPECT((i & 1) ? std::string(i+1, 's') : not_found,store.get(i));
phase();//5
for (i = 1; i < max; ++i)
EXPECT(i & 1, store.del(i));
phase();//6
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;
//
std::cout << "[Simple Test]" << std::endl;
regular_test(SIMPLE_TEST_MAX);
//
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");
verbose=0;
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;
}