brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 0ecd213 Raw
72 lines · cpp
1//===- llvm/unittest/Support/BitsetTest.cpp -------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/ADT/Bitset.h"10#include "gtest/gtest.h"11 12using namespace llvm;13 14namespace {15 16template <unsigned NumBits>17class TestBitsetUInt64Array : public Bitset<NumBits> {18  static constexpr unsigned NumElts = (NumBits + 63) / 64;19 20public:21  TestBitsetUInt64Array(const std::array<uint64_t, NumElts> &B)22      : Bitset<NumBits>(B) {}23 24  bool verifyValue(const std::array<uint64_t, NumElts> &B) const {25    for (unsigned I = 0; I != NumBits; ++I) {26      bool ReferenceVal =27          (B[(I / 64)] & (static_cast<uint64_t>(1) << (I % 64))) != 0;28      if (ReferenceVal != this->test(I))29        return false;30    }31 32    return true;33  }34 35  void verifyStorageSize(size_t elements_64_bit, size_t elements_32_bit) {36    if constexpr (sizeof(uintptr_t) == sizeof(uint64_t))37      EXPECT_EQ(sizeof(*this), elements_64_bit * sizeof(uintptr_t));38    else39      EXPECT_EQ(sizeof(*this), elements_32_bit * sizeof(uintptr_t));40  }41};42 43TEST(BitsetTest, Construction) {44  std::array<uint64_t, 2> TestVals = {0x123456789abcdef3, 0x1337d3a0b22c24};45  TestBitsetUInt64Array<96> Test(TestVals);46  EXPECT_TRUE(Test.verifyValue(TestVals));47  Test.verifyStorageSize(2, 3);48 49  TestBitsetUInt64Array<65> Test1(TestVals);50  EXPECT_TRUE(Test1.verifyValue(TestVals));51  Test1.verifyStorageSize(2, 3);52 53  std::array<uint64_t, 1> TestSingleVal = {0x12345678abcdef99};54 55  TestBitsetUInt64Array<64> Test64(TestSingleVal);56  EXPECT_TRUE(Test64.verifyValue(TestSingleVal));57  Test64.verifyStorageSize(1, 2);58 59  TestBitsetUInt64Array<30> Test30(TestSingleVal);60  EXPECT_TRUE(Test30.verifyValue(TestSingleVal));61  Test30.verifyStorageSize(1, 1);62 63  TestBitsetUInt64Array<32> Test32(TestSingleVal);64  EXPECT_TRUE(Test32.verifyValue(TestSingleVal));65  Test32.verifyStorageSize(1, 1);66 67  TestBitsetUInt64Array<33> Test33(TestSingleVal);68  EXPECT_TRUE(Test33.verifyValue(TestSingleVal));69  Test33.verifyStorageSize(1, 2);70}71} // namespace72