llvm/llvm/unittests/Support/CRCTest.cpp

//===- llvm/unittest/Support/CRCTest.cpp - CRC tests ----------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements unit tests for CRC calculation functions.
//
//===----------------------------------------------------------------------===//

#include "llvm/Support/CRC.h"
#include "llvm/ADT/StringExtras.h"
#include "gtest/gtest.h"
#include <stdlib.h>

usingnamespacellvm;

namespace {

TEST(CRCTest, CRC32) {}

#if (SIZE_MAX > UINT32_MAX) && defined(EXPENSIVE_CHECKS)
TEST(CRCTest, LargeCRC32) {
  // Check that crc32 can handle inputs with sizes larger than 32 bits.
  size_t TestSize = (size_t)UINT32_MAX + 42;
  uint8_t *TestData = (uint8_t*)calloc(TestSize, 1);
  if (!TestData)
    GTEST_SKIP();

  // Test expectation generated with:
  // $ truncate --size=`echo 2^32-1+42 | bc` /tmp/foo
  // $ crc32 /tmp/foo
  EXPECT_EQ(0xE46F28FBU, llvm::crc32(ArrayRef(TestData, TestSize)));

  free(TestData);
}
#endif

} // end anonymous namespace