forked from felixguendling/cista
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash_map_verification.cc
executable file
·56 lines (47 loc) · 1.2 KB
/
hash_map_verification.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
#include <cinttypes>
#include <cstring>
#include <unordered_map>
#include "cista/containers/hash_map.h"
#if defined(GENERATE_SEED)
int main() {}
#else
/**
* Check hash_map<int, int>
*
* Input bytes:
* 0-3: key
* 4-7: value
* 9: operation => less or equal 128 insert,
* => greater 128 delete
*/
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) {
std::unordered_map<int, int> ref;
cista::raw::hash_map<int, int> uut;
for (auto bytes_to_process = size; bytes_to_process > 8;
bytes_to_process -= 9, data += 9) {
auto key = 0;
auto value = 0;
auto const insert = data[8] <= 128 ? true : false;
std::memcpy(&key, data, sizeof(key));
std::memcpy(&value, data + sizeof(key), sizeof(value));
if (insert) {
ref.emplace(key, value);
uut.emplace(key, value);
} else {
ref.erase(key);
uut.erase(key);
}
}
for (auto const& [key, value] : ref) {
if (uut.find(key) == end(uut)) {
abort();
}
}
for (auto const& [key, value] : uut) {
if (ref.find(key) == end(ref)) {
abort();
}
}
return 0;
}
#endif