proxygen
ChecksumTest.cpp File Reference
#include <folly/hash/Checksum.h>
#include <boost/crc.hpp>
#include <folly/Benchmark.h>
#include <folly/Random.h>
#include <folly/hash/Hash.h>
#include <folly/hash/detail/ChecksumDetail.h>
#include <folly/portability/GFlags.h>
#include <folly/portability/GTest.h>

Go to the source code of this file.

Functions

 TEST (Checksum, crc32c_software)
 
 TEST (Checksum, crc32c_continuation_software)
 
 TEST (Checksum, crc32c_hardware)
 
 TEST (Checksum, crc32c_hardware_eq)
 
 TEST (Checksum, crc32c_continuation_hardware)
 
 TEST (Checksum, crc32c_autodetect)
 
 TEST (Checksum, crc32c_continuation_autodetect)
 
 TEST (Checksum, crc32)
 
 TEST (Checksum, crc32_continuation)
 
 TEST (Checksum, crc32_type)
 
 TEST (Checksum, crc32_combine)
 
 TEST (Checksum, crc32c_combine)
 
void benchmarkHardwareCRC32C (unsigned long iters, size_t blockSize)
 
void benchmarkSoftwareCRC32C (unsigned long iters, size_t blockSize)
 
void benchmarkHardwareCRC32 (unsigned long iters, size_t blockSize)
 
void benchmarkSoftwareCRC32 (unsigned long iters, size_t blockSize)
 
void benchmarkCombineHardwareCrc32 (unsigned long iters, size_t blockSize)
 
void benchmarkCombineSoftwareLinear (unsigned long iters, size_t blockSize)
 
void benchmarkCombineHardwareCrc32c (unsigned long iters, size_t blockSize)
 
 BENCHMARK (crc32c_hardware_1KB_block, iters)
 
 BENCHMARK (crc32c_software_1KB_block, iters)
 
 BENCHMARK (crc32_hardware_1KB_block, iters)
 
 BENCHMARK (crc32_software_1KB_block, iters)
 
 BENCHMARK_DRAW_LINE ()
 
 BENCHMARK (crc32c_hardware_64KB_block, iters)
 
 BENCHMARK (crc32c_software_64KB_block, iters)
 
 BENCHMARK (crc32_hardware_64KB_block, iters)
 
 BENCHMARK (crc32_software_64KB_block, iters)
 
 BENCHMARK (crc32c_hardware_512KB_block, iters)
 
 BENCHMARK (crc32c_software_512KB_block, iters)
 
 BENCHMARK (crc32_hardware_512KB_block, iters)
 
 BENCHMARK (crc32_software_512KB_block, iters)
 
 BENCHMARK (crc32_combine_linear_512KB_block, iters)
 
 BENCHMARK (crc32_combine_512KB_block, iters)
 
 BENCHMARK (crc32c_combine_512KB_block, iters)
 
int main (int argc, char **argv)
 

Function Documentation

BENCHMARK ( crc32c_hardware_1KB_block  ,
iters   
)

Definition at line 306 of file ChecksumTest.cpp.

References benchmarkHardwareCRC32C().

306  {
307  benchmarkHardwareCRC32C(iters, 1024);
308 }
void benchmarkHardwareCRC32C(unsigned long iters, size_t blockSize)
BENCHMARK ( crc32c_software_1KB_block  ,
iters   
)

Definition at line 310 of file ChecksumTest.cpp.

References benchmarkSoftwareCRC32C().

310  {
311  benchmarkSoftwareCRC32C(iters, 1024);
312 }
void benchmarkSoftwareCRC32C(unsigned long iters, size_t blockSize)
BENCHMARK ( crc32_hardware_1KB_block  ,
iters   
)

Definition at line 314 of file ChecksumTest.cpp.

References benchmarkHardwareCRC32().

314  {
315  benchmarkHardwareCRC32(iters, 1024);
316 }
void benchmarkHardwareCRC32(unsigned long iters, size_t blockSize)
BENCHMARK ( crc32_software_1KB_block  ,
iters   
)

Definition at line 318 of file ChecksumTest.cpp.

References BENCHMARK_DRAW_LINE(), and benchmarkSoftwareCRC32().

318  {
319  benchmarkSoftwareCRC32(iters, 1024);
320 }
void benchmarkSoftwareCRC32(unsigned long iters, size_t blockSize)
BENCHMARK ( crc32c_hardware_64KB_block  ,
iters   
)

Definition at line 325 of file ChecksumTest.cpp.

References benchmarkHardwareCRC32C().

325  {
326  benchmarkHardwareCRC32C(iters, 64 * 1024);
327 }
void benchmarkHardwareCRC32C(unsigned long iters, size_t blockSize)
BENCHMARK ( crc32c_software_64KB_block  ,
iters   
)

Definition at line 329 of file ChecksumTest.cpp.

References benchmarkSoftwareCRC32C().

329  {
330  benchmarkSoftwareCRC32C(iters, 64 * 1024);
331 }
void benchmarkSoftwareCRC32C(unsigned long iters, size_t blockSize)
BENCHMARK ( crc32_hardware_64KB_block  ,
iters   
)

Definition at line 333 of file ChecksumTest.cpp.

References benchmarkHardwareCRC32().

333  {
334  benchmarkHardwareCRC32(iters, 64 * 1024);
335 }
void benchmarkHardwareCRC32(unsigned long iters, size_t blockSize)
BENCHMARK ( crc32_software_64KB_block  ,
iters   
)

Definition at line 337 of file ChecksumTest.cpp.

References BENCHMARK_DRAW_LINE(), and benchmarkSoftwareCRC32().

337  {
338  benchmarkSoftwareCRC32(iters, 64 * 1024);
339 }
void benchmarkSoftwareCRC32(unsigned long iters, size_t blockSize)
BENCHMARK ( crc32c_hardware_512KB_block  ,
iters   
)

Definition at line 344 of file ChecksumTest.cpp.

References benchmarkHardwareCRC32C().

344  {
345  benchmarkHardwareCRC32C(iters, 512 * 1024);
346 }
void benchmarkHardwareCRC32C(unsigned long iters, size_t blockSize)
BENCHMARK ( crc32c_software_512KB_block  ,
iters   
)

Definition at line 348 of file ChecksumTest.cpp.

References benchmarkSoftwareCRC32C().

348  {
349  benchmarkSoftwareCRC32C(iters, 512 * 1024);
350 }
void benchmarkSoftwareCRC32C(unsigned long iters, size_t blockSize)
BENCHMARK ( crc32_hardware_512KB_block  ,
iters   
)

Definition at line 352 of file ChecksumTest.cpp.

References benchmarkHardwareCRC32().

352  {
353  benchmarkHardwareCRC32(iters, 512 * 1024);
354 }
void benchmarkHardwareCRC32(unsigned long iters, size_t blockSize)
BENCHMARK ( crc32_software_512KB_block  ,
iters   
)

Definition at line 356 of file ChecksumTest.cpp.

References BENCHMARK_DRAW_LINE(), and benchmarkSoftwareCRC32().

356  {
357  benchmarkSoftwareCRC32(iters, 512 * 1024);
358 }
void benchmarkSoftwareCRC32(unsigned long iters, size_t blockSize)
BENCHMARK ( crc32_combine_linear_512KB_block  ,
iters   
)

Definition at line 362 of file ChecksumTest.cpp.

References benchmarkCombineSoftwareLinear().

362  {
363  benchmarkCombineSoftwareLinear(iters, 512 * 1024);
364 }
void benchmarkCombineSoftwareLinear(unsigned long iters, size_t blockSize)
BENCHMARK ( crc32_combine_512KB_block  ,
iters   
)

Definition at line 366 of file ChecksumTest.cpp.

References benchmarkCombineHardwareCrc32().

366  {
367  benchmarkCombineHardwareCrc32(iters, 512 * 1024);
368 }
void benchmarkCombineHardwareCrc32(unsigned long iters, size_t blockSize)
BENCHMARK ( crc32c_combine_512KB_block  ,
iters   
)

Definition at line 370 of file ChecksumTest.cpp.

References benchmarkCombineHardwareCrc32c().

370  {
371  benchmarkCombineHardwareCrc32c(iters, 512 * 1024);
372 }
void benchmarkCombineHardwareCrc32c(unsigned long iters, size_t blockSize)
BENCHMARK_DRAW_LINE ( )

Referenced by BENCHMARK().

void benchmarkCombineHardwareCrc32 ( unsigned long  iters,
size_t  blockSize 
)

Definition at line 267 of file ChecksumTest.cpp.

References folly::crc32_combine(), folly::doNotOptimizeAway(), i, and uint32_t.

Referenced by BENCHMARK().

267  {
268  // Arbitrarily chosen checksums
269  uint32_t checksum1 = 0xEDB88320;
270  uint32_t checksum2 = 0x82F63B78;
271  uint32_t result;
272  for (unsigned long i = 0; i < iters; i++) {
273  result = folly::crc32_combine(checksum1, checksum2, blockSize);
274  folly::doNotOptimizeAway(result);
275  }
276 }
uint32_t crc32_combine(uint32_t crc1, uint32_t crc2, size_t crc2len)
Definition: Checksum.cpp:149
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void benchmarkCombineHardwareCrc32c ( unsigned long  iters,
size_t  blockSize 
)

Definition at line 293 of file ChecksumTest.cpp.

References folly::crc32c_combine(), folly::doNotOptimizeAway(), i, and uint32_t.

Referenced by BENCHMARK().

293  {
294  // Arbitrarily chosen checksums
295  uint32_t checksum1 = 0xEDB88320;
296  uint32_t checksum2 = 0x82F63B78;
297  uint32_t result;
298  for (unsigned long i = 0; i < iters; i++) {
299  result = folly::crc32c_combine(checksum1, checksum2, blockSize);
300  folly::doNotOptimizeAway(result);
301  }
302 }
uint32_t crc32c_combine(uint32_t crc1, uint32_t crc2, size_t crc2len)
Definition: Checksum.cpp:164
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void benchmarkCombineSoftwareLinear ( unsigned long  iters,
size_t  blockSize 
)

Definition at line 278 of file ChecksumTest.cpp.

References folly::crc32c(), folly::doNotOptimizeAway(), i, and uint32_t.

Referenced by BENCHMARK().

278  {
279  // Arbitrarily chosen checksums
280  std::vector<uint8_t> zbuffer;
281  zbuffer.reserve(blockSize);
282  memset(zbuffer.data(), 0, blockSize);
283  uint32_t checksum1 = 0xEDB88320;
284  uint32_t checksum2 = 0x82F63B78;
285  uint32_t result;
286  for (unsigned long i = 0; i < iters; i++) {
287  result = folly::crc32c(zbuffer.data(), blockSize, checksum1);
288  result ^= checksum2;
289  folly::doNotOptimizeAway(result);
290  }
291 }
uint32_t crc32c(const uint8_t *data, size_t nbytes, uint32_t startingChecksum)
Definition: Checksum.cpp:128
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void benchmarkHardwareCRC32 ( unsigned long  iters,
size_t  blockSize 
)

Definition at line 246 of file ChecksumTest.cpp.

References folly::detail::crc32_hw(), folly::detail::crc32_hw_supported(), folly::doNotOptimizeAway(), i, and uint32_t.

Referenced by BENCHMARK().

246  {
248  uint32_t checksum;
249  for (unsigned long i = 0; i < iters; i++) {
250  checksum = folly::detail::crc32_hw(buffer, blockSize);
251  folly::doNotOptimizeAway(checksum);
252  }
253  } else {
254  LOG(WARNING) << "skipping hardware-accelerated CRC-32 benchmarks"
255  << " (not supported on this CPU)";
256  }
257 }
std::vector< uint8_t > buffer(kBufferSize+16)
bool crc32_hw_supported()
Definition: Checksum.cpp:87
uint32_t crc32_hw(const uint8_t *, size_t, uint32_t)
Definition: Checksum.cpp:76
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void benchmarkHardwareCRC32C ( unsigned long  iters,
size_t  blockSize 
)

Definition at line 225 of file ChecksumTest.cpp.

References folly::detail::crc32c_hw(), folly::detail::crc32c_hw_supported(), folly::doNotOptimizeAway(), i, and uint32_t.

Referenced by BENCHMARK().

225  {
227  uint32_t checksum;
228  for (unsigned long i = 0; i < iters; i++) {
229  checksum = folly::detail::crc32c_hw(buffer, blockSize);
230  folly::doNotOptimizeAway(checksum);
231  }
232  } else {
233  LOG(WARNING) << "skipping hardware-accelerated CRC-32C benchmarks"
234  << " (not supported on this CPU)";
235  }
236 }
std::vector< uint8_t > buffer(kBufferSize+16)
uint32_t crc32c_hw(const uint8_t *data, size_t nbytes, uint32_t startingChecksum=~0U)
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
bool crc32c_hw_supported()
Definition: Checksum.cpp:83
void benchmarkSoftwareCRC32 ( unsigned long  iters,
size_t  blockSize 
)

Definition at line 259 of file ChecksumTest.cpp.

References folly::detail::crc32_sw(), folly::doNotOptimizeAway(), i, and uint32_t.

Referenced by BENCHMARK().

259  {
260  uint32_t checksum;
261  for (unsigned long i = 0; i < iters; i++) {
262  checksum = folly::detail::crc32_sw(buffer, blockSize);
263  folly::doNotOptimizeAway(checksum);
264  }
265 }
std::vector< uint8_t > buffer(kBufferSize+16)
uint32_t crc32_sw(const uint8_t *data, size_t nbytes, uint32_t startingChecksum)
Definition: Checksum.cpp:121
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
void benchmarkSoftwareCRC32C ( unsigned long  iters,
size_t  blockSize 
)

Definition at line 238 of file ChecksumTest.cpp.

References folly::detail::crc32c_sw(), folly::doNotOptimizeAway(), i, and uint32_t.

Referenced by BENCHMARK().

238  {
239  uint32_t checksum;
240  for (unsigned long i = 0; i < iters; i++) {
241  checksum = folly::detail::crc32c_sw(buffer, blockSize);
242  folly::doNotOptimizeAway(checksum);
243  }
244 }
std::vector< uint8_t > buffer(kBufferSize+16)
uint32_t crc32c_sw(const uint8_t *data, size_t nbytes, uint32_t startingChecksum)
Definition: Checksum.cpp:115
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
int main ( int  argc,
char **  argv 
)

Definition at line 374 of file ChecksumTest.cpp.

References buffer(), folly::test::end(), folly::hash::fnv64_buf(), testing::InitGoogleTest(), RUN_ALL_TESTS(), folly::runBenchmarks(), uint64_t, and uint8_t.

374  {
376  gflags::ParseCommandLineFlags(&argc, &argv, true);
377 
378  // Populate a buffer with a deterministic pattern
379  // on which to compute checksums
380  const uint8_t* src = buffer;
381  uint64_t* dst = (uint64_t*)buffer;
382  const uint64_t* end = (const uint64_t*)(buffer + BUFFER_SIZE);
383  *dst++ = 0;
384  while (dst < end) {
385  *dst++ = folly::hash::fnv64_buf((const char*)src, sizeof(uint64_t));
386  src += sizeof(uint64_t);
387  }
388 
389  auto ret = RUN_ALL_TESTS();
390  if (!ret && FLAGS_benchmark) {
392  }
393  return ret;
394 }
std::vector< uint8_t > buffer(kBufferSize+16)
uint64_t fnv64_buf(const void *buf, size_t n, uint64_t hash=FNV_64_HASH_START) noexcept
Definition: Hash.h:199
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: gtest.h:2232
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: gtest.cc:5370
TEST ( Checksum  ,
crc32c_software   
)

Definition at line 108 of file ChecksumTest.cpp.

References folly::detail::crc32c_sw().

108  {
109  testCRC32C(folly::detail::crc32c_sw);
110 }
uint32_t crc32c_sw(const uint8_t *data, size_t nbytes, uint32_t startingChecksum)
Definition: Checksum.cpp:115
TEST ( Checksum  ,
crc32c_continuation_software   
)

Definition at line 112 of file ChecksumTest.cpp.

References folly::detail::crc32c_sw().

112  {
113  testCRC32CContinuation(folly::detail::crc32c_sw);
114 }
uint32_t crc32c_sw(const uint8_t *data, size_t nbytes, uint32_t startingChecksum)
Definition: Checksum.cpp:115
TEST ( Checksum  ,
crc32c_hardware   
)

Definition at line 116 of file ChecksumTest.cpp.

References folly::detail::crc32c_hw(), and folly::detail::crc32c_hw_supported().

116  {
118  testCRC32C(folly::detail::crc32c_hw);
119  } else {
120  LOG(WARNING) << "skipping hardware-accelerated CRC-32C tests"
121  << " (not supported on this CPU)";
122  }
123 }
uint32_t crc32c_hw(const uint8_t *data, size_t nbytes, uint32_t startingChecksum=~0U)
bool crc32c_hw_supported()
Definition: Checksum.cpp:83
TEST ( Checksum  ,
crc32c_hardware_eq   
)

Definition at line 125 of file ChecksumTest.cpp.

References folly::detail::crc32c_hw(), folly::detail::crc32c_hw_supported(), folly::detail::crc32c_sw(), EXPECT_EQ, and i.

125  {
127  for (int i = 0; i < 1000; i++) {
128  auto sw = folly::detail::crc32c_sw(buffer, i, 0);
129  auto hw = folly::detail::crc32c_hw(buffer, i, 0);
130  EXPECT_EQ(sw, hw);
131  }
132  } else {
133  LOG(WARNING) << "skipping hardware-accelerated CRC-32C tests"
134  << " (not supported on this CPU)";
135  }
136 }
std::vector< uint8_t > buffer(kBufferSize+16)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
uint32_t crc32c_hw(const uint8_t *data, size_t nbytes, uint32_t startingChecksum=~0U)
uint32_t crc32c_sw(const uint8_t *data, size_t nbytes, uint32_t startingChecksum)
Definition: Checksum.cpp:115
bool crc32c_hw_supported()
Definition: Checksum.cpp:83
TEST ( Checksum  ,
crc32c_continuation_hardware   
)

Definition at line 138 of file ChecksumTest.cpp.

References folly::detail::crc32c_hw(), and folly::detail::crc32c_hw_supported().

138  {
140  testCRC32CContinuation(folly::detail::crc32c_hw);
141  } else {
142  LOG(WARNING) << "skipping hardware-accelerated CRC-32C tests"
143  << " (not supported on this CPU)";
144  }
145 }
uint32_t crc32c_hw(const uint8_t *data, size_t nbytes, uint32_t startingChecksum=~0U)
bool crc32c_hw_supported()
Definition: Checksum.cpp:83
TEST ( Checksum  ,
crc32c_autodetect   
)

Definition at line 147 of file ChecksumTest.cpp.

References folly::crc32c().

147  {
148  testCRC32C(folly::crc32c);
149 }
uint32_t crc32c(const uint8_t *data, size_t nbytes, uint32_t startingChecksum)
Definition: Checksum.cpp:128
TEST ( Checksum  ,
crc32c_continuation_autodetect   
)

Definition at line 151 of file ChecksumTest.cpp.

References folly::crc32c().

151  {
152  testCRC32CContinuation(folly::crc32c);
153 }
uint32_t crc32c(const uint8_t *data, size_t nbytes, uint32_t startingChecksum)
Definition: Checksum.cpp:128
TEST ( Checksum  ,
crc32   
)

Definition at line 155 of file ChecksumTest.cpp.

References folly::detail::crc32_hw(), folly::detail::crc32_sw(), folly::detail::crc32c_hw_supported(), EXPECT_EQ, and uint32_t.

155  {
157  // Just check that sw and hw match
158  for (auto expected : expectedResults) {
159  uint32_t sw_res =
160  folly::detail::crc32_sw(buffer + expected.offset, expected.length, 0);
161  uint32_t hw_res =
162  folly::detail::crc32_hw(buffer + expected.offset, expected.length, 0);
163  EXPECT_EQ(sw_res, hw_res);
164  }
165  } else {
166  LOG(WARNING) << "skipping hardware-accelerated CRC-32 tests"
167  << " (not supported on this CPU)";
168  }
169 }
std::vector< uint8_t > buffer(kBufferSize+16)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
uint32_t crc32_sw(const uint8_t *data, size_t nbytes, uint32_t startingChecksum)
Definition: Checksum.cpp:121
uint32_t crc32_hw(const uint8_t *, size_t, uint32_t)
Definition: Checksum.cpp:76
bool crc32c_hw_supported()
Definition: Checksum.cpp:83
TEST ( Checksum  ,
crc32_continuation   
)

Definition at line 171 of file ChecksumTest.cpp.

References folly::detail::crc32_hw(), folly::detail::crc32_sw(), folly::detail::crc32c_hw_supported(), EXPECT_EQ, and uint32_t.

171  {
173  // Just check that sw and hw match
174  for (auto expected : expectedResults) {
175  auto halflen = expected.length / 2;
176  uint32_t sw_res =
177  folly::detail::crc32_sw(buffer + expected.offset, halflen, 0);
178  sw_res = folly::detail::crc32_sw(
179  buffer + expected.offset + halflen, halflen, sw_res);
180  uint32_t hw_res =
181  folly::detail::crc32_hw(buffer + expected.offset, halflen, 0);
182  hw_res = folly::detail::crc32_hw(
183  buffer + expected.offset + halflen, halflen, hw_res);
184  EXPECT_EQ(sw_res, hw_res);
185  uint32_t sw_res2 =
186  folly::detail::crc32_sw(buffer + expected.offset, halflen * 2, 0);
187  EXPECT_EQ(sw_res, sw_res2);
188  uint32_t hw_res2 =
189  folly::detail::crc32_hw(buffer + expected.offset, halflen * 2, 0);
190  EXPECT_EQ(hw_res, hw_res2);
191  }
192  } else {
193  LOG(WARNING) << "skipping hardware-accelerated CRC-32 tests"
194  << " (not supported on this CPU)";
195  }
196 }
std::vector< uint8_t > buffer(kBufferSize+16)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
uint32_t crc32_sw(const uint8_t *data, size_t nbytes, uint32_t startingChecksum)
Definition: Checksum.cpp:121
uint32_t crc32_hw(const uint8_t *, size_t, uint32_t)
Definition: Checksum.cpp:76
bool crc32c_hw_supported()
Definition: Checksum.cpp:83
TEST ( Checksum  ,
crc32_type   
)

Definition at line 198 of file ChecksumTest.cpp.

198  {
199  // Test that crc32_type matches boost::crc_32_type
200  testMatchesBoost32Type();
201 }
TEST ( Checksum  ,
crc32_combine   
)

Definition at line 203 of file ChecksumTest.cpp.

References folly::crc32(), folly::crc32_combine(), EXPECT_EQ, and folly::Random::rand64().

203  {
204  for (size_t totlen = 1024; totlen < BUFFER_SIZE; totlen += BUFFER_SIZE / 8) {
205  auto mid = folly::Random::rand64(0, totlen);
206  auto crc1 = folly::crc32(&buffer[0], mid, 0);
207  auto crc2 = folly::crc32(&buffer[mid], totlen - mid, 0);
208  auto crcfull = folly::crc32(&buffer[0], totlen, 0);
209  auto combined = folly::crc32_combine(crc1, crc2, totlen - mid);
210  EXPECT_EQ(combined, crcfull);
211  }
212 }
std::vector< uint8_t > buffer(kBufferSize+16)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
uint32_t crc32(const uint8_t *data, size_t nbytes, uint32_t startingChecksum)
Definition: Checksum.cpp:136
uint32_t crc32_combine(uint32_t crc1, uint32_t crc2, size_t crc2len)
Definition: Checksum.cpp:149
static uint64_t rand64()
Definition: Random.h:263
TEST ( Checksum  ,
crc32c_combine   
)

Definition at line 214 of file ChecksumTest.cpp.

References folly::crc32c(), folly::crc32c_combine(), EXPECT_EQ, and folly::Random::rand64().

214  {
215  for (size_t totlen = 1024; totlen < BUFFER_SIZE; totlen += BUFFER_SIZE / 8) {
216  auto mid = folly::Random::rand64(0, totlen);
217  auto crc1 = folly::crc32c(&buffer[0], mid, 0);
218  auto crc2 = folly::crc32c(&buffer[mid], totlen - mid, 0);
219  auto crcfull = folly::crc32c(&buffer[0], totlen, 0);
220  auto combined = folly::crc32c_combine(crc1, crc2, totlen - mid);
221  EXPECT_EQ(combined, crcfull);
222  }
223 }
std::vector< uint8_t > buffer(kBufferSize+16)
uint32_t crc32c(const uint8_t *data, size_t nbytes, uint32_t startingChecksum)
Definition: Checksum.cpp:128
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
uint32_t crc32c_combine(uint32_t crc1, uint32_t crc2, size_t crc2len)
Definition: Checksum.cpp:164
static uint64_t rand64()
Definition: Random.h:263