mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-09 06:23:01 +08:00
Add more cmdList unit tests
Related-To: NEO-4515 Change-Id: I0bb41e108731c605b820fe4a63fb818c9ad67abe Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
08546b65c7
commit
36eec1fe8b
@@ -20,6 +20,7 @@ set(L0_MOCKS_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_driver.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_driver_handle.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_driver_handle.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_kernel.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_manager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_manager.cpp
|
||||
)
|
||||
|
||||
71
level_zero/core/test/unit_tests/mocks/mock_kernel.h
Normal file
71
level_zero/core/test/unit_tests/mocks/mock_kernel.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/device_binary_format/patchtokens_decoder.h"
|
||||
#include "shared/source/kernel/kernel_descriptor.h"
|
||||
#include "shared/source/kernel/kernel_descriptor_from_patchtokens.h"
|
||||
|
||||
#include "level_zero/core/source/kernel/kernel_imp.h"
|
||||
#include "level_zero/core/test/unit_tests/mock.h"
|
||||
#include "level_zero/core/test/unit_tests/white_box.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
template <>
|
||||
struct WhiteBox<::L0::KernelImmutableData> : public ::L0::KernelImmutableData {
|
||||
using BaseClass = ::L0::KernelImmutableData;
|
||||
using ::L0::KernelImmutableData::crossThreadDataSize;
|
||||
using ::L0::KernelImmutableData::crossThreadDataTemplate;
|
||||
using ::L0::KernelImmutableData::device;
|
||||
using ::L0::KernelImmutableData::isaGraphicsAllocation;
|
||||
using ::L0::KernelImmutableData::kernelDescriptor;
|
||||
using ::L0::KernelImmutableData::privateMemoryGraphicsAllocation;
|
||||
using ::L0::KernelImmutableData::residencyContainer;
|
||||
|
||||
WhiteBox() : ::L0::KernelImmutableData() {}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Mock<::L0::Kernel> : public ::L0::KernelImp {
|
||||
using BaseClass = ::L0::KernelImp;
|
||||
|
||||
Mock() : BaseClass(nullptr) {
|
||||
NEO::PatchTokenBinary::KernelFromPatchtokens kernelTokens;
|
||||
iOpenCL::SKernelBinaryHeaderCommon kernelHeader;
|
||||
kernelTokens.header = &kernelHeader;
|
||||
|
||||
iOpenCL::SPatchExecutionEnvironment execEnv = {};
|
||||
kernelTokens.tokens.executionEnvironment = &execEnv;
|
||||
|
||||
this->kernelImmData = &immutableData;
|
||||
|
||||
auto allocation = new NEO::GraphicsAllocation(0, NEO::GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY,
|
||||
nullptr, 0, 0, 4096,
|
||||
MemoryPool::System4KBPages);
|
||||
|
||||
immutableData.isaGraphicsAllocation.reset(allocation);
|
||||
|
||||
NEO::populateKernelDescriptor(descriptor, kernelTokens, 8);
|
||||
immutableData.kernelDescriptor = &descriptor;
|
||||
}
|
||||
~Mock() {
|
||||
delete immutableData.isaGraphicsAllocation.release();
|
||||
}
|
||||
|
||||
void setBufferSurfaceState(uint32_t argIndex, void *address, NEO::GraphicsAllocation *alloc) override {}
|
||||
std::unique_ptr<Kernel> clone() const override {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
WhiteBox<::L0::KernelImmutableData> immutableData;
|
||||
NEO::KernelDescriptor descriptor;
|
||||
};
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
@@ -5,15 +5,32 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/gmm_helper/gmm_helper.h"
|
||||
#include "shared/test/unit_test/cmd_parse/gen_cmd_parse.h"
|
||||
|
||||
#include "test.h"
|
||||
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_kernel.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
using CommandListCreate = Test<DeviceFixture>;
|
||||
|
||||
TEST(zeCommandListCreateImmediate, redirectsToObject) {
|
||||
Mock<Device> device;
|
||||
ze_command_queue_desc_t desc = {};
|
||||
ze_command_list_handle_t commandList = {};
|
||||
|
||||
EXPECT_CALL(device, createCommandListImmediate(&desc, &commandList))
|
||||
.Times(1)
|
||||
.WillRepeatedly(::testing::Return(ZE_RESULT_SUCCESS));
|
||||
|
||||
auto result = zeCommandListCreateImmediate(device.toHandle(), &desc, &commandList);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(CommandListCreate, whenCommandListIsCreatedThenItIsInitialized) {
|
||||
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device.get()));
|
||||
ASSERT_NE(nullptr, commandList);
|
||||
@@ -81,5 +98,80 @@ TEST_F(CommandListCreate, givenInvalidProductFamilyThenReturnsNullPointer) {
|
||||
EXPECT_EQ(nullptr, commandList);
|
||||
}
|
||||
|
||||
HWTEST_F(CommandListCreate, whenCommandListIsCreatedThenStateBaseAddressCmdIsAddedAndCorrectlyProgrammed) {
|
||||
using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
|
||||
|
||||
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device.get()));
|
||||
auto &commandContainer = commandList->commandContainer;
|
||||
auto gmmHelper = commandContainer.getDevice()->getGmmHelper();
|
||||
|
||||
ASSERT_NE(nullptr, commandContainer.getCommandStream());
|
||||
auto usedSpaceBefore = commandContainer.getCommandStream()->getUsed();
|
||||
|
||||
auto result = commandList->close();
|
||||
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
auto usedSpaceAfter = commandContainer.getCommandStream()->getUsed();
|
||||
ASSERT_GT(usedSpaceAfter, usedSpaceBefore);
|
||||
|
||||
GenCmdList cmdList;
|
||||
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
|
||||
cmdList, ptrOffset(commandContainer.getCommandStream()->getCpuBase(), 0), usedSpaceAfter));
|
||||
auto itor = find<STATE_BASE_ADDRESS *>(cmdList.begin(), cmdList.end());
|
||||
ASSERT_NE(cmdList.end(), itor);
|
||||
auto cmdSba = genCmdCast<STATE_BASE_ADDRESS *>(*itor);
|
||||
|
||||
auto dsh = commandContainer.getIndirectHeap(NEO::HeapType::DYNAMIC_STATE);
|
||||
auto ioh = commandContainer.getIndirectHeap(NEO::HeapType::INDIRECT_OBJECT);
|
||||
auto ssh = commandContainer.getIndirectHeap(NEO::HeapType::SURFACE_STATE);
|
||||
|
||||
EXPECT_TRUE(cmdSba->getDynamicStateBaseAddressModifyEnable());
|
||||
EXPECT_TRUE(cmdSba->getDynamicStateBufferSizeModifyEnable());
|
||||
EXPECT_EQ(dsh->getHeapGpuBase(), cmdSba->getDynamicStateBaseAddress());
|
||||
EXPECT_EQ(dsh->getHeapSizeInPages(), cmdSba->getDynamicStateBufferSize());
|
||||
|
||||
EXPECT_TRUE(cmdSba->getIndirectObjectBaseAddressModifyEnable());
|
||||
EXPECT_TRUE(cmdSba->getIndirectObjectBufferSizeModifyEnable());
|
||||
EXPECT_EQ(ioh->getHeapGpuBase(), cmdSba->getIndirectObjectBaseAddress());
|
||||
EXPECT_EQ(ioh->getHeapSizeInPages(), cmdSba->getIndirectObjectBufferSize());
|
||||
|
||||
EXPECT_TRUE(cmdSba->getSurfaceStateBaseAddressModifyEnable());
|
||||
EXPECT_EQ(ssh->getHeapGpuBase(), cmdSba->getSurfaceStateBaseAddress());
|
||||
|
||||
EXPECT_EQ(gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER), cmdSba->getStatelessDataPortAccessMemoryObjectControlState());
|
||||
}
|
||||
|
||||
HWTEST_F(CommandListCreate, givenNotEnoughSpaceInCommandStreamWhenAppendingFunctionThenBbEndIsAddedAndNewCmdBufferAllocated) {
|
||||
using MI_BATCH_BUFFER_END = typename FamilyType::MI_BATCH_BUFFER_END;
|
||||
Mock<Kernel> kernel;
|
||||
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device.get()));
|
||||
|
||||
auto &commandContainer = commandList->commandContainer;
|
||||
const auto stream = commandContainer.getCommandStream();
|
||||
const auto streamCpu = stream->getCpuBase();
|
||||
|
||||
auto available = stream->getAvailableSpace();
|
||||
stream->getSpace(available - sizeof(MI_BATCH_BUFFER_END) - 16);
|
||||
auto bbEndPosition = stream->getSpace(0);
|
||||
|
||||
ze_group_count_t dispatchFunctionArguments{1, 1, 1};
|
||||
commandList->appendLaunchFunction(kernel.toHandle(), &dispatchFunctionArguments, nullptr, 0, nullptr);
|
||||
|
||||
auto usedSpaceAfter = commandContainer.getCommandStream()->getUsed();
|
||||
ASSERT_GT(usedSpaceAfter, 0u);
|
||||
|
||||
const auto streamCpu2 = stream->getCpuBase();
|
||||
|
||||
EXPECT_NE(nullptr, streamCpu2);
|
||||
EXPECT_NE(streamCpu, streamCpu2);
|
||||
|
||||
EXPECT_EQ(2u, commandContainer.getCmdBufferAllocations().size());
|
||||
|
||||
GenCmdList cmdList;
|
||||
FamilyType::PARSE::parseCommandBuffer(cmdList, bbEndPosition, 2 * sizeof(MI_BATCH_BUFFER_END));
|
||||
auto itor = find<MI_BATCH_BUFFER_END *>(cmdList.begin(), cmdList.end());
|
||||
EXPECT_NE(cmdList.end(), itor);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
Reference in New Issue
Block a user