-
Notifications
You must be signed in to change notification settings - Fork 2
/
crc32c_test.cc
36 lines (31 loc) · 906 Bytes
/
crc32c_test.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
#include <string.h>
#include <iostream>
#include <random>
#include "crc32c.h"
extern "C" {
uint32_t crc32c_hw(const char *, size_t);
uint32_t crc32c_sw(const char *, size_t);
}
const int MINSIZE = 1;
const int MAXSIZE = 1048576;
int main(int argc, char **argv) {
std::knuth_b rndeng((std::random_device()()));
std::uniform_int_distribution<int> size_dist(MINSIZE, MAXSIZE);
std::uniform_int_distribution<int> d_dist(0, 255);
std::string buf;
for (int i = 0; i < 100; i++) {
size_t len = size_dist(rndeng);
buf.resize(len);
for (size_t j = 0; j < len; j++) {
buf[j] = d_dist(rndeng);
}
uint32_t crc_hw = crc32c_hw(buf.data(), len);
uint32_t crc_sw = crc32c_sw(buf.data(), len);
if (crc_hw != crc_sw) {
fprintf(stderr, "crc mismatch: hw 0x%08x vs sw 0x%08x buffer len %ld\n",
crc_hw, crc_sw, len);
}
buf.clear();
}
return 0;
}