mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Moved unit test for getMaxGpuFrequency on Linux to shared code
Related-To: NEO-4544 Change-Id: I5319e9485bbaa973f73bc11dd07effa184f27e64 Signed-off-by: Slawomir Milczarek <slawomir.milczarek@intel.com>
This commit is contained in:

committed by
sys_ocldev

parent
4cc605db20
commit
52deab65e0
@ -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()
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -21,7 +21,6 @@
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <linux/limits.h>
|
||||
|
||||
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";
|
||||
|
@ -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);
|
||||
|
||||
|
@ -9,8 +9,26 @@
|
||||
|
||||
#include "drm_neo.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
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<uint8_t[]> Drm::query(uint32_t queryId) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
12
shared/test/unit_test/os_interface/linux/CMakeLists.txt
Normal file
12
shared/test/unit_test/os_interface/linux/CMakeLists.txt
Normal file
@ -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})
|
34
shared/test/unit_test/os_interface/linux/drm_query_tests.cpp
Normal file
34
shared/test/unit_test/os_interface/linux/drm_query_tests.cpp
Normal file
@ -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);
|
||||
}
|
Reference in New Issue
Block a user