mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 23:03:02 +08:00
Add unit tests for level zero CommandList
Change-Id: Ie6dc0fb9177188873aef96670d7e933a15af75cf Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
4e4d160efd
commit
9ad71b47b6
@@ -12,6 +12,7 @@
|
||||
#include "shared/source/device/device_info.h"
|
||||
|
||||
#include "level_zero/core/source/device/device.h"
|
||||
#include "level_zero/core/source/device/device_imp.h"
|
||||
#include "level_zero/core/source/driver/driver_handle.h"
|
||||
#include "level_zero/core/test/unit_tests/mock.h"
|
||||
#include "level_zero/core/test/unit_tests/white_box.h"
|
||||
@@ -110,6 +111,17 @@ struct Mock<Device> : public Device {
|
||||
MOCK_CONST_METHOD0(getDebugSurface, NEO::GraphicsAllocation *());
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Mock<L0::DeviceImp> : public L0::DeviceImp {
|
||||
using Base = L0::DeviceImp;
|
||||
|
||||
explicit Mock(NEO::Device *device, NEO::ExecutionEnvironment *execEnv) {
|
||||
device->incRefInternal();
|
||||
Base::execEnvironment = execEnv;
|
||||
Base::neoDevice = device;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
|
||||
|
||||
@@ -9,4 +9,4 @@ target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/deferred_deleter_test.cpp
|
||||
)
|
||||
|
||||
add_subdirectories()
|
||||
add_subdirectories()
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#
|
||||
# Copyright (C) 2020 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist.cpp
|
||||
)
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/test/unit_test/helpers/default_hw_info.h"
|
||||
|
||||
#include "opencl/test/unit_test/mocks/mock_device.h"
|
||||
#include "test.h"
|
||||
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_device.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
struct L0DeviceFixture {
|
||||
void SetUp() {
|
||||
neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get());
|
||||
device = std::make_unique<Mock<L0::DeviceImp>>(neoDevice, neoDevice->getExecutionEnvironment());
|
||||
}
|
||||
|
||||
void TearDown() {
|
||||
}
|
||||
|
||||
NEO::MockDevice *neoDevice = nullptr;
|
||||
std::unique_ptr<Mock<L0::DeviceImp>> device = nullptr;
|
||||
};
|
||||
|
||||
using CommandListCreate = Test<L0DeviceFixture>;
|
||||
|
||||
TEST_F(CommandListCreate, whenCommandListIsCreatedThenItIsInitialized) {
|
||||
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device.get()));
|
||||
ASSERT_NE(nullptr, commandList);
|
||||
|
||||
EXPECT_EQ(device.get(), commandList->device);
|
||||
ASSERT_GT(commandList->commandContainer.getCmdBufferAllocations().size(), 0u);
|
||||
|
||||
auto numAllocations = 0u;
|
||||
auto allocation = whitebox_cast(commandList->commandContainer.getCmdBufferAllocations()[0]);
|
||||
ASSERT_NE(allocation, nullptr);
|
||||
|
||||
++numAllocations;
|
||||
|
||||
ASSERT_NE(nullptr, commandList->commandContainer.getCommandStream());
|
||||
for (uint32_t i = 0; i < NEO::HeapType::NUM_TYPES; i++) {
|
||||
ASSERT_NE(commandList->commandContainer.getIndirectHeap(static_cast<NEO::HeapType>(i)), nullptr);
|
||||
++numAllocations;
|
||||
ASSERT_NE(commandList->commandContainer.getIndirectHeapAllocation(static_cast<NEO::HeapType>(i)), nullptr);
|
||||
}
|
||||
|
||||
EXPECT_LT(0u, commandList->commandContainer.getCommandStream()->getAvailableSpace());
|
||||
ASSERT_EQ(commandList->commandContainer.getResidencyContainer().size(), numAllocations);
|
||||
EXPECT_EQ(commandList->commandContainer.getResidencyContainer().front(), allocation);
|
||||
}
|
||||
|
||||
TEST_F(CommandListCreate, givenRegularCommandListThenDefaultNumIddPerBlockIsUsed) {
|
||||
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device.get()));
|
||||
ASSERT_NE(nullptr, commandList);
|
||||
|
||||
const uint32_t defaultNumIdds = CommandList::defaultNumIddsPerBlock;
|
||||
EXPECT_EQ(defaultNumIdds, commandList->commandContainer.getNumIddPerBlock());
|
||||
}
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
Reference in New Issue
Block a user