#include <folly/Checksum.h>
+#include <boost/crc.hpp>
#include <folly/Benchmark.h>
#include <folly/Hash.h>
}
}
+void testMatchesBoost32Type() {
+ for (auto expected : expectedResults) {
+ boost::crc_32_type result;
+ result.process_bytes(buffer + expected.offset, expected.length);
+ const uint32_t boostResult = result.checksum();
+ const uint32_t follyResult =
+ folly::crc32_type(buffer + expected.offset, expected.length);
+ EXPECT_EQ(follyResult, boostResult);
+ }
+}
+
} // namespace
TEST(Checksum, crc32c_software) {
}
}
+TEST(Checksum, crc32c_hardware_eq) {
+ if (folly::detail::crc32c_hw_supported()) {
+ for (int i = 0; i < 1000; i++) {
+ auto sw = folly::detail::crc32c_sw(buffer, i, 0);
+ auto hw = folly::detail::crc32c_hw(buffer, i, 0);
+ EXPECT_EQ(sw, hw);
+ }
+ } else {
+ LOG(WARNING) << "skipping hardware-accelerated CRC-32C tests"
+ << " (not supported on this CPU)";
+ }
+}
+
TEST(Checksum, crc32c_continuation_hardware) {
if (folly::detail::crc32c_hw_supported()) {
testCRC32CContinuation(folly::detail::crc32c_hw);
}
}
+TEST(Checksum, crc32_type) {
+ // Test that crc32_type matches boost::crc_32_type
+ testMatchesBoost32Type();
+}
+
void benchmarkHardwareCRC32C(unsigned long iters, size_t blockSize) {
if (folly::detail::crc32c_hw_supported()) {
uint32_t checksum;