Skip to content

Commit 3fafdf3

Browse files
Correct check in getQueueFamilyName
Signed-off-by: Filip Hazubski <[email protected]>
1 parent a204b11 commit 3fafdf3

File tree

6 files changed

+34
-6
lines changed

6 files changed

+34
-6
lines changed

opencl/source/cl_device/cl_device.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ cl_command_queue_capabilities_intel ClDevice::getQueueFamilyCapabilities(EngineG
253253
return CL_QUEUE_DEFAULT_CAPABILITIES_INTEL;
254254
}
255255

256-
void ClDevice::getQueueFamilyName(char *outputName, size_t maxOutputNameLength, EngineGroupType type) {
256+
void ClDevice::getQueueFamilyName(char *outputName, EngineGroupType type) {
257257
std::string name{};
258258

259259
const auto &clHwHelper = ClHwHelper::get(getHardwareInfo().platform.eRenderCoreFamily);
@@ -276,8 +276,8 @@ void ClDevice::getQueueFamilyName(char *outputName, size_t maxOutputNameLength,
276276
}
277277
}
278278

279-
UNRECOVERABLE_IF(name.length() > maxOutputNameLength + 1);
280-
strncpy_s(outputName, maxOutputNameLength, name.c_str(), name.size());
279+
UNRECOVERABLE_IF(name.size() >= CL_QUEUE_FAMILY_MAX_NAME_SIZE_INTEL);
280+
strncpy_s(outputName, CL_QUEUE_FAMILY_MAX_NAME_SIZE_INTEL, name.c_str(), name.size());
281281
}
282282
Platform *ClDevice::getPlatform() const {
283283
return castToObject<Platform>(platformId);

opencl/source/cl_device/cl_device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class ClDevice : public BaseObject<_cl_device_id> {
128128

129129
static cl_command_queue_capabilities_intel getQueueFamilyCapabilitiesAll();
130130
MOCKABLE_VIRTUAL cl_command_queue_capabilities_intel getQueueFamilyCapabilities(EngineGroupType type);
131-
void getQueueFamilyName(char *outputName, size_t maxOutputNameLength, EngineGroupType type);
131+
void getQueueFamilyName(char *outputName, EngineGroupType type);
132132
Platform *getPlatform() const;
133133

134134
protected:

opencl/source/cl_device/cl_device_caps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ void ClDevice::initializeCaps() {
388388
properties.capabilities = getQueueFamilyCapabilities(engineGroupType);
389389
properties.count = static_cast<cl_uint>(enginesInFamily.size());
390390
properties.properties = deviceInfo.queueOnHostProperties;
391-
getQueueFamilyName(properties.name, CL_QUEUE_FAMILY_MAX_NAME_SIZE_INTEL, engineGroupType);
391+
getQueueFamilyName(properties.name, engineGroupType);
392392
deviceInfo.queueFamilyProperties.push_back(properties);
393393
}
394394
}

opencl/source/helpers/cl_hw_helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,6 @@ class ClHwHelperHw : public ClHwHelper {
7474
ClHwHelperHw() = default;
7575
};
7676

77+
extern ClHwHelper *clHwHelperFactory[IGFX_MAX_CORE];
78+
7779
} // namespace NEO

opencl/test/unit_test/device/device_caps_tests.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "shared/test/common/mocks/mock_execution_environment.h"
1717
#include "shared/test/common/mocks/mock_sip.h"
1818

19+
#include "opencl/source/helpers/cl_hw_helper.h"
1920
#include "opencl/source/platform/extensions.h"
2021
#include "opencl/test/unit_test/fixtures/device_info_fixture.h"
2122
#include "opencl/test/unit_test/helpers/hw_helper_tests.h"
@@ -1684,6 +1685,31 @@ HWTEST_F(QueueFamilyNameTest, givenBcsWhenGettingQueueFamilyNameThenReturnProper
16841685
HWTEST_F(QueueFamilyNameTest, givenInvalidEngineGroupWhenGettingQueueFamilyNameThenReturnEmptyName) {
16851686
verify(EngineGroupType::MaxEngineGroups, "");
16861687
}
1688+
1689+
HWTEST_F(QueueFamilyNameTest, givenTooBigQueueFamilyNameWhenGettingQueueFamilyNameThenExceptionIsThrown) {
1690+
struct MockClHwHelper : NEO::ClHwHelperHw<FamilyType> {
1691+
bool getQueueFamilyName(std::string &name, EngineGroupType type) const override {
1692+
name = familyNameOverride;
1693+
return true;
1694+
}
1695+
std::string familyNameOverride = "";
1696+
};
1697+
1698+
MockClHwHelper clHwHelper{};
1699+
VariableBackup<ClHwHelper *> clHwHelperFactoryBackup{
1700+
&NEO::clHwHelperFactory[static_cast<size_t>(defaultHwInfo->platform.eRenderCoreFamily)]};
1701+
clHwHelperFactoryBackup = &clHwHelper;
1702+
1703+
char name[CL_QUEUE_FAMILY_MAX_NAME_SIZE_INTEL] = "";
1704+
1705+
clHwHelper.familyNameOverride = std::string(CL_QUEUE_FAMILY_MAX_NAME_SIZE_INTEL - 1, 'a');
1706+
device->getQueueFamilyName(name, EngineGroupType::MaxEngineGroups);
1707+
EXPECT_EQ(0, std::strcmp(name, clHwHelper.familyNameOverride.c_str()));
1708+
1709+
clHwHelper.familyNameOverride = std::string(CL_QUEUE_FAMILY_MAX_NAME_SIZE_INTEL, 'a');
1710+
EXPECT_ANY_THROW(device->getQueueFamilyName(name, EngineGroupType::MaxEngineGroups));
1711+
}
1712+
16871713
HWCMDTEST_F(IGFX_GEN8_CORE, DeviceGetCapsTest, givenSysInfoWhenDeviceCreatedThenMaxWorkGroupCalculatedCorrectly) {
16881714
HardwareInfo myHwInfo = *defaultHwInfo;
16891715
GT_SYSTEM_INFO &mySysInfo = myHwInfo.gtSystemInfo;

opencl/test/unit_test/fixtures/device_info_fixture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct QueueFamilyNameTest : ::testing::Test {
4444

4545
void verify(EngineGroupType type, const char *expectedName) {
4646
char name[CL_QUEUE_FAMILY_MAX_NAME_SIZE_INTEL];
47-
device->getQueueFamilyName(name, sizeof(name), type);
47+
device->getQueueFamilyName(name, type);
4848
EXPECT_EQ(0, std::strcmp(name, expectedName));
4949
}
5050

0 commit comments

Comments
 (0)