diff --git a/opencl/test/unit_test/core_unit_tests_files.cmake b/opencl/test/unit_test/core_unit_tests_files.cmake index e75cd60dc8..ecc3d3d79e 100644 --- a/opencl/test/unit_test/core_unit_tests_files.cmake +++ b/opencl/test/unit_test/core_unit_tests_files.cmake @@ -24,6 +24,7 @@ if(WIN32) else() append_sources_from_properties(NEO_CORE_UNIT_TESTS_SOURCES NEO_CORE_DIRECT_SUBMISSION_LINUX_TESTS + NEO_CORE_OS_INTERFACE_TESTS_LINUX ) endif() diff --git a/opencl/test/unit_test/os_interface/linux/drm_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_tests.cpp index 871b30f5fa..f0e17be8cf 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_tests.cpp @@ -6,9 +6,11 @@ */ #include "shared/source/helpers/file_io.h" +#include "shared/source/helpers/hw_info.h" #include "shared/source/os_interface/device_factory.h" #include "shared/source/os_interface/linux/os_context_linux.h" #include "shared/source/os_interface/linux/os_interface.h" +#include "shared/test/unit_test/helpers/default_hw_info.h" #include "opencl/test/unit_test/fixtures/memory_management_fixture.h" #include "opencl/test/unit_test/os_interface/linux/drm_mock.h" @@ -32,32 +34,15 @@ TEST(DrmTest, GetDeviceID) { delete pDrm; } -TEST(DrmTest, GivenValidConfigFileWhenFrequencyIsQueriedThenValidValueIsReturned) { - - int expectedMaxFrequency = 1000; - - DrmMock drm{}; - - std::string gtMaxFreqFile = "test_files/linux/devices/device/drm/card1/gt_max_freq_mhz"; - - EXPECT_TRUE(fileExists(gtMaxFreqFile)); - drm.setPciPath("device"); - - int maxFrequency = 0; - int ret = drm.getMaxGpuFrequency(maxFrequency); - EXPECT_EQ(0, ret); - - EXPECT_EQ(expectedMaxFrequency, maxFrequency); -} - -TEST(DrmTest, GivenNoConfigFileWhenFrequencyIsQueriedThenReturnZero) { +TEST(DrmTest, GivenInvalidPciPathWhenFrequencyIsQueriedThenReturnError) { DrmMock drm{}; + auto hwInfo = *defaultHwInfo; int maxFrequency = 0; drm.setPciPath("invalidPci"); - int ret = drm.getMaxGpuFrequency(maxFrequency); - EXPECT_EQ(0, ret); + int ret = drm.getMaxGpuFrequency(hwInfo, maxFrequency); + EXPECT_NE(0, ret); EXPECT_EQ(0, maxFrequency); } diff --git a/shared/source/os_interface/linux/drm_neo.cpp b/shared/source/os_interface/linux/drm_neo.cpp index 30328469d9..90065f7572 100644 --- a/shared/source/os_interface/linux/drm_neo.cpp +++ b/shared/source/os_interface/linux/drm_neo.cpp @@ -21,7 +21,6 @@ #include #include -#include #include namespace NEO { @@ -102,22 +101,6 @@ int Drm::getEnabledPooledEu(int &enabled) { return getParamIoctl(I915_PARAM_HAS_POOLED_EU, &enabled); } -int Drm::getMaxGpuFrequency(int &maxGpuFrequency) { - maxGpuFrequency = 0; - std::string clockSysFsPath = getSysFsPciPath(); - - clockSysFsPath += "/gt_max_freq_mhz"; - - std::ifstream ifs(clockSysFsPath.c_str(), std::ifstream::in); - if (ifs.fail()) { - return 0; - } - - ifs >> maxGpuFrequency; - ifs.close(); - return 0; -} - std::string Drm::getSysFsPciPath() { std::string path = std::string(Os::sysFsPciPathPrefix) + hwDeviceId->getPciPath() + "/drm"; std::string expectedFilePrefix = path + "/card"; diff --git a/shared/source/os_interface/linux/drm_neo.h b/shared/source/os_interface/linux/drm_neo.h index 2ccb6a6c54..df68ff289e 100644 --- a/shared/source/os_interface/linux/drm_neo.h +++ b/shared/source/os_interface/linux/drm_neo.h @@ -56,7 +56,7 @@ class Drm { int getEuTotal(int &euTotal); int getSubsliceTotal(int &subsliceTotal); - int getMaxGpuFrequency(int &maxGpuFrequency); + int getMaxGpuFrequency(HardwareInfo &hwInfo, int &maxGpuFrequency); int getEnabledPooledEu(int &enabled); int getMinEuInPool(int &minEUinPool); diff --git a/shared/source/os_interface/linux/drm_query.cpp b/shared/source/os_interface/linux/drm_query.cpp index 404adefc54..41a621b121 100644 --- a/shared/source/os_interface/linux/drm_query.cpp +++ b/shared/source/os_interface/linux/drm_query.cpp @@ -9,8 +9,26 @@ #include "drm_neo.h" +#include + namespace NEO { +int Drm::getMaxGpuFrequency(HardwareInfo &hwInfo, int &maxGpuFrequency) { + maxGpuFrequency = 0; + std::string clockSysFsPath = getSysFsPciPath(); + + clockSysFsPath += "/gt_max_freq_mhz"; + + std::ifstream ifs(clockSysFsPath.c_str(), std::ifstream::in); + if (ifs.fail()) { + return -1; + } + + ifs >> maxGpuFrequency; + ifs.close(); + return 0; +} + std::unique_ptr Drm::query(uint32_t queryId) { return nullptr; } diff --git a/shared/source/os_interface/linux/hw_info_config.cpp b/shared/source/os_interface/linux/hw_info_config.cpp index b2160e42ef..40c374542c 100644 --- a/shared/source/os_interface/linux/hw_info_config.cpp +++ b/shared/source/os_interface/linux/hw_info_config.cpp @@ -118,7 +118,7 @@ int HwInfoConfig::configureHwInfo(const HardwareInfo *inHwInfo, HardwareInfo *ou } int maxGpuFreq = 0; - drm->getMaxGpuFrequency(maxGpuFreq); + drm->getMaxGpuFrequency(*outHwInfo, maxGpuFreq); GTTYPE gtType = drm->getGtType(); if (gtType == GTTYPE_UNDEFINED) { diff --git a/shared/test/unit_test/os_interface/linux/CMakeLists.txt b/shared/test/unit_test/os_interface/linux/CMakeLists.txt new file mode 100644 index 0000000000..562634c995 --- /dev/null +++ b/shared/test/unit_test/os_interface/linux/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (C) 2020 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +set(NEO_CORE_OS_INTERFACE_TESTS_LINUX + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_query_tests.cpp +) + +set_property(GLOBAL PROPERTY NEO_CORE_OS_INTERFACE_TESTS_LINUX ${NEO_CORE_OS_INTERFACE_TESTS_LINUX}) diff --git a/shared/test/unit_test/os_interface/linux/drm_query_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_query_tests.cpp new file mode 100644 index 0000000000..1663537125 --- /dev/null +++ b/shared/test/unit_test/os_interface/linux/drm_query_tests.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/helpers/file_io.h" +#include "shared/source/helpers/hw_info.h" +#include "shared/test/unit_test/helpers/default_hw_info.h" + +#include "opencl/test/unit_test/os_interface/linux/drm_mock.h" + +#include "gtest/gtest.h" + +using namespace NEO; + +TEST(DrmQueryTest, GivenGtMaxFreqFileExistsWhenFrequencyIsQueriedThenValidValueIsReturned) { + int expectedMaxFrequency = 1000; + + DrmMock drm{}; + auto hwInfo = *defaultHwInfo; + + std::string gtMaxFreqFile = "test_files/linux/devices/device/drm/card1/gt_max_freq_mhz"; + + EXPECT_TRUE(fileExists(gtMaxFreqFile)); + drm.setPciPath("device"); + + int maxFrequency = 0; + int ret = drm.getMaxGpuFrequency(hwInfo, maxFrequency); + EXPECT_EQ(0, ret); + + EXPECT_EQ(expectedMaxFrequency, maxFrequency); +}