@@ -1287,5 +1287,76 @@ HWTEST2_F(CommandListCreate, givenNonEmptyCommandsToPatchWhenClearCommandsToPatc
1287
1287
EXPECT_TRUE (pCommandList->commandsToPatch .empty ());
1288
1288
}
1289
1289
1290
+ template <NEO::AllocationType AllocType>
1291
+ class MyDeviceMock : public Mock <Device> {
1292
+ public:
1293
+ NEO::GraphicsAllocation *allocateMemoryFromHostPtr (const void *buffer, size_t size, bool hostCopyAllowed) override {
1294
+ auto alloc = std::make_unique<NEO::MockGraphicsAllocation>(const_cast <void *>(buffer), reinterpret_cast <uintptr_t >(buffer), size);
1295
+ alloc->allocationType = AllocType;
1296
+ return alloc.release ();
1297
+ }
1298
+ const NEO::HardwareInfo &getHwInfo () const override {
1299
+ return neoDevice->getHardwareInfo ();
1300
+ }
1301
+ };
1302
+
1303
+ HWTEST2_F (CommandListCreate, givenHostPtrAllocAllocWhenInternalMemCreatedThenNewAllocAddedToDealocationContainer, IsAtLeastSkl) {
1304
+ auto myDevice = std::make_unique<MyDeviceMock<NEO::AllocationType::INTERNAL_HOST_MEMORY>>();
1305
+ myDevice->neoDevice = device->getNEODevice ();
1306
+ auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
1307
+ commandList->initialize (myDevice.get (), NEO::EngineGroupType::Copy, 0u );
1308
+ auto buffer = std::make_unique<uint8_t >(0x100 );
1309
+
1310
+ auto deallocationSize = commandList->commandContainer .getDeallocationContainer ().size ();
1311
+ auto alloc = commandList->getHostPtrAlloc (buffer.get (), 0x80 , true );
1312
+ EXPECT_EQ (deallocationSize + 1 , commandList->commandContainer .getDeallocationContainer ().size ());
1313
+ EXPECT_NE (alloc, nullptr );
1314
+ driverHandle.get ()->getMemoryManager ()->freeGraphicsMemory (alloc);
1315
+ commandList->commandContainer .getDeallocationContainer ().clear ();
1316
+ }
1317
+
1318
+ HWTEST2_F (CommandListCreate, givenHostPtrAllocAllocWhenExternalMemCreatedThenNewAllocAddedToHostPtrMap, IsAtLeastSkl) {
1319
+ auto myDevice = std::make_unique<MyDeviceMock<NEO::AllocationType::EXTERNAL_HOST_PTR>>();
1320
+ myDevice->neoDevice = device->getNEODevice ();
1321
+ auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
1322
+ commandList->initialize (myDevice.get (), NEO::EngineGroupType::Copy, 0u );
1323
+ auto buffer = std::make_unique<uint8_t >(0x100 );
1324
+
1325
+ auto hostPtrMapSize = commandList->getHostPtrMap ().size ();
1326
+ auto alloc = commandList->getHostPtrAlloc (buffer.get (), 0x100 , true );
1327
+ EXPECT_EQ (hostPtrMapSize + 1 , commandList->getHostPtrMap ().size ());
1328
+ EXPECT_NE (alloc, nullptr );
1329
+ driverHandle.get ()->getMemoryManager ()->freeGraphicsMemory (alloc);
1330
+ commandList->hostPtrMap .clear ();
1331
+ }
1332
+
1333
+ HWTEST2_F (CommandListCreate, givenGetAlignedAllocationWhenInternalMemWithinDifferentAllocThenReturnNewAlloc, IsAtLeastSkl) {
1334
+ auto myDevice = std::make_unique<MyDeviceMock<NEO::AllocationType::INTERNAL_HOST_MEMORY>>();
1335
+ myDevice->neoDevice = device->getNEODevice ();
1336
+ auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
1337
+ commandList->initialize (myDevice.get (), NEO::EngineGroupType::Copy, 0u );
1338
+ auto buffer = std::make_unique<uint8_t >(0x100 );
1339
+
1340
+ auto outData1 = commandList->getAlignedAllocation (device, buffer.get (), 0x100 , true );
1341
+ auto outData2 = commandList->getAlignedAllocation (device, &buffer.get ()[5 ], 0x1 , true );
1342
+ EXPECT_NE (outData1.alloc , outData2.alloc );
1343
+ driverHandle.get ()->getMemoryManager ()->freeGraphicsMemory (outData1.alloc );
1344
+ driverHandle.get ()->getMemoryManager ()->freeGraphicsMemory (outData2.alloc );
1345
+ commandList->commandContainer .getDeallocationContainer ().clear ();
1346
+ }
1347
+ HWTEST2_F (CommandListCreate, givenGetAlignedAllocationWhenExternalMemWithinDifferentAllocThenReturnPreviouslyAllocatedMem, IsAtLeastSkl) {
1348
+ auto myDevice = std::make_unique<MyDeviceMock<NEO::AllocationType::EXTERNAL_HOST_PTR>>();
1349
+ myDevice->neoDevice = device->getNEODevice ();
1350
+ auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
1351
+ commandList->initialize (myDevice.get (), NEO::EngineGroupType::Copy, 0u );
1352
+ auto buffer = std::make_unique<uint8_t >(0x100 );
1353
+
1354
+ auto outData1 = commandList->getAlignedAllocation (device, buffer.get (), 0x100 , true );
1355
+ auto outData2 = commandList->getAlignedAllocation (device, &buffer.get ()[5 ], 0x1 , true );
1356
+ EXPECT_EQ (outData1.alloc , outData2.alloc );
1357
+ driverHandle.get ()->getMemoryManager ()->freeGraphicsMemory (outData1.alloc );
1358
+ commandList->hostPtrMap .clear ();
1359
+ }
1360
+
1290
1361
} // namespace ult
1291
1362
} // namespace L0
0 commit comments