21 #include <glog/logging.h> 25 using namespace folly;
44 std::fill(buf, buf + 256,
T(0));
61 runSimpleTest8<uint8_t>();
65 runSimpleTest8<Unaligned<uint8_t>>();
89 std::fill(buf, buf + 256,
T(0));
106 runSimpleTest64<uint64_t>();
110 runSimpleTest64<Unaligned<uint64_t>>();
116 T buf[] = {0x12, 0x34, 0x56, 0x78};
142 runMultiBitTest8<uint8_t>();
146 runMultiBitTest8<Unaligned<uint8_t>>();
152 T buf[] = {0x12, 0x34, 0x56, 0x78};
178 runSignedMultiBitTest8<int8_t>();
181 template <
class T,
class R = T>
184 T buf[] = {0x123456789abcdef0, 0x13579bdf2468ace0};
201 runMultiBitTest64<uint64_t>();
209 runMultiBitTest64<Unaligned<uint64_t>,
uint64_t>();
213 template <
bool aligned,
class T>
217 reinterpret_cast<Unaligned<T>*
>(buf), start, bits, value);
220 template <
bool aligned,
class T>
222 testSet(
uint8_t* buf,
size_t start,
size_t bits,
T value) {
223 Bits<T>::set(reinterpret_cast<T*>(buf), start, bits, value);
226 template <
bool aligned,
class T>
228 testGet(
uint8_t* buf,
size_t start,
size_t bits) {
233 template <
bool aligned,
class T>
235 testGet(
uint8_t* buf,
size_t start,
size_t bits) {
236 return Bits<T>::get(reinterpret_cast<T*>(buf), start, bits);
239 template <
class T,
bool negate = false>
240 T testValue(
int bits) {
244 auto value = std::pow(2, bits) * (
negate ? -2.0 : 2.0) / 3.0;
247 return static_cast<T>(
value);
253 for (
size_t offset = 0; offset <= 64; ++offset) {
257 EXPECT_EQ(value, (testGet<true, int32_t>(buf, offset, size)));
264 for (
size_t s = 0;
s <= N; ++
s) {
269 template <
size_t N,
typename T,
bool NEG,
bool aligned>
271 for (
size_t s = 0;
s <= N; ++
s) {
272 CHECK_LE(
s + w, 8 * bufSize) <<
s <<
' ' << w <<
' ' << bufSize;
273 testSet<aligned>(buf, w,
s, testValue<T, NEG>(
s));
274 EXPECT_EQ((testValue<T, NEG>(s)), (testGet<aligned, T>(buf, w, s))) <<
s;
279 template <
size_t N,
typename T,
bool NEG,
bool aligned>
281 for (
size_t s = 0;
s <= N; ++
s) {
282 CHECK_LE(
s + r, 8 * bufSize);
283 EXPECT_EQ((testValue<T, NEG>(
s)), (testGet<aligned, T>(buf, r,
s))) <<
s;
288 template <
bool aligned>
318 bufSize = (bufSize + 7) / 8;
320 bufSize = (bufSize + 7) / 8 * 8;
321 std::vector<uint8_t>
buffer(bufSize);
326 testSetLoop<8, uint8_t, false, aligned>(w, bufSize, buf);
327 testSetLoop<16, uint16_t, false, aligned>(w, bufSize, buf);
328 testSetLoop<32, uint32_t, false, aligned>(w, bufSize, buf);
329 testSetLoop<64, uint64_t, false, aligned>(w, bufSize, buf);
332 testSetLoop<7, int8_t, false, aligned>(w, bufSize, buf);
333 testSetLoop<15, int16_t, false, aligned>(w, bufSize, buf);
334 testSetLoop<31, int32_t, false, aligned>(w, bufSize, buf);
335 testSetLoop<63, int64_t, false, aligned>(w, bufSize, buf);
338 testSetLoop<7, int8_t, true, aligned>(w, bufSize, buf);
339 testSetLoop<15, int16_t, true, aligned>(w, bufSize, buf);
340 testSetLoop<31, int32_t, true, aligned>(w, bufSize, buf);
341 testSetLoop<63, int64_t, true, aligned>(w, bufSize, buf);
347 testGetLoop<8, uint8_t, false, aligned>(r, bufSize, buf);
348 testGetLoop<16, uint16_t, false, aligned>(r, bufSize, buf);
349 testGetLoop<32, uint32_t, false, aligned>(r, bufSize, buf);
350 testGetLoop<64, uint64_t, false, aligned>(r, bufSize, buf);
353 testGetLoop<7, int8_t, false, aligned>(r, bufSize, buf);
354 testGetLoop<15, int16_t, false, aligned>(r, bufSize, buf);
355 testGetLoop<31, int32_t, false, aligned>(r, bufSize, buf);
356 testGetLoop<63, int64_t, false, aligned>(r, bufSize, buf);
359 testGetLoop<7, int8_t, true, aligned>(r, bufSize, buf);
360 testGetLoop<15, int16_t, true, aligned>(r, bufSize, buf);
361 testGetLoop<31, int32_t, true, aligned>(r, bufSize, buf);
362 testGetLoop<63, int64_t, true, aligned>(r, bufSize, buf);
367 testConcatenation<false>();
371 testConcatenation<true>();
376 gflags::ParseCommandLineFlags(&argc, &argv,
true);
std::vector< uint8_t > buffer(kBufferSize+16)
void testGetLoop(size_t &r, size_t bufSize, uint8_t *buf)
static void set(T *p, size_t bit)
Negate< Predicate > negate(Predicate pred)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
static UnderlyingType get(const T *p, size_t bitStart, size_t count)
void testSetLoop(size_t &w, size_t bufSize, uint8_t *buf)
#define EXPECT_EQ(val1, val2)
—— Concurrent Priority Queue Implementation ——
void runSignedMultiBitTest8()
constexpr auto size(C const &c) -> decltype(c.size())
static void clear(T *p, size_t bit)
static const char *const value
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
PUSHMI_INLINE_VAR constexpr detail::get_fn< T > get
TEST(SequencedExecutor, CPUThreadPoolExecutor)
int main(int argc, char *argv[])