From fe0ab11fbbabec4793f9925e66b6c4c8b6881f50 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Thu, 25 Nov 2021 17:46:11 +0000 Subject: [PATCH] Add test for cmdlist reserve space Signed-off-by: Mateusz Jablonski --- .../sources/cmdlist/test_cmdlist_5.cpp | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_5.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_5.cpp index aaa363eb15..b62c11b14a 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_5.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_5.cpp @@ -874,5 +874,53 @@ HWTEST2_F(MultiTileImmediateInternalCommandListTest, GivenMultiTileDeviceWhenCre EXPECT_EQ(1u, commandList->partitionCount); } +HWTEST_F(CommandListCreate, WhenReservingSpaceThenCommandsAddedToBatchBuffer) { + ze_result_t returnValue; + std::unique_ptr commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue)); + EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue); + ASSERT_NE(nullptr, commandList); + ASSERT_NE(nullptr, commandList->commandContainer.getCommandStream()); + auto commandStream = commandList->commandContainer.getCommandStream(); + + auto usedSpaceBefore = commandStream->getUsed(); + + using MI_NOOP = typename FamilyType::MI_NOOP; + MI_NOOP cmd = FamilyType::cmdInitNoop; + uint32_t uniqueIDforTest = 0x12345u; + cmd.setIdentificationNumber(uniqueIDforTest); + + size_t sizeToReserveForCommand = sizeof(cmd); + void *ptrToReservedMemory = nullptr; + returnValue = commandList->reserveSpace(sizeToReserveForCommand, &ptrToReservedMemory); + ASSERT_EQ(ZE_RESULT_SUCCESS, returnValue); + + if (ptrToReservedMemory != nullptr) { + *reinterpret_cast(ptrToReservedMemory) = cmd; + } + + auto usedSpaceAfter = commandStream->getUsed(); + ASSERT_GT(usedSpaceAfter, usedSpaceBefore); + + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, commandStream->getCpuBase(), usedSpaceAfter)); + + auto itor = cmdList.begin(); + while (itor != cmdList.end()) { + using MI_NOOP = typename FamilyType::MI_NOOP; + itor = find(itor, cmdList.end()); + if (itor == cmdList.end()) + break; + + auto cmd = genCmdCast(*itor); + if (uniqueIDforTest == cmd->getIdentificationNumber()) { + break; + } + + itor++; + } + ASSERT_NE(itor, cmdList.end()); +} + } // namespace ult } // namespace L0