proxygen
JemallocNodumpAllocatorTest.cpp File Reference

Go to the source code of this file.

Functions

 TEST (JemallocNodumpAllocatorTest, Basic)
 
 TEST (JemallocNodumpAllocatorTest, IOBuf)
 

Function Documentation

TEST ( JemallocNodumpAllocatorTest  ,
Basic   
)

Definition at line 23 of file JemallocNodumpAllocatorTest.cpp.

References folly::JemallocNodumpAllocator::allocate(), folly::JemallocNodumpAllocator::deallocate(), EXPECT_NE, folly::JemallocNodumpAllocator::getArenaIndex(), ptr, and folly::usingJEMalloc().

23  {
25 
26 #ifdef FOLLY_JEMALLOC_NODUMP_ALLOCATOR_SUPPORTED
27  if (folly::usingJEMalloc()) {
28  EXPECT_NE(0, jna.getArenaIndex());
29  }
30 #endif // FOLLY_JEMALLOC_NODUMP_ALLOCATOR_SUPPORTED
31 
32  auto ptr = jna.allocate(1024);
33  EXPECT_NE(nullptr, ptr);
34  jna.deallocate(ptr);
35 }
void * ptr
bool usingJEMalloc() noexcept
Definition: Malloc.h:147
static void deallocate(void *p, void *userData)
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
TEST ( JemallocNodumpAllocatorTest  ,
IOBuf   
)

Definition at line 37 of file JemallocNodumpAllocatorTest.cpp.

References folly::JemallocNodumpAllocator::allocate(), folly::IOBuf::capacity(), data, folly::IOBuf::data(), EXPECT_EQ, EXPECT_NE, folly::JemallocNodumpAllocator::getArenaIndex(), i, ptr, folly::size(), folly::IOBuf::TAKE_OWNERSHIP, uint8_t, folly::usingJEMalloc(), and folly::IOBuf::writableData().

37  {
39 
40 #ifdef FOLLY_JEMALLOC_NODUMP_ALLOCATOR_SUPPORTED
41  if (folly::usingJEMalloc()) {
42  EXPECT_NE(0, jna.getArenaIndex());
43  }
44 #endif // FOLLY_JEMALLOC_NODUMP_ALLOCATOR_SUPPORTED
45 
46  const size_t size{1024};
47  void* ptr = jna.allocate(size);
48  EXPECT_NE(nullptr, ptr);
50  EXPECT_EQ(size, ioBuf.capacity());
51  EXPECT_EQ(ptr, ioBuf.data());
52  uint8_t* data = ioBuf.writableData();
53  EXPECT_EQ(ptr, data);
54  for (auto i = 0u; i < ioBuf.capacity(); ++i) {
55  data[i] = 'A';
56  }
57  uint8_t* p = static_cast<uint8_t*>(ptr);
58  for (auto i = 0u; i < size; ++i) {
59  EXPECT_EQ('A', p[i]);
60  }
61 }
void * ptr
bool usingJEMalloc() noexcept
Definition: Malloc.h:147
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43