@@ -1070,5 +1070,118 @@ HWTEST2_F(CommandListCreate, givenCopyOnlyCommandListWhenAppendBlitFillCalledWit
10701070 EXPECT_EQ (allocValue, pattern[i % 4 ]);
10711071 }
10721072}
1073+
1074+ HWTEST2_F (CommandListCreate, givenHostAllocInMapWhenGettingAllocInRangeThenAllocFromMapReturned, Platforms) {
1075+ auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
1076+ commandList->initialize (device, true );
1077+ uint64_t gpuAddress = 0x1200 ;
1078+ const void *cpuPtr = reinterpret_cast <const void *>(gpuAddress);
1079+ size_t allocSize = 0x1000 ;
1080+ NEO::MockGraphicsAllocation alloc (const_cast <void *>(cpuPtr), gpuAddress, allocSize);
1081+ commandList->hostPtrMap .insert (std::make_pair (cpuPtr, &alloc));
1082+
1083+ auto newBufferPtr = ptrOffset (cpuPtr, 0x10 );
1084+ auto newBufferSize = allocSize - 0x20 ;
1085+ auto newAlloc = commandList->getAllocationFromHostPtrMap (newBufferPtr, newBufferSize);
1086+ EXPECT_NE (newAlloc, nullptr );
1087+ commandList->hostPtrMap .clear ();
1088+ }
1089+
1090+ HWTEST2_F (CommandListCreate, givenHostAllocInMapWhenSizeIsOutOfRangeThenNullPtrReturned, Platforms) {
1091+ auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
1092+ commandList->initialize (device, true );
1093+ uint64_t gpuAddress = 0x1200 ;
1094+ const void *cpuPtr = reinterpret_cast <const void *>(gpuAddress);
1095+ size_t allocSize = 0x1000 ;
1096+ NEO::MockGraphicsAllocation alloc (const_cast <void *>(cpuPtr), gpuAddress, allocSize);
1097+ commandList->hostPtrMap .insert (std::make_pair (cpuPtr, &alloc));
1098+
1099+ auto newBufferPtr = ptrOffset (cpuPtr, 0x10 );
1100+ auto newBufferSize = allocSize + 0x20 ;
1101+ auto newAlloc = commandList->getAllocationFromHostPtrMap (newBufferPtr, newBufferSize);
1102+ EXPECT_EQ (newAlloc, nullptr );
1103+ commandList->hostPtrMap .clear ();
1104+ }
1105+
1106+ HWTEST2_F (CommandListCreate, givenHostAllocInMapWhenPtrIsOutOfRangeThenNullPtrReturned, Platforms) {
1107+ auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
1108+ commandList->initialize (device, true );
1109+ uint64_t gpuAddress = 0x1200 ;
1110+ const void *cpuPtr = reinterpret_cast <const void *>(gpuAddress);
1111+ size_t allocSize = 0x1000 ;
1112+ NEO::MockGraphicsAllocation alloc (const_cast <void *>(cpuPtr), gpuAddress, allocSize);
1113+ commandList->hostPtrMap .insert (std::make_pair (cpuPtr, &alloc));
1114+
1115+ auto newBufferPtr = reinterpret_cast <const void *>(gpuAddress - 0x100 );
1116+ auto newBufferSize = allocSize - 0x200 ;
1117+ auto newAlloc = commandList->getAllocationFromHostPtrMap (newBufferPtr, newBufferSize);
1118+ EXPECT_EQ (newAlloc, nullptr );
1119+ commandList->hostPtrMap .clear ();
1120+ }
1121+
1122+ HWTEST2_F (CommandListCreate, givenHostAllocInMapWhenGetHostPtrAllocCalledThenCorrectOffsetIsSet, Platforms) {
1123+ auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
1124+ commandList->initialize (device, true );
1125+ uint64_t gpuAddress = 0x1200 ;
1126+ const void *cpuPtr = reinterpret_cast <const void *>(gpuAddress);
1127+ size_t allocSize = 0x1000 ;
1128+ NEO::MockGraphicsAllocation alloc (const_cast <void *>(cpuPtr), gpuAddress, allocSize);
1129+ commandList->hostPtrMap .insert (std::make_pair (cpuPtr, &alloc));
1130+ size_t expectedOffset = 0x10 ;
1131+ auto newBufferPtr = ptrOffset (cpuPtr, expectedOffset);
1132+ auto newBufferSize = allocSize - 0x20 ;
1133+ size_t offset = 0 ;
1134+ auto newAlloc = commandList->getHostPtrAlloc (newBufferPtr, newBufferSize, &offset);
1135+ EXPECT_NE (newAlloc, nullptr );
1136+ EXPECT_EQ (offset, expectedOffset);
1137+ commandList->hostPtrMap .clear ();
1138+ }
1139+
1140+ HWTEST2_F (CommandListCreate, givenHostAllocInMapWhenPtrIsInMapThenAllocationReturned, Platforms) {
1141+ auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
1142+ commandList->initialize (device, true );
1143+ uint64_t gpuAddress = 0x1200 ;
1144+ const void *cpuPtr = reinterpret_cast <const void *>(gpuAddress);
1145+ size_t allocSize = 0x1000 ;
1146+ NEO::MockGraphicsAllocation alloc (const_cast <void *>(cpuPtr), gpuAddress, allocSize);
1147+ commandList->hostPtrMap .insert (std::make_pair (cpuPtr, &alloc));
1148+
1149+ auto newBufferPtr = cpuPtr;
1150+ auto newBufferSize = allocSize - 0x20 ;
1151+ auto newAlloc = commandList->getAllocationFromHostPtrMap (newBufferPtr, newBufferSize);
1152+ EXPECT_EQ (newAlloc, &alloc);
1153+ commandList->hostPtrMap .clear ();
1154+ }
1155+ HWTEST2_F (CommandListCreate, givenHostAllocInMapWhenPtrIsInMapButWithBiggerSizeThenNullPtrReturned, Platforms) {
1156+ auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
1157+ commandList->initialize (device, true );
1158+ uint64_t gpuAddress = 0x1200 ;
1159+ const void *cpuPtr = reinterpret_cast <const void *>(gpuAddress);
1160+ size_t allocSize = 0x1000 ;
1161+ NEO::MockGraphicsAllocation alloc (const_cast <void *>(cpuPtr), gpuAddress, allocSize);
1162+ commandList->hostPtrMap .insert (std::make_pair (cpuPtr, &alloc));
1163+
1164+ auto newBufferPtr = cpuPtr;
1165+ auto newBufferSize = allocSize + 0x20 ;
1166+ auto newAlloc = commandList->getAllocationFromHostPtrMap (newBufferPtr, newBufferSize);
1167+ EXPECT_EQ (newAlloc, nullptr );
1168+ commandList->hostPtrMap .clear ();
1169+ }
1170+ HWTEST2_F (CommandListCreate, givenHostAllocInMapWhenPtrLowerThanAnyInMapThenNullPtrReturned, Platforms) {
1171+ auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
1172+ commandList->initialize (device, true );
1173+ uint64_t gpuAddress = 0x1200 ;
1174+ const void *cpuPtr = reinterpret_cast <const void *>(gpuAddress);
1175+ size_t allocSize = 0x1000 ;
1176+ NEO::MockGraphicsAllocation alloc (const_cast <void *>(cpuPtr), gpuAddress, allocSize);
1177+ commandList->hostPtrMap .insert (std::make_pair (cpuPtr, &alloc));
1178+
1179+ auto newBufferPtr = reinterpret_cast <const void *>(gpuAddress - 0x10 );
1180+ auto newBufferSize = allocSize - 0x20 ;
1181+ auto newAlloc = commandList->getAllocationFromHostPtrMap (newBufferPtr, newBufferSize);
1182+ EXPECT_EQ (newAlloc, nullptr );
1183+ commandList->hostPtrMap .clear ();
1184+ }
1185+
10731186} // namespace ult
10741187} // namespace L0
0 commit comments