| 77 | |
| 78 | template <typename T> |
| 79 | [[nodiscard]] bool IsCorrectSubByteData(const std::string& filePath, uint64_t offset, Util::Span<const T> expectedSpan) |
| 80 | { |
| 81 | blob_metadata metadata; |
| 82 | TestUtil::ReadData<blob_metadata>(filePath, metadata, offset); |
| 83 | // sizing this int8 vector with the int4 span size is an overestimation - should be |
| 84 | // fine for this test since we need the buffer only anyway |
| 85 | std::vector<uint8_t> v(expectedSpan.Size()); |
| 86 | Util::Span<T> outputSpan((void*)v.data(), expectedSpan.Size()); |
| 87 | TestUtil::ReadBlobFile(filePath, metadata.offset, outputSpan); |
| 88 | |
| 89 | auto ourBytesPtr = static_cast<const T*>(outputSpan.Data()); |
| 90 | auto otherBytesPtr = static_cast<const T*>(expectedSpan.Data()); |
| 91 | |
| 92 | // scan bytes up to but not including padding |
| 93 | std::size_t numBits = outputSpan.Size() * T::SizeInBits; |
| 94 | std::size_t remainderBits = numBits % 8; |
| 95 | |
| 96 | std::size_t numFullBytes = numBits / 8; |
| 97 | std::size_t numRemainingElements = remainderBits / T::SizeInBits; |
| 98 | |
| 99 | for (size_t i = 0; i < numFullBytes; i++) { |
| 100 | if (ourBytesPtr[i] != otherBytesPtr[i]) { |
| 101 | return false; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | // scan remainder, ignore garbage bits |
| 106 | for (size_t i = 0; i < numRemainingElements; i++) { |
| 107 | auto mask = T::BitMask << (i * T::SizeInBits); |
| 108 | auto ourVal = ourBytesPtr[numFullBytes].data & mask; |
| 109 | auto otherVal = otherBytesPtr[numFullBytes].data & mask; |
| 110 | if (ourVal != otherVal) { |
| 111 | return false; |
| 112 | } |
| 113 | } |
| 114 | return true; |
| 115 | } |
| 116 | |
| 117 | template <typename T> |
| 118 | [[nodiscard]] bool IsCorrectData(const std::string& filePath, uint64_t offset, Util::Span<const T> expectedSpan) |
no test coverage detected