@@ -162,3 +162,79 @@ TEST_F(UnifiedSharingTestsWithMemoryManager, givenUnifiedSharingHandlerWhenAcqui
162162 sharingHandler->release (buffer.get ());
163163 EXPECT_EQ (1u , sharingHandler->releaseResourceCalled );
164164}
165+
166+ struct UnifiedSharingCreateAllocationTests : UnifiedSharingTestsWithMemoryManager {
167+ struct MemoryManagerCheckingAllocationMethod : MockMemoryManager {
168+ using MockMemoryManager::MockMemoryManager;
169+
170+ GraphicsAllocation *createGraphicsAllocationFromNTHandle (void *handle, uint32_t rootDeviceIndex) override {
171+ this ->createFromNTHandleCalled = true ;
172+ this ->handle = (osHandle)(uint64_t )handle;
173+ return nullptr ;
174+ }
175+ GraphicsAllocation *createGraphicsAllocationFromSharedHandle (osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override {
176+ this ->createFromSharedHandleCalled = true ;
177+ this ->handle = handle;
178+ this ->properties = std::make_unique<AllocationProperties>(properties);
179+ return nullptr ;
180+ }
181+
182+ bool createFromNTHandleCalled = false ;
183+ bool createFromSharedHandleCalled = false ;
184+ osHandle handle;
185+ std::unique_ptr<AllocationProperties> properties;
186+ };
187+
188+ struct MockSharingHandler : UnifiedSharing {
189+ using UnifiedSharing::createGraphicsAllocation;
190+ };
191+
192+ void SetUp () override {
193+ UnifiedSharingTestsWithMemoryManager::SetUp ();
194+ this ->memoryManager = std::make_unique<MemoryManagerCheckingAllocationMethod>();
195+ this ->memoryManagerBackup = std::make_unique<VariableBackup<MemoryManager *>>(&this ->context ->memoryManager , this ->memoryManager .get ());
196+ }
197+
198+ std::unique_ptr<MemoryManagerCheckingAllocationMethod> memoryManager;
199+ std::unique_ptr<VariableBackup<MemoryManager *>> memoryManagerBackup;
200+ };
201+
202+ TEST_F (UnifiedSharingCreateAllocationTests, givenWindowsNtHandleWhenCreateGraphicsAllocationIsCalledThenUseNtHandleMethod) {
203+ UnifiedSharingMemoryDescription desc{};
204+ desc.handle = reinterpret_cast <void *>(0x1234 );
205+ desc.type = UnifiedSharingHandleType::Win32Nt;
206+ GraphicsAllocation::AllocationType allocationType = GraphicsAllocation::AllocationType::SHARED_IMAGE;
207+ MockSharingHandler::createGraphicsAllocation (this ->context .get (), desc, allocationType);
208+
209+ EXPECT_TRUE (memoryManager->createFromNTHandleCalled );
210+ EXPECT_FALSE (memoryManager->createFromSharedHandleCalled );
211+ EXPECT_EQ ((osHandle)(uint64_t )desc.handle , memoryManager->handle );
212+ }
213+
214+ TEST_F (UnifiedSharingCreateAllocationTests, givenWindowsSharedHandleWhenCreateGraphicsAllocationIsCalledThenUseSharedHandleMethod) {
215+ UnifiedSharingMemoryDescription desc{};
216+ desc.handle = reinterpret_cast <void *>(0x1234 );
217+ desc.type = UnifiedSharingHandleType::Win32Shared;
218+ GraphicsAllocation::AllocationType allocationType = GraphicsAllocation::AllocationType::SHARED_IMAGE;
219+ MockSharingHandler::createGraphicsAllocation (this ->context .get (), desc, allocationType);
220+
221+ EXPECT_FALSE (memoryManager->createFromNTHandleCalled );
222+ EXPECT_TRUE (memoryManager->createFromSharedHandleCalled );
223+ EXPECT_EQ ((osHandle)(uint64_t )desc.handle , memoryManager->handle );
224+ const AllocationProperties expectedProperties{0u , false , 0u , allocationType, false };
225+ EXPECT_EQ (expectedProperties.allFlags , memoryManager->properties ->allFlags );
226+ }
227+
228+ TEST_F (UnifiedSharingCreateAllocationTests, givenLinuxSharedHandleWhenCreateGraphicsAllocationIsCalledThenUseSharedHandleMethod) {
229+ UnifiedSharingMemoryDescription desc{};
230+ desc.handle = reinterpret_cast <void *>(0x1234 );
231+ desc.type = UnifiedSharingHandleType::LinuxFd;
232+ GraphicsAllocation::AllocationType allocationType = GraphicsAllocation::AllocationType::SHARED_IMAGE;
233+ MockSharingHandler::createGraphicsAllocation (this ->context .get (), desc, allocationType);
234+
235+ EXPECT_FALSE (memoryManager->createFromNTHandleCalled );
236+ EXPECT_TRUE (memoryManager->createFromSharedHandleCalled );
237+ EXPECT_EQ ((osHandle)(uint64_t )desc.handle , memoryManager->handle );
238+ const AllocationProperties expectedProperties{0u , false , 0u , allocationType, false };
239+ EXPECT_EQ (expectedProperties.allFlags , memoryManager->properties ->allFlags );
240+ }
0 commit comments