fills up the memory pool and returns the allocations in the outparam
| 187 | |
| 188 | // fills up the memory pool and returns the allocations in the outparam |
| 189 | void fillUpMemoryPool(MemoryPool& mp, |
| 190 | const std::set<uint32_t>& allocSizes, |
| 191 | AllocInfoT& poolAllocs) { |
| 192 | for (const auto size : allocSizes) { |
| 193 | // ensure it is power of two. |
| 194 | ASSERT_EQ(size & (size - 1), 0); |
| 195 | } |
| 196 | |
| 197 | const auto maxSize = mp.getPoolSize(); |
| 198 | using ClassFullT = std::unordered_map<uint32_t, bool>; |
| 199 | ClassFullT isClassFull; |
| 200 | |
| 201 | // pick a random class and allocate from that until the memory is full. If |
| 202 | // an allocation class fails allocation, it should not succeed any later. |
| 203 | while (mp.getCurrentAllocSize() < maxSize) { |
| 204 | const unsigned int randomClass = |
| 205 | folly::Random::rand32() % allocSizes.size(); |
| 206 | const auto classSize = *(std::next(allocSizes.begin(), randomClass)); |
| 207 | void* memory = mp.allocate(classSize); |
| 208 | if (memory != nullptr) { |
| 209 | poolAllocs[classSize].push_back(memory); |
| 210 | const auto it = isClassFull.find(classSize); |
| 211 | if (it != isClassFull.end()) { |
| 212 | ASSERT_FALSE(isClassFull[classSize]); |
| 213 | } |
| 214 | } else { |
| 215 | const auto it = isClassFull.find(classSize); |
| 216 | if (it == isClassFull.end()) { |
| 217 | isClassFull[classSize] = true; |
| 218 | } else { |
| 219 | ASSERT_TRUE(isClassFull[classSize]); |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | TEST_F(MemoryPoolTest, Free) { |
| 226 | auto slabAlloc = createSlabAllocator(35); |
no test coverage detected