21
21
*/
22
22
23
23
#include " runtime/memory_manager/os_agnostic_memory_manager.h"
24
+ #include " unit_tests/mocks/mock_memory_manager.h"
24
25
25
26
#include " test.h"
26
27
#include " gtest/gtest.h"
@@ -32,50 +33,10 @@ class MemoryManagerGetAlloctionDataTest : public testing::TestWithParam<Graphics
32
33
void TearDown () override {}
33
34
};
34
35
35
- class MockOsAgnosticMemoryManager : public OsAgnosticMemoryManager {
36
- public:
37
- using MemoryManager::allocateGraphicsMemory;
38
- using MemoryManager::getAllocationData;
39
- MockOsAgnosticMemoryManager (bool enable64kbPages) : OsAgnosticMemoryManager(enable64kbPages) {
40
- }
41
- GraphicsAllocation *allocateGraphicsMemory (size_t size, size_t alignment, bool forcePin, bool uncacheable) override {
42
- allocationCreated = true ;
43
- return OsAgnosticMemoryManager::allocateGraphicsMemory (size, alignment, forcePin, uncacheable);
44
- }
45
- GraphicsAllocation *allocateGraphicsMemory64kb (size_t size, size_t alignment, bool forcePin, bool preferRenderCompressed) override {
46
- allocation64kbPageCreated = true ;
47
- preferRenderCompressedFlagPassed = preferRenderCompressed;
48
- return OsAgnosticMemoryManager::allocateGraphicsMemory64kb (size, alignment, forcePin, preferRenderCompressed);
49
- }
50
-
51
- GraphicsAllocation *allocateGraphicsMemoryInDevicePool (const AllocationData &allocationData, AllocationStatus &status) override {
52
- if (failInDevicePool) {
53
- status = AllocationStatus::RetryInNonDevicePool;
54
- return nullptr ;
55
- }
56
- if (failInDevicePoolWithError) {
57
- status = AllocationStatus::Error;
58
- return nullptr ;
59
- }
60
-
61
- auto allocation = OsAgnosticMemoryManager::allocateGraphicsMemoryInDevicePool (allocationData, status);
62
- if (allocation) {
63
- allocationInDevicePoolCreated = true ;
64
- }
65
- return allocation;
66
- }
67
- bool allocationCreated = false ;
68
- bool allocation64kbPageCreated = false ;
69
- bool allocationInDevicePoolCreated = false ;
70
- bool failInDevicePool = false ;
71
- bool failInDevicePoolWithError = false ;
72
- bool preferRenderCompressedFlagPassed = false ;
73
- };
74
-
75
36
TEST (MemoryManagerGetAlloctionDataTest, givenMustBeZeroCopyAndAllocateMemoryFlagsAndNullptrWhenAllocationDataIsQueriedThenCorrectFlagsAndSizeAreSet) {
76
37
AllocationData allocData;
77
38
78
- MockOsAgnosticMemoryManager ::getAllocationData (allocData, true , true , false , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
39
+ MockMemoryManager ::getAllocationData (allocData, true , true , false , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
79
40
80
41
EXPECT_TRUE (allocData.flags .mustBeZeroCopy );
81
42
EXPECT_TRUE (allocData.flags .useSystemMemory );
@@ -86,7 +47,7 @@ TEST(MemoryManagerGetAlloctionDataTest, givenMustBeZeroCopyAndAllocateMemoryFlag
86
47
TEST (MemoryManagerGetAlloctionDataTest, givenMustBeZeroCopyFlagFalseWhenAllocationDataIsQueriedThenMustBeZeroCopyAndUseSystemMemoryFlagsAreNotSet) {
87
48
AllocationData allocData;
88
49
89
- MockOsAgnosticMemoryManager ::getAllocationData (allocData, false , true , false , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
50
+ MockMemoryManager ::getAllocationData (allocData, false , true , false , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
90
51
91
52
EXPECT_FALSE (allocData.flags .mustBeZeroCopy );
92
53
EXPECT_FALSE (allocData.flags .useSystemMemory );
@@ -97,22 +58,22 @@ TEST(MemoryManagerGetAlloctionDataTest, givenMustBeZeroCopyFlagFalseWhenAllocati
97
58
TEST (MemoryManagerGetAlloctionDataTest, givenAllocateMemoryFlagTrueWhenHostPtrIsNotNullThenAllocationDataHasHostPtrNulled) {
98
59
AllocationData allocData;
99
60
char memory = 0 ;
100
- MockOsAgnosticMemoryManager ::getAllocationData (allocData, false , true , false , false , &memory, sizeof (memory), GraphicsAllocation::AllocationType::BUFFER);
61
+ MockMemoryManager ::getAllocationData (allocData, false , true , false , false , &memory, sizeof (memory), GraphicsAllocation::AllocationType::BUFFER);
101
62
102
63
EXPECT_EQ (sizeof (memory), allocData.size );
103
64
EXPECT_EQ (nullptr , allocData.hostPtr );
104
65
}
105
66
106
67
TEST (MemoryManagerGetAlloctionDataTest, givenForcePinFlagTrueWhenAllocationDataIsQueriedThenCorrectFlagIsSet) {
107
68
AllocationData allocData;
108
- MockOsAgnosticMemoryManager ::getAllocationData (allocData, false , true , true , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
69
+ MockMemoryManager ::getAllocationData (allocData, false , true , true , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
109
70
110
71
EXPECT_TRUE (allocData.flags .forcePin );
111
72
}
112
73
113
74
TEST (MemoryManagerGetAlloctionDataTest, givenUncacheableFlagTrueWhenAllocationDataIsQueriedThenCorrectFlagIsSet) {
114
75
AllocationData allocData;
115
- MockOsAgnosticMemoryManager ::getAllocationData (allocData, false , true , false , true , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
76
+ MockMemoryManager ::getAllocationData (allocData, false , true , false , true , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
116
77
117
78
EXPECT_TRUE (allocData.flags .uncacheable );
118
79
}
@@ -123,7 +84,7 @@ TEST_P(MemoryManagerGetAlloctionData32BitAnd64kbPagesAllowedTest, givenAllocatio
123
84
AllocationData allocData;
124
85
125
86
auto allocType = GetParam ();
126
- MockOsAgnosticMemoryManager ::getAllocationData (allocData, false , true , false , false , nullptr , 10 , allocType);
87
+ MockMemoryManager ::getAllocationData (allocData, false , true , false , false , nullptr , 10 , allocType);
127
88
128
89
EXPECT_TRUE (allocData.flags .allow32Bit );
129
90
EXPECT_TRUE (allocData.flags .allow64kbPages );
@@ -133,11 +94,11 @@ TEST_P(MemoryManagerGetAlloctionData32BitAnd64kbPagesAllowedTest, givenAllocatio
133
94
TEST_P (MemoryManagerGetAlloctionData32BitAnd64kbPagesAllowedTest, given64kbAllowedAllocationTypeWhenAllocatingThenPreferRenderCompressionOnlyForSpecificTypes) {
134
95
auto allocType = GetParam ();
135
96
AllocationData allocData;
136
- MockOsAgnosticMemoryManager ::getAllocationData (allocData, false , true , false , false , nullptr , 10 , allocType);
97
+ MockMemoryManager ::getAllocationData (allocData, false , true , false , false , nullptr , 10 , allocType);
137
98
bool bufferCompressedType = (allocType == GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
138
99
EXPECT_TRUE (allocData.flags .allow64kbPages );
139
100
140
- MockOsAgnosticMemoryManager mockMemoryManager (true );
101
+ MockMemoryManager mockMemoryManager (true );
141
102
auto allocation = mockMemoryManager.allocateGraphicsMemory (allocData);
142
103
143
104
EXPECT_TRUE (mockMemoryManager.allocation64kbPageCreated );
@@ -152,7 +113,7 @@ TEST_P(MemoryManagerGetAlloctionData32BitAnd64kbPagesNotAllowedTest, givenAlloca
152
113
AllocationData allocData;
153
114
154
115
auto allocType = GetParam ();
155
- MockOsAgnosticMemoryManager ::getAllocationData (allocData, false , true , false , false , nullptr , 10 , allocType);
116
+ MockMemoryManager ::getAllocationData (allocData, false , true , false , false , nullptr , 10 , allocType);
156
117
157
118
EXPECT_FALSE (allocData.flags .allow32Bit );
158
119
EXPECT_FALSE (allocData.flags .allow64kbPages );
@@ -189,7 +150,7 @@ TEST(MemoryManagerTest, givenForced32BitSetWhenGraphicsMemoryFor32BitAllowedType
189
150
memoryManager.setForce32BitAllocations (true );
190
151
191
152
AllocationData allocData;
192
- MockOsAgnosticMemoryManager ::getAllocationData (allocData, false , true , false , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
153
+ MockMemoryManager ::getAllocationData (allocData, false , true , false , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
193
154
194
155
auto allocation = memoryManager.allocateGraphicsMemory (allocData);
195
156
ASSERT_NE (nullptr , allocation);
@@ -209,7 +170,7 @@ TEST(MemoryManagerTest, givenForced32BitEnabledWhenGraphicsMemorywihtoutAllow32B
209
170
memoryManager.setForce32BitAllocations (true );
210
171
211
172
AllocationData allocData;
212
- MockOsAgnosticMemoryManager ::getAllocationData (allocData, false , true , false , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
173
+ MockMemoryManager ::getAllocationData (allocData, false , true , false , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
213
174
allocData.flags .allow32Bit = false ;
214
175
215
176
auto allocation = memoryManager.allocateGraphicsMemory (allocData);
@@ -224,7 +185,7 @@ TEST(MemoryManagerTest, givenForced32BitDisabledWhenGraphicsMemoryWith32BitFlagF
224
185
memoryManager.setForce32BitAllocations (false );
225
186
226
187
AllocationData allocData;
227
- MockOsAgnosticMemoryManager ::getAllocationData (allocData, false , true , false , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
188
+ MockMemoryManager ::getAllocationData (allocData, false , true , false , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
228
189
229
190
auto allocation = memoryManager.allocateGraphicsMemory (allocData);
230
191
ASSERT_NE (nullptr , allocation);
@@ -236,7 +197,7 @@ TEST(MemoryManagerTest, givenForced32BitDisabledWhenGraphicsMemoryWith32BitFlagF
236
197
TEST (MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryMustBeZeroCopyAndIsAllocatedWithNullptrForBufferThen64kbAllocationIsReturned) {
237
198
OsAgnosticMemoryManager memoryManager (true );
238
199
AllocationData allocData;
239
- MockOsAgnosticMemoryManager ::getAllocationData (allocData, true , true , false , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
200
+ MockMemoryManager ::getAllocationData (allocData, true , true , false , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
240
201
241
202
auto allocation = memoryManager.allocateGraphicsMemory (allocData);
242
203
ASSERT_NE (nullptr , allocation);
@@ -249,9 +210,9 @@ TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryMustBeZeroCopyAnd
249
210
}
250
211
251
212
TEST (MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryWithoutAllow64kbPagesFlagsIsAllocatedThenNon64kbAllocationIsReturned) {
252
- MockOsAgnosticMemoryManager memoryManager (true );
213
+ MockMemoryManager memoryManager (true );
253
214
AllocationData allocData;
254
- MockOsAgnosticMemoryManager ::getAllocationData (allocData, false , true , false , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
215
+ MockMemoryManager ::getAllocationData (allocData, false , true , false , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
255
216
allocData.flags .allow64kbPages = false ;
256
217
257
218
auto allocation = memoryManager.allocateGraphicsMemory (allocData);
@@ -263,9 +224,9 @@ TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryWithoutAllow64kbP
263
224
}
264
225
265
226
TEST (MemoryManagerTest, givenDisabled64kbPagesWhenGraphicsMemoryMustBeZeroCopyAndIsAllocatedWithNullptrForBufferThenNon64kbAllocationIsReturned) {
266
- MockOsAgnosticMemoryManager memoryManager (false );
227
+ MockMemoryManager memoryManager (false );
267
228
AllocationData allocData;
268
- MockOsAgnosticMemoryManager ::getAllocationData (allocData, true , true , false , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
229
+ MockMemoryManager ::getAllocationData (allocData, true , true , false , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
269
230
270
231
auto allocation = memoryManager.allocateGraphicsMemory (allocData);
271
232
ASSERT_NE (nullptr , allocation);
@@ -281,7 +242,7 @@ TEST(MemoryManagerTest, givenForced32BitAndEnabled64kbPagesWhenGraphicsMemoryMus
281
242
memoryManager.setForce32BitAllocations (true );
282
243
283
244
AllocationData allocData;
284
- MockOsAgnosticMemoryManager ::getAllocationData (allocData, true , true , false , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
245
+ MockMemoryManager ::getAllocationData (allocData, true , true , false , false , nullptr , 10 , GraphicsAllocation::AllocationType::BUFFER);
285
246
286
247
auto allocation = memoryManager.allocateGraphicsMemory (allocData);
287
248
ASSERT_NE (nullptr , allocation);
@@ -298,7 +259,7 @@ TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryIsAllocatedWithHo
298
259
OsAgnosticMemoryManager memoryManager (true );
299
260
AllocationData allocData;
300
261
char memory[1 ];
301
- MockOsAgnosticMemoryManager ::getAllocationData (allocData, true , false , false , false , &memory, 1 , GraphicsAllocation::AllocationType::BUFFER);
262
+ MockMemoryManager ::getAllocationData (allocData, true , false , false , false , &memory, 1 , GraphicsAllocation::AllocationType::BUFFER);
302
263
303
264
auto allocation = memoryManager.allocateGraphicsMemory (allocData);
304
265
ASSERT_NE (nullptr , allocation);
@@ -309,9 +270,9 @@ TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryIsAllocatedWithHo
309
270
}
310
271
311
272
TEST (MemoryManagerTest, givenMemoryManagerWhenGraphicsMemoryAllocationInDevicePoolFailsThenFallbackAllocationIsReturned) {
312
- MockOsAgnosticMemoryManager memoryManager (false );
273
+ MockMemoryManager memoryManager (false );
313
274
AllocationData allocData;
314
- MockOsAgnosticMemoryManager ::getAllocationData (allocData, false , true , false , false , nullptr , MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER);
275
+ MockMemoryManager ::getAllocationData (allocData, false , true , false , false , nullptr , MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER);
315
276
316
277
memoryManager.failInDevicePool = true ;
317
278
@@ -324,15 +285,15 @@ TEST(MemoryManagerTest, givenMemoryManagerWhenGraphicsMemoryAllocationInDevicePo
324
285
}
325
286
326
287
TEST (MemoryManagerTest, givenMemoryManagerWhenZeroCopyFlagIsNotSetThenAllocateGraphicsMemoryInPreferredPoolCanAllocateInDevicePool) {
327
- MockOsAgnosticMemoryManager memoryManager (false );
288
+ MockMemoryManager memoryManager (false );
328
289
329
290
auto allocation = memoryManager.allocateGraphicsMemoryInPreferredPool (false , true , false , false , nullptr , MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER);
330
291
EXPECT_NE (nullptr , allocation);
331
292
memoryManager.freeGraphicsMemory (allocation);
332
293
}
333
294
334
295
TEST (MemoryManagerTest, givenMemoryManagerWhenZeroCopyFlagIsNotSetAndAllocateInDevicePoolFailsWithErrorThenAllocateGraphicsMemoryInPreferredPoolReturnsNullptr) {
335
- MockOsAgnosticMemoryManager memoryManager (false );
296
+ MockMemoryManager memoryManager (false );
336
297
337
298
memoryManager.failInDevicePoolWithError = true ;
338
299
0 commit comments