From 9a89426ec1b6236e773ca0b5d089eb0782308e57 Mon Sep 17 00:00:00 2001 From: "Woloszyn, Wojciech" Date: Wed, 21 Nov 2018 07:47:21 -0800 Subject: [PATCH] Refactor unit tests - refactor image fixture - add hwInfo fixture - add missing case to mockGmm Change-Id: I5f0886b8bd8f36938e1eedc5a0a63fe01248fcad Signed-off-by: Woloszyn, Wojciech --- unit_tests/device/device_caps_tests.cpp | 6 ++-- unit_tests/fixtures/CMakeLists.txt | 2 +- unit_tests/fixtures/image_fixture.h | 9 +++--- unit_tests/gen10/hw_helper_tests_gen10.cpp | 24 ++++++++-------- unit_tests/gen8/hw_helper_tests_gen8.cpp | 16 +++++------ unit_tests/gen9/hw_helper_tests_gen9.cpp | 20 ++++++------- unit_tests/helpers/CMakeLists.txt | 1 + unit_tests/helpers/hw_helper_tests.cpp | 11 +------- unit_tests/helpers/hw_helper_tests.h | 8 ++---- unit_tests/helpers/hw_info_helper.h | 31 +++++++++++++++++++++ unit_tests/mocks/mock_gmm_resource_info.cpp | 5 ++++ unit_tests/mocks/mock_gmm_resource_info.h | 2 ++ 12 files changed, 80 insertions(+), 55 deletions(-) create mode 100644 unit_tests/helpers/hw_info_helper.h diff --git a/unit_tests/device/device_caps_tests.cpp b/unit_tests/device/device_caps_tests.cpp index 649a1d2957..b09578e7e4 100644 --- a/unit_tests/device/device_caps_tests.cpp +++ b/unit_tests/device/device_caps_tests.cpp @@ -860,7 +860,7 @@ typedef HwHelperTest DeviceCapsWithModifiedHwInfoTest; TEST_F(DeviceCapsWithModifiedHwInfoTest, GivenLocalMemorySupportedAndOsEnableLocalMemoryAndEnableLocalMemoryDebugVarWhenSetThenGetEnableLocalMemoryReturnCorrectValue) { DebugManagerStateRestore dbgRestore; VariableBackup orgOsEnableLocalMemory(&OSInterface::osEnableLocalMemory); - std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(&hwInfo)); + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(&hwInfoHelper.hwInfo)); bool orgHwCapsLocalMemorySupported = device->getHardwareCapabilities().localMemorySupported; DebugManager.flags.EnableLocalMemory.set(false); @@ -889,9 +889,9 @@ TEST_F(DeviceCapsWithModifiedHwInfoTest, GivenLocalMemorySupportedAndOsEnableLoc TEST_F(DeviceCapsWithModifiedHwInfoTest, givenPlatformWithSourceLevelDebuggerNotSupportedWhenDeviceIsCreatedThenSourceLevelDebuggerActiveIsSetToFalse) { - hwInfo.capabilityTable.sourceLevelDebuggerSupported = false; + hwInfoHelper.hwInfo.capabilityTable.sourceLevelDebuggerSupported = false; - std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(&hwInfo)); + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(&hwInfoHelper.hwInfo)); const auto &caps = device->getDeviceInfo(); EXPECT_EQ(nullptr, device->getSourceLevelDebugger()); diff --git a/unit_tests/fixtures/CMakeLists.txt b/unit_tests/fixtures/CMakeLists.txt index 07c7907605..46e5ac3f49 100644 --- a/unit_tests/fixtures/CMakeLists.txt +++ b/unit_tests/fixtures/CMakeLists.txt @@ -40,4 +40,4 @@ set(IGDRCL_SRCS_tests_fixtures ${CMAKE_CURRENT_SOURCE_DIR}/ult_command_stream_receiver_fixture.h ) target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_fixtures}) -set_property(GLOBAL PROPERTY IGDRCL_SRCS_tests_fixtures ${IGDRCL_SRCS_tests_fixtures}) \ No newline at end of file +set_property(GLOBAL PROPERTY IGDRCL_SRCS_tests_fixtures ${IGDRCL_SRCS_tests_fixtures}) diff --git a/unit_tests/fixtures/image_fixture.h b/unit_tests/fixtures/image_fixture.h index cab7c705ca..e087ce9c4d 100644 --- a/unit_tests/fixtures/image_fixture.h +++ b/unit_tests/fixtures/image_fixture.h @@ -12,6 +12,7 @@ #include "runtime/helpers/options.h" #include "runtime/mem_obj/image.h" #include "runtime/platform/platform.h" +#include "unit_tests/helpers/hw_info_helper.h" #include "unit_tests/mocks/mock_context.h" #include "CL/cl.h" #include @@ -108,18 +109,16 @@ class ImageClearColorFixture { public: using GmmHelper = OCLRT::GmmHelper; using MockContext = OCLRT::MockContext; - using HardwareInfo = OCLRT::HardwareInfo; using Image = OCLRT::Image; using ImageHw = OCLRT::ImageHw; using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE; using AUXILIARY_SURFACE_MODE = typename FamilyType::RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE; void SetUp() { - localHwInfo = *OCLRT::platformDevices[0]; - localHwInfo.capabilityTable.ftrRenderCompressedImages = true; + hwInfoHelper.hwInfo.capabilityTable.ftrRenderCompressedImages = true; OCLRT::platformImpl.reset(); - OCLRT::constructPlatform()->peekExecutionEnvironment()->initGmm(&localHwInfo); + OCLRT::constructPlatform()->peekExecutionEnvironment()->initGmm(&hwInfoHelper.hwInfo); surfaceState = RENDER_SURFACE_STATE::sInit(); surfaceState.setAuxiliarySurfaceMode(AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_CCS_E); @@ -133,7 +132,7 @@ class ImageClearColorFixture { } RENDER_SURFACE_STATE surfaceState; - HardwareInfo localHwInfo = {}; + HwInfoHelper hwInfoHelper; protected: MockContext context; diff --git a/unit_tests/gen10/hw_helper_tests_gen10.cpp b/unit_tests/gen10/hw_helper_tests_gen10.cpp index faff008aaa..b5d93d8488 100644 --- a/unit_tests/gen10/hw_helper_tests_gen10.cpp +++ b/unit_tests/gen10/hw_helper_tests_gen10.cpp @@ -18,8 +18,8 @@ GEN10TEST_F(HwHelperTestCnl, whenCnlRevIdForStepCThenSetCapabilityCoherencyFlagF auto &helper = HwHelper::get(renderCoreFamily); bool coherency = true; - HardwareInfo testHwInfo = hwInfo; - PLATFORM testPlatform = *hwInfo.pPlatform; + HardwareInfo testHwInfo = hwInfoHelper.hwInfo; + PLATFORM testPlatform = *hwInfoHelper.hwInfo.pPlatform; testHwInfo.pPlatform = &testPlatform; testPlatform.usRevId = 0x3; helper.setCapabilityCoherencyFlag(&testHwInfo, coherency); @@ -30,8 +30,8 @@ GEN10TEST_F(HwHelperTestCnl, whenCnlRevIdForStepDThenSetCapabilityCoherencyFlagT auto &helper = HwHelper::get(renderCoreFamily); bool coherency = false; - HardwareInfo testHwInfo = hwInfo; - PLATFORM testPlatform = *hwInfo.pPlatform; + HardwareInfo testHwInfo = hwInfoHelper.hwInfo; + PLATFORM testPlatform = *hwInfoHelper.hwInfo.pPlatform; testHwInfo.pPlatform = &testPlatform; testPlatform.usRevId = 0x4; helper.setCapabilityCoherencyFlag(&testHwInfo, coherency); @@ -42,28 +42,28 @@ GEN10TEST_F(HwHelperTestCnl, setupPreemptionRegisters) { auto &helper = HwHelper::get(renderCoreFamily); bool preemption = false; - preemption = helper.setupPreemptionRegisters(&hwInfo, preemption); + preemption = helper.setupPreemptionRegisters(&hwInfoHelper.hwInfo, preemption); EXPECT_FALSE(preemption); - EXPECT_FALSE(hwInfo.capabilityTable.whitelistedRegisters.csChicken1_0x2580); + EXPECT_FALSE(hwInfoHelper.hwInfo.capabilityTable.whitelistedRegisters.csChicken1_0x2580); preemption = true; - preemption = helper.setupPreemptionRegisters(&hwInfo, preemption); + preemption = helper.setupPreemptionRegisters(&hwInfoHelper.hwInfo, preemption); EXPECT_TRUE(preemption); - EXPECT_TRUE(hwInfo.capabilityTable.whitelistedRegisters.csChicken1_0x2580); + EXPECT_TRUE(hwInfoHelper.hwInfo.capabilityTable.whitelistedRegisters.csChicken1_0x2580); } GEN10TEST_F(HwHelperTestCnl, adjustDefaultEngineType) { - auto engineType = hwInfo.capabilityTable.defaultEngineType; + auto engineType = hwInfoHelper.hwInfo.capabilityTable.defaultEngineType; auto &helper = HwHelper::get(renderCoreFamily); - helper.adjustDefaultEngineType(&hwInfo); - EXPECT_EQ(engineType, hwInfo.capabilityTable.defaultEngineType); + helper.adjustDefaultEngineType(&hwInfoHelper.hwInfo); + EXPECT_EQ(engineType, hwInfoHelper.hwInfo.capabilityTable.defaultEngineType); } GEN10TEST_F(HwHelperTestCnl, givenGen10PlatformWhenSetupHardwareCapabilitiesIsCalledThenDefaultImplementationIsUsed) { auto &helper = HwHelper::get(renderCoreFamily); // Test default method implementation - testDefaultImplementationOfSetupHardwareCapabilities(helper, hwInfo); + testDefaultImplementationOfSetupHardwareCapabilities(helper, hwInfoHelper.hwInfo); } GEN10TEST_F(HwHelperTestCnl, whenGetConfigureAddressSpaceModeThenReturnZero) { diff --git a/unit_tests/gen8/hw_helper_tests_gen8.cpp b/unit_tests/gen8/hw_helper_tests_gen8.cpp index a23d4c3e12..e4449117f6 100644 --- a/unit_tests/gen8/hw_helper_tests_gen8.cpp +++ b/unit_tests/gen8/hw_helper_tests_gen8.cpp @@ -20,7 +20,7 @@ GEN8TEST_F(HwHelperTestBdw, setCapabilityCoherencyFlag) { auto &helper = HwHelper::get(renderCoreFamily); bool coherency = false; - helper.setCapabilityCoherencyFlag(&hwInfo, coherency); + helper.setCapabilityCoherencyFlag(&hwInfoHelper.hwInfo, coherency); EXPECT_TRUE(coherency); } @@ -28,25 +28,25 @@ GEN8TEST_F(HwHelperTestBdw, setupPreemptionRegisters) { auto &helper = HwHelper::get(renderCoreFamily); bool preemption = false; - preemption = helper.setupPreemptionRegisters(&hwInfo, preemption); + preemption = helper.setupPreemptionRegisters(&hwInfoHelper.hwInfo, preemption); EXPECT_FALSE(preemption); preemption = true; - preemption = helper.setupPreemptionRegisters(&hwInfo, preemption); + preemption = helper.setupPreemptionRegisters(&hwInfoHelper.hwInfo, preemption); EXPECT_FALSE(preemption); } GEN8TEST_F(HwHelperTestBdw, adjustDefaultEngineType) { - auto engineType = hwInfo.capabilityTable.defaultEngineType; + auto engineType = hwInfoHelper.hwInfo.capabilityTable.defaultEngineType; auto &helper = HwHelper::get(renderCoreFamily); - helper.adjustDefaultEngineType(&hwInfo); - EXPECT_EQ(engineType, hwInfo.capabilityTable.defaultEngineType); + helper.adjustDefaultEngineType(&hwInfoHelper.hwInfo); + EXPECT_EQ(engineType, hwInfoHelper.hwInfo.capabilityTable.defaultEngineType); } GEN8TEST_F(HwHelperTestBdw, givenGen8PlatformWhenSetupHardwareCapabilitiesIsCalledThenSpecificImplementationIsUsed) { auto &helper = HwHelper::get(renderCoreFamily); HardwareCapabilities hwCaps = {0}; - helper.setupHardwareCapabilities(&hwCaps, hwInfo); + helper.setupHardwareCapabilities(&hwCaps, hwInfoHelper.hwInfo); EXPECT_EQ(2048u, hwCaps.image3DMaxHeight); EXPECT_EQ(2048u, hwCaps.image3DMaxWidth); @@ -57,4 +57,4 @@ GEN8TEST_F(HwHelperTestBdw, givenGen8PlatformWhenSetupHardwareCapabilitiesIsCall GEN8TEST_F(HwHelperTestBdw, whenGetConfigureAddressSpaceModeThenReturnZero) { auto &helper = HwHelper::get(renderCoreFamily); EXPECT_EQ(0u, helper.getConfigureAddressSpaceMode()); -} \ No newline at end of file +} diff --git a/unit_tests/gen9/hw_helper_tests_gen9.cpp b/unit_tests/gen9/hw_helper_tests_gen9.cpp index 1fe041d831..685babad81 100644 --- a/unit_tests/gen9/hw_helper_tests_gen9.cpp +++ b/unit_tests/gen9/hw_helper_tests_gen9.cpp @@ -18,7 +18,7 @@ GEN9TEST_F(HwHelperTestSkl, setCapabilityCoherencyFlag) { auto &helper = HwHelper::get(renderCoreFamily); bool coherency = false; - helper.setCapabilityCoherencyFlag(&hwInfo, coherency); + helper.setCapabilityCoherencyFlag(&hwInfoHelper.hwInfo, coherency); EXPECT_TRUE(coherency); } @@ -26,28 +26,28 @@ GEN9TEST_F(HwHelperTestSkl, setupPreemptionRegisters) { auto &helper = HwHelper::get(renderCoreFamily); bool preemption = false; - preemption = helper.setupPreemptionRegisters(&hwInfo, preemption); + preemption = helper.setupPreemptionRegisters(&hwInfoHelper.hwInfo, preemption); EXPECT_FALSE(preemption); - EXPECT_FALSE(hwInfo.capabilityTable.whitelistedRegisters.csChicken1_0x2580); + EXPECT_FALSE(hwInfoHelper.hwInfo.capabilityTable.whitelistedRegisters.csChicken1_0x2580); preemption = true; - preemption = helper.setupPreemptionRegisters(&hwInfo, preemption); + preemption = helper.setupPreemptionRegisters(&hwInfoHelper.hwInfo, preemption); EXPECT_TRUE(preemption); - EXPECT_TRUE(hwInfo.capabilityTable.whitelistedRegisters.csChicken1_0x2580); + EXPECT_TRUE(hwInfoHelper.hwInfo.capabilityTable.whitelistedRegisters.csChicken1_0x2580); } GEN9TEST_F(HwHelperTestSkl, adjustDefaultEngineType) { - auto engineType = hwInfo.capabilityTable.defaultEngineType; + auto engineType = hwInfoHelper.hwInfo.capabilityTable.defaultEngineType; auto &helper = HwHelper::get(renderCoreFamily); - helper.adjustDefaultEngineType(&hwInfo); - EXPECT_EQ(engineType, hwInfo.capabilityTable.defaultEngineType); + helper.adjustDefaultEngineType(&hwInfoHelper.hwInfo); + EXPECT_EQ(engineType, hwInfoHelper.hwInfo.capabilityTable.defaultEngineType); } GEN9TEST_F(HwHelperTestSkl, givenGen9PlatformWhenSetupHardwareCapabilitiesIsCalledThenDefaultImplementationIsUsed) { auto &helper = HwHelper::get(renderCoreFamily); // Test default method implementation - testDefaultImplementationOfSetupHardwareCapabilities(helper, hwInfo); + testDefaultImplementationOfSetupHardwareCapabilities(helper, hwInfoHelper.hwInfo); } GEN9TEST_F(HwHelperTestSkl, givenDebuggingActiveWhenSipKernelTypeIsQueriedThenDbgCsrLocalTypeIsReturned) { @@ -60,4 +60,4 @@ GEN9TEST_F(HwHelperTestSkl, givenDebuggingActiveWhenSipKernelTypeIsQueriedThenDb GEN9TEST_F(HwHelperTestSkl, whenGetConfigureAddressSpaceModeThenReturnZero) { auto &helper = HwHelper::get(renderCoreFamily); EXPECT_EQ(0u, helper.getConfigureAddressSpaceMode()); -} \ No newline at end of file +} diff --git a/unit_tests/helpers/CMakeLists.txt b/unit_tests/helpers/CMakeLists.txt index 0a9cad0a82..8cd4a0e5ca 100644 --- a/unit_tests/helpers/CMakeLists.txt +++ b/unit_tests/helpers/CMakeLists.txt @@ -26,6 +26,7 @@ set(IGDRCL_SRCS_tests_helpers ${CMAKE_CURRENT_SOURCE_DIR}/hw_helper_default_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/hw_helper_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/hw_helper_tests.h + ${CMAKE_CURRENT_SOURCE_DIR}/hw_info_helper.h ${CMAKE_CURRENT_SOURCE_DIR}/hw_parse.h ${CMAKE_CURRENT_SOURCE_DIR}/hw_parse.inl ${CMAKE_CURRENT_SOURCE_DIR}/kernel_commands_tests.cpp diff --git a/unit_tests/helpers/hw_helper_tests.cpp b/unit_tests/helpers/hw_helper_tests.cpp index 29468559e9..617834e414 100644 --- a/unit_tests/helpers/hw_helper_tests.cpp +++ b/unit_tests/helpers/hw_helper_tests.cpp @@ -11,15 +11,6 @@ #include "unit_tests/helpers/unit_test_helper.h" void HwHelperTest::SetUp() { - memcpy(&testPlatform, platformDevices[0]->pPlatform, sizeof(testPlatform)); - memcpy(&testFtrTable, platformDevices[0]->pSkuTable, sizeof(testFtrTable)); - memcpy(&testWaTable, platformDevices[0]->pWaTable, sizeof(testWaTable)); - memcpy(&testSysInfo, platformDevices[0]->pSysInfo, sizeof(testSysInfo)); - hwInfo.capabilityTable = platformDevices[0]->capabilityTable; - hwInfo.pPlatform = &testPlatform; - hwInfo.pSkuTable = &testFtrTable; - hwInfo.pSysInfo = &testSysInfo; - hwInfo.pWaTable = &testWaTable; } void HwHelperTest::TearDown() { } @@ -80,7 +71,7 @@ TEST_F(HwHelperTest, givenEngineTypeRcsWhenCsTraitsAreQueiredThenCorrectNameInTr HWTEST_F(HwHelperTest, givenHwHelperWhenAskedForPageTableManagerSupportThenReturnCorrectValue) { auto &helper = HwHelper::get(renderCoreFamily); - EXPECT_EQ(helper.isPageTableManagerSupported(hwInfo), UnitTestHelper::isPageTableManagerSupported(hwInfo)); + EXPECT_EQ(helper.isPageTableManagerSupported(hwInfoHelper.hwInfo), UnitTestHelper::isPageTableManagerSupported(hwInfoHelper.hwInfo)); } TEST(DwordBuilderTest, setNonMaskedBits) { diff --git a/unit_tests/helpers/hw_helper_tests.h b/unit_tests/helpers/hw_helper_tests.h index 5caec95c8c..a01379657f 100644 --- a/unit_tests/helpers/hw_helper_tests.h +++ b/unit_tests/helpers/hw_helper_tests.h @@ -10,6 +10,7 @@ #include "runtime/device/device.h" #include "runtime/helpers/hw_helper.h" #include "test.h" +#include "unit_tests/helpers/hw_info_helper.h" using namespace OCLRT; @@ -17,12 +18,7 @@ class HwHelperTest : public testing::Test { protected: void SetUp() override; void TearDown() override; - - PLATFORM testPlatform; - FeatureTable testFtrTable; - WorkaroundTable testWaTable; - GT_SYSTEM_INFO testSysInfo; - HardwareInfo hwInfo; + HwInfoHelper hwInfoHelper; }; void testDefaultImplementationOfSetupHardwareCapabilities(HwHelper &hwHelper, const HardwareInfo &hwInfo); diff --git a/unit_tests/helpers/hw_info_helper.h b/unit_tests/helpers/hw_info_helper.h new file mode 100644 index 0000000000..2c06eff879 --- /dev/null +++ b/unit_tests/helpers/hw_info_helper.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2018 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/helpers/hw_info.h" +#include "runtime/helpers/options.h" + +using namespace OCLRT; + +struct HwInfoHelper { + HwInfoHelper() { + memcpy(&testPlatform, platformDevices[0]->pPlatform, sizeof(testPlatform)); + memcpy(&testFtrTable, platformDevices[0]->pSkuTable, sizeof(testFtrTable)); + memcpy(&testWaTable, platformDevices[0]->pWaTable, sizeof(testWaTable)); + memcpy(&testSysInfo, platformDevices[0]->pSysInfo, sizeof(testSysInfo)); + hwInfo.capabilityTable = platformDevices[0]->capabilityTable; + hwInfo.pPlatform = &testPlatform; + hwInfo.pSkuTable = &testFtrTable; + hwInfo.pSysInfo = &testSysInfo; + hwInfo.pWaTable = &testWaTable; + } + + PLATFORM testPlatform; + FeatureTable testFtrTable; + WorkaroundTable testWaTable; + GT_SYSTEM_INFO testSysInfo; + HardwareInfo hwInfo; +}; diff --git a/unit_tests/mocks/mock_gmm_resource_info.cpp b/unit_tests/mocks/mock_gmm_resource_info.cpp index 6c3c3afec5..ccefee2e8e 100644 --- a/unit_tests/mocks/mock_gmm_resource_info.cpp +++ b/unit_tests/mocks/mock_gmm_resource_info.cpp @@ -87,6 +87,11 @@ void MockGmmResourceInfo::setSurfaceFormat() { } }; + if (mockResourceCreateParams.Format == GMM_RESOURCE_FORMAT::GMM_FORMAT_P010) { + tempSurface.GMMSurfaceFormat = GMM_RESOURCE_FORMAT::GMM_FORMAT_P010; + surfaceFormatInfo = &tempSurface; + } + iterate(SurfaceFormats::readOnly()); iterate(SurfaceFormats::writeOnly()); iterate(SurfaceFormats::readWrite()); diff --git a/unit_tests/mocks/mock_gmm_resource_info.h b/unit_tests/mocks/mock_gmm_resource_info.h index fc37485bc5..ce79ac6ff4 100644 --- a/unit_tests/mocks/mock_gmm_resource_info.h +++ b/unit_tests/mocks/mock_gmm_resource_info.h @@ -7,6 +7,7 @@ #pragma once #include "runtime/gmm_helper/resource_info.h" +#include "runtime/helpers/surface_formats.h" #include "gmock/gmock.h" #if defined(__clang__) @@ -83,6 +84,7 @@ class MockGmmResourceInfo : public GmmResourceInfo { uint32_t getOffsetCalled = 0u; uint32_t arrayIndexPassedToGetOffset = 0; + SurfaceFormatInfo tempSurface{}; protected: MockGmmResourceInfo();