proxygen
folly::test Namespace Reference

Namespaces

 detail
 

Classes

struct  Barrier
 
class  CaptureFD
 
class  ChangeToTempDir
 
struct  DeterministicAtomicImpl
 
struct  DeterministicMutex
 
class  DeterministicSchedule
 
struct  EnvVarSaver
 
class  FileUtilTest
 
class  IovecBuffers
 
class  ManualSchedule
 
class  MockAsyncServerSocket
 
class  MockAsyncSocket
 
class  MockAsyncSSLSocket
 
class  MockAsyncTransport
 
struct  MockAsyncUDPSocket
 
class  MockReadCallback
 
class  MockReplaySafetyCallback
 
class  MockTimeoutManager
 
class  MockWriteCallback
 
class  MovableInt
 
struct  One
 
class  ReadFileFd
 
class  Server
 
class  TemporaryDirectory
 
class  TemporaryFile
 
class  TestAcceptCallback
 
class  TestAdlIterable
 
class  TestBothIndexingAndIter
 
class  TestConnectionEventCallback
 
class  TestRValueConstruct
 
class  TestWriteChainAsyncTransportWrapper
 
struct  TupleTo
 
struct  TupleTo2
 
struct  TupleTo2< TemplateSeq< std::size_t, Ns... > >
 
struct  TupleTo< std::tuple< U, Us... >, T >
 
struct  TupleTo< std::tuple<>, std::tuple<> >
 
struct  Two
 
struct  UniformSubset
 
class  WriteFileAtomic
 

Typedefs

typedef DeterministicSchedule DSched
 
template<typename T >
using ManualAtomic = test::DeterministicAtomicImpl< T, ManualSchedule >
 
template<template< typename > class Atomic>
using TestDistributedMutex = detail::distributed_mutex::DistributedMutex< Atomic, false >
 
using AuxAct = std::function< void(bool)>
 
using AuxChk = std::function< void(uint64_t)>
 
template<typename T >
using DeterministicAtomic = DeterministicAtomicImpl< T, DeterministicSchedule >
 
using OneOrTwo = boost::variant< One, Two >
 

Functions

auto begin (TestAdlIterable &instance)
 
auto begin (const TestAdlIterable &instance)
 
auto end (TestAdlIterable &instance)
 
auto end (const TestAdlIterable &instance)
 
void doWork (int work)
 
template<typename Example , typename Req = bool, typename Mutex = std::mutex, template< typename > class Atom = std::atomic>
uint64_t fc_test (int nthreads, int lines, int numRecs, int work, int ops, bool combining, bool dedicated, bool tc, bool syncops, bool excl=false, bool allocAll=false)
 
uint64_t run_test (int nthreads, int lines, int numRecs, int work, int ops, bool combining, bool simple, bool dedicated, bool tc, bool syncops, bool excl=false, bool allocAll=false)
 
 TEST (ProgramOptionsTest, Errors)
 
 TEST (ProgramOptionsTest, Help)
 
 TEST (ProgramOptionsTest, DevFull)
 
 TEST (ProgramOptionsTest, CutArguments)
 
 TEST (ProgramOptionsTest, Success)
 
 TEST (ProgramOptionsTest, Aliases)
 
 TEST (ProgramOptionsTest, BuiltinCommand)
 
 TEST (ProgramOptionsTest, GFlagsStyleDefaultValues)
 
 TEST (ProgramOptionsTest, GFlagsStyleFlagsSet)
 
 TEST (ProgramOptionsTest, GFlagsStyleBoolFlagsNegation)
 
 TEST (ProgramOptionsTest, GNUStyleDefaultValues)
 
 TEST (ProgramOptionsTest, GNUStyleFlagsSet)
 
 TEST (ProgramOptionsTest, GNUStyleBoolFlagsNegation)
 
 TEST (ProgramOptionsTest, GNUStyleSubCommand)
 
 TEST (ProgramOptionsTest, GNUStyleSubCommandUnrecognizedOptionFirst)
 
 TEST (TupleOps, Copiable)
 
bool operator== (const MovableInt &a, const MovableInt &b)
 
 TEST (TupleOps, Movable)
 
template<class U , class T >
tupleTo (const T &input)
 
template<class U , class T , class Seq = typename TemplateTupleRange<U>::type, class Enable = typename std::enable_if< (std::tuple_size<U>::value == std::tuple_size<T>::value)>::type>
tupleTo2 (const T &input)
 
 TEST (TupleOps, TupleTo)
 
 TEST (TupleOps, TupleTo2)
 
template<typename Func >
auto msvcSuppressAbortOnInvalidParams (Func func) -> decltype(func())
 
std::string glogErrorPattern ()
 
std::string glogWarningPattern ()
 
std::string glogErrOrWarnPattern ()
 
 MATCHER_P (BufMatches, expected,"")
 
 TEST (WriteChainAsyncTransportWrapperTest, TestSimpleIov)
 
 TEST (WriteChainAsyncTransportWrapperTest, TestChainedIov)
 
 TEST (WriteChainAsyncTransportWrapperTest, TestSimpleBuf)
 
 TEST (RecordIOTest, Simple)
 
 TEST (RecordIOTest, SmallRecords)
 
 TEST (RecordIOTest, MultipleFileIds)
 
 TEST (RecordIOTest, ExtraMagic)
 
 TEST (RecordIOTest, Randomized)
 
int createConnectedSocket (int port)
 
void runCloseTest (bool abortive)
 
 TEST (ShutdownSocketSetTest, OrderlyClose)
 
 TEST (ShutdownSocketSetTest, AbortiveClose)
 
void runKillTest (bool abortive)
 
 TEST (ShutdownSocketSetTest, OrderlyKill)
 
 TEST (ShutdownSocketSetTest, AbortiveKill)
 
template<bool MayBlock, template< typename > class Atom>
void run_basic_test ()
 
template<bool MayBlock, template< typename > class Atom>
void run_pingpong_test (int numRounds)
 
template<bool MayBlock, template< typename > class Atom, typename Clock >
void run_basic_timed_wait_tests ()
 
template<bool MayBlock, template< typename > class Atom, typename Clock >
void run_timed_wait_tmo_tests ()
 
template<bool MayBlock, template< typename > class Atom, typename Clock >
void run_timed_wait_regular_test ()
 
template<bool MayBlock, template< typename > class Atom>
void run_try_wait_tests ()
 
int futexWakeImpl (const detail::Futex< ManualAtomic > *, int, uint32_t)
 
detail::FutexResult futexWaitImpl (const detail::Futex< ManualAtomic > *, uint32_t, std::chrono::system_clock::time_point const *, std::chrono::steady_clock::time_point const *, uint32_t)
 
template<typename Clock , typename Duration >
std::cv_status atomic_wait_until (const ManualAtomic< std::uintptr_t > *, std::uintptr_t, const std::chrono::time_point< Clock, Duration > &)
 
void atomic_notify_one (const ManualAtomic< std::uintptr_t > *)
 
 TEST (AtomicBitSet, Simple)
 
detail::FutexResult futexWaitImpl (const detail::Futex< DeterministicAtomic > *futex, uint32_t expected, std::chrono::system_clock::time_point const *absSystemTimeout, std::chrono::steady_clock::time_point const *absSteadyTimeout, uint32_t waitMask)
 
int futexWakeImpl (const detail::Futex< test::DeterministicAtomic > *futex, int count, uint32_t wakeMask)
 
detail::FutexResult futexWaitImpl (const detail::Futex< test::DeterministicAtomic > *futex, uint32_t expected, std::chrono::system_clock::time_point const *absSystemTime, std::chrono::steady_clock::time_point const *absSteadyTime, uint32_t waitMask)
 
template<typename Integer >
void atomic_wait (const DeterministicAtomic< Integer > *, Integer)
 
template<typename Integer , typename Clock , typename Duration >
std::cv_status atomic_wait_until (const DeterministicAtomic< Integer > *, Integer, const std::chrono::time_point< Clock, Duration > &)
 
template<typename Integer >
void atomic_notify_one (const DeterministicAtomic< Integer > *)
 
template<typename Integer >
void atomic_notify_all (const DeterministicAtomic< Integer > *)
 
 TEST (ExceptionTest, Simple)
 
 TEST (ExceptionTest, makeSystemError)
 
 TEST_F (FileUtilTest, read)
 
 TEST_F (FileUtilTest, pread)
 
 TEST_F (FileUtilTest, readv)
 
 TEST (FileUtilTest2, wrapv)
 
 TEST_F (FileUtilTest, preadv)
 
 TEST (String, readFile)
 
 TEST_F (ReadFileFd, ReadZeroBytes)
 
 TEST_F (ReadFileFd, ReadPartial)
 
 TEST_F (ReadFileFd, ReadFull)
 
 TEST_F (ReadFileFd, WriteOnlyFd)
 
 TEST_F (ReadFileFd, InvalidFd)
 
 TEST_F (WriteFileAtomic, writeNew)
 
 TEST_F (WriteFileAtomic, overwrite)
 
 TEST_F (WriteFileAtomic, directoryPermissions)
 
 TEST_F (WriteFileAtomic, multipleFiles)
 
 TEST (MPMCPipeline, Trivial)
 
 TEST (MPMCPipeline, TrivialAmplification)
 
 TEST (MPMCPipeline, MultiThreaded)
 
 TEST (Overload, BoostVariant)
 
 TEST (Overload, DiscriminatedPtr)
 
 TEST (Overload, Pattern)
 
template<typename T1 , typename T2 >
::testing::AssertionResult AreWithinSecs (T1 val1, T2 val2, std::chrono::seconds acceptableDeltaSecs)
 
void testVarint (uint64_t val, std::initializer_list< uint8_t > bytes)
 
 TEST (Varint, Interface)
 
 TEST (Varint, Simple)
 
void testVarintFail (std::initializer_list< uint8_t > bytes)
 
 TEST (Varint, Fail)
 
 TEST (ZigZag, Simple)
 
unsigned staticTracepointTestFunc (unsigned v)
 

Variables

ShutdownSocketSet shutdownSocketSet
 
static std::unordered_map< const detail::Futex< DeterministicAtomic > *, std::list< std::pair< uint32_t, bool * > > > futexQueues
 
static std::mutex futexLock
 

Typedef Documentation

using folly::test::AuxAct = typedef std::function<void(bool)>

Definition at line 51 of file DeterministicSchedule.h.

using folly::test::AuxChk = typedef std::function<void(uint64_t)>

Definition at line 52 of file DeterministicSchedule.h.

Definition at line 458 of file DeterministicSchedule.h.

Definition at line 26 of file BatonTestHelpers.h.

Definition at line 148 of file DistributedMutexTest.cpp.

using folly::test::OneOrTwo = typedef boost::variant<One, Two>

Definition at line 34 of file OverloadTest.cpp.

template<template< typename > class Atomic>
using folly::test::TestDistributedMutex = typedef detail::distributed_mutex::DistributedMutex<Atomic, false>

Definition at line 151 of file DistributedMutexTest.cpp.

Function Documentation

template<typename T1 , typename T2 >
::testing::AssertionResult folly::test::AreWithinSecs ( T1  val1,
T2  val2,
std::chrono::seconds  acceptableDeltaSecs 
)

Definition at line 129 of file TestUtils.h.

References testing::AssertionFailure(), and testing::AssertionSuccess().

129  {
130  auto deltaSecs =
131  std::chrono::duration_cast<std::chrono::seconds>(val1 - val2);
132  if (deltaSecs <= acceptableDeltaSecs &&
133  deltaSecs >= -1 * acceptableDeltaSecs) {
135  } else {
137  << val1.count() << " and " << val2.count() << " are not within "
138  << acceptableDeltaSecs.count() << " secs of each other";
139  }
140 }
GTEST_API_ AssertionResult AssertionFailure()
Definition: gtest.cc:1015
GTEST_API_ AssertionResult AssertionSuccess()
Definition: gtest.cc:1010
template<typename Integer >
void folly::test::atomic_notify_all ( const DeterministicAtomic< Integer > *  )

Definition at line 490 of file DeterministicSchedule.h.

490 {}
void folly::test::atomic_notify_one ( const ManualAtomic< std::uintptr_t > *  )

Definition at line 182 of file DistributedMutexTest.cpp.

References Atom, DEFINE_int32, EXPECT_EQ, h, i, folly::test::DeterministicSchedule::join(), folly::gen::move, mutex, sum(), folly::test::DeterministicSchedule::thread(), threads, and value.

182  {
183  ManualSchedule::beforeSharedAccess();
184 }
template<typename Integer >
void folly::test::atomic_notify_one ( const DeterministicAtomic< Integer > *  )

Definition at line 488 of file DeterministicSchedule.h.

488 {}
template<typename Integer >
void folly::test::atomic_wait ( const DeterministicAtomic< Integer > *  ,
Integer   
)

Implementations of the atomic_wait API for DeterministicAtomic, these are no-ops here. Which for a correct implementation should not make a difference because threads are required to have atomic operations around waits and wakes

Definition at line 479 of file DeterministicSchedule.h.

479 {}
template<typename Clock , typename Duration >
std::cv_status folly::test::atomic_wait_until ( const ManualAtomic< std::uintptr_t > *  ,
std::uintptr_t  ,
const std::chrono::time_point< Clock, Duration > &   
)

Definition at line 174 of file DistributedMutexTest.cpp.

177  {
178  ManualSchedule::beforeSharedAccess();
179  return std::cv_status::no_timeout;
180 }
template<typename Integer , typename Clock , typename Duration >
std::cv_status folly::test::atomic_wait_until ( const DeterministicAtomic< Integer > *  ,
Integer  ,
const std::chrono::time_point< Clock, Duration > &   
)

Definition at line 481 of file DeterministicSchedule.h.

484  {
485  return std::cv_status::no_timeout;
486 }
auto folly::test::begin ( TestAdlIterable instance)

Definition at line 56 of file ForeachTest.cpp.

References folly::test::TestAdlIterable::vec.

Referenced by folly::for_each_detail::adl::adl_begin(), folly::detail::as_sorted(), folly::basic_fbstring< char >::assign(), folly::AtomicHashMap< int64_t, int64_t >::begin(), BENCHMARK(), folly::Bits< T, Traits >::blockCount(), folly::small_vector< Observer< T > *, InlineObservers >::cbegin(), folly::ConcurrentSkipList< T, Comp, NodeAlloc, MAX_HEIGHT >::Accessor::cbegin(), folly::BasicFixedString< Char, N >::cbegin(), folly::basic_fbstring< char >::cbegin(), folly::small_vector< Observer< T > *, InlineObservers >::clear(), folly::IOBuf::cloneOneInto(), folly::Bits< T, Traits >::count(), folly::Random::create(), proxygen::StructuredHeaders::decodeBase64(), folly::ssl::OpenSSLCertUtils::derDecode(), folly::compression::BitVectorEncoder< Value, SkipValue, kSkipQuantum, kForwardQuantum >::encode(), folly::compression::EliasFanoEncoderV2< Value, SkipValue, kSkipQuantum, kForwardQuantum >::encode(), folly::sorted_vector_set< folly::RequestData * >::equal_range(), folly::Range< unsigned char * >::equals(), folly::basic_fbstring< char >::erase(), folly::basic_fbstring< E, T, A, Storage >::find_first_not_of(), folly::basic_fbstring< E, T, A, Storage >::find_first_of(), folly::basic_fbstring< E, T, A, Storage >::find_last_not_of(), folly::basic_fbstring< E, T, A, Storage >::find_last_of(), folly::findFirstSet(), folly::small_vector< Observer< T > *, InlineObservers >::front(), folly::basic_fbstring< char >::front(), folly::getGlobalBenchmarkBaselineIndex(), folly::dynamic::hash(), folly::hash::hash_range(), folly::small_vector< Observer< T > *, InlineObservers >::insert(), folly::basic_fbstring< char >::insert(), folly::small_vector< Observer< T > *, InlineObservers >::insertImpl(), folly::basic_fbstring< E, T, A, Storage >::insertImpl(), folly::basic_fbstring< E, T, A, Storage >::insertImplDiscr(), folly::detail::internalJoin(), folly::basic_fbstring< char >::isSane(), folly::sorted_vector_set< folly::RequestData * >::lower_bound(), folly::sorted_vector_map< Key, Value, Compare, Allocator, GrowthPolicy, Container >::lower_bound(), fizz::CertUtils::makePeerCert(), folly::small_vector< Observer< T > *, InlineObservers >::makeSizeInternal(), testing::internal::BeginEndDistanceIsMatcher< DistanceMatcher >::Impl< Container >::MatchAndExplain(), folly::TimeoutQueue::nextExpiration(), folly::compression::BitVectorEncoder< Value, SkipValue, kSkipQuantum, kForwardQuantum >::Layout::openList(), folly::compression::EliasFanoEncoderV2< Value, SkipValue, kSkipQuantum, kForwardQuantum >::Layout::openList(), folly::BasicFixedString< Char, N >::operator std::basic_string< Char >(), folly::pushmi::reduce_fn::operator()(), folly::pushmi::for_each_fn::operator()(), folly::pushmi::operators::from_fn::operator()(), folly::pushmi::operators::flow_from_fn::operator()(), folly::small_vector< Observer< T > *, InlineObservers >::operator<(), operator<<(), folly::operator<<(), folly::StringKeyedSetBase< Compare, Alloc >::operator=(), folly::StringKeyedMap< Value, Compare, Alloc >::operator=(), folly::F14VectorSet< Key, Hasher, KeyEqual, Alloc >::operator=(), folly::F14VectorMap< Key, Mapped, Hasher, KeyEqual, Alloc >::operator=(), folly::small_vector< Observer< T > *, InlineObservers >::operator==(), testing::internal::NativeArray< Element >::operator==(), folly::small_vector< Observer< T > *, InlineObservers >::operator[](), folly::basic_fbstring< char >::operator[](), testing::internal::UniversalPrinter< T >::Print(), folly::FutureDAG::remove(), folly::small_vector< Observer< T > *, InlineObservers >::rend(), folly::basic_fbstring< char >::rend(), folly::basic_fbstring< char >::replace(), folly::basic_fbstring< E, T, A, Storage >::replaceAliased(), folly::Range< unsigned char * >::replaceAt(), folly::basic_fbstring< E, T, A, Storage >::replaceImpl(), folly::basic_fbstring< E, T, A, Storage >::replaceImplDiscr(), folly::small_vector< Observer< T > *, InlineObservers >::resize(), folly::basic_fbstring< E, T, A, Storage >::rfind(), folly::Random::seed(), folly::SSLContext::setCipherList(), folly::SSLContext::setSignatureAlgorithms(), folly::small_vector< Observer< T > *, InlineObservers >::shrink_to_fit(), folly::small_vector< Observer< T > *, InlineObservers >::small_vector(), folly::io::test::supportedCodecs(), fizz::test::TEST(), TEST(), folly::BasicFixedString< Char, N >::toRange(), folly::BasicFixedString< Char, N >::toStdString(), folly::tryDecodeVarint(), testing::internal::UniversalPrintArray(), testing::internal::UniversalPrintCharArray(), folly::sorted_vector_set< folly::RequestData * >::upper_bound(), folly::sorted_vector_map< Key, Value, Compare, Allocator, GrowthPolicy, Container >::upper_bound(), proxygen::CodecUtil::validateHeaderValue(), folly::gen::detail::Zip< Container >::Zip(), and testing::internal::GTestFlagSaver::~GTestFlagSaver().

56  {
57  return instance.vec.begin();
58 }
auto folly::test::begin ( const TestAdlIterable instance)

Definition at line 59 of file ForeachTest.cpp.

References folly::test::TestAdlIterable::vec.

59  {
60  return instance.vec.begin();
61 }
int folly::test::createConnectedSocket ( int  port)

Definition at line 127 of file ShutdownSocketSetTest.cpp.

References addr, folly::netops::connect(), and folly::netops::socket().

Referenced by runCloseTest(), and runKillTest().

127  {
128  int sock = fsp::socket(PF_INET, SOCK_STREAM, 0);
129  CHECK_ERR(sock);
130  sockaddr_in addr;
131  addr.sin_family = AF_INET;
132  addr.sin_port = htons(port);
133  addr.sin_addr.s_addr = htonl((127 << 24) | 1); // XXX
134  CHECK_ERR(
135  connect(sock, reinterpret_cast<const sockaddr*>(&addr), sizeof(addr)));
136  return sock;
137 }
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
Definition: NetOps.cpp:94
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
ThreadPoolListHook * addr
void folly::test::doWork ( int  work)

Definition at line 31 of file FlatCombiningTestHelpers.h.

References a, Atom, folly::doNotOptimizeAway(), i, mutex, Mutex, and uint64_t.

Referenced by fc_test().

31  {
32  uint64_t a = 0;
33  for (int i = work; i > 0; --i) {
34  a += i;
35  }
37 }
char a
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
auto folly::test::end ( TestAdlIterable instance)

Definition at line 62 of file ForeachTest.cpp.

References folly::test::TestAdlIterable::vec.

Referenced by Add(), folly::addBenchmark(), folly::for_each_detail::adl::adl_end(), folly::basic_fbstring< char >::append(), testing::internal::ArrayAwareFind(), folly::detail::as_sorted(), folly::Range< unsigned char * >::assign(), folly::small_vector< Observer< T > *, InlineObservers >::assign(), folly::basic_fbstring< char >::assign(), folly::sorted_vector_map< Key, Value, Compare, Allocator, GrowthPolicy, Container >::at(), folly::MultiLevelTimeSeries< VT, CT >::avg(), folly::small_vector< Observer< T > *, InlineObservers >::back(), folly::basic_fbstring< char >::back(), BENCHMARK(), folly::Bits< T, Traits >::blockCount(), folly::BucketedTimeSeries< VT, CT >::buckets(), folly::LogName::canonicalize(), folly::small_vector< Observer< T > *, InlineObservers >::cend(), folly::ConcurrentSkipList< T, Comp, NodeAlloc, MAX_HEIGHT >::Accessor::cend(), folly::BasicFixedString< Char, N >::cend(), folly::basic_fbstring< char >::cend(), folly::UnboundedQueue< T, false, 6 >::cleanUpRemainingItems(), folly::small_vector< Observer< T > *, InlineObservers >::clear(), folly::IOBuf::cloneOneInto(), folly::Bits< T, Traits >::count(), folly::AtomicHashMap< int64_t, int64_t >::count(), folly::sorted_vector_set< folly::RequestData * >::count(), folly::sorted_vector_map< Key, Value, Compare, Allocator, GrowthPolicy, Container >::count(), folly::Random::create(), testing::internal::edit_distance::CreateUnifiedDiff(), proxygen::compress::QMINScheme::decode(), proxygen::StructuredHeaders::decodeBase64(), proxygen::HTTPMessage::doHeaderTokenCheck(), folly::StringKeyedSetBase< Compare, Alloc >::emplace(), folly::StringKeyedMap< Value, Compare, Alloc >::emplace(), folly::small_vector< Observer< T > *, InlineObservers >::emplace(), folly::small_vector< Observer< T > *, InlineObservers >::emplace_back(), folly::compression::BitVectorEncoder< Value, SkipValue, kSkipQuantum, kForwardQuantum >::encode(), folly::compression::EliasFanoEncoderV2< Value, SkipValue, kSkipQuantum, kForwardQuantum >::encode(), folly::sorted_vector_set< folly::RequestData * >::equal_range(), folly::Range< unsigned char * >::equals(), folly::StringKeyedSetBase< Compare, Alloc >::erase(), folly::StringKeyedMap< Value, Compare, Alloc >::erase(), folly::sorted_vector_set< folly::RequestData * >::erase(), folly::sorted_vector_map< Key, Value, Compare, Allocator, GrowthPolicy, Container >::erase(), folly::small_vector< Observer< T > *, InlineObservers >::erase(), folly::basic_fbstring< char >::erase(), folly::sorted_vector_set< folly::RequestData * >::find(), folly::sorted_vector_map< Key, Value, Compare, Allocator, GrowthPolicy, Container >::find(), folly::basic_fbstring< E, T, A, Storage >::find_first_not_of(), folly::basic_fbstring< E, T, A, Storage >::find_first_of(), folly::findFirstSet(), testing::internal::FlagToEnvVar(), folly::detail::MemoryIdler::flushLocalMallocCaches(), ForEach< ValueType >::ForEach(), folly::symbolizer::AddressFormatter::format(), folly::CustomLogFormatter::formatMessage(), folly::GlogStyleFormatter::formatMessage(), folly::getGlobalBenchmarkBaselineIndex(), folly::settings::detail::getSavedValue(), testing::internal::GetUnitTestImpl(), folly::LogName::hash(), folly::dynamic::hash(), folly::hash::SpookyHashV1::Hash128(), folly::hash::SpookyHashV2::Hash128(), folly::hash::hash_range(), folly::FormatArg::initSlow(), folly::StringKeyedSetBase< Compare, Alloc >::insert(), folly::StringKeyedMap< Value, Compare, Alloc >::insert(), folly::sorted_vector_set< folly::RequestData * >::insert(), folly::small_vector< Observer< T > *, InlineObservers >::insert(), folly::sorted_vector_map< Key, Value, Compare, Allocator, GrowthPolicy, Container >::insert(), folly::basic_fbstring< char >::isSane(), folly::symbolizer::ElfFile::iterateStrings(), folly::symbolizer::ElfFile::iterateSymbols(), folly::sorted_vector_set< folly::RequestData * >::lower_bound(), folly::sorted_vector_map< Key, Value, Compare, Allocator, GrowthPolicy, Container >::lower_bound(), main(), folly::small_vector< Observer< T > *, InlineObservers >::makeSizeInternal(), testing::internal::BeginEndDistanceIsMatcher< DistanceMatcher >::Impl< Container >::MatchAndExplain(), folly::detail::moveObjectsRight(), folly::detail::notThereYet(), folly::BasicFixedString< Char, N >::operator std::basic_string< Char >(), folly::pushmi::reduce_fn::operator()(), folly::pushmi::for_each_fn::operator()(), folly::pushmi::operators::from_fn::operator()(), folly::BaseFormatter< Derived, containerMode, Args >::operator()(), folly::pushmi::operators::flow_from_fn::operator()(), folly::small_vector< Observer< T > *, InlineObservers >::operator<(), operator<<(), folly::StringKeyedMap< Value, Compare, Alloc >::operator=(), folly::StringKeyedSetBase< Compare, Alloc >::operator=(), folly::F14VectorSet< Key, Hasher, KeyEqual, Alloc >::operator=(), folly::F14VectorMap< Key, Mapped, Hasher, KeyEqual, Alloc >::operator=(), folly::small_vector< Observer< T > *, InlineObservers >::operator==(), folly::StringKeyedMap< Value, Compare, Alloc >::operator[](), folly::sorted_vector_map< Key, Value, Compare, Allocator, GrowthPolicy, Container >::operator[](), testing::internal::ParseInt32(), folly::parseLeadingNumber(), folly::small_vector< Observer< T > *, InlineObservers >::pop_back(), folly::symbolizer::SymbolizePrinter::printTerse(), std::chrono::PrintTo(), folly::TimeseriesHistogram< T, CT, C >::rate(), folly::MultiLevelTimeSeries< VT, CT >::rate(), folly::small_vector< Observer< T > *, InlineObservers >::rbegin(), folly::basic_fbstring< char >::rbegin(), proxygen::readFileToIOBuf(), readThread(), folly::FutureDAG::remove(), folly::basic_fbstring< E, T, A, Storage >::replaceAliased(), folly::basic_fbstring< E, T, A, Storage >::replaceImpl(), folly::basic_fbstring< E, T, A, Storage >::replaceImplDiscr(), folly::small_vector< Observer< T > *, InlineObservers >::resize(), folly::TimeoutQueue::runInternal(), folly::Random::seed(), testing::internal::UnitTestImpl::set_catch_exceptions(), folly::SSLContext::setCipherList(), folly::SSLContext::setSignatureAlgorithms(), folly::hash::SpookyHashV1::Short(), folly::hash::SpookyHashV2::Short(), folly::small_vector< Observer< T > *, InlineObservers >::shrink_to_fit(), testing::internal::StringStreamToString(), folly::io::test::supportedCodecs(), folly::BenchmarkSuspender::tally(), fizz::test::TEST(), TEST(), TEST_F(), testConnectOptWrite(), folly::BasicFixedString< Char, N >::toRange(), folly::BasicFixedString< Char, N >::toStdString(), folly::io::detail::CursorBase< Cursor, const IOBuf >::totalLength(), folly::tryDecodeVarint(), folly::json_pointer::unescape(), folly::hash::SpookyHashV1::Update(), folly::hash::SpookyHashV2::Update(), folly::sorted_vector_set< folly::RequestData * >::upper_bound(), folly::sorted_vector_map< Key, Value, Compare, Allocator, GrowthPolicy, Container >::upper_bound(), proxygen::CodecUtil::validateHeaderValue(), and testing::internal::GTestFlagSaver::~GTestFlagSaver().

62  {
63  return instance.vec.end();
64 }
auto folly::test::end ( const TestAdlIterable instance)

Definition at line 65 of file ForeachTest.cpp.

References folly::test::TestAdlIterable::vec.

65  {
66  return instance.vec.end();
67 }
template<typename Example , typename Req = bool, typename Mutex = std::mutex, template< typename > class Atom = std::atomic>
uint64_t folly::test::fc_test ( int  nthreads,
int  lines,
int  numRecs,
int  work,
int  ops,
bool  combining,
bool  dedicated,
bool  tc,
bool  syncops,
bool  excl = false,
bool  allocAll = false 
)

Definition at line 44 of file FlatCombiningTestHelpers.h.

References BENCHMARK_SUSPEND, count, folly::BenchmarkSuspender::dismiss(), doWork(), i, mutex, now(), nthreads, ops, start, sum(), folly::pushmi::detail::t, tc, threads, uint64_t, and v.

55  {
56  using FC = FlatCombining<Example, Mutex, Atom, Req>;
57  using Rec = typename FC::Rec;
58 
60 
61  std::atomic<bool> start{false};
62  std::atomic<int> started{0};
63  Example ex(lines, dedicated, numRecs);
64  std::atomic<uint64_t> total{0};
65  bool mutex = false;
66 
67  if (allocAll) {
68  std::vector<Rec*> v(numRecs);
69  for (int i = 0; i < numRecs; ++i) {
70  v[i] = ex.allocRec();
71  }
72  for (int i = numRecs; i > 0; --i) {
73  ex.freeRec(v[i - 1]);
74  }
75  }
76 
77  std::vector<std::thread> threads(nthreads);
78  for (int tid = 0; tid < nthreads; ++tid) {
79  threads[tid] = std::thread([&, tid] {
80  started.fetch_add(1);
81  Rec* myrec = (combining && tc) ? ex.allocRec() : nullptr;
82  uint64_t sum = 0;
83  while (!start.load()) {
84  ;
85  }
86 
87  if (!combining) {
88  // no combining
89  for (int i = tid; i < ops; i += nthreads) {
90  sum += ex.fetchAddNoFC(1);
91  doWork(work); // unrelated work
92  }
93  } else if (syncops) {
94  // sync combining
95  for (int i = tid; i < ops; i += nthreads) {
96  sum += ex.fetchAdd(1, myrec);
97  doWork(work); // unrelated work
98  }
99  } else {
100  // async combining
101  for (int i = tid; i < ops; i += nthreads) {
102  ex.add(1, myrec);
103  doWork(work); // unrelated work
104  }
105  }
106 
107  if (excl) {
108  // test of exclusive access through a lock holder
109  {
110  std::unique_lock<Mutex> l;
111  ex.holdLock(l);
112  CHECK(!mutex);
113  mutex = true;
114  VLOG(2) << tid << " " << ex.getVal() << " ...........";
115  using namespace std::chrono_literals;
116  /* sleep override */ // for coverage
117  std::this_thread::sleep_for(10ms);
118  VLOG(2) << tid << " " << ex.getVal() << " ===========";
119  CHECK(mutex);
120  mutex = false;
121  }
122  // test of explicit acquisition and release of exclusive access
123  ex.acquireExclusive();
124  {
125  CHECK(!mutex);
126  mutex = true;
127  VLOG(2) << tid << " " << ex.getVal() << " ...........";
128  using namespace std::chrono_literals;
129  /* sleep override */ // for coverage
130  std::this_thread::sleep_for(10ms);
131  VLOG(2) << tid << " " << ex.getVal() << " ===========";
132  CHECK(mutex);
133  mutex = false;
134  }
135  ex.releaseExclusive();
136  }
137 
138  total.fetch_add(sum);
139  if (combining && tc) {
140  ex.freeRec(myrec);
141  }
142  });
143  }
144 
145  while (started.load() < nthreads) {
146  ;
147  }
148  auto tbegin = std::chrono::steady_clock::now();
149 
150  // begin time measurement
151  susp.dismiss();
152  start.store(true);
153 
154  for (auto& t : threads) {
155  t.join();
156  }
157 
158  if (!syncops) {
159  // complete any pending asynch ops
160  ex.drainAll();
161  }
162 
163  // end time measurement
164  uint64_t duration = 0;
166  auto tend = std::chrono::steady_clock::now();
167  CHECK_EQ(ops, ex.getVal());
168  if (syncops) {
169  uint64_t n = (uint64_t)ops;
170  uint64_t expected = n * (n - 1) / 2;
171  CHECK_EQ(expected, total);
172  }
173  duration =
174  std::chrono::duration_cast<std::chrono::nanoseconds>(tend - tbegin)
175  .count();
176  }
177  return duration;
178 }
std::atomic< int64_t > sum(0)
auto v
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
std::chrono::steady_clock::time_point now()
static bool dedicated
void doWork(int work)
std::vector< std::thread::id > threads
static int nthreads
static bool tc
const int ops
S lines(StringPiece source)
Definition: String.h:80
auto start
int * count
static bool syncops
std::mutex mutex
detail::FutexResult folly::test::futexWaitImpl ( const detail::Futex< ManualAtomic > *  ,
uint32_t  ,
std::chrono::system_clock::time_point const *  ,
std::chrono::steady_clock::time_point const *  ,
uint32_t   
)

Definition at line 163 of file DistributedMutexTest.cpp.

168  {
169  ManualSchedule::beforeSharedAccess();
170  return detail::FutexResult::AWOKEN;
171 }
detail::FutexResult folly::test::futexWaitImpl ( const detail::Futex< DeterministicAtomic > *  futex,
uint32_t  expected,
std::chrono::system_clock::time_point const *  absSystemTimeout,
std::chrono::steady_clock::time_point const *  absSteadyTimeout,
uint32_t  waitMask 
)

Definition at line 310 of file DeterministicSchedule.cpp.

References folly::test::DeterministicSchedule::afterSharedAccess(), folly::test::DeterministicSchedule::beforeSharedAccess(), FOLLY_TEST_DSCHED_VLOG, futexQueues, folly::test::DeterministicSchedule::getRandNumber(), folly::detail::INTERRUPTED, and folly::detail::TIMEDOUT.

315  {
316  using namespace test;
317  using namespace std::chrono;
318  using namespace folly::detail;
319 
320  bool hasTimeout = absSystemTimeout != nullptr || absSteadyTimeout != nullptr;
321  bool awoken = false;
322  FutexResult result = FutexResult::AWOKEN;
323 
324  DeterministicSchedule::beforeSharedAccess();
326  "futexWait(" << futex << ", " << std::hex << expected << ", .., "
327  << std::hex << waitMask << ") beginning..");
328  futexLock.lock();
329  if (futex->load_direct() == expected) {
330  auto& queue = futexQueues[futex];
331  queue.emplace_back(waitMask, &awoken);
332  auto ours = queue.end();
333  ours--;
334  while (!awoken) {
335  futexLock.unlock();
336  DeterministicSchedule::afterSharedAccess();
337  DeterministicSchedule::beforeSharedAccess();
338  futexLock.lock();
339 
340  // Simulate spurious wake-ups, timeouts each time with
341  // a 10% probability if we haven't been woken up already
342  if (!awoken && hasTimeout &&
343  DeterministicSchedule::getRandNumber(100) < 10) {
344  assert(futexQueues.count(futex) != 0 && &futexQueues[futex] == &queue);
345  queue.erase(ours);
346  if (queue.empty()) {
347  futexQueues.erase(futex);
348  }
349  // Simulate ETIMEDOUT 90% of the time and other failures
350  // remaining time
351  result = DeterministicSchedule::getRandNumber(100) >= 10
352  ? FutexResult::TIMEDOUT
353  : FutexResult::INTERRUPTED;
354  break;
355  }
356  }
357  } else {
358  result = FutexResult::VALUE_CHANGED;
359  }
360  futexLock.unlock();
361 
362  char const* resultStr = "?";
363  switch (result) {
364  case FutexResult::AWOKEN:
365  resultStr = "AWOKEN";
366  break;
367  case FutexResult::TIMEDOUT:
368  resultStr = "TIMEDOUT";
369  break;
370  case FutexResult::INTERRUPTED:
371  resultStr = "INTERRUPTED";
372  break;
373  case FutexResult::VALUE_CHANGED:
374  resultStr = "VALUE_CHANGED";
375  break;
376  }
378  "futexWait(" << futex << ", " << std::hex << expected << ", .., "
379  << std::hex << waitMask << ") -> " << resultStr);
380  DeterministicSchedule::afterSharedAccess();
381  return result;
382 }
static std::mutex futexLock
#define FOLLY_TEST_DSCHED_VLOG(...)
static std::unordered_map< const detail::Futex< DeterministicAtomic > *, std::list< std::pair< uint32_t, bool * > > > futexQueues
detail::FutexResult folly::test::futexWaitImpl ( const detail::Futex< test::DeterministicAtomic > *  futex,
uint32_t  expected,
std::chrono::system_clock::time_point const *  absSystemTime,
std::chrono::steady_clock::time_point const *  absSteadyTime,
uint32_t  waitMask 
)
int folly::test::futexWakeImpl ( const detail::Futex< ManualAtomic > *  ,
int  ,
uint32_t   
)

Futex extensions for ManualAtomic

Note that doing nothing in these should still result in a program that is well defined, since futex wait calls should be tolerant to spurious wakeups

Definition at line 159 of file DistributedMutexTest.cpp.

159  {
160  ManualSchedule::beforeSharedAccess();
161  return 1;
162 }
int folly::test::futexWakeImpl ( const detail::Futex< test::DeterministicAtomic > *  futex,
int  count,
uint32_t  wakeMask 
)

Definition at line 384 of file DeterministicSchedule.cpp.

References folly::test::DeterministicSchedule::afterSharedAccess(), folly::test::DeterministicSchedule::beforeSharedAccess(), count, FOLLY_TEST_DSCHED_VLOG, and futexQueues.

387  {
388  using namespace test;
389  using namespace std::chrono;
390 
391  int rv = 0;
392  DeterministicSchedule::beforeSharedAccess();
393  futexLock.lock();
394  if (futexQueues.count(futex) > 0) {
395  auto& queue = futexQueues[futex];
396  auto iter = queue.begin();
397  while (iter != queue.end() && rv < count) {
398  auto cur = iter++;
399  if ((cur->first & wakeMask) != 0) {
400  *(cur->second) = true;
401  rv++;
402  queue.erase(cur);
403  }
404  }
405  if (queue.empty()) {
406  futexQueues.erase(futex);
407  }
408  }
409  futexLock.unlock();
411  "futexWake(" << futex << ", " << count << ", " << std::hex << wakeMask
412  << ") -> " << rv);
413  DeterministicSchedule::afterSharedAccess();
414  return rv;
415 }
static std::mutex futexLock
#define FOLLY_TEST_DSCHED_VLOG(...)
int * count
static std::unordered_map< const detail::Futex< DeterministicAtomic > *, std::list< std::pair< uint32_t, bool * > > > futexQueues
std::string folly::test::glogErrorPattern ( )
inline

Use these patterns together with CaptureFD and EXPECT_PCRE_MATCH() to test for the presence (or absence) of log lines at a particular level:

CaptureFD stderr(2); LOG(INFO) << "All is well"; EXPECT_NO_PCRE_MATCH(glogErrOrWarnPattern(), stderr.readIncremental()); LOG(ERROR) << "Uh-oh"; EXPECT_PCRE_MATCH(glogErrorPattern(), stderr.readIncremental());

Definition at line 205 of file TestUtil.h.

Referenced by TEST().

205  {
206  return ".*(^|\n)E[0-9].*";
207 }
std::string folly::test::glogErrOrWarnPattern ( )
inline

Definition at line 212 of file TestUtil.h.

Referenced by TEST().

212  {
213  return ".*(^|\n)[EW][0-9].*";
214 }
std::string folly::test::glogWarningPattern ( )
inline

Definition at line 208 of file TestUtil.h.

Referenced by TEST().

208  {
209  return ".*(^|\n)W[0-9].*";
210 }
folly::test::MATCHER_P ( BufMatches  ,
expected  ,
""   
)

Definition at line 54 of file WriteChainAsyncTransportWrapperTest.cpp.

References folly::eq.

54  {
56  return eq(*arg, *expected);
57 }
template<typename Func >
auto folly::test::msvcSuppressAbortOnInvalidParams ( Func  func) -> decltype(func())

Definition at line 166 of file TestUtil.h.

References folly::test::detail::disableInvalidParameters(), folly::test::detail::enableInvalidParameters(), and SCOPE_EXIT.

Referenced by folly::WriteErrorCallback::readDataAvailable(), TEST(), and TEST_F().

166  {
167  auto savedState = detail::disableInvalidParameters();
168  SCOPE_EXIT {
170  };
171  return func();
172 }
#define SCOPE_EXIT
Definition: ScopeGuard.h:274
SavedState disableInvalidParameters()
Definition: TestUtil.cpp:146
void enableInvalidParameters(SavedState)
Definition: TestUtil.cpp:169
bool folly::test::operator== ( const MovableInt a,
const MovableInt b 
)

Definition at line 58 of file TupleOpsTest.cpp.

References folly::test::MovableInt::value().

Referenced by TEST().

58  {
59  return a.value() == b.value();
60 }
char b
char a
template<bool MayBlock, template< typename > class Atom>
void folly::test::run_basic_test ( )

Definition at line 29 of file BatonTestHelpers.h.

References Atom, b, folly::Baton< MayBlock, Atom >::post(), and folly::Baton< MayBlock, Atom >::wait().

29  {
30  Baton<MayBlock, Atom> b;
31  b.post();
32  b.wait();
33 }
char b
template<bool MayBlock, template< typename > class Atom, typename Clock >
void folly::test::run_basic_timed_wait_tests ( )

Definition at line 57 of file BatonTestHelpers.h.

References Atom, b, EXPECT_TRUE, now(), folly::Baton< MayBlock, Atom >::post(), and folly::Baton< MayBlock, Atom >::try_wait_until().

57  {
58  Baton<MayBlock, Atom> b;
59  b.post();
60  // tests if early delivery works fine
61  EXPECT_TRUE(b.try_wait_until(Clock::now()));
62 }
char b
std::chrono::steady_clock::time_point now()
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
template<bool MayBlock, template< typename > class Atom>
void folly::test::run_pingpong_test ( int  numRounds)

Definition at line 36 of file BatonTestHelpers.h.

References a, Atom, b, i, folly::test::DeterministicSchedule::join(), and folly::test::DeterministicSchedule::thread().

36  {
37  using B = Baton<MayBlock, Atom>;
38  B batons[17];
39  B& a = batons[0];
40  B& b = batons[16]; // to get it on a different cache line
41  auto thr = DSched::thread([&] {
42  for (int i = 0; i < numRounds; ++i) {
43  a.wait();
44  a.reset();
45  b.post();
46  }
47  });
48  for (int i = 0; i < numRounds; ++i) {
49  a.post();
50  b.wait();
51  b.reset();
52  }
53  DSched::join(thr);
54 }
char b
static std::thread thread(Func &&func, Args &&...args)
char a
static void join(std::thread &child)
#define B(name, bit)
Definition: CpuId.h:178
uint64_t folly::test::run_test ( int  nthreads,
int  lines,
int  numRecs,
int  work,
int  ops,
bool  combining,
bool  simple,
bool  dedicated,
bool  tc,
bool  syncops,
bool  excl = false,
bool  allocAll = false 
)

Definition at line 180 of file FlatCombiningTestHelpers.h.

References dedicated, folly::gen::lines(), M, mutex, nthreads, ops, syncops, and tc.

Referenced by BENCHMARK(), BENCHMARK_RELATIVE(), test(), and TEST_P().

192  {
193  using M = std::mutex;
194  if (simple) {
195  using Example = FcSimpleExample<M>;
196  return fc_test<Example, bool, M>(
197  nthreads,
198  lines,
199  numRecs,
200  work,
201  ops,
202  combining,
203  dedicated,
204  tc,
205  syncops,
206  excl,
207  allocAll);
208  } else {
209  using Example = FcCustomExample<Req, M>;
210  return fc_test<Example, Req, M>(
211  nthreads,
212  lines,
213  numRecs,
214  work,
215  ops,
216  combining,
217  dedicated,
218  tc,
219  syncops,
220  excl,
221  allocAll);
222  }
223 }
static bool simple
static bool dedicated
static int nthreads
static bool tc
const int ops
S lines(StringPiece source)
Definition: String.h:80
**Optimized Holders **The template hazptr_array< M > provides most of the functionality *of M hazptr_holder s but with faster construction destruction *for M
Definition: Hazptr.h:104
static bool syncops
std::mutex mutex
template<bool MayBlock, template< typename > class Atom, typename Clock >
void folly::test::run_timed_wait_regular_test ( )

Definition at line 77 of file BatonTestHelpers.h.

References b, EXPECT_TRUE, folly::test::DeterministicSchedule::join(), now(), folly::Baton< MayBlock, Atom >::post(), folly::test::DeterministicSchedule::thread(), folly::Baton< MayBlock, Atom >::try_wait_until(), and folly::value().

77  {
78  Baton<MayBlock, Atom> b;
79 
80  auto thr = DSched::thread([&] {
81  // To wait forever we'd like to use time_point<Clock>::max, but
82  // std::condition_variable does math to convert the timeout to
83  // system_clock without handling overflow.
84  auto farFuture = Clock::now() + std::chrono::hours(1000);
85  bool rv = b.try_wait_until(farFuture);
86  if (!std::is_same<Atom<int>, DeterministicAtomic<int>>::value) {
87  // DeterministicAtomic ignores actual times, so doesn't guarantee
88  // a lack of timeout
89  EXPECT_TRUE(rv);
90  }
91  });
92 
93  if (!std::is_same<Atom<int>, DeterministicAtomic<int>>::value) {
94  // If we are using std::atomic (or EmulatedFutexAtomic) then
95  // a sleep here guarantees to a large extent that 'thr' will
96  // execute wait before we post it, thus testing late delivery. For
97  // DeterministicAtomic, we just rely on DeterministicSchedule to do
98  // the scheduling. The test won't fail if we lose the race, we just
99  // don't get coverage.
100  std::this_thread::sleep_for(std::chrono::milliseconds(2));
101  }
102 
103  b.post();
104  DSched::join(thr);
105 }
char b
std::chrono::steady_clock::time_point now()
static std::thread thread(Func &&func, Args &&...args)
static const char *const value
Definition: Conv.cpp:50
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
static void join(std::thread &child)
template<bool MayBlock, template< typename > class Atom, typename Clock >
void folly::test::run_timed_wait_tmo_tests ( )

Definition at line 65 of file BatonTestHelpers.h.

References Atom, b, EXPECT_FALSE, folly::test::DeterministicSchedule::join(), now(), folly::test::DeterministicSchedule::thread(), and folly::Baton< MayBlock, Atom >::try_wait_until().

65  {
66  Baton<MayBlock, Atom> b;
67 
68  auto thr = DSched::thread([&] {
69  bool rv = b.try_wait_until(Clock::now() + std::chrono::milliseconds(1));
70  // main thread is guaranteed to not post until timeout occurs
71  EXPECT_FALSE(rv);
72  });
73  DSched::join(thr);
74 }
char b
std::chrono::steady_clock::time_point now()
static std::thread thread(Func &&func, Args &&...args)
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
static void join(std::thread &child)
template<bool MayBlock, template< typename > class Atom>
void folly::test::run_try_wait_tests ( )

Definition at line 108 of file BatonTestHelpers.h.

References b, EXPECT_FALSE, EXPECT_TRUE, folly::Baton< MayBlock, Atom >::post(), folly::Baton< MayBlock, Atom >::ready(), and folly::Baton< MayBlock, Atom >::try_wait().

108  {
109  Baton<MayBlock, Atom> b;
110  EXPECT_FALSE(b.ready());
111  EXPECT_FALSE(b.try_wait());
112  b.post();
113  EXPECT_TRUE(b.ready());
114  EXPECT_TRUE(b.try_wait());
115 }
char b
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
void folly::test::runCloseTest ( bool  abortive)

Definition at line 139 of file ShutdownSocketSetTest.cpp.

References c, folly::netops::close(), folly::test::Server::closeClients(), createConnectedSocket(), EXPECT_EQ, folly::test::Server::join(), folly::test::Server::port(), fizz::detail::read(), and folly::test::Server::stop().

Referenced by TEST().

139  {
140  Server server;
141 
142  int sock = createConnectedSocket(server.port());
143 
144  std::thread stopper([&server, abortive] {
145  std::this_thread::sleep_for(std::chrono::milliseconds(200));
146  server.stop(abortive);
147  server.join();
148  });
149 
150  char c;
151  int r = read(sock, &c, 1);
152  if (abortive) {
153  int e = errno;
154  EXPECT_EQ(-1, r);
155  EXPECT_EQ(ECONNRESET, e);
156  } else {
157  EXPECT_EQ(0, r);
158  }
159 
160  close(sock);
161 
162  stopper.join();
163 
164  EXPECT_EQ(0, server.closeClients(false)); // closed by server when it exited
165 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
int createConnectedSocket(int port)
size_t read(T &out, folly::io::Cursor &cursor)
Definition: Types-inl.h:258
char c
int close(NetworkSocket s)
Definition: NetOps.cpp:90
void folly::test::runKillTest ( bool  abortive)

Definition at line 175 of file ShutdownSocketSetTest.cpp.

References c, folly::netops::close(), folly::test::Server::closeClients(), createConnectedSocket(), EXPECT_EQ, folly::test::Server::join(), folly::test::Server::port(), fizz::detail::read(), and folly::ShutdownSocketSet::shutdownAll().

Referenced by TEST().

175  {
176  Server server;
177 
178  int sock = createConnectedSocket(server.port());
179 
180  std::thread killer([&server, abortive] {
181  std::this_thread::sleep_for(std::chrono::milliseconds(200));
182  shutdownSocketSet.shutdownAll(abortive);
183  server.join();
184  });
185 
186  char c;
187  int r = read(sock, &c, 1);
188 
189  // "abortive" is just a hint for ShutdownSocketSet, so accept both
190  // behaviors
191  if (abortive) {
192  if (r == -1) {
193  EXPECT_EQ(ECONNRESET, errno);
194  } else {
195  EXPECT_EQ(r, 0);
196  }
197  } else {
198  EXPECT_EQ(0, r);
199  }
200 
201  close(sock);
202 
203  killer.join();
204 
205  // NOT closed by server when it exited
206  EXPECT_EQ(1, server.closeClients(false));
207 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
int createConnectedSocket(int port)
size_t read(T &out, folly::io::Cursor &cursor)
Definition: Types-inl.h:258
ShutdownSocketSet shutdownSocketSet
void shutdownAll(bool abortive=false)
char c
int close(NetworkSocket s)
Definition: NetOps.cpp:90
unsigned folly::test::staticTracepointTestFunc ( unsigned  v)

Definition at line 24 of file StaticTracepointTestModule.cpp.

References FOLLY_SDT_WITH_SEMAPHORE, and v.

Referenced by TEST().

24  {
25  unsigned res = v * v;
26  FOLLY_SDT_WITH_SEMAPHORE(folly, test_semaphore_extern, v, res);
27  return res;
28 }
auto v
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
#define FOLLY_SDT_WITH_SEMAPHORE(provider, name,...)
folly::test::TEST ( AtomicBitSet  ,
Simple   
)

Definition at line 26 of file AtomicBitSetTest.cpp.

References EXPECT_EQ, EXPECT_FALSE, i, folly::AtomicBitSet< N >::reset(), folly::AtomicBitSet< N >::set(), and folly::AtomicBitSet< N >::size().

26  {
27  constexpr size_t kSize = 1000;
28  AtomicBitSet<kSize> bs;
29 
30  EXPECT_EQ(kSize, bs.size());
31 
32  for (size_t i = 0; i < kSize; ++i) {
33  EXPECT_FALSE(bs[i]);
34  }
35 
36  bs.set(42);
37  for (size_t i = 0; i < kSize; ++i) {
38  EXPECT_EQ(i == 42, bs[i]);
39  }
40 
41  bs.set(43);
42  for (size_t i = 0; i < kSize; ++i) {
43  EXPECT_EQ((i == 42 || i == 43), bs[i]);
44  }
45 
46  bs.reset(42);
47  for (size_t i = 0; i < kSize; ++i) {
48  EXPECT_EQ((i == 43), bs[i]);
49  }
50 
51  bs.reset(43);
52  for (size_t i = 0; i < kSize; ++i) {
53  EXPECT_FALSE(bs[i]);
54  }
55 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
folly::test::TEST ( TupleOps  ,
Copiable   
)

Definition at line 27 of file TupleOpsTest.cpp.

References EXPECT_EQ, EXPECT_TRUE, std::tr1::make_tuple(), string, folly::pushmi::detail::t, folly::tuplePrepend(), and folly::value().

27  {
28  auto t = std::make_tuple(10, std::string("hello"), 30);
29 
30  EXPECT_EQ(10, std::get<0>(t));
31  auto t1 = tupleRange<1>(t);
32  EXPECT_EQ("hello", std::get<0>(t1));
33  EXPECT_EQ(2, std::tuple_size<decltype(t1)>::value);
34  auto t2 = tupleRange<1, 1>(t);
35  EXPECT_EQ(1, std::tuple_size<decltype(t2)>::value);
36  EXPECT_EQ("hello", std::get<0>(t2));
37  EXPECT_EQ(30, std::get<0>(tupleRange<1>(tupleRange<1>(t))));
38 
39  EXPECT_TRUE(t == tuplePrepend(std::get<0>(t), tupleRange<1>(t)));
40 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
tuple make_tuple()
Definition: gtest-tuple.h:675
static const char *const value
Definition: Conv.cpp:50
auto tuplePrepend(T &&car, U &&cdr) -> decltype(std::tuple_cat(std::make_tuple(std::forward< T >(car)), std::forward< U >(cdr)))
Definition: TupleOps.h:117
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
const char * string
Definition: Conv.cpp:212
folly::test::TEST ( MPMCPipeline  ,
Trivial   
)

Definition at line 30 of file MPMCPipelineTest.cpp.

References a, folly::MPMCPipeline< In, Stages >::blockingRead(), folly::MPMCPipeline< In, Stages >::blockingReadStage(), folly::MPMCPipeline< In, Stages >::blockingWrite(), folly::MPMCPipeline< In, Stages >::blockingWriteStage(), EXPECT_EQ, s, folly::MPMCPipeline< In, Stages >::sizeGuess(), string, ticket, and val.

30  {
31  MPMCPipeline<int, std::string> a(2, 2);
32  EXPECT_EQ(0, a.sizeGuess());
33  a.blockingWrite(42);
34  EXPECT_EQ(1, a.sizeGuess());
35 
36  int val;
37  auto ticket = a.blockingReadStage<0>(val);
38  EXPECT_EQ(42, val);
39  EXPECT_EQ(1, a.sizeGuess());
40 
41  a.blockingWriteStage<0>(ticket, "hello world");
42  EXPECT_EQ(1, a.sizeGuess());
43 
44  std::string s;
45 
46  a.blockingRead(s);
47  EXPECT_EQ("hello world", s);
48  EXPECT_EQ(0, a.sizeGuess());
49 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
double val
Definition: String.cpp:273
static constexpr StringPiece ticket
char a
const char * string
Definition: Conv.cpp:212
static set< string > s
folly::test::TEST ( Overload  ,
BoostVariant   
)

Definition at line 36 of file OverloadTest.cpp.

References EXPECT_EQ, EXPECT_TRUE, folly::test::One::toString(), folly::value(), and folly::variant_match().

36  {
37  OneOrTwo one(One{});
38  OneOrTwo two(Two{});
39 
41  one, [](const One&) { return true; }, [](const Two&) { return false; }));
43  two, [](const One&) { return false; }, [](const Two&) { return true; }));
44 
45  auto toString = [](const auto& variant) {
46  return variant_match(
47  variant, [](const auto& value) { return value.toString(); });
48  };
49  EXPECT_EQ(toString(one), "One");
50  EXPECT_EQ(toString(two), "Two");
51 }
folly::StringPiece toString(StateEnum state)
Definition: State.cpp:16
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static const char *const value
Definition: Conv.cpp:50
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
decltype(auto) variant_match(Variant &&variant, Cases &&...cases)
Definition: Overload.h:74
boost::variant< One, Two > OneOrTwo
folly::test::TEST ( ExceptionTest  ,
Simple   
)

Definition at line 39 of file ExceptionTest.cpp.

References ASSERT_TRUE, folly::checkFopenError(), folly::checkFopenErrorExplicit(), folly::checkKernelError(), folly::checkPosixError(), folly::checkUnixError(), folly::checkUnixErrorExplicit(), EXPECT_NO_THROW, EXPECT_SYSTEM_ERROR, folly::test::TemporaryDirectory::path(), SCOPE_EXIT, folly::throwSystemError(), and folly::throwSystemErrorExplicit().

39  {
40  // Make sure errno isn't used when we don't want it to, set it to something
41  // else than what we set when we call Explicit functions
42  errno = ERANGE;
43  EXPECT_SYSTEM_ERROR(throwSystemErrorExplicit(EIO, "hello"), EIO, "hello");
44  errno = ERANGE;
46  throwSystemErrorExplicit(EIO, "hello", " world"), EIO, "hello world");
47  errno = ERANGE;
49  throwSystemError("hello", " world"), ERANGE, "hello world");
50 
51  EXPECT_NO_THROW(checkPosixError(0, "hello", " world"));
52  errno = ERANGE;
54  checkPosixError(EIO, "hello", " world"), EIO, "hello world");
55 
56  EXPECT_NO_THROW(checkKernelError(0, "hello", " world"));
57  EXPECT_NO_THROW(checkKernelError(EIO, "hello", " world"));
58  errno = ERANGE;
60  checkKernelError(-EIO, "hello", " world"), EIO, "hello world");
61 
62  EXPECT_NO_THROW(checkUnixError(0, "hello", " world"));
63  EXPECT_NO_THROW(checkUnixError(1, "hello", " world"));
64  errno = ERANGE;
66  checkUnixError(-1, "hello", " world"), ERANGE, "hello world");
67 
68  EXPECT_NO_THROW(checkUnixErrorExplicit(0, EIO, "hello", " world"));
69  EXPECT_NO_THROW(checkUnixErrorExplicit(1, EIO, "hello", " world"));
70  errno = ERANGE;
72  checkUnixErrorExplicit(-1, EIO, "hello", " world"), EIO, "hello world");
73 
74  TemporaryDirectory tmpdir;
75  auto exnpath = tmpdir.path() / "ExceptionTest";
76  auto fp = fopen(exnpath.string().c_str(), "w+b");
77  ASSERT_TRUE(fp != nullptr);
78  SCOPE_EXIT {
79  fclose(fp);
80  };
81 
82  EXPECT_NO_THROW(checkFopenError(fp, "hello", " world"));
83  errno = ERANGE;
85  checkFopenError(nullptr, "hello", " world"), ERANGE, "hello world");
86 
87  EXPECT_NO_THROW(checkFopenErrorExplicit(fp, EIO, "hello", " world"));
88  errno = ERANGE;
90  checkFopenErrorExplicit(nullptr, EIO, "hello", " world"),
91  EIO,
92  "hello world");
93 }
#define EXPECT_NO_THROW(statement)
Definition: gtest.h:1845
#define SCOPE_EXIT
Definition: ScopeGuard.h:274
void checkUnixErrorExplicit(ssize_t ret, int savedErrno, Args &&...args)
Definition: Exception.h:108
void checkPosixError(int err, Args &&...args)
Definition: Exception.h:83
void checkFopenErrorExplicit(FILE *fp, int savedErrno, Args &&...args)
Definition: Exception.h:125
void checkFopenError(FILE *fp, Args &&...args)
Definition: Exception.h:118
void checkKernelError(ssize_t ret, Args &&...args)
Definition: Exception.h:92
void throwSystemErrorExplicit(int err, const char *msg)
Definition: Exception.h:65
void checkUnixError(ssize_t ret, Args &&...args)
Definition: Exception.h:101
#define EXPECT_SYSTEM_ERROR(statement, err, msg)
void throwSystemError(Args &&...args)
Definition: Exception.h:76
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
folly::test::TEST ( MPMCPipeline  ,
TrivialAmplification   
)

Definition at line 51 of file MPMCPipelineTest.cpp.

References a, folly::MPMCPipeline< In, Stages >::blockingRead(), folly::MPMCPipeline< In, Stages >::blockingReadStage(), folly::MPMCPipeline< In, Stages >::blockingWrite(), folly::MPMCPipeline< In, Stages >::blockingWriteStage(), EXPECT_EQ, s, folly::MPMCPipeline< In, Stages >::sizeGuess(), string, ticket, and val.

51  {
52  MPMCPipeline<int, MPMCPipelineStage<std::string, 2>> a(2, 2);
53  EXPECT_EQ(0, a.sizeGuess());
54  a.blockingWrite(42);
55  EXPECT_EQ(2, a.sizeGuess());
56 
57  int val;
58  auto ticket = a.blockingReadStage<0>(val);
59  EXPECT_EQ(42, val);
60  EXPECT_EQ(2, a.sizeGuess());
61 
62  a.blockingWriteStage<0>(ticket, "hello world");
63  EXPECT_EQ(2, a.sizeGuess());
64  a.blockingWriteStage<0>(ticket, "goodbye");
65  EXPECT_EQ(2, a.sizeGuess());
66 
67  std::string s;
68 
69  a.blockingRead(s);
70  EXPECT_EQ("hello world", s);
71  EXPECT_EQ(1, a.sizeGuess());
72 
73  a.blockingRead(s);
74  EXPECT_EQ("goodbye", s);
75  EXPECT_EQ(0, a.sizeGuess());
76 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
double val
Definition: String.cpp:273
static constexpr StringPiece ticket
char a
const char * string
Definition: Conv.cpp:212
static set< string > s
folly::test::TEST ( Overload  ,
DiscriminatedPtr   
)

Definition at line 53 of file OverloadTest.cpp.

References EXPECT_EQ, EXPECT_TRUE, folly::test::One::toString(), folly::value(), and folly::variant_match().

53  {
54  using V = DiscriminatedPtr<One, Two>;
55  One one_obj;
56  Two two_obj;
57  V one_ptr(&one_obj);
58  V two_ptr(&two_obj);
59 
61  one_ptr,
62  [](const One*) { return true; },
63  [](const Two*) { return false; }));
65  two_ptr,
66  [](const One*) { return false; },
67  [](const Two*) { return true; }));
68 
69  auto toString = [](const auto& variant) {
70  return variant_match(
71  variant, [](const auto* value) { return value->toString(); });
72  };
73  EXPECT_EQ(toString(one_ptr), "One");
74  EXPECT_EQ(toString(two_ptr), "Two");
75 }
folly::StringPiece toString(StateEnum state)
Definition: State.cpp:16
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static const char *const value
Definition: Conv.cpp:50
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
decltype(auto) variant_match(Variant &&variant, Cases &&...cases)
Definition: Overload.h:74
folly::test::TEST ( RecordIOTest  ,
Simple   
)

Definition at line 57 of file RecordIOTest.cpp.

References ASSERT_FALSE, folly::RecordIOReader::begin(), folly::RecordIOReader::end(), EXPECT_EQ, EXPECT_TRUE, folly::test::TemporaryFile::fd(), folly::gen::first, and folly::RecordIOWriter::write().

57  {
58  TemporaryFile file;
59  {
60  RecordIOWriter writer(File(file.fd()));
61  writer.write(iobufs({"hello ", "world"}));
62  writer.write(iobufs({"goodbye"}));
63  }
64  {
65  RecordIOReader reader(File(file.fd()));
66  auto it = reader.begin();
67  ASSERT_FALSE(it == reader.end());
68  EXPECT_EQ("hello world", sp((it++)->first));
69  ASSERT_FALSE(it == reader.end());
70  EXPECT_EQ("goodbye", sp((it++)->first));
71  EXPECT_TRUE(it == reader.end());
72  }
73  {
74  RecordIOWriter writer(File(file.fd()));
75  writer.write(iobufs({"meow"}));
76  writer.write(iobufs({"woof"}));
77  }
78  {
79  RecordIOReader reader(File(file.fd()));
80  auto it = reader.begin();
81  ASSERT_FALSE(it == reader.end());
82  EXPECT_EQ("hello world", sp((it++)->first));
83  ASSERT_FALSE(it == reader.end());
84  EXPECT_EQ("goodbye", sp((it++)->first));
85  ASSERT_FALSE(it == reader.end());
86  EXPECT_EQ("meow", sp((it++)->first));
87  ASSERT_FALSE(it == reader.end());
88  EXPECT_EQ("woof", sp((it++)->first));
89  EXPECT_TRUE(it == reader.end());
90  }
91 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
constexpr detail::First first
Definition: Base-inl.h:2553
folly::test::TEST ( WriteChainAsyncTransportWrapperTest  ,
TestSimpleIov   
)

Definition at line 59 of file WriteChainAsyncTransportWrapperTest.cpp.

References testing::_, folly::IOBuf::copyBuffer(), EXPECT_CALL, and folly::WriteChainAsyncTransportWrapper< T >::writev().

59  {
60  TestWriteChainAsyncTransportWrapper transport;
61  auto buf = folly::IOBuf::copyBuffer("foo");
62 
63  EXPECT_CALL(transport, writeChain(_, BufMatches(buf.get()), _));
64 
65  auto iov = buf->getIov();
66  transport.writev(nullptr, iov.data(), iov.size());
67 }
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
folly::test::TEST ( TupleOps  ,
Movable   
)

Definition at line 62 of file TupleOpsTest.cpp.

References EXPECT_TRUE, std::tr1::make_tuple(), folly::test::MovableInt::MovableInt(), folly::gen::move, string, folly::T, folly::tuplePrepend(), and tupleTo().

62  {
63  auto t1 = std::make_tuple(MovableInt(10), std::string("hello"), 30);
64  auto t2 = std::make_tuple(MovableInt(10), std::string("hello"), 30);
65  auto t3 = std::make_tuple(MovableInt(10), std::string("hello"), 30);
66 
67  auto t1car = std::get<0>(std::move(t1));
68  auto t2cdr = tupleRange<1>(std::move(t2));
69 
70  EXPECT_TRUE(t3 == tuplePrepend(std::move(t1car), std::move(t2cdr)));
71 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
tuple make_tuple()
Definition: gtest-tuple.h:675
auto tuplePrepend(T &&car, U &&cdr) -> decltype(std::tuple_cat(std::make_tuple(std::forward< T >(car)), std::forward< U >(cdr)))
Definition: TupleOps.h:117
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
const char * string
Definition: Conv.cpp:212
folly::test::TEST ( ProgramOptionsTest  ,
Errors   
)

Definition at line 67 of file NestedCommandLineAppTest.cpp.

Referenced by TEST().

67  {
68  callHelper({}, 1);
69  callHelper({"--wtf", "foo"}, 1);
70  callHelper({"qux"}, 1);
71  callHelper({"--global-foo", "x", "foo"}, 1);
72 }
folly::test::TEST ( WriteChainAsyncTransportWrapperTest  ,
TestChainedIov   
)

Definition at line 69 of file WriteChainAsyncTransportWrapperTest.cpp.

References testing::_, folly::IOBuf::copyBuffer(), EXPECT_CALL, and folly::WriteChainAsyncTransportWrapper< T >::writev().

69  {
70  TestWriteChainAsyncTransportWrapper transport;
71  auto buf = folly::IOBuf::copyBuffer("hello");
72  buf->prependChain(folly::IOBuf::copyBuffer("world"));
73 
74  EXPECT_CALL(transport, writeChain(_, BufMatches(buf.get()), _));
75 
76  auto iov = buf->getIov();
77  transport.writev(nullptr, iov.data(), iov.size());
78 }
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
folly::test::TEST ( Varint  ,
Interface   
)

Definition at line 70 of file VarintTest.cpp.

References c, folly::decodeVarint(), and EXPECT_EQ.

70  {
71  // Make sure decodeVarint() accepts all of StringPiece, MutableStringPiece,
72  // ByteRange, and MutableByteRange.
73  char c = 0;
74 
75  StringPiece sp(&c, 1);
76  EXPECT_EQ(decodeVarint(sp), 0);
77 
78  MutableStringPiece msp(&c, 1);
79  EXPECT_EQ(decodeVarint(msp), 0);
80 
81  ByteRange br(reinterpret_cast<unsigned char*>(&c), 1);
82  EXPECT_EQ(decodeVarint(br), 0);
83 
84  MutableByteRange mbr(reinterpret_cast<unsigned char*>(&c), 1);
85  EXPECT_EQ(decodeVarint(mbr), 0);
86 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Range< char * > MutableStringPiece
Definition: Range.h:1162
uint64_t decodeVarint(Range< T * > &data)
Definition: Varint.h:135
Range< unsigned char * > MutableByteRange
Definition: Range.h:1164
Range< const unsigned char * > ByteRange
Definition: Range.h:1163
Range< const char * > StringPiece
char c
folly::test::TEST ( ProgramOptionsTest  ,
GFlagsStyleDefaultValues   
)

Definition at line 71 of file ProgramOptionsTest.cpp.

References EXPECT_EQ, and folly::GFLAGS.

71  {
72  EXPECT_EQ(
73  "flag_bool_true 1\n"
74  "flag_bool_false 0\n"
75  "flag_int 42\n"
76  "flag_string foo\n",
77  callHelper(ProgramOptionsStyle::GFLAGS, {}));
78 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
folly::test::TEST ( ProgramOptionsTest  ,
Help   
)

Definition at line 74 of file NestedCommandLineAppTest.cpp.

74  {
75  // Not actually checking help output, just verifying that help doesn't fail
76  callHelper({"--version"});
77  callHelper({"--help"});
78  callHelper({"--help", "foo"});
79  callHelper({"--help", "bar"});
80  callHelper({"--help", "--", "bar"});
81  callHelper({"help"});
82  callHelper({"help", "foo"});
83  callHelper({"help", "bar"});
84 
85  // wrong command name
86  callHelper({"--help", "qux"}, 1);
87  callHelper({"help", "qux"}, 1);
88 
89  // anything after -- is parsed as arguments
90  callHelper({"--", "help", "bar"}, 1);
91 }
folly::test::TEST ( Overload  ,
Pattern   
)

Definition at line 77 of file OverloadTest.cpp.

References folly::apply_visitor(), EXPECT_FALSE, EXPECT_TRUE, folly::overload(), and folly::variant_match().

77  {
78  OneOrTwo one(One{});
79  OneOrTwo two(Two{});
80 
81  auto is_one_overload = overload(
82  [](const One&) { return true; }, [](const Two&) { return false; });
83  EXPECT_TRUE(boost::apply_visitor(is_one_overload, one));
84  EXPECT_TRUE(variant_match(one, is_one_overload));
85  EXPECT_FALSE(variant_match(two, is_one_overload));
86 
87  auto is_two_overload = overload(
88  [](const One&) { return false; }, [](const Two&) { return true; });
89  EXPECT_TRUE(boost::apply_visitor(is_two_overload, two));
90  EXPECT_FALSE(variant_match(one, is_two_overload));
91  EXPECT_TRUE(variant_match(two, is_two_overload));
92 
93  auto is_one_copy = overload(is_one_overload);
94  auto is_one_const_copy =
95  overload(static_cast<const decltype(is_one_overload)&>(is_one_overload));
96  EXPECT_TRUE(variant_match(one, is_one_copy));
97  EXPECT_TRUE(variant_match(one, is_one_const_copy));
98  EXPECT_FALSE(variant_match(two, is_one_copy));
99  EXPECT_FALSE(variant_match(two, is_one_const_copy));
100 }
auto overload(Fns...fns) -> overload_fn< Fns... >
Definition: boosters.h:251
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
decltype(auto) apply_visitor(Visitor &&visitor, const DiscriminatedPtr< Args... > &variant)
decltype(auto) variant_match(Variant &&variant, Cases &&...cases)
Definition: Overload.h:74
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
boost::variant< One, Two > OneOrTwo
folly::test::TEST ( MPMCPipeline  ,
MultiThreaded   
)

Definition at line 78 of file MPMCPipelineTest.cpp.

References a, folly::MPMCPipeline< In, Stages >::blockingRead(), folly::MPMCPipeline< In, Stages >::blockingReadStage(), folly::MPMCPipeline< In, Stages >::blockingWrite(), folly::MPMCPipeline< In, Stages >::blockingWriteStage(), EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, i, folly::MPMCPipeline< In, Stages >::read(), folly::MPMCPipeline< In, Stages >::sizeGuess(), string, folly::pushmi::detail::t, threads, ticket, and val.

78  {
79  constexpr size_t numThreadsPerStage = 6;
80  MPMCPipeline<int, std::string, std::string> a(5, 5, 5);
81 
82  std::vector<std::thread> threads;
83  threads.reserve(numThreadsPerStage * 2 + 1);
84  for (size_t i = 0; i < numThreadsPerStage; ++i) {
85  threads.emplace_back([&a] {
86  for (;;) {
87  int val;
88  auto ticket = a.blockingReadStage<0>(val);
89  if (val == -1) { // stop
90  // We still need to propagate
91  a.blockingWriteStage<0>(ticket, "");
92  break;
93  }
94  a.blockingWriteStage<0>(ticket, folly::to<std::string>(val, " hello"));
95  }
96  });
97  }
98 
99  for (size_t i = 0; i < numThreadsPerStage; ++i) {
100  threads.emplace_back([&a] {
101  for (;;) {
103  auto ticket = a.blockingReadStage<1>(val);
104  if (val.empty()) { // stop
105  // We still need to propagate
106  a.blockingWriteStage<1>(ticket, "");
107  break;
108  }
109  a.blockingWriteStage<1>(ticket, folly::to<std::string>(val, " world"));
110  }
111  });
112  }
113 
114  std::vector<std::string> results;
115  threads.emplace_back([&a, &results]() {
116  for (;;) {
118  a.blockingRead(val);
119  if (val.empty()) {
120  break;
121  }
122  results.push_back(val);
123  }
124  });
125 
126  constexpr size_t numValues = 1000;
127  for (size_t i = 0; i < numValues; ++i) {
128  a.blockingWrite(i);
129  }
130  for (size_t i = 0; i < numThreadsPerStage; ++i) {
131  a.blockingWrite(-1);
132  }
133 
134  for (auto& t : threads) {
135  t.join();
136  }
137 
138  // The consumer thread dequeued the first empty string, there should be
139  // numThreadsPerStage - 1 left.
140  EXPECT_EQ(numThreadsPerStage - 1, a.sizeGuess());
141  for (size_t i = 0; i < numThreadsPerStage - 1; ++i) {
143  a.blockingRead(val);
144  EXPECT_TRUE(val.empty());
145  }
146  {
147  std::string tmp;
148  EXPECT_FALSE(a.read(tmp));
149  }
150  EXPECT_EQ(0, a.sizeGuess());
151 
152  EXPECT_EQ(numValues, results.size());
153  for (size_t i = 0; i < results.size(); ++i) {
154  EXPECT_EQ(folly::to<std::string>(i, " hello world"), results[i]);
155  }
156 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
double val
Definition: String.cpp:273
static constexpr StringPiece ticket
std::vector< std::thread::id > threads
char a
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
const char * string
Definition: Conv.cpp:212
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
folly::test::TEST ( ProgramOptionsTest  ,
GFlagsStyleFlagsSet   
)

Definition at line 80 of file ProgramOptionsTest.cpp.

References EXPECT_EQ, and folly::GFLAGS.

80  {
81  EXPECT_EQ(
82  "flag_bool_true 1\n"
83  "flag_bool_false 1\n"
84  "flag_int 43\n"
85  "flag_string bar\n",
86  callHelper(
87  ProgramOptionsStyle::GFLAGS,
88  {
89  "--flag_bool_true",
90  "--flag_bool_false",
91  "--flag_int",
92  "43",
93  "--flag_string",
94  "bar",
95  }));
96 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
folly::test::TEST ( WriteChainAsyncTransportWrapperTest  ,
TestSimpleBuf   
)

Definition at line 80 of file WriteChainAsyncTransportWrapperTest.cpp.

References testing::_, folly::IOBuf::copyBuffer(), EXPECT_CALL, and folly::WriteChainAsyncTransportWrapper< T >::write().

80  {
81  TestWriteChainAsyncTransportWrapper transport;
82  auto buf = folly::IOBuf::copyBuffer("foobar");
83 
84  EXPECT_CALL(transport, writeChain(_, BufMatches(buf.get()), _));
85 
86  transport.write(nullptr, buf->data(), buf->length());
87 }
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
folly::test::TEST ( Varint  ,
Simple   
)

Definition at line 88 of file VarintTest.cpp.

References testVarint().

88  {
89  testVarint(0, {0});
90  testVarint(1, {1});
91  testVarint(127, {127});
92  testVarint(128, {0x80, 0x01});
93  testVarint(300, {0xac, 0x02});
94  testVarint(16383, {0xff, 0x7f});
95  testVarint(16384, {0x80, 0x80, 0x01});
96 
97  testVarint(static_cast<uint32_t>(-1), {0xff, 0xff, 0xff, 0xff, 0x0f});
98  testVarint(
99  static_cast<uint64_t>(-1),
100  {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01});
101 }
void testVarint(uint64_t val, std::initializer_list< uint8_t > bytes)
Definition: VarintTest.cpp:35
folly::test::TEST ( RecordIOTest  ,
SmallRecords   
)

Definition at line 93 of file RecordIOTest.cpp.

References ASSERT_FALSE, folly::RecordIOReader::begin(), folly::RecordIOReader::end(), EXPECT_EQ, EXPECT_TRUE, folly::test::TemporaryFile::fd(), folly::gen::first, i, folly::IOBuf::wrapBuffer(), and folly::RecordIOWriter::write().

93  {
94  constexpr size_t kSize = 10;
95  char tmp[kSize];
96  memset(tmp, 'x', kSize);
97  TemporaryFile file;
98  {
99  RecordIOWriter writer(File(file.fd()));
100  for (size_t i = 0; i < kSize; ++i) { // record of size 0 should be ignored
101  writer.write(IOBuf::wrapBuffer(tmp, i));
102  }
103  }
104  {
105  RecordIOReader reader(File(file.fd()));
106  auto it = reader.begin();
107  for (size_t i = 1; i < kSize; ++i) {
108  ASSERT_FALSE(it == reader.end());
109  EXPECT_EQ(StringPiece(tmp, i), sp((it++)->first));
110  }
111  EXPECT_TRUE(it == reader.end());
112  }
113 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
Range< const char * > StringPiece
constexpr detail::First first
Definition: Base-inl.h:2553
folly::test::TEST ( ProgramOptionsTest  ,
DevFull   
)

Definition at line 93 of file NestedCommandLineAppTest.cpp.

References folly::File::fd().

93  {
94  folly::File full("/dev/full", O_RDWR);
95  callHelper({"--help"}, 1, full.fd());
96 }
folly::test::TEST ( ExceptionTest  ,
makeSystemError   
)

Definition at line 95 of file ExceptionTest.cpp.

References folly::Range< Iter >::contains(), EXPECT_EQ, EXPECT_TRUE, folly::makeSystemError(), and folly::makeSystemErrorExplicit().

95  {
96  errno = ENOENT;
97  auto ex = makeSystemErrorExplicit(EDEADLK, "stuck");
98  EXPECT_EQ(EDEADLK, ex.code().value());
99  EXPECT_EQ(std::system_category(), ex.code().category());
100  EXPECT_TRUE(StringPiece{ex.what()}.contains("stuck"))
101  << "what() string missing input message: " << ex.what();
102 
103  ex = makeSystemErrorExplicit(EDOM, 300, " is bigger than max=", 255);
104  EXPECT_EQ(EDOM, ex.code().value());
105  EXPECT_EQ(std::system_category(), ex.code().category());
106  EXPECT_TRUE(StringPiece{ex.what()}.contains("300 is bigger than max=255"))
107  << "what() string missing input message: " << ex.what();
108 
109  errno = EINVAL;
110  ex = makeSystemError("bad argument ", 1234, ": bogus");
111  EXPECT_EQ(EINVAL, ex.code().value());
112  EXPECT_EQ(std::system_category(), ex.code().category());
113  EXPECT_TRUE(StringPiece{ex.what()}.contains("bad argument 1234: bogus"))
114  << "what() string missing input message: " << ex.what();
115 
116  errno = 0;
117  ex = makeSystemError("unexpected success");
118  EXPECT_EQ(0, ex.code().value());
119  EXPECT_EQ(std::system_category(), ex.code().category());
120  EXPECT_TRUE(StringPiece{ex.what()}.contains("unexpected success"))
121  << "what() string missing input message: " << ex.what();
122 }
std::system_error makeSystemErrorExplicit(int err, const char *msg)
Definition: Exception.h:38
std::system_error makeSystemError(const char *msg)
Definition: Exception.h:55
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
bool contains(const const_range_type &other) const
Definition: Range.h:812
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Range< const char * > StringPiece
folly::test::TEST ( ProgramOptionsTest  ,
GFlagsStyleBoolFlagsNegation   
)

Definition at line 98 of file ProgramOptionsTest.cpp.

References EXPECT_EQ, and folly::GFLAGS.

98  {
99  EXPECT_EQ(
100  "flag_bool_true 0\n"
101  "flag_bool_false 0\n"
102  "flag_int 42\n"
103  "flag_string foo\n",
104  callHelper(
105  ProgramOptionsStyle::GFLAGS,
106  {
107  "--noflag_bool_true",
108  "--noflag_bool_false",
109  }));
110 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
folly::test::TEST ( ProgramOptionsTest  ,
CutArguments   
)

Definition at line 98 of file NestedCommandLineAppTest.cpp.

References EXPECT_EQ.

98  {
99  // anything after -- is parsed as arguments
100  EXPECT_EQ(
101  "running foo\n"
102  "foo global-foo 43\n"
103  "foo local-foo 42\n"
104  "foo arg b\n"
105  "foo arg --local-foo\n"
106  "foo arg 44\n"
107  "foo arg a\n",
108  callHelper(
109  {"foo", "--global-foo", "43", "--", "b", "--local-foo", "44", "a"}));
110 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
folly::test::TEST ( Varint  ,
Fail   
)

Definition at line 110 of file VarintTest.cpp.

References testVarintFail().

110  {
111  testVarintFail({0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff});
112 }
void testVarintFail(std::initializer_list< uint8_t > bytes)
Definition: VarintTest.cpp:103
folly::test::TEST ( ProgramOptionsTest  ,
GNUStyleDefaultValues   
)

Definition at line 112 of file ProgramOptionsTest.cpp.

References EXPECT_EQ, and folly::GNU.

112  {
113  EXPECT_EQ(
114  "flag-bool-true 1\n"
115  "flag-bool-false 0\n"
116  "flag-int 42\n"
117  "flag-string foo\n",
118  callHelper(ProgramOptionsStyle::GNU, {}));
119 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
folly::test::TEST ( ProgramOptionsTest  ,
Success   
)

Definition at line 112 of file NestedCommandLineAppTest.cpp.

References EXPECT_EQ.

112  {
113  EXPECT_EQ(
114  "running foo\n"
115  "foo global-foo 42\n"
116  "foo local-foo 42\n",
117  callHelper({"foo"}));
118 
119  EXPECT_EQ(
120  "running foo\n"
121  "foo global-foo 43\n"
122  "foo local-foo 44\n"
123  "foo arg a\n"
124  "foo arg b\n",
125  callHelper({"--global-foo", "43", "foo", "--local-foo", "44", "a", "b"}));
126 
127  // Check that global flags can still be given after the command
128  EXPECT_EQ(
129  "running foo\n"
130  "foo global-foo 43\n"
131  "foo local-foo 44\n"
132  "foo arg a\n"
133  "foo arg b\n",
134  callHelper({"foo", "--global-foo", "43", "--local-foo", "44", "a", "b"}));
135 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
folly::test::TEST ( ZigZag  ,
Simple   
)

Definition at line 114 of file VarintTest.cpp.

References folly::BENCHMARK(), folly::decodeVarint(), folly::decodeZigZag(), folly::Range< Iter >::empty(), folly::encodeVarint(), folly::encodeZigZag(), EXPECT_EQ, i, folly::INFO, folly::kMaxVarintLength64, folly::range(), rng, start, uint64_t, uint8_t, and val.

114  {
115  EXPECT_EQ(0, encodeZigZag(0));
116  EXPECT_EQ(1, encodeZigZag(-1));
117  EXPECT_EQ(2, encodeZigZag(1));
118  EXPECT_EQ(3, encodeZigZag(-2));
119  EXPECT_EQ(4, encodeZigZag(2));
120 
121  EXPECT_EQ(0, decodeZigZag(0));
122  EXPECT_EQ(-1, decodeZigZag(1));
123  EXPECT_EQ(1, decodeZigZag(2));
124  EXPECT_EQ(-2, decodeZigZag(3));
125  EXPECT_EQ(2, decodeZigZag(4));
126 }
uint64_t encodeZigZag(int64_t val)
Definition: Varint.h:96
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
int64_t decodeZigZag(uint64_t val)
Definition: Varint.h:103
folly::test::TEST ( RecordIOTest  ,
MultipleFileIds   
)

Definition at line 115 of file RecordIOTest.cpp.

References ASSERT_FALSE, folly::RecordIOReader::begin(), folly::RecordIOReader::end(), EXPECT_EQ, EXPECT_TRUE, folly::test::TemporaryFile::fd(), folly::gen::first, and folly::RecordIOWriter::write().

115  {
116  TemporaryFile file;
117  {
118  RecordIOWriter writer(File(file.fd()), 1);
119  writer.write(iobufs({"hello"}));
120  }
121  {
122  RecordIOWriter writer(File(file.fd()), 2);
123  writer.write(iobufs({"world"}));
124  }
125  {
126  RecordIOWriter writer(File(file.fd()), 1);
127  writer.write(iobufs({"goodbye"}));
128  }
129  {
130  RecordIOReader reader(File(file.fd()), 0); // return all
131  auto it = reader.begin();
132  ASSERT_FALSE(it == reader.end());
133  EXPECT_EQ("hello", sp((it++)->first));
134  ASSERT_FALSE(it == reader.end());
135  EXPECT_EQ("world", sp((it++)->first));
136  ASSERT_FALSE(it == reader.end());
137  EXPECT_EQ("goodbye", sp((it++)->first));
138  EXPECT_TRUE(it == reader.end());
139  }
140  {
141  RecordIOReader reader(File(file.fd()), 1);
142  auto it = reader.begin();
143  ASSERT_FALSE(it == reader.end());
144  EXPECT_EQ("hello", sp((it++)->first));
145  ASSERT_FALSE(it == reader.end());
146  EXPECT_EQ("goodbye", sp((it++)->first));
147  EXPECT_TRUE(it == reader.end());
148  }
149  {
150  RecordIOReader reader(File(file.fd()), 2);
151  auto it = reader.begin();
152  ASSERT_FALSE(it == reader.end());
153  EXPECT_EQ("world", sp((it++)->first));
154  EXPECT_TRUE(it == reader.end());
155  }
156  {
157  RecordIOReader reader(File(file.fd()), 3);
158  auto it = reader.begin();
159  EXPECT_TRUE(it == reader.end());
160  }
161 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
constexpr detail::First first
Definition: Base-inl.h:2553
folly::test::TEST ( ProgramOptionsTest  ,
GNUStyleFlagsSet   
)

Definition at line 121 of file ProgramOptionsTest.cpp.

References EXPECT_EQ, and folly::GNU.

121  {
122  EXPECT_EQ(
123  "flag-bool-true 1\n"
124  "flag-bool-false 1\n"
125  "flag-int 43\n"
126  "flag-string bar\n",
127  callHelper(
128  ProgramOptionsStyle::GNU,
129  {
130  "--flag-bool-true",
131  "--flag-bool-false",
132  "--flag-int",
133  "43",
134  "--flag-string",
135  "bar",
136  }));
137 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
folly::test::TEST ( ProgramOptionsTest  ,
Aliases   
)

Definition at line 137 of file NestedCommandLineAppTest.cpp.

References EXPECT_EQ.

137  {
138  EXPECT_EQ(
139  "running foo\n"
140  "foo global-foo 43\n"
141  "foo local-foo 44\n"
142  "foo arg a\n"
143  "foo arg b\n",
144  callHelper({"--global-foo", "43", "bar", "--local-foo", "44", "a", "b"}));
145 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
folly::test::TEST ( ProgramOptionsTest  ,
GNUStyleBoolFlagsNegation   
)

Definition at line 139 of file ProgramOptionsTest.cpp.

References EXPECT_EQ, and folly::GNU.

139  {
140  EXPECT_EQ(
141  "flag-bool-true 0\n"
142  "flag-bool-false 0\n"
143  "flag-int 42\n"
144  "flag-string foo\n",
145  callHelper(
146  ProgramOptionsStyle::GNU,
147  {
148  "--no-flag-bool-true",
149  "--no-flag-bool-false",
150  }));
151 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
folly::test::TEST ( TupleOps  ,
TupleTo   
)

Definition at line 143 of file TupleOpsTest.cpp.

References CHECK_TUPLE_TO.

143  {
145 }
#define CHECK_TUPLE_TO(converter)
U tupleTo(const T &input)
folly::test::TEST ( ProgramOptionsTest  ,
BuiltinCommand   
)

Definition at line 147 of file NestedCommandLineAppTest.cpp.

References ASSERT_FALSE, ASSERT_TRUE, folly::NestedCommandLineApp::isBuiltinCommand(), folly::NestedCommandLineApp::kHelpCommand, folly::NestedCommandLineApp::kVersionCommand, and folly::Range< Iter >::str().

147  {
148  NestedCommandLineApp app;
149  ASSERT_TRUE(app.isBuiltinCommand(NestedCommandLineApp::kHelpCommand.str()));
150  ASSERT_TRUE(
151  app.isBuiltinCommand(NestedCommandLineApp::kVersionCommand.str()));
152  ASSERT_FALSE(app.isBuiltinCommand(
153  NestedCommandLineApp::kHelpCommand.str() + "nonsense"));
154 }
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
folly::test::TEST ( TupleOps  ,
TupleTo2   
)

Definition at line 147 of file TupleOpsTest.cpp.

References CHECK_TUPLE_TO, and tupleTo2().

147  {
149 }
U tupleTo2(const T &input)
#define CHECK_TUPLE_TO(converter)
folly::test::TEST ( ProgramOptionsTest  ,
GNUStyleSubCommand   
)

Definition at line 153 of file ProgramOptionsTest.cpp.

References EXPECT_EQ, and folly::GNU.

153  {
154  EXPECT_EQ(
155  "flag-bool-true 1\n"
156  "flag-bool-false 1\n"
157  "flag-int 43\n"
158  "flag-string foo\n"
159  "command hello\n"
160  "arg --wtf\n"
161  "arg 100\n"
162  "arg -x\n"
163  "arg -xy\n",
164  callHelper(
165  ProgramOptionsStyle::GNU,
166  {
167  "--flag-bool-false",
168  "hello",
169  "--wtf",
170  "--flag-int",
171  "43",
172  "100",
173  "-x",
174  "-xy",
175  }));
176 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
folly::test::TEST ( RecordIOTest  ,
ExtraMagic   
)

Definition at line 163 of file RecordIOTest.cpp.

References ASSERT_FALSE, folly::RecordIOReader::begin(), folly::RecordIOReader::end(), EXPECT_EQ, EXPECT_TRUE, folly::test::TemporaryFile::fd(), folly::gen::first, folly::recordio_helpers::headerSize(), folly::recordio_helpers::recordio_detail::Header::kMagic, fizz::detail::read(), uint32_t, uint8_t, val, folly::RecordIOWriter::write(), and fizz::detail::write().

163  {
164  TemporaryFile file;
165  {
166  RecordIOWriter writer(File(file.fd()));
167  writer.write(iobufs({"hello"}));
168  }
170  EXPECT_EQ(0, lseek(file.fd(), 0, SEEK_SET));
171  EXPECT_EQ(sizeof(buf), read(file.fd(), buf, sizeof(buf)));
172  // Append an extra magic
174  EXPECT_EQ(sizeof(magic), write(file.fd(), &magic, sizeof(magic)));
175  // and an extra record
176  EXPECT_EQ(sizeof(buf), write(file.fd(), buf, sizeof(buf)));
177  {
178  RecordIOReader reader(File(file.fd()));
179  auto it = reader.begin();
180  ASSERT_FALSE(it == reader.end());
181  EXPECT_EQ("hello", sp((it++)->first));
182  ASSERT_FALSE(it == reader.end());
183  EXPECT_EQ("hello", sp((it++)->first));
184  EXPECT_TRUE(it == reader.end());
185  }
186 }
constexpr size_t headerSize()
Definition: RecordIO-inl.h:101
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
size_t read(T &out, folly::io::Cursor &cursor)
Definition: Types-inl.h:258
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
const uint8_t kMagic[2]
Definition: Dump.cpp:28
constexpr detail::First first
Definition: Base-inl.h:2553
folly::test::TEST ( ShutdownSocketSetTest  ,
OrderlyClose   
)

Definition at line 167 of file ShutdownSocketSetTest.cpp.

References runCloseTest().

167  {
168  runCloseTest(false);
169 }
void runCloseTest(bool abortive)
folly::test::TEST ( ShutdownSocketSetTest  ,
AbortiveClose   
)

Definition at line 171 of file ShutdownSocketSetTest.cpp.

References runCloseTest().

171  {
172  runCloseTest(true);
173 }
void runCloseTest(bool abortive)
folly::test::TEST ( ProgramOptionsTest  ,
GNUStyleSubCommandUnrecognizedOptionFirst   
)

Definition at line 178 of file ProgramOptionsTest.cpp.

References EXPECT_EQ, and folly::GNU.

178  {
179  EXPECT_EQ(
180  "flag-bool-true 1\n"
181  "flag-bool-false 1\n"
182  "flag-int 43\n"
183  "flag-string foo\n"
184  "arg --wtf\n"
185  "arg hello\n"
186  "arg 100\n"
187  "arg -x\n"
188  "arg -xy\n",
189  callHelper(
190  ProgramOptionsStyle::GNU,
191  {
192  "--flag-bool-false",
193  "--wtf",
194  "hello",
195  "--flag-int",
196  "43",
197  "100",
198  "-x",
199  "-xy",
200  }));
201 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
folly::test::TEST ( RecordIOTest  ,
Randomized   
)

Definition at line 197 of file RecordIOTest.cpp.

References ASSERT_LT, folly::basic_fbstring< E, T, A, Storage >::clear(), EXPECT_EQ, folly::test::TemporaryFile::fd(), folly::RecordIOWriter::filePos(), folly::gen::first, folly::recordio_helpers::headerSize(), i, k, folly::gen::move, folly::basic_fbstring< E, T, A, Storage >::push_back(), records, folly::basic_fbstring< E, T, A, Storage >::reserve(), SCOPED_TRACE, folly::basic_fbstring< E, T, A, Storage >::size(), and folly::RecordIOWriter::write().

197  {
198  SCOPED_TRACE(to<std::string>("Random seed is ", FLAGS_random_seed));
199  std::mt19937 rnd(FLAGS_random_seed);
200 
201  size_t recordCount = std::uniform_int_distribution<uint32_t>(30, 300)(rnd);
202 
203  std::uniform_int_distribution<uint32_t> recordSizeDist(1, 3 << 16);
204  std::uniform_int_distribution<uint32_t> charDist(0, 255);
205  std::uniform_int_distribution<uint32_t> junkDist(0, 1 << 20);
206  // corrupt 1/5 of all records
207  std::uniform_int_distribution<uint32_t> corruptDist(0, 4);
208 
209  std::vector<std::pair<fbstring, off_t>> records;
210  std::vector<off_t> corruptPositions;
211  records.reserve(recordCount);
212  TemporaryFile file;
213 
214  fbstring record;
215  // Recreate the writer multiple times so we test that we create a
216  // continuous stream
217  for (size_t i = 0; i < 3; ++i) {
218  RecordIOWriter writer(File(file.fd()));
219  for (size_t j = 0; j < recordCount; ++j) {
220  off_t beginPos = writer.filePos();
221  record.clear();
222  size_t recordSize = recordSizeDist(rnd);
223  record.reserve(recordSize);
224  for (size_t k = 0; k < recordSize; ++k) {
225  record.push_back(charDist(rnd));
226  }
227  writer.write(iobufs({record}));
228 
229  bool corrupt = (corruptDist(rnd) == 0);
230  if (corrupt) {
231  // Corrupt one random byte in the record (including header)
232  std::uniform_int_distribution<uint32_t> corruptByteDist(
233  0, recordSize + recordio_helpers::headerSize() - 1);
234  off_t corruptRel = corruptByteDist(rnd);
235  VLOG(1) << "n=" << records.size() << " bpos=" << beginPos
236  << " rsize=" << record.size() << " corrupt rel=" << corruptRel
237  << " abs=" << beginPos + corruptRel;
238  corruptPositions.push_back(beginPos + corruptRel);
239  } else {
240  VLOG(2) << "n=" << records.size() << " bpos=" << beginPos
241  << " rsize=" << record.size() << " good";
242  records.emplace_back(std::move(record), beginPos);
243  }
244  }
245  VLOG(1) << "n=" << records.size() << " close abs=" << writer.filePos();
246  }
247 
248  for (auto& pos : corruptPositions) {
249  corrupt(file.fd(), pos);
250  }
251 
252  {
253  size_t i = 0;
254  RecordIOReader reader(File(file.fd()));
255  for (auto& r : reader) {
256  SCOPED_TRACE(i);
257  ASSERT_LT(i, records.size());
258  EXPECT_EQ(records[i].first, sp(r.first));
259  EXPECT_EQ(records[i].second, r.second);
260  ++i;
261  }
262  EXPECT_EQ(records.size(), i);
263  }
264 }
constexpr size_t headerSize()
Definition: RecordIO-inl.h:101
#define ASSERT_LT(val1, val2)
Definition: gtest.h:1968
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
#define SCOPED_TRACE(message)
Definition: gtest.h:2115
basic_fbstring< char > fbstring
Definition: FBString.h:2904
fbstring records
KeyT k
constexpr detail::First first
Definition: Base-inl.h:2553
folly::test::TEST ( ShutdownSocketSetTest  ,
OrderlyKill   
)

Definition at line 209 of file ShutdownSocketSetTest.cpp.

References runKillTest().

209  {
210  runKillTest(false);
211 }
void runKillTest(bool abortive)
folly::test::TEST ( ShutdownSocketSetTest  ,
AbortiveKill   
)

Definition at line 213 of file ShutdownSocketSetTest.cpp.

References runKillTest().

213  {
214  runKillTest(true);
215 }
void runKillTest(bool abortive)
folly::test::TEST ( FileUtilTest2  ,
wrapv   
)

Definition at line 248 of file FileUtilTest.cpp.

References ASSERT_EQ, EXPECT_EQ, folly::test::TemporaryFile::fd(), i, int32_t, folly::test::IovecBuffers::iov(), folly::test::IovecBuffers::size(), sizes, sum(), and folly::fileutil_detail::wrapvFull().

248  {
249  TemporaryFile tempFile("file-util-test");
250  std::vector<size_t> sizes;
251  size_t sum = 0;
252  for (int32_t i = 0; i < 1500; ++i) {
253  sizes.push_back(i % 3 + 1);
254  sum += sizes.back();
255  }
256  IovecBuffers buf(sizes);
257  ASSERT_EQ(sum, buf.size());
258  auto iov = buf.iov();
259  EXPECT_EQ(sum, wrapvFull(writev, tempFile.fd(), iov.data(), iov.size()));
260 }
std::atomic< int64_t > sum(0)
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int sizes[]
ssize_t wrapvFull(F f, int fd, iovec *iov, int count, Offset...offset)
folly::test::TEST ( String  ,
readFile   
)

Definition at line 276 of file FileUtilTest.cpp.

References EXPECT_EQ, EXPECT_TRUE, folly::test::TemporaryFile::path(), folly::readFile(), and folly::writeFile().

276  {
277  const TemporaryFile afileTemp, emptyFileTemp;
278  auto afile = afileTemp.path().string();
279  auto emptyFile = emptyFileTemp.path().string();
280 
281  EXPECT_TRUE(writeFile(string(), emptyFile.c_str()));
282  EXPECT_TRUE(writeFile(StringPiece("bar"), afile.c_str()));
283 
284  {
285  string contents;
286  EXPECT_TRUE(readFile(emptyFile.c_str(), contents));
287  EXPECT_EQ(contents, "");
288  EXPECT_TRUE(readFile(afile.c_str(), contents, 0));
289  EXPECT_EQ("", contents);
290  EXPECT_TRUE(readFile(afile.c_str(), contents, 2));
291  EXPECT_EQ("ba", contents);
292  EXPECT_TRUE(readFile(afile.c_str(), contents));
293  EXPECT_EQ("bar", contents);
294  }
295  {
296  vector<unsigned char> contents;
297  EXPECT_TRUE(readFile(emptyFile.c_str(), contents));
298  EXPECT_EQ(vector<unsigned char>(), contents);
299  EXPECT_TRUE(readFile(afile.c_str(), contents, 0));
300  EXPECT_EQ(vector<unsigned char>(), contents);
301  EXPECT_TRUE(readFile(afile.c_str(), contents, 2));
302  EXPECT_EQ(vector<unsigned char>({'b', 'a'}), contents);
303  EXPECT_TRUE(readFile(afile.c_str(), contents));
304  EXPECT_EQ(vector<unsigned char>({'b', 'a', 'r'}), contents);
305  }
306 }
bool readFile(int fd, Container &out, size_t num_bytes=std::numeric_limits< size_t >::max())
Definition: FileUtil.h:125
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
bool writeFile(const Container &data, const char *filename, int flags=O_WRONLY|O_CREAT|O_TRUNC, mode_t mode=0666)
Definition: FileUtil.h:211
Range< const char * > StringPiece
folly::test::TEST_F ( FileUtilTest  ,
read   
)

Definition at line 163 of file FileUtilTest.cpp.

References EXPECT_EQ, folly::test::FileUtilTest::in_, folly::test::FileUtilTest::readers_, string, and folly::fileutil_detail::wrapFull().

Referenced by TEST_F(), and fizz::test::TEST_F().

163  {
164  for (auto& p : readers_) {
165  std::string out(in_.size(), '\0');
166  EXPECT_EQ(p.first, wrapFull(p.second, 0, &out[0], out.size()));
167  if (p.first != (decltype(p.first))(-1)) {
168  EXPECT_EQ(in_.substr(0, p.first), out.substr(0, p.first));
169  }
170  }
171 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Input & in_
Definition: json.cpp:342
ssize_t wrapFull(F f, int fd, void *buf, size_t count, Offset...offset)
const char * string
Definition: Conv.cpp:212
folly::test::TEST_F ( FileUtilTest  ,
pread   
)

Definition at line 173 of file FileUtilTest.cpp.

References EXPECT_EQ, folly::test::FileUtilTest::in_, folly::test::FileUtilTest::readers_, string, and folly::fileutil_detail::wrapFull().

173  {
174  for (auto& p : readers_) {
175  std::string out(in_.size(), '\0');
176  EXPECT_EQ(p.first, wrapFull(p.second, 0, &out[0], out.size(), off_t(42)));
177  if (p.first != (decltype(p.first))(-1)) {
178  EXPECT_EQ(in_.substr(0, p.first), out.substr(0, p.first));
179  }
180  }
181 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Input & in_
Definition: json.cpp:342
ssize_t wrapFull(F f, int fd, void *buf, size_t count, Offset...offset)
const char * string
Definition: Conv.cpp:212
folly::test::TEST_F ( FileUtilTest  ,
readv   
)

Definition at line 235 of file FileUtilTest.cpp.

References ASSERT_EQ, EXPECT_EQ, folly::test::FileUtilTest::in_, folly::test::FileUtilTest::readers_, and folly::fileutil_detail::wrapvFull().

235  {
236  for (auto& p : readers_) {
237  IovecBuffers buf({12, 19, 31});
238  ASSERT_EQ(62, buf.size());
239 
240  auto iov = buf.iov();
241  EXPECT_EQ(p.first, wrapvFull(p.second, 0, iov.data(), iov.size()));
242  if (p.first != (decltype(p.first))(-1)) {
243  EXPECT_EQ(in_.substr(0, p.first), buf.join().substr(0, p.first));
244  }
245  }
246 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
ssize_t wrapvFull(F f, int fd, iovec *iov, int count, Offset...offset)
Input & in_
Definition: json.cpp:342
folly::test::TEST_F ( FileUtilTest  ,
preadv   
)

Definition at line 262 of file FileUtilTest.cpp.

References ASSERT_EQ, EXPECT_EQ, folly::test::FileUtilTest::in_, folly::test::FileUtilTest::readers_, and folly::fileutil_detail::wrapvFull().

262  {
263  for (auto& p : readers_) {
264  IovecBuffers buf({12, 19, 31});
265  ASSERT_EQ(62, buf.size());
266 
267  auto iov = buf.iov();
268  EXPECT_EQ(
269  p.first, wrapvFull(p.second, 0, iov.data(), iov.size(), off_t(42)));
270  if (p.first != (decltype(p.first))(-1)) {
271  EXPECT_EQ(in_.substr(0, p.first), buf.join().substr(0, p.first));
272  }
273  }
274 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
ssize_t wrapvFull(F f, int fd, iovec *iov, int count, Offset...offset)
Input & in_
Definition: json.cpp:342
folly::test::TEST_F ( ReadFileFd  ,
ReadZeroBytes   
)

Definition at line 317 of file FileUtilTest.cpp.

References EXPECT_EQ, EXPECT_TRUE, folly::readFile(), and string.

317  {
318  std::string contents;
319  EXPECT_TRUE(readFile(aFile.fd(), contents, 0));
320  EXPECT_EQ("", contents);
321 }
bool readFile(int fd, Container &out, size_t num_bytes=std::numeric_limits< size_t >::max())
Definition: FileUtil.h:125
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
const char * string
Definition: Conv.cpp:212
folly::test::TEST_F ( ReadFileFd  ,
ReadPartial   
)

Definition at line 323 of file FileUtilTest.cpp.

References EXPECT_EQ, EXPECT_TRUE, folly::readFile(), and string.

323  {
324  std::string contents;
325  EXPECT_TRUE(readFile(aFile.fd(), contents, 2));
326  EXPECT_EQ("ba", contents);
327 }
bool readFile(int fd, Container &out, size_t num_bytes=std::numeric_limits< size_t >::max())
Definition: FileUtil.h:125
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
const char * string
Definition: Conv.cpp:212
folly::test::TEST_F ( ReadFileFd  ,
ReadFull   
)

Definition at line 329 of file FileUtilTest.cpp.

References EXPECT_EQ, EXPECT_TRUE, folly::readFile(), and string.

329  {
330  std::string contents;
331  EXPECT_TRUE(readFile(aFile.fd(), contents));
332  EXPECT_EQ("bar", contents);
333 }
bool readFile(int fd, Container &out, size_t num_bytes=std::numeric_limits< size_t >::max())
Definition: FileUtil.h:125
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
const char * string
Definition: Conv.cpp:212
folly::test::TEST_F ( ReadFileFd  ,
WriteOnlyFd   
)

Definition at line 335 of file FileUtilTest.cpp.

References EXPECT_FALSE, f, folly::INFO, folly::readFile(), and string.

335  {
336  File f(aFile.path().string(), O_WRONLY);
337  std::string contents;
338  EXPECT_FALSE(readFile(f.fd(), contents));
339  PLOG(INFO);
340 }
auto f
bool readFile(int fd, Container &out, size_t num_bytes=std::numeric_limits< size_t >::max())
Definition: FileUtil.h:125
const char * string
Definition: Conv.cpp:212
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
folly::test::TEST_F ( ReadFileFd  ,
InvalidFd   
)

Definition at line 342 of file FileUtilTest.cpp.

References EXPECT_FALSE, f, folly::INFO, msvcSuppressAbortOnInvalidParams(), folly::readFile(), and string.

342  {
343  File f(aFile.path().string());
344  f.close();
345  std::string contents;
347  [&] { EXPECT_FALSE(readFile(f.fd(), contents)); });
348  PLOG(INFO);
349 }
auto f
bool readFile(int fd, Container &out, size_t num_bytes=std::numeric_limits< size_t >::max())
Definition: FileUtil.h:125
auto msvcSuppressAbortOnInvalidParams(Func func) -> decltype(func())
Definition: TestUtil.h:166
const char * string
Definition: Conv.cpp:212
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
folly::test::TEST_F ( WriteFileAtomic  ,
writeNew   
)

Definition at line 394 of file FileUtilTest.cpp.

References EXPECT_EQ, and folly::writeFileAtomic().

394  {
395  // Call writeFileAtomic() to create a new file
396  auto path = tmpPath("foo");
397  auto contents = StringPiece{"contents\n"};
398  writeFileAtomic(path, contents);
399 
400  // The directory should contain exactly 1 file now, with the correct contents
401  EXPECT_EQ(set<string>{"foo"}, listTmpDir());
402  EXPECT_EQ(contents, readData(path));
403  EXPECT_EQ(0644, getPerms(path));
404 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void writeFileAtomic(StringPiece filename, iovec *iov, int count, mode_t permissions)
Definition: FileUtil.cpp:224
Range< const char * > StringPiece
folly::test::TEST_F ( WriteFileAtomic  ,
overwrite   
)

Definition at line 406 of file FileUtilTest.cpp.

References EXPECT_EQ, string, and folly::writeFileAtomic().

406  {
407  // Call writeFileAtomic() to create a new file
408  auto path = tmpPath("foo");
409  auto contents1 = StringPiece{"contents\n"};
410  writeFileAtomic(path, contents1);
411 
412  EXPECT_EQ(set<string>{"foo"}, listTmpDir());
413  EXPECT_EQ(contents1, readData(path));
414  EXPECT_EQ(0644, getPerms(path));
415 
416  // Now overwrite the file with different contents
417  auto contents2 = StringPiece{"testing"};
418  writeFileAtomic(path, contents2);
419  EXPECT_EQ(set<string>{"foo"}, listTmpDir());
420  EXPECT_EQ(contents2, readData(path));
421  EXPECT_EQ(0644, getPerms(path));
422 
423  // Test overwriting with relatively large contents, and different permissions
424  auto contents3 =
425  "asdf" + string(10240, '\n') + "foobar\n" + string(10240, 'b') + "\n";
426  writeFileAtomic(path, contents3, 0444);
427  EXPECT_EQ(set<string>{"foo"}, listTmpDir());
428  EXPECT_EQ(contents3, readData(path));
429  EXPECT_EQ(0444, getPerms(path));
430 
431  // Test overwriting with empty contents
432  //
433  // Note that the file's permissions are 0444 at this point (read-only),
434  // but we writeFileAtomic() should still replace it successfully. Since we
435  // update it with a rename we need write permissions on the parent directory,
436  // but not the destination file.
437  auto contents4 = StringPiece("");
438  writeFileAtomic(path, contents4, 0400);
439  EXPECT_EQ(set<string>{"foo"}, listTmpDir());
440  EXPECT_EQ(contents4, readData(path));
441  EXPECT_EQ(0400, getPerms(path));
442 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void writeFileAtomic(StringPiece filename, iovec *iov, int count, mode_t permissions)
Definition: FileUtil.cpp:224
const char * string
Definition: Conv.cpp:212
Range< const char * > StringPiece
folly::test::TEST_F ( WriteFileAtomic  ,
directoryPermissions   
)

Definition at line 444 of file FileUtilTest.cpp.

References EXPECT_EQ, EXPECT_THROW, SCOPE_EXIT, and folly::writeFileAtomic().

444  {
445  // Test writeFileAtomic() when we do not have write permission in the target
446  // directory.
447  //
448  // Make the test directory read-only
449  setDirPerms(0555);
450  SCOPE_EXIT {
451  // Restore directory permissions before we exit, just to ensure the code
452  // will be able to clean up the directory.
453  try {
454  setDirPerms(0755);
455  } catch (const std::exception&) {
456  // Intentionally ignore errors here, in case an exception is already
457  // being thrown.
458  }
459  };
460 
461  // writeFileAtomic() should fail, and the directory should still be empty
462  auto path1 = tmpPath("foo");
463  auto contents = StringPiece("testing");
464  EXPECT_THROW(writeFileAtomic(path1, contents), std::system_error);
465  EXPECT_EQ(set<string>{}, listTmpDir());
466 
467  // Make the directory writable again, then create the file
468  setDirPerms(0755);
469  writeFileAtomic(path1, contents, 0400);
470  EXPECT_EQ(contents, readData(path1));
471  EXPECT_EQ(set<string>{"foo"}, listTmpDir());
472 
473  // Make the directory read-only again
474  // Creating another file now should fail and we should still have only the
475  // first file.
476  setDirPerms(0555);
477  EXPECT_THROW(
478  writeFileAtomic(tmpPath("another_file.txt"), "x\n"), std::system_error);
479  EXPECT_EQ(set<string>{"foo"}, listTmpDir());
480 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define SCOPE_EXIT
Definition: ScopeGuard.h:274
void writeFileAtomic(StringPiece filename, iovec *iov, int count, mode_t permissions)
Definition: FileUtil.cpp:224
Range< const char * > StringPiece
folly::test::TEST_F ( WriteFileAtomic  ,
multipleFiles   
)

Definition at line 482 of file FileUtilTest.cpp.

References EXPECT_EQ, EXPECT_THROW, fail(), mode, TEST_F(), and folly::writeFileAtomic().

482  {
483  // Test creating multiple files in the same directory
484  writeFileAtomic(tmpPath("foo.txt"), "foo");
485  writeFileAtomic(tmpPath("bar.txt"), "bar", 0400);
486  writeFileAtomic(tmpPath("foo_txt"), "underscore", 0440);
487  writeFileAtomic(tmpPath("foo.txt2"), "foo2", 0444);
488 
489  auto expectedPaths = set<string>{"foo.txt", "bar.txt", "foo_txt", "foo.txt2"};
490  EXPECT_EQ(expectedPaths, listTmpDir());
491  EXPECT_EQ("foo", readData(tmpPath("foo.txt")));
492  EXPECT_EQ("bar", readData(tmpPath("bar.txt")));
493  EXPECT_EQ("underscore", readData(tmpPath("foo_txt")));
494  EXPECT_EQ("foo2", readData(tmpPath("foo.txt2")));
495  EXPECT_EQ(0644, getPerms(tmpPath("foo.txt")));
496  EXPECT_EQ(0400, getPerms(tmpPath("bar.txt")));
497  EXPECT_EQ(0440, getPerms(tmpPath("foo_txt")));
498  EXPECT_EQ(0444, getPerms(tmpPath("foo.txt2")));
499 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void writeFileAtomic(StringPiece filename, iovec *iov, int count, mode_t permissions)
Definition: FileUtil.cpp:224
void folly::test::testVarint ( uint64_t  val,
std::initializer_list< uint8_t bytes 
)

Definition at line 35 of file VarintTest.cpp.

References folly::decodeVarint(), folly::Range< Iter >::empty(), folly::encodeVarint(), folly::encodeVarintSize(), EXPECT_EQ, EXPECT_TRUE, folly::kMaxVarintLength64, folly::Range< Iter >::size(), uint64_t, and uint8_t.

Referenced by TEST().

35  {
36  size_t n = bytes.size();
37  ByteRange expected(&*bytes.begin(), n);
38 
39  {
41  EXPECT_EQ(expected.size(), encodeVarint(val, buf));
42  EXPECT_TRUE(ByteRange(buf, expected.size()) == expected);
43  EXPECT_EQ(expected.size(), encodeVarintSize(val));
44  }
45 
46  {
47  ByteRange r = expected;
48  uint64_t decoded = decodeVarint(r);
49  EXPECT_TRUE(r.empty());
50  EXPECT_EQ(val, decoded);
51  }
52 
53  if (n < kMaxVarintLength64) {
54  // Try from a full buffer too, different code path
56  memcpy(buf, &*bytes.begin(), n);
57 
58  uint8_t fills[] = {0, 0x7f, 0x80, 0xff};
59 
60  for (uint8_t fill : fills) {
61  memset(buf + n, fill, kMaxVarintLength64 - n);
63  uint64_t decoded = decodeVarint(r);
64  EXPECT_EQ(val, decoded);
65  EXPECT_EQ(kMaxVarintLength64 - n, r.size());
66  }
67  }
68 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr size_t kMaxVarintLength64
Definition: Varint.h:50
double val
Definition: String.cpp:273
uint64_t decodeVarint(Range< T * > &data)
Definition: Varint.h:135
int encodeVarintSize(uint64_t val)
Definition: Varint.h:119
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Range< const unsigned char * > ByteRange
Definition: Range.h:1163
size_t encodeVarint(uint64_t val, uint8_t *buf)
Definition: Varint.h:109
void folly::test::testVarintFail ( std::initializer_list< uint8_t bytes)

Definition at line 103 of file VarintTest.cpp.

References folly::data(), EXPECT_FALSE, and folly::tryDecodeVarint().

Referenced by TEST().

103  {
104  size_t n = bytes.size();
105  ByteRange data(&*bytes.begin(), n);
106  auto ret = tryDecodeVarint(data);
107  EXPECT_FALSE(ret.hasValue());
108 }
Range< const unsigned char * > ByteRange
Definition: Range.h:1163
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Expected< uint64_t, DecodeVarintError > tryDecodeVarint(Range< T * > &data)
Definition: Varint.h:147
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
template<class U , class T >
U folly::test::tupleTo ( const T input)

Definition at line 105 of file TupleOpsTest.cpp.

Referenced by TEST().

105  {
106  return TupleTo<U, T>::convert(input);
107 }
template<class U , class T , class Seq = typename TemplateTupleRange<U>::type, class Enable = typename std::enable_if< (std::tuple_size<U>::value == std::tuple_size<T>::value)>::type>
U folly::test::tupleTo2 ( const T input)

Definition at line 130 of file TupleOpsTest.cpp.

Referenced by TEST().

130  {
131  return TupleTo2<Seq>::template convert<U>(input);
132 }

Variable Documentation

std::mutex folly::test::futexLock
static

Definition at line 45 of file DeterministicSchedule.cpp.

std::unordered_map< const detail::Futex<DeterministicAtomic>*, std::list<std::pair<uint32_t, bool*> > > folly::test::futexQueues
static

Definition at line 43 of file DeterministicSchedule.cpp.

Referenced by futexWaitImpl(), and futexWakeImpl().