MCPcopy Create free account
hub / github.com/apache/impala / TEST_F

Function TEST_F

be/src/runtime/bufferpool/free-list-test.cc:94–132  ·  view source on GitHub ↗

Functional test for a small free list.

Source from the content-addressed store, hash-verified

92
93// Functional test for a small free list.
94TEST_F(FreeListTest, SmallList) {
95 const int LIST_SIZE = 2;
96 FreeList small_list;
97
98 // PopFreeBuffer() on empty list returns false.
99 BufferHandle buffer;
100 ASSERT_FALSE(small_list.PopFreeBuffer(&buffer));
101 ASSERT_FALSE(small_list.PopFreeBuffer(&buffer));
102
103 // Add various numbers of buffers to the free list and check that they're
104 // either freed or returned in the order expected.
105 for (int num_buffers = 0; num_buffers <= LIST_SIZE + 2; ++num_buffers) {
106 for (int attempt = 0; attempt < 10; ++attempt) {
107 LOG(INFO) << "num_buffers " << num_buffers << " attempt " << attempt;
108 vector<BufferHandle> buffers;
109 AllocateBuffers(num_buffers, MIN_BUFFER_LEN, &buffers);
110
111 // Keep track of the addresses so we can validate the buffer order.
112 const vector<const void*> addrs = GetSortedAddrs(buffers);
113
114 // Try shuffling to make sure we don't always just add in ascending order.
115 std::shuffle(buffers.begin(), buffers.end(), rng_);
116 AddFreeBuffers(&small_list, &buffers);
117 // Shrink list down to LIST_SIZE.
118 FreeBuffers(
119 small_list.GetBuffersToFree(max<int64_t>(0, small_list.Size() - LIST_SIZE)));
120
121 // The LIST_SIZE buffers with the lowest address should be retained, and the
122 // remaining buffers should have been freed.
123 for (int i = 0; i < min(num_buffers, LIST_SIZE); ++i) {
124 ASSERT_TRUE(small_list.PopFreeBuffer(&buffer)) << i;
125 ASSERT_EQ(addrs[i], buffer.data()) << i;
126 buffers.push_back(move(buffer));
127 }
128 ASSERT_FALSE(small_list.PopFreeBuffer(&buffer));
129 FreeBuffers(move(buffers));
130 }
131 }
132}
133
134// Functional test that makes sure the free lists return buffers in ascending order
135TEST_F(FreeListTest, ReturnOrder) {

Callers

nothing calls this directly

Calls 11

shuffleFunction · 0.85
minFunction · 0.85
moveFunction · 0.85
GetBuffersToFreeMethod · 0.80
push_backMethod · 0.80
PopFreeBufferMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
SizeMethod · 0.45
dataMethod · 0.45
FreeMethod · 0.45

Tested by

no test coverage detected