diff --git a/opencl/source/cl_device/cl_device.cpp b/opencl/source/cl_device/cl_device.cpp index e973abbe46..b2c4d93f66 100644 --- a/opencl/source/cl_device/cl_device.cpp +++ b/opencl/source/cl_device/cl_device.cpp @@ -253,7 +253,7 @@ cl_command_queue_capabilities_intel ClDevice::getQueueFamilyCapabilities(EngineG return CL_QUEUE_DEFAULT_CAPABILITIES_INTEL; } -void ClDevice::getQueueFamilyName(char *outputName, size_t maxOutputNameLength, EngineGroupType type) { +void ClDevice::getQueueFamilyName(char *outputName, EngineGroupType type) { std::string name{}; const auto &clHwHelper = ClHwHelper::get(getHardwareInfo().platform.eRenderCoreFamily); @@ -276,8 +276,8 @@ void ClDevice::getQueueFamilyName(char *outputName, size_t maxOutputNameLength, } } - UNRECOVERABLE_IF(name.length() > maxOutputNameLength + 1); - strncpy_s(outputName, maxOutputNameLength, name.c_str(), name.size()); + UNRECOVERABLE_IF(name.size() >= CL_QUEUE_FAMILY_MAX_NAME_SIZE_INTEL); + strncpy_s(outputName, CL_QUEUE_FAMILY_MAX_NAME_SIZE_INTEL, name.c_str(), name.size()); } Platform *ClDevice::getPlatform() const { return castToObject(platformId); diff --git a/opencl/source/cl_device/cl_device.h b/opencl/source/cl_device/cl_device.h index 946b4a1166..308dee3e9b 100644 --- a/opencl/source/cl_device/cl_device.h +++ b/opencl/source/cl_device/cl_device.h @@ -128,7 +128,7 @@ class ClDevice : public BaseObject<_cl_device_id> { static cl_command_queue_capabilities_intel getQueueFamilyCapabilitiesAll(); MOCKABLE_VIRTUAL cl_command_queue_capabilities_intel getQueueFamilyCapabilities(EngineGroupType type); - void getQueueFamilyName(char *outputName, size_t maxOutputNameLength, EngineGroupType type); + void getQueueFamilyName(char *outputName, EngineGroupType type); Platform *getPlatform() const; protected: diff --git a/opencl/source/cl_device/cl_device_caps.cpp b/opencl/source/cl_device/cl_device_caps.cpp index c51f39a0dd..8985e890cd 100644 --- a/opencl/source/cl_device/cl_device_caps.cpp +++ b/opencl/source/cl_device/cl_device_caps.cpp @@ -388,7 +388,7 @@ void ClDevice::initializeCaps() { properties.capabilities = getQueueFamilyCapabilities(engineGroupType); properties.count = static_cast(enginesInFamily.size()); properties.properties = deviceInfo.queueOnHostProperties; - getQueueFamilyName(properties.name, CL_QUEUE_FAMILY_MAX_NAME_SIZE_INTEL, engineGroupType); + getQueueFamilyName(properties.name, engineGroupType); deviceInfo.queueFamilyProperties.push_back(properties); } } diff --git a/opencl/source/helpers/cl_hw_helper.h b/opencl/source/helpers/cl_hw_helper.h index 547de96a54..e9a36e124b 100644 --- a/opencl/source/helpers/cl_hw_helper.h +++ b/opencl/source/helpers/cl_hw_helper.h @@ -74,4 +74,6 @@ class ClHwHelperHw : public ClHwHelper { ClHwHelperHw() = default; }; +extern ClHwHelper *clHwHelperFactory[IGFX_MAX_CORE]; + } // namespace NEO diff --git a/opencl/test/unit_test/device/device_caps_tests.cpp b/opencl/test/unit_test/device/device_caps_tests.cpp index 1bb3a9c538..129b2fe292 100644 --- a/opencl/test/unit_test/device/device_caps_tests.cpp +++ b/opencl/test/unit_test/device/device_caps_tests.cpp @@ -16,6 +16,7 @@ #include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_sip.h" +#include "opencl/source/helpers/cl_hw_helper.h" #include "opencl/source/platform/extensions.h" #include "opencl/test/unit_test/fixtures/device_info_fixture.h" #include "opencl/test/unit_test/helpers/hw_helper_tests.h" @@ -1684,6 +1685,31 @@ HWTEST_F(QueueFamilyNameTest, givenBcsWhenGettingQueueFamilyNameThenReturnProper HWTEST_F(QueueFamilyNameTest, givenInvalidEngineGroupWhenGettingQueueFamilyNameThenReturnEmptyName) { verify(EngineGroupType::MaxEngineGroups, ""); } + +HWTEST_F(QueueFamilyNameTest, givenTooBigQueueFamilyNameWhenGettingQueueFamilyNameThenExceptionIsThrown) { + struct MockClHwHelper : NEO::ClHwHelperHw { + bool getQueueFamilyName(std::string &name, EngineGroupType type) const override { + name = familyNameOverride; + return true; + } + std::string familyNameOverride = ""; + }; + + MockClHwHelper clHwHelper{}; + VariableBackup clHwHelperFactoryBackup{ + &NEO::clHwHelperFactory[static_cast(defaultHwInfo->platform.eRenderCoreFamily)]}; + clHwHelperFactoryBackup = &clHwHelper; + + char name[CL_QUEUE_FAMILY_MAX_NAME_SIZE_INTEL] = ""; + + clHwHelper.familyNameOverride = std::string(CL_QUEUE_FAMILY_MAX_NAME_SIZE_INTEL - 1, 'a'); + device->getQueueFamilyName(name, EngineGroupType::MaxEngineGroups); + EXPECT_EQ(0, std::strcmp(name, clHwHelper.familyNameOverride.c_str())); + + clHwHelper.familyNameOverride = std::string(CL_QUEUE_FAMILY_MAX_NAME_SIZE_INTEL, 'a'); + EXPECT_ANY_THROW(device->getQueueFamilyName(name, EngineGroupType::MaxEngineGroups)); +} + HWCMDTEST_F(IGFX_GEN8_CORE, DeviceGetCapsTest, givenSysInfoWhenDeviceCreatedThenMaxWorkGroupCalculatedCorrectly) { HardwareInfo myHwInfo = *defaultHwInfo; GT_SYSTEM_INFO &mySysInfo = myHwInfo.gtSystemInfo; diff --git a/opencl/test/unit_test/fixtures/device_info_fixture.h b/opencl/test/unit_test/fixtures/device_info_fixture.h index 4a04f2720a..93dfc3afff 100644 --- a/opencl/test/unit_test/fixtures/device_info_fixture.h +++ b/opencl/test/unit_test/fixtures/device_info_fixture.h @@ -44,7 +44,7 @@ struct QueueFamilyNameTest : ::testing::Test { void verify(EngineGroupType type, const char *expectedName) { char name[CL_QUEUE_FAMILY_MAX_NAME_SIZE_INTEL]; - device->getQueueFamilyName(name, sizeof(name), type); + device->getQueueFamilyName(name, type); EXPECT_EQ(0, std::strcmp(name, expectedName)); }