+TEST(Checksum, crc32) {
+ if (folly::detail::crc32c_hw_supported()) {
+ // Just check that sw and hw match
+ for (auto expected : expectedResults) {
+ uint32_t sw_res =
+ folly::detail::crc32_sw(buffer + expected.offset, expected.length, 0);
+ uint32_t hw_res =
+ folly::detail::crc32_hw(buffer + expected.offset, expected.length, 0);
+ EXPECT_EQ(sw_res, hw_res);
+ }
+ } else {
+ LOG(WARNING) << "skipping hardware-accelerated CRC-32 tests"
+ << " (not supported on this CPU)";
+ }
+}
+
+TEST(Checksum, crc32_continuation) {
+ if (folly::detail::crc32c_hw_supported()) {
+ // Just check that sw and hw match
+ for (auto expected : expectedResults) {
+ auto halflen = expected.length / 2;
+ uint32_t sw_res =
+ folly::detail::crc32_sw(buffer + expected.offset, halflen, 0);
+ sw_res = folly::detail::crc32_sw(
+ buffer + expected.offset + halflen, halflen, sw_res);
+ uint32_t hw_res =
+ folly::detail::crc32_hw(buffer + expected.offset, halflen, 0);
+ hw_res = folly::detail::crc32_hw(
+ buffer + expected.offset + halflen, halflen, hw_res);
+ EXPECT_EQ(sw_res, hw_res);
+ uint32_t sw_res2 =
+ folly::detail::crc32_sw(buffer + expected.offset, halflen * 2, 0);
+ EXPECT_EQ(sw_res, sw_res2);
+ uint32_t hw_res2 =
+ folly::detail::crc32_hw(buffer + expected.offset, halflen * 2, 0);
+ EXPECT_EQ(hw_res, hw_res2);
+ }
+ } else {
+ LOG(WARNING) << "skipping hardware-accelerated CRC-32 tests"
+ << " (not supported on this CPU)";
+ }
+}
+