|
1 | 1 | /*
|
2 |
| - * Copyright (C) 2018-2021 Intel Corporation |
| 2 | + * Copyright (C) 2018-2022 Intel Corporation |
3 | 3 | *
|
4 | 4 | * SPDX-License-Identifier: MIT
|
5 | 5 | *
|
@@ -174,6 +174,31 @@ TEST(HeapAllocatorTest, GivenOnlyMoreThanTwiceBiggerSizeChunksInFreedChunksWhenG
|
174 | 174 | EXPECT_EQ(deltaSize, freedChunks[2].size);
|
175 | 175 | }
|
176 | 176 |
|
| 177 | +TEST(HeapAllocatorTest, GivenMoreThanTwiceBiggerSizeChunksInFreedChunksWhenGetIsCalledAndAlignmentDoesNotThenNullIsReturned) { |
| 178 | + uint64_t ptrBase = 0x100000llu; |
| 179 | + size_t size = 1024 * 4096; |
| 180 | + auto pLowerBound = ptrBase; |
| 181 | + |
| 182 | + auto allocAlign = 8162u; |
| 183 | + |
| 184 | + auto heapAllocator = std::make_unique<HeapAllocatorUnderTest>(ptrBase, size, allocationAlignment, sizeThreshold); |
| 185 | + |
| 186 | + std::vector<HeapChunk> freedChunks; |
| 187 | + uint64_t ptrExpected = 0llu; |
| 188 | + size_t requestedSize = 2 * 4096; |
| 189 | + |
| 190 | + freedChunks.emplace_back(pLowerBound, 9 * 4096); |
| 191 | + pLowerBound += 9 * 4096; |
| 192 | + freedChunks.emplace_back(pLowerBound, 3 * 4096); |
| 193 | + |
| 194 | + EXPECT_EQ(2u, freedChunks.size()); |
| 195 | + |
| 196 | + auto ptrReturned = heapAllocator->getFromFreedChunks(requestedSize, freedChunks, allocAlign); |
| 197 | + |
| 198 | + EXPECT_EQ(ptrExpected, ptrReturned); |
| 199 | + EXPECT_EQ(2u, freedChunks.size()); |
| 200 | +} |
| 201 | + |
177 | 202 | TEST(HeapAllocatorTest, GivenStoredChunkAdjacentToLeftBoundaryOfIncomingChunkWhenStoreIsCalledThenChunkIsMerged) {
|
178 | 203 | uint64_t ptrBase = 0x100000llu;
|
179 | 204 | size_t size = 1024 * 4096;
|
|
0 commit comments