// They key here is accuracy; too low numbers means the accuracy was
// coarse. We up the ante until we get to at least minNanoseconds
// timings.
- static uint64_t resolutionInNs = 0, coarseResolutionInNs = 0;
+ static uint64_t resolutionInNs = 0;
if (!resolutionInNs) {
timespec ts;
CHECK_EQ(0, clock_getres(detail::DEFAULT_CLOCK_ID, &ts));
#include <cstddef>
#include <type_traits>
#include <limits>
+#include <glog/logging.h>
#include <folly/Bits.h>
#include <folly/Portability.h>
template <class T, class Traits>
inline void Bits<T, Traits>::set(T* p, size_t bitStart, size_t count,
UnderlyingType value) {
- assert(count <= sizeof(UnderlyingType) * 8);
+ DCHECK_LE(count, sizeof(UnderlyingType) * 8);
size_t cut = bitsPerBlock - count;
- assert(value == (value << cut >> cut));
+ DCHECK_EQ(value, value << cut >> cut);
size_t idx = blockIndex(bitStart);
size_t offset = bitOffset(bitStart);
if (std::is_signed<UnderlyingType>::value) {
template <class T, class Traits>
inline auto Bits<T, Traits>::get(const T* p, size_t bitStart, size_t count)
-> UnderlyingType {
- assert(count <= sizeof(UnderlyingType) * 8);
+ DCHECK_LE(count, sizeof(UnderlyingType) * 8);
size_t idx = blockIndex(bitStart);
size_t offset = bitOffset(bitStart);
UnderlyingType ret;
#include <syscall.h>
#include <linux/futex.h>
#include <sys/time.h>
-#include <cassert>
#include <climits>
#include <atomic>
#include <thread>
+#include <glog/logging.h>
#include <folly/Bits.h>
#include <folly/Likely.h>
// #waiters gets to 0, the less likely it is that we'll do spurious wakeups
// (and thus system calls).
uint64_t prev = val_.fetch_add(kSubWaiter, std::memory_order_seq_cst);
- assert((prev & kWaiterMask) != 0);
+ DCHECK_NE((prev & kWaiterMask), 0);
}
inline void EventCount::wait(Key key) noexcept {
// #waiters gets to 0, the less likely it is that we'll do spurious wakeups
// (and thus system calls)
uint64_t prev = val_.fetch_add(kSubWaiter, std::memory_order_seq_cst);
- assert((prev & kWaiterMask) != 0);
+ DCHECK_NE((prev & kWaiterMask), 0);
}
template <class Condition>
template <typename T>
inline size_t TaskIterator<T>::getTaskID() const {
- assert(id_ != -1);
+ assert(id_ != static_cast<size_t>(-1));
return id_;
}
#include <unistd.h>
#include <algorithm>
-#include <cassert>
#include <cstring>
#include <stdexcept>
+#include <glog/logging.h>
#include <folly/Likely.h>
#include <folly/Portability.h>
} // anonymous namespace
void Fiber::setData(intptr_t data) {
- assert(state_ == AWAITING);
+ DCHECK_EQ(state_, AWAITING);
data_ = data;
state_ = READY_TO_RUN;
void Fiber::fiberFunc() {
while (loopForever) {
- assert(state_ == NOT_STARTED);
+ DCHECK_EQ(state_, NOT_STARTED);
threadId_ = localThreadId();
state_ = RUNNING;
try {
if (resultFunc_) {
- assert(finallyFunc_);
- assert(!func_);
+ DCHECK(finallyFunc_);
+ DCHECK(!func_);
resultFunc_();
} else {
- assert(func_);
+ DCHECK(func_);
func_();
}
} catch (...) {
fiberManager_.activeFiber_ = nullptr;
- auto fiber = reinterpret_cast<Fiber*>(
- jumpContext(&fcontext_, &fiberManager_.mainContext_, 0));
- assert(fiber == this);
+ auto context = jumpContext(&fcontext_, &fiberManager_.mainContext_, 0);
+ DCHECK_EQ(reinterpret_cast<Fiber*>(context), this);
}
}
intptr_t Fiber::preempt(State state) {
- assert(fiberManager_.activeFiber_ == this);
- assert(state_ == RUNNING);
- assert(state != RUNNING);
+ DCHECK_EQ(fiberManager_.activeFiber_, this);
+ DCHECK_EQ(state_, RUNNING);
+ DCHECK_NE(state, RUNNING);
fiberManager_.activeFiber_ = nullptr;
state_ = state;
auto ret = jumpContext(&fcontext_, &fiberManager_.mainContext_, 0);
- assert(fiberManager_.activeFiber_ == this);
- assert(state_ == READY_TO_RUN);
+ DCHECK_EQ(fiberManager_.activeFiber_, this);
+ DCHECK_EQ(state_, READY_TO_RUN);
state_ = RUNNING;
return ret;
typedef typename std::result_of<
typename std::iterator_traits<InputIterator>::value_type()>::type Result;
assert(n > 0);
- assert(n <= std::distance(first, last));
+ assert(std::distance(first, last) >= 0);
+ assert(n <= static_cast<size_t>(std::distance(first, last)));
struct Context {
std::vector<std::pair<size_t, Result>> results;
>::value, std::vector<size_t>>::type
collectN(InputIterator first, InputIterator last, size_t n) {
assert(n > 0);
- assert(n <= std::distance(first, last));
+ assert(std::distance(first, last) >= 0);
+ assert(n <= static_cast<size_t>(std::distance(first, last)));
struct Context {
std::vector<size_t> taskIndices;
TEST(FiberManager, batonTryWait) {
FiberManager manager(folly::make_unique<SimpleLoopController>());
- auto& loopController =
- dynamic_cast<SimpleLoopController&>(manager.loopController());
// Check if try_wait and post work as expected
Baton b;
TEST(FiberManager, RequestContext) {
FiberManager fm(folly::make_unique<SimpleLoopController>());
- auto& loopController =
- dynamic_cast<SimpleLoopController&>(fm.loopController());
bool checkRun1 = false;
bool checkRun2 = false;
[&pendingRequests](Promise<int> promise) {
pendingRequests.push(std::move(promise));
});
- assert(result == 0);
+ DCHECK_EQ(result, 0);
}
});
Promise<int> pi;
Future<bool> fb = pb.getFuture();
Future<int> fi = pi.getFuture();
- bool flag = false;
auto f = collect(std::move(fb), std::move(fi));
pb.setValue(true);
EXPECT_FALSE(f.isReady());
VLOG(5) << "AsyncPipeReader::handlerReady() this=" << this << ", fd=" << fd_;
assert(readCallback_ != nullptr);
- uint16_t numReads = 0;
while (readCallback_) {
// Get the buffer to read into.
void* buf = nullptr;
// Do this here to ensure we initialize this once before any use of
// AsyncSSLSocket instances and not as part of library load.
static const auto eorAwareBioMethodInitializer = initEorBioMethod();
+ (void)eorAwareBioMethodInitializer;
+
setup_SSL_CTX(ctx_->getSSLCtx());
}
int ret = pthread_create(&thread_, nullptr, Main, this);
assert(ret == 0);
+ (void)ret;
std::cerr << "Accepting connections on " << address_ << std::endl;
}
uint8_t readbuf[128];
uint32_t bytesRead = socket->readAll(readbuf, sizeof(readbuf));
+ LOG(ERROR) << "readAll returned " << bytesRead << " instead of throwing";
} catch (AsyncSocketException &e) {
ex = true;
}
TEST_F(HHWheelTimerTest, FireOnce) {
StackWheelTimer t(&eventBase, milliseconds(1));
- const HHWheelTimer::Callback* nullCallback = nullptr;
-
TestTimeout t1;
TestTimeout t2;
TestTimeout t3;
*/
TEST_F(HHWheelTimerTest, TestSchedulingWithinCallback) {
StackWheelTimer t(&eventBase, milliseconds(10));
- const HHWheelTimer::Callback* nullCallback = nullptr;
TestTimeout t1;
// Delayed to simulate the steady_clock counter lagging
unique_ptr<IOBuf> iobuf2(IOBuf::create(20));
iobuf2->append(20);
- IOBuf* iob2ptr = iobuf2.get();
+ iobuf2.get();
iobuf1->prependChain(std::move(iobuf2));
EXPECT_TRUE(iobuf1->isChained());
}
BENCHMARK(skipBenchmark, iters) {
- uint8_t buf;
while (iters--) {
Cursor c(iobuf_read_benchmark.get());
for(int i = 0; i < benchmark_size ; i++) {
queue.append(stringToIOBuf(SCL("Hello,")));
queue.append(stringToIOBuf(SCL(" World")));
checkConsistency(queue);
- bool exceptionFired = false;
EXPECT_THROW({prefix = queue.split(13);}, std::underflow_error);
checkConsistency(queue);
}
EXPECT_EQ(0, iob->headroom());
EXPECT_EQ(100, iob->length());
const void* p1 = iob->buffer();
- const uint8_t* d1 = iob->data();
iob->reserve(100, 2512); // allocation sizes are multiples of 256
EXPECT_LE(100, iob->headroom());
if (folly::usingJEMalloc()) {
EXPECT_TRUE(success);
// check correctness
- size_t cap = m->capacity();
- ValueT val;
EXPECT_GT(m->numSubMaps(), 1); // make sure we grew
success = true;
EXPECT_EQ(m->size(), numEntries);
// Check findAt
success = true;
- KeyT key(0);
AHMapT::const_iterator retIt;
for (int32_t i = 0; i < int32_t(numEntries); i++) {
retIt = m->find(i);
// check correctness
EXPECT_EQ(sizeAHM, numInserts);
bool success = true;
- ValueT val;
for (int i = 0; i < numInserts; ++i) {
KeyT key = randomizeKey(i);
success &= (globalAHM->find(key)->second == genVal(key));
const int kInsertPerThread = 100000;
int raceFinalSizeEstimate;
-void* raceIterateThread(void* jj) {
- int64_t j = (int64_t) jj;
+void* raceIterateThread(void*) {
int count = 0;
AHMapT::iterator it = globalAHM->begin();
return nullptr;
}
-void* raceInsertRandomThread(void* jj) {
- int64_t j = (int64_t) jj;
+void* raceInsertRandomThread(void*) {
for (int i = 0; i < kInsertPerThread; ++i) {
KeyT key = rand();
globalAHM->insert(key, genVal(key));
globalAHM.reset(new AHMapT(raceFinalSizeEstimate / 9, config));
vector<pthread_t> threadIds;
- for (int64_t j = 0; j < kInsertThreads + kIterateThreads; j++) {
+ for (int j = 0; j < kInsertThreads + kIterateThreads; j++) {
pthread_t tid;
void *(*thread)(void*) =
(j < kInsertThreads ? raceInsertRandomThread : raceIterateThread);
- if (pthread_create(&tid, nullptr, thread, (void*) j) != 0) {
+ if (pthread_create(&tid, nullptr, thread, nullptr) != 0) {
LOG(ERROR) << "Could not start thread";
} else {
threadIds.push_back(tid);
using namespace std;
using namespace folly;
-static int8_t s8;
-static uint8_t u8;
-static int16_t s16;
-static uint16_t u16;
-static int32_t s32;
-static uint32_t u32;
-static int64_t s64;
-static uint64_t u64;
+
TEST(Conv, digits10Minimal) {
// Not much of a test (and it's included in the test below anyway).
TEST(Conv, Integral2Integral) {
// Same size, different signs
- s64 = numeric_limits<uint8_t>::max();
+ int64_t s64 = numeric_limits<uint8_t>::max();
EXPECT_EQ(to<uint8_t>(s64), s64);
s64 = numeric_limits<int8_t>::max();
EXPECT_EQ(i, 42);
try {
auto i = to<int>(42.1);
+ LOG(ERROR) << "to<int> returned " << i << " instead of throwing";
EXPECT_TRUE(false);
} catch (std::range_error& e) {
//LOG(INFO) << e.what();
EXPECT_EQ(j, 42);
try {
auto i = to<char>(y);
- LOG(ERROR) << static_cast<unsigned int>(i);
+ LOG(ERROR) << "to<char> returned "
+ << static_cast<unsigned int>(i)
+ << " instead of throwing";
EXPECT_TRUE(false);
} catch (std::range_error& e) {
//LOG(INFO) << e.what();
EXPECT_EQ(j, 100);
try {
auto i = to<A>(5000000000L);
+ LOG(ERROR) << "to<A> returned "
+ << static_cast<unsigned int>(i)
+ << " instead of throwing";
EXPECT_TRUE(false);
} catch (std::range_error& e) {
//LOG(INFO) << e.what();
EXPECT_EQ(e, x);
try {
auto i = to<int32_t>(x);
- LOG(ERROR) << to<uint32_t>(x);
+ LOG(ERROR) << "to<int32_t> returned " << i << " instead of throwing";
EXPECT_TRUE(false);
} catch (std::range_error& e) {
}
EXPECT_EQ(e, E::x);
try {
auto i = to<int32_t>(E::x);
- LOG(ERROR) << to<uint32_t>(E::x);
+ LOG(ERROR) << "to<int32_t> returned " << i << " instead of throwing";
EXPECT_TRUE(false);
} catch (std::range_error& e) {
}
bool hasTimeout = absSystemTimeout != nullptr || absSteadyTimeout != nullptr;
bool awoken = false;
FutexResult result = FutexResult::AWOKEN;
- int futexErrno = 0;
DeterministicSchedule::beforeSharedAccess();
FOLLY_TEST_DSCHED_VLOG(this << ".futexWait(" << std::hex << expected
dynamic d1 = dynamic::object;
dynamic d2 = dynamic::object;
auto foo = d1 < d2;
+ LOG(ERROR) << "operator < returned "
+ << static_cast<int>(foo)
+ << " instead of throwing";
} catch (std::exception const& e) {
caught = true;
}
}
template <class String> void clause11_21_4_2_f(String & test) {
// Constructor from char*
- const size_t
- pos = random(0, test.size()),
- n = random(0, test.size() - pos);
+ const size_t pos = random(0, test.size());
String before(test.data(), test.size());
String s(test.c_str() + pos);
String after(test.data(), test.size());
void expectWouldBlock(ssize_t r) {
int savedErrno = errno;
EXPECT_EQ(-1, r);
- EXPECT_EQ(EAGAIN, savedErrno) << errnoStr(errno);
+ EXPECT_EQ(EAGAIN, savedErrno) << errnoStr(savedErrno);
}
void expectOK(ssize_t r) {
int savedErrno = errno;
- EXPECT_LE(0, r) << ": errno=" << errnoStr(errno);
+ EXPECT_LE(0, r) << ": errno=" << errnoStr(savedErrno);
}
} // namespace
BENCHMARK_SUSPEND {
setupBenchmark(iters);
- int sumKeys = 0;
- std::string sumValues = "";
}
FOR_EACH (iter, bmMap) {
}
BENCHMARK(ManualLoopNoAssign, iters) {
+ int sumKeys = 0;
+ std::string sumValues;
+
BENCHMARK_SUSPEND {
setupBenchmark(iters);
}
- int sumKeys = 0;
- std::string sumValues;
for (auto iter = bmMap.begin(); iter != bmMap.end(); ++iter) {
sumKeys += iter->first;
}
BENCHMARK(ForEachKVMacro, iters) {
+ int sumKeys = 0;
+ std::string sumValues;
+
BENCHMARK_SUSPEND {
setupBenchmark(iters);
}
- int sumKeys = 0;
- std::string sumValues;
FOR_EACH_KV (k, v, bmMap) {
sumKeys += k;
}
TEST(Format, Float) {
- double d = 1;
EXPECT_EQ("1", sformat("{}", 1.0));
EXPECT_EQ("0.1", sformat("{}", 0.1));
EXPECT_EQ("0.01", sformat("{}", 0.01));
};
TEST(IPAddress, InvalidMask) {
for (auto& tc : invalidMasks) {
- uint8_t mask = tc.second;
auto ip = IPAddress(tc.first);
EXPECT_THROW(ip.mask(tc.second), IPAddressFormatException);
}
other.s_ = "";
}
MoveTester& operator=(const MoveTester&) = default;
- MoveTester& operator=(MoveTester&&) = default;
+ MoveTester& operator=(MoveTester&& other) noexcept {
+ s_ = std::move(other.s_);
+ other.s_ = "";
+ return *this;
+ }
private:
friend bool operator==(const MoveTester& o1, const MoveTester& o2);
std::string s_;
// intended explicit operator bool, for if (opt).
bool b(mbool);
+ EXPECT_FALSE(b);
// Truthy tests work and are not ambiguous
if (mbool && mshort && mstr && mint) { // only checks not-empty
size_t numThreads,
bool useSeparateLocks) {
char padding1[64];
+ (void)padding1;
Lock globalLock;
int valueProtectedByLock = 10;
char padding2[64];
+ (void)padding2;
Atom<bool> go(false);
Atom<bool>* goPtr = &go; // workaround for clang bug
vector<thread> threads(numThreads);
double writeFraction,
bool useSeparateLocks) {
char padding1[64];
+ (void)padding1;
Lock globalLock;
int valueProtectedByLock = 0;
char padding2[64];
+ (void)padding2;
Atom<bool> go(false);
Atom<bool>* goPtr = &go; // workaround for clang bug
vector<thread> threads(numThreads);
long randVal;
lrand48_r(&buffer, &randVal);
bool writeOp = randVal < writeThreshold;
- SharedMutexToken token;
if (writeOp) {
locker.lock(lock);
if (!useSeparateLocks) {
template <typename Lock, template <typename> class Atom = atomic>
static void runPingPong(size_t numRounds, size_t burnCount) {
char padding1[56];
+ (void)padding1;
pair<Lock, char[56]> locks[3];
char padding2[56];
+ (void)padding2;
Atom<int> avail(0);
auto availPtr = &avail; // workaround for clang crash
using SingletonCreationError = Singleton<T, Tag, CreationErrorTag>;
TEST(Singleton, SingletonCreationError) {
- auto& vault = *SingletonVault::singleton<CreationErrorTag>();
+ SingletonVault::singleton<CreationErrorTag>();
SingletonCreationError<ErrorConstructor> error_once_singleton;
// first time should error out
namespace {
bool readToString(int fd, std::string& buf, size_t maxSize) {
- size_t bytesRead = 0;
-
buf.resize(maxSize);
char* dest = &buf.front();
size_t remaining = maxSize;
if (i & 1) {
SYNCHRONIZED_DUAL (v, pv, m, pm) {
- size_t s = m.size();
+ (void)m.size();
v.push_back(i);
}
} else {
SYNCHRONIZED_DUAL (m, pm, v, pv) {
- size_t s = m.size();
+ (void)m.size();
v.push_back(i);
}
}
EXPECT_EQ(1, q.add(0, 0, cb));
- int64_t now = 0;
EXPECT_EQ(0, q.runOnce(0));
EXPECT_EQ(1, count);
EXPECT_EQ(0, q.runOnce(0));
for (int i = 0; i < 12; i++) {
const auto& itv = intervals[i];
- int c = mhts.count(itv.start, itv.end);
// Some of the older intervals that fall in the alltime bucket
// are off by 1 or 2 in their estimated counts.
size_t tolerance = 0;
BENCHMARK(VarintEncoding, iters) {
uint8_t* start = &(*gEncoded.begin());
uint8_t* p = start;
- bool empty = (iters == 0);
while (iters--) {
p = start;
for (auto& v : gValues) {