1 /*
2  * Copyright (C) 2020-2021 Intel Corporation
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  */
7 
8 #include "shared/source/os_interface/hw_info_config.h"
9 #include "shared/test/common/helpers/hw_helper_tests.h"
10 #include "shared/test/common/mocks/mock_graphics_allocation.h"
11 
12 #include "opencl/source/helpers/cl_hw_helper.h"
13 
14 using HwHelperTestDg1 = HwHelperTest;
15 
DG1TEST_F(HwHelperTestDg1,givenDg1A0WhenAdjustDefaultEngineTypeCalledThenRcsIsReturned)16 DG1TEST_F(HwHelperTestDg1, givenDg1A0WhenAdjustDefaultEngineTypeCalledThenRcsIsReturned) {
17     auto &helper = HwHelper::get(renderCoreFamily);
18     const auto &hwInfoConfig = *HwInfoConfig::get(productFamily);
19     hardwareInfo.featureTable.flags.ftrCCSNode = true;
20     hardwareInfo.platform.usRevId = hwInfoConfig.getHwRevIdFromStepping(REVISION_A0, hardwareInfo);
21 
22     helper.adjustDefaultEngineType(&hardwareInfo);
23     EXPECT_EQ(aub_stream::ENGINE_RCS, hardwareInfo.capabilityTable.defaultEngineType);
24 }
25 
DG1TEST_F(HwHelperTestDg1,givenDg1BWhenAdjustDefaultEngineTypeCalledThenCcsIsReturned)26 DG1TEST_F(HwHelperTestDg1, givenDg1BWhenAdjustDefaultEngineTypeCalledThenCcsIsReturned) {
27     auto &helper = HwHelper::get(renderCoreFamily);
28     const auto &hwInfoConfig = *HwInfoConfig::get(productFamily);
29     hardwareInfo.featureTable.flags.ftrCCSNode = true;
30     hardwareInfo.platform.usRevId = hwInfoConfig.getHwRevIdFromStepping(REVISION_B, hardwareInfo);
31 
32     helper.adjustDefaultEngineType(&hardwareInfo);
33     EXPECT_EQ(aub_stream::ENGINE_RCS, hardwareInfo.capabilityTable.defaultEngineType);
34 }
35 
DG1TEST_F(HwHelperTestDg1,givenDg1AndVariousSteppingsWhenGettingIsWorkaroundRequiredThenCorrectValueIsReturned)36 DG1TEST_F(HwHelperTestDg1, givenDg1AndVariousSteppingsWhenGettingIsWorkaroundRequiredThenCorrectValueIsReturned) {
37     const auto &hwHelper = HwHelper::get(hardwareInfo.platform.eRenderCoreFamily);
38     const auto &hwInfoConfig = *HwInfoConfig::get(hardwareInfo.platform.eProductFamily);
39     uint32_t steppings[] = {
40         REVISION_A0,
41         REVISION_B,
42         CommonConstants::invalidStepping};
43 
44     for (auto stepping : steppings) {
45         hardwareInfo.platform.usRevId = hwInfoConfig.getHwRevIdFromStepping(stepping, hardwareInfo);
46 
47         switch (stepping) {
48         case REVISION_A0:
49             EXPECT_TRUE(hwHelper.isWorkaroundRequired(REVISION_A0, REVISION_B, hardwareInfo));
50             [[fallthrough]];
51         default:
52             EXPECT_FALSE(hwHelper.isWorkaroundRequired(REVISION_B, REVISION_A0, hardwareInfo));
53             EXPECT_FALSE(hwHelper.isWorkaroundRequired(REVISION_A0, REVISION_D, hardwareInfo));
54         }
55     }
56 }
57 
DG1TEST_F(HwHelperTestDg1,givenBufferAllocationTypeWhenSetExtraAllocationDataIsCalledThenIsLockableIsSet)58 DG1TEST_F(HwHelperTestDg1, givenBufferAllocationTypeWhenSetExtraAllocationDataIsCalledThenIsLockableIsSet) {
59     auto &hwHelper = HwHelper::get(renderCoreFamily);
60     AllocationData allocData{};
61     allocData.flags.useSystemMemory = true;
62     AllocationProperties allocProperties(0, 1, GraphicsAllocation::AllocationType::BUFFER, {});
63     allocData.storageInfo.isLockable = false;
64     hwHelper.setExtraAllocationData(allocData, allocProperties, *defaultHwInfo);
65     EXPECT_TRUE(allocData.storageInfo.isLockable);
66 }
67