MCPcopy Create free account
hub / github.com/facebook/CacheLib / testAllAlignment

Function testAllAlignment

cachelib/common/tests/BytesEqualTest.cpp:51–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51void testAllAlignment(bool equal) {
52 auto d = generateRandomString();
53 auto a = d;
54 a.reserve(kMaxKeySize + 8);
55 // ensure we checked all possible alignments
56 uint64_t byte_align = 0;
57 // we care about 0 - 8 byte alignment.
58 for (int i = 0; i < 8; i++) {
59 // push a's alignment by this many bytes by padding in the front.
60 if (i != 0) {
61 a.insert(a.begin(), 'X');
62 }
63 const int aAlign = ((uintptr_t)(void*)&a[i]) % 8;
64 auto b = equal ? d : generateRandomString();
65 b.reserve(kMaxKeySize + 8);
66 for (int j = 0; j < 8; j++) {
67 // push a's alignment by this many bytes by padding in the front.
68 if (j != 0) {
69 b.insert(b.begin(), 'X');
70 }
71 const int bAlign = ((uintptr_t)(void*)&b[j]) % 8;
72 byte_align |= (1ULL << (aAlign * 8 + bAlign));
73 for (int len = 0; len < kMaxKeySize; len++) {
74 // a has been pushed by i bytes and b has been pushed by j bytes from
75 // their default 1 byte aligned locations.
76 checkCorrectness(&a[i], &b[j], len);
77 }
78 }
79 }
80 ASSERT_EQ(byte_align, std::numeric_limits<uint64_t>::max());
81}
82
83TEST(bytesEqual, alignment_equal) { testAllAlignment(true); }
84

Callers 1

TESTFunction · 0.85

Calls 4

checkCorrectnessFunction · 0.85
generateRandomStringFunction · 0.70
insertMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected