2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2018-09-18 15:11:08 +08:00
|
|
|
* Copyright (C) 2017-2018 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-01-09 21:25:30 +08:00
|
|
|
#include "runtime/helpers/options.h"
|
2018-10-02 04:36:15 +08:00
|
|
|
#include "unit_tests/helpers/debug_manager_state_restore.h"
|
|
|
|
#include "unit_tests/helpers/hw_helper_tests.h"
|
2018-10-03 01:10:29 +08:00
|
|
|
#include "unit_tests/helpers/unit_test_helper.h"
|
2018-01-09 21:25:30 +08:00
|
|
|
|
|
|
|
void HwHelperTest::SetUp() {
|
|
|
|
}
|
|
|
|
void HwHelperTest::TearDown() {
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-10-03 01:10:29 +08:00
|
|
|
TEST_F(HwHelperTest, getReturnsValidHwHelperHw) {
|
2017-12-21 07:45:38 +08:00
|
|
|
auto &helper = HwHelper::get(renderCoreFamily);
|
|
|
|
EXPECT_NE(nullptr, &helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
HWTEST_F(HwHelperTest, getBindingTableStateSurfaceStatePointerReturnsCorrectPointer) {
|
|
|
|
using BINDING_TABLE_STATE = typename FamilyType::BINDING_TABLE_STATE;
|
|
|
|
BINDING_TABLE_STATE bindingTableState[4];
|
|
|
|
|
|
|
|
bindingTableState[2].getRawData(0) = 0x00123456;
|
|
|
|
|
|
|
|
auto &helper = HwHelper::get(renderCoreFamily);
|
|
|
|
|
|
|
|
auto pointer = helper.getBindingTableStateSurfaceStatePointer(bindingTableState, 2);
|
|
|
|
EXPECT_EQ(0x00123456u, pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
HWTEST_F(HwHelperTest, getBindingTableStateSizeReturnsCorrectSize) {
|
|
|
|
using BINDING_TABLE_STATE = typename FamilyType::BINDING_TABLE_STATE;
|
|
|
|
|
|
|
|
auto &helper = HwHelper::get(renderCoreFamily);
|
|
|
|
|
|
|
|
auto pointer = helper.getBindingTableStateSize();
|
|
|
|
EXPECT_EQ(sizeof(BINDING_TABLE_STATE), pointer);
|
|
|
|
}
|
|
|
|
|
2018-10-03 01:10:29 +08:00
|
|
|
TEST_F(HwHelperTest, getBindingTableStateAlignementReturnsCorrectSize) {
|
2017-12-21 07:45:38 +08:00
|
|
|
auto &helper = HwHelper::get(renderCoreFamily);
|
|
|
|
EXPECT_NE(0u, helper.getBindingTableStateAlignement());
|
|
|
|
}
|
|
|
|
|
|
|
|
HWTEST_F(HwHelperTest, getInterfaceDescriptorDataSizeReturnsCorrectSize) {
|
|
|
|
using INTERFACE_DESCRIPTOR_DATA = typename FamilyType::INTERFACE_DESCRIPTOR_DATA;
|
|
|
|
auto &helper = HwHelper::get(renderCoreFamily);
|
|
|
|
|
|
|
|
EXPECT_EQ(sizeof(INTERFACE_DESCRIPTOR_DATA), helper.getInterfaceDescriptorDataSize());
|
|
|
|
}
|
|
|
|
|
2018-10-03 01:10:29 +08:00
|
|
|
TEST_F(HwHelperTest, givenDebuggingInactiveWhenSipKernelTypeIsQueriedThenCsrTypeIsReturned) {
|
2018-04-06 20:25:22 +08:00
|
|
|
auto &helper = HwHelper::get(renderCoreFamily);
|
|
|
|
EXPECT_NE(nullptr, &helper);
|
|
|
|
|
|
|
|
auto sipType = helper.getSipKernelType(false);
|
|
|
|
EXPECT_EQ(SipKernelType::Csr, sipType);
|
|
|
|
}
|
|
|
|
|
2018-10-03 01:10:29 +08:00
|
|
|
TEST_F(HwHelperTest, givenEngineTypeRcsWhenCsTraitsAreQueiredThenCorrectNameInTraitsIsReturned) {
|
2018-09-26 03:44:36 +08:00
|
|
|
auto &helper = HwHelper::get(renderCoreFamily);
|
|
|
|
EXPECT_NE(nullptr, &helper);
|
|
|
|
|
|
|
|
auto &csTraits = helper.getCsTraits(EngineType::ENGINE_RCS);
|
|
|
|
EXPECT_STREQ("RCS", csTraits.name);
|
|
|
|
}
|
|
|
|
|
2018-10-03 01:10:29 +08:00
|
|
|
HWTEST_F(HwHelperTest, givenHwHelperWhenAskedForPageTableManagerSupportThenReturnCorrectValue) {
|
|
|
|
auto &helper = HwHelper::get(renderCoreFamily);
|
2018-11-21 23:47:21 +08:00
|
|
|
EXPECT_EQ(helper.isPageTableManagerSupported(hwInfoHelper.hwInfo), UnitTestHelper<FamilyType>::isPageTableManagerSupported(hwInfoHelper.hwInfo));
|
2018-10-03 01:10:29 +08:00
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
TEST(DwordBuilderTest, setNonMaskedBits) {
|
|
|
|
uint32_t dword = 0;
|
|
|
|
|
|
|
|
// expect non-masked bit 2
|
|
|
|
uint32_t expectedDword = (1 << 2);
|
|
|
|
dword = DwordBuilder::build(2, false, true, 0); // set 2nd bit
|
|
|
|
EXPECT_EQ(expectedDword, dword);
|
|
|
|
|
|
|
|
// expect non-masked bits 2 and 3
|
|
|
|
expectedDword |= (1 << 3);
|
|
|
|
dword = DwordBuilder::build(3, false, true, dword); // set 3rd bit with init value
|
|
|
|
EXPECT_EQ(expectedDword, dword);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DwordBuilderTest, setMaskedBits) {
|
|
|
|
uint32_t dword = 0;
|
|
|
|
|
|
|
|
// expect masked bit 2
|
|
|
|
uint32_t expectedDword = (1 << 2);
|
|
|
|
expectedDword |= (1 << (2 + 16));
|
|
|
|
dword = DwordBuilder::build(2, true, true, 0); // set 2nd bit (masked)
|
|
|
|
EXPECT_EQ(expectedDword, dword);
|
|
|
|
|
|
|
|
// expect masked bits 2 and 3
|
|
|
|
expectedDword |= (1 << 3);
|
|
|
|
expectedDword |= (1 << (3 + 16));
|
|
|
|
dword = DwordBuilder::build(3, true, true, dword); // set 3rd bit (masked) with init value
|
|
|
|
EXPECT_EQ(expectedDword, dword);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DwordBuilderTest, setMaskedBitsWithDifferentBitValue) {
|
|
|
|
// expect only mask bit
|
|
|
|
uint32_t expectedDword = 1 << (2 + 16);
|
|
|
|
auto dword = DwordBuilder::build(2, true, false, 0);
|
|
|
|
EXPECT_EQ(expectedDword, dword);
|
|
|
|
|
|
|
|
// expect masked bits 3
|
|
|
|
expectedDword = (1 << 3);
|
|
|
|
expectedDword |= (1 << (3 + 16));
|
|
|
|
dword = DwordBuilder::build(3, true, true, 0);
|
|
|
|
EXPECT_EQ(expectedDword, dword);
|
|
|
|
}
|
2018-02-05 18:48:58 +08:00
|
|
|
|
|
|
|
using LriHelperTests = ::testing::Test;
|
|
|
|
|
|
|
|
HWTEST_F(LriHelperTests, givenAddressAndOffsetWhenHelperIsUsedThenProgramCmdStream) {
|
|
|
|
using MI_LOAD_REGISTER_IMM = typename FamilyType::MI_LOAD_REGISTER_IMM;
|
|
|
|
std::unique_ptr<uint8_t> buffer(new uint8_t[128]);
|
|
|
|
|
|
|
|
LinearStream stream(buffer.get(), 128);
|
|
|
|
uint32_t address = 0x8888;
|
|
|
|
uint32_t data = 0x1234;
|
|
|
|
|
|
|
|
auto expectedLri = MI_LOAD_REGISTER_IMM::sInit();
|
|
|
|
expectedLri.setRegisterOffset(address);
|
|
|
|
expectedLri.setDataDword(data);
|
|
|
|
|
|
|
|
auto lri = LriHelper<FamilyType>::program(&stream, address, data);
|
|
|
|
|
|
|
|
EXPECT_EQ(sizeof(MI_LOAD_REGISTER_IMM), stream.getUsed());
|
2018-03-05 18:03:38 +08:00
|
|
|
EXPECT_EQ(lri, stream.getCpuBase());
|
2018-02-05 18:48:58 +08:00
|
|
|
EXPECT_TRUE(memcmp(lri, &expectedLri, sizeof(MI_LOAD_REGISTER_IMM)) == 0);
|
|
|
|
}
|
2018-04-27 15:42:32 +08:00
|
|
|
|
2018-11-23 17:32:15 +08:00
|
|
|
using PipeControlHelperTests = ::testing::Test;
|
|
|
|
|
|
|
|
HWTEST_F(PipeControlHelperTests, givenPostSyncWriteTimestampModeWhenHelperIsUsedThenProperFieldsAreProgrammed) {
|
|
|
|
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
|
|
|
|
std::unique_ptr<uint8_t> buffer(new uint8_t[128]);
|
|
|
|
|
|
|
|
LinearStream stream(buffer.get(), 128);
|
|
|
|
uint64_t address = 0x1234567887654321;
|
|
|
|
uint64_t immediateData = 0x1234;
|
|
|
|
|
|
|
|
auto expectedPipeControl = PIPE_CONTROL::sInit();
|
|
|
|
expectedPipeControl.setCommandStreamerStallEnable(true);
|
|
|
|
expectedPipeControl.setPostSyncOperation(PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_TIMESTAMP);
|
|
|
|
expectedPipeControl.setAddress(static_cast<uint32_t>(address & 0x0000FFFFFFFFULL));
|
|
|
|
expectedPipeControl.setAddressHigh(static_cast<uint32_t>(address >> 32));
|
|
|
|
|
|
|
|
auto pipeControl = PipeControlHelper<FamilyType>::obtainPipeControlAndProgramPostSyncOperation(&stream, PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_TIMESTAMP, address, immediateData);
|
|
|
|
|
|
|
|
EXPECT_EQ(sizeof(PIPE_CONTROL), stream.getUsed());
|
|
|
|
EXPECT_EQ(pipeControl, stream.getCpuBase());
|
|
|
|
EXPECT_TRUE(memcmp(pipeControl, &expectedPipeControl, sizeof(PIPE_CONTROL)) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
HWTEST_F(PipeControlHelperTests, givenPostSyncWriteImmediateDataModeWhenHelperIsUsedThenProperFieldsAreProgrammed) {
|
|
|
|
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
|
|
|
|
std::unique_ptr<uint8_t> buffer(new uint8_t[128]);
|
|
|
|
|
|
|
|
LinearStream stream(buffer.get(), 128);
|
|
|
|
uint64_t address = 0x1234567887654321;
|
|
|
|
uint64_t immediateData = 0x1234;
|
|
|
|
|
|
|
|
auto expectedPipeControl = PIPE_CONTROL::sInit();
|
|
|
|
expectedPipeControl.setCommandStreamerStallEnable(true);
|
|
|
|
expectedPipeControl.setPostSyncOperation(PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA);
|
|
|
|
expectedPipeControl.setAddress(static_cast<uint32_t>(address & 0x0000FFFFFFFFULL));
|
|
|
|
expectedPipeControl.setAddressHigh(static_cast<uint32_t>(address >> 32));
|
|
|
|
expectedPipeControl.setImmediateData(immediateData);
|
|
|
|
|
|
|
|
auto pipeControl = PipeControlHelper<FamilyType>::obtainPipeControlAndProgramPostSyncOperation(&stream, PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA, address, immediateData);
|
|
|
|
|
|
|
|
EXPECT_EQ(sizeof(PIPE_CONTROL), stream.getUsed());
|
|
|
|
EXPECT_EQ(pipeControl, stream.getCpuBase());
|
|
|
|
EXPECT_TRUE(memcmp(pipeControl, &expectedPipeControl, sizeof(PIPE_CONTROL)) == 0);
|
|
|
|
}
|
|
|
|
|
2018-04-27 15:42:32 +08:00
|
|
|
TEST(HwInfoTest, givenHwInfoWhenIsCoreThenPlatformTypeIsCore) {
|
|
|
|
HardwareInfo hwInfo;
|
|
|
|
hwInfo.capabilityTable.isCore = true;
|
|
|
|
auto platformType = getPlatformType(hwInfo);
|
|
|
|
EXPECT_STREQ("core", platformType);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(HwInfoTest, givenHwInfoWhenIsNotCoreThenPlatformTypeIsLp) {
|
|
|
|
HardwareInfo hwInfo;
|
|
|
|
hwInfo.capabilityTable.isCore = false;
|
|
|
|
auto platformType = getPlatformType(hwInfo);
|
|
|
|
EXPECT_STREQ("lp", platformType);
|
|
|
|
}
|
2018-10-02 04:36:15 +08:00
|
|
|
|
|
|
|
TEST(HwInfoTest, givenHwInfoWhenChosenEngineTypeQueriedThenDefaultIsReturned) {
|
|
|
|
HardwareInfo hwInfo;
|
|
|
|
hwInfo.capabilityTable.defaultEngineType = EngineType::ENGINE_RCS;
|
|
|
|
auto engineType = getChosenEngineType(hwInfo);
|
|
|
|
EXPECT_EQ(EngineType::ENGINE_RCS, engineType);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(HwInfoTest, givenNodeOrdinalSetWhenChosenEngineTypeQueriedThenSetValueIsReturned) {
|
|
|
|
DebugManagerStateRestore dbgRestore;
|
|
|
|
DebugManager.flags.NodeOrdinal.set(EngineType::ENGINE_VECS);
|
|
|
|
HardwareInfo hwInfo;
|
|
|
|
hwInfo.capabilityTable.defaultEngineType = EngineType::ENGINE_RCS;
|
|
|
|
auto engineType = getChosenEngineType(hwInfo);
|
|
|
|
EXPECT_EQ(EngineType::ENGINE_VECS, engineType);
|
|
|
|
}
|