diff --git a/Jenkinsfile b/Jenkinsfile index 18e7781114..a7be3bc9dd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ #!groovy dependenciesRevision='2016dec18656a06fbc3608d55f91577f89936522-1414' strategy='EQUAL' -allowedCD=256 +allowedCD=255 allowedF=21 diff --git a/opencl/source/accelerators/intel_accelerator.cpp b/opencl/source/accelerators/intel_accelerator.cpp index 6d77a66c85..10a9dffd15 100644 --- a/opencl/source/accelerators/intel_accelerator.cpp +++ b/opencl/source/accelerators/intel_accelerator.cpp @@ -20,12 +20,13 @@ cl_int IntelAccelerator::getInfo(cl_accelerator_info_intel paramName, void *paramValue, size_t *paramValueSizeRet) const { cl_int result = CL_SUCCESS; - size_t ret = 0; + size_t ret = GetInfo::invalidSourceSize; + auto getInfoStatus = GetInfoStatus::INVALID_VALUE; switch (paramName) { case CL_ACCELERATOR_DESCRIPTOR_INTEL: { ret = getDescriptorSize(); - result = changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, getDescriptor(), ret)); + getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, getDescriptor(), ret); } break; @@ -34,7 +35,7 @@ cl_int IntelAccelerator::getInfo(cl_accelerator_info_intel paramName, auto v = getReference(); ret = sizeof(cl_uint); - result = changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, &v, ret)); + getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, &v, ret); } break; @@ -42,7 +43,7 @@ cl_int IntelAccelerator::getInfo(cl_accelerator_info_intel paramName, case CL_ACCELERATOR_CONTEXT_INTEL: { ret = sizeof(cl_context); cl_context ctx = static_cast(pContext); - result = changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, &ctx, ret)); + getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, &ctx, ret); } break; @@ -50,19 +51,18 @@ cl_int IntelAccelerator::getInfo(cl_accelerator_info_intel paramName, case CL_ACCELERATOR_TYPE_INTEL: { auto v = getTypeId(); ret = sizeof(cl_accelerator_type_intel); - result = changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, &v, ret)); + getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, &v, ret); } break; default: - result = CL_INVALID_VALUE; + getInfoStatus = GetInfoStatus::INVALID_VALUE; break; } - if (paramValueSizeRet) { - *paramValueSizeRet = ret; - } + result = changeGetInfoStatusToCLResultType(getInfoStatus); + GetInfo::setParamValueReturnSize(paramValueSizeRet, ret, getInfoStatus); return result; } diff --git a/opencl/source/cl_device/cl_device_info.cpp b/opencl/source/cl_device/cl_device_info.cpp index 94ef63650c..5abe0f675e 100644 --- a/opencl/source/cl_device/cl_device_info.cpp +++ b/opencl/source/cl_device/cl_device_info.cpp @@ -61,7 +61,7 @@ cl_int ClDevice::getDeviceInfo(cl_device_info paramName, void *paramValue, size_t *paramValueSizeRet) { cl_int retVal = CL_INVALID_VALUE; - size_t srcSize = 0; + size_t srcSize = GetInfo::invalidSourceSize; size_t retSize = 0; size_t value = 0u; cl_uint param; @@ -193,11 +193,10 @@ cl_int ClDevice::getDeviceInfo(cl_device_info paramName, ClDeviceHelper::getExtraDeviceInfo(*this, paramName, param, src, srcSize, retSize); } - retVal = changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, src, srcSize)); + auto getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, src, srcSize); - if (paramValueSizeRet) { - *paramValueSizeRet = retSize; - } + retVal = changeGetInfoStatusToCLResultType(getInfoStatus); + GetInfo::setParamValueReturnSize(paramValueSizeRet, retSize, getInfoStatus); return retVal; } diff --git a/opencl/source/context/context.cpp b/opencl/source/context/context.cpp index 2b42cc7208..b8c3d8645a 100644 --- a/opencl/source/context/context.cpp +++ b/opencl/source/context/context.cpp @@ -209,7 +209,7 @@ bool Context::createImpl(const cl_context_properties *properties, cl_int Context::getInfo(cl_context_info paramName, size_t paramValueSize, void *paramValue, size_t *paramValueSizeRet) { cl_int retVal; - size_t valueSize = 0; + size_t valueSize = GetInfo::invalidSourceSize; const void *pValue = nullptr; cl_uint numDevices; cl_uint refCount = 0; @@ -249,15 +249,13 @@ cl_int Context::getInfo(cl_context_info paramName, size_t paramValueSize, break; } + GetInfoStatus getInfoStatus = GetInfoStatus::SUCCESS; if (callGetinfo) { - retVal = changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, pValue, valueSize)); - } else { - retVal = CL_SUCCESS; + getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, pValue, valueSize); } - if (paramValueSizeRet) { - *paramValueSizeRet = valueSize; - } + retVal = changeGetInfoStatusToCLResultType(getInfoStatus); + GetInfo::setParamValueReturnSize(paramValueSizeRet, valueSize, getInfoStatus); return retVal; } diff --git a/opencl/source/event/event.cpp b/opencl/source/event/event.cpp index eda741045b..1f8a160100 100644 --- a/opencl/source/event/event.cpp +++ b/opencl/source/event/event.cpp @@ -148,7 +148,7 @@ cl_int Event::getEventProfilingInfo(cl_profiling_info paramName, size_t *paramValueSizeRet) { cl_int retVal; const void *src = nullptr; - size_t srcSize = 0; + size_t srcSize = GetInfo::invalidSourceSize; // CL_PROFILING_INFO_NOT_AVAILABLE if event refers to the clEnqueueSVMFree command if (isUserEvent() != CL_FALSE || // or is a user event object. @@ -210,11 +210,9 @@ cl_int Event::getEventProfilingInfo(cl_profiling_info paramName, return CL_INVALID_VALUE; } - retVal = changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, src, srcSize)); - - if (paramValueSizeRet) { - *paramValueSizeRet = srcSize; - } + auto getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, src, srcSize); + retVal = changeGetInfoStatusToCLResultType(getInfoStatus); + GetInfo::setParamValueReturnSize(paramValueSizeRet, srcSize, getInfoStatus); return retVal; } // namespace NEO diff --git a/opencl/source/kernel/kernel.cpp b/opencl/source/kernel/kernel.cpp index 3423258c11..57d828cd9f 100644 --- a/opencl/source/kernel/kernel.cpp +++ b/opencl/source/kernel/kernel.cpp @@ -444,7 +444,7 @@ cl_int Kernel::getInfo(cl_kernel_info paramName, size_t paramValueSize, void *paramValue, size_t *paramValueSizeRet) const { cl_int retVal; const void *pSrc = nullptr; - size_t srcSize = 0; + size_t srcSize = GetInfo::invalidSourceSize; cl_uint numArgs = 0; const _cl_program *prog; const _cl_context *ctxt; @@ -500,11 +500,9 @@ cl_int Kernel::getInfo(cl_kernel_info paramName, size_t paramValueSize, break; } - retVal = changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, pSrc, srcSize)); - - if (paramValueSizeRet) { - *paramValueSizeRet = srcSize; - } + auto getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, pSrc, srcSize); + retVal = changeGetInfoStatusToCLResultType(getInfoStatus); + GetInfo::setParamValueReturnSize(paramValueSizeRet, srcSize, getInfoStatus); return retVal; } @@ -513,7 +511,7 @@ cl_int Kernel::getArgInfo(cl_uint argIndx, cl_kernel_arg_info paramName, size_t void *paramValue, size_t *paramValueSizeRet) const { cl_int retVal; const void *pSrc = nullptr; - size_t srcSize = 0; + size_t srcSize = GetInfo::invalidSourceSize; auto numArgs = (cl_uint)kernelInfo.kernelArgInfo.size(); const auto &argInfo = kernelInfo.kernelArgInfo[argIndx]; @@ -559,11 +557,9 @@ cl_int Kernel::getArgInfo(cl_uint argIndx, cl_kernel_arg_info paramName, size_t break; } - retVal = changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, pSrc, srcSize)); - - if (paramValueSizeRet) { - *paramValueSizeRet = srcSize; - } + auto getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, pSrc, srcSize); + retVal = changeGetInfoStatusToCLResultType(getInfoStatus); + GetInfo::setParamValueReturnSize(paramValueSizeRet, srcSize, getInfoStatus); return retVal; } diff --git a/opencl/source/mem_obj/image.cpp b/opencl/source/mem_obj/image.cpp index daeda6162c..e69efef27d 100644 --- a/opencl/source/mem_obj/image.cpp +++ b/opencl/source/mem_obj/image.cpp @@ -801,7 +801,7 @@ cl_int Image::getImageInfo(cl_image_info paramName, void *paramValue, size_t *paramValueSizeRet) { cl_int retVal; - size_t srcParamSize = 0; + size_t srcParamSize = GetInfo::invalidSourceSize; void *srcParam = nullptr; auto imageDesc = getImageDesc(); auto surfFmtInfo = getSurfaceFormatInfo(); @@ -890,11 +890,9 @@ cl_int Image::getImageInfo(cl_image_info paramName, break; } - retVal = changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, srcParam, srcParamSize)); - - if (paramValueSizeRet) { - *paramValueSizeRet = srcParamSize; - } + auto getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, srcParam, srcParamSize); + retVal = changeGetInfoStatusToCLResultType(getInfoStatus); + GetInfo::setParamValueReturnSize(paramValueSizeRet, srcParamSize, getInfoStatus); return retVal; } diff --git a/opencl/source/mem_obj/mem_obj.cpp b/opencl/source/mem_obj/mem_obj.cpp index 0bed6068e9..28b613febe 100644 --- a/opencl/source/mem_obj/mem_obj.cpp +++ b/opencl/source/mem_obj/mem_obj.cpp @@ -118,7 +118,7 @@ cl_int MemObj::getMemObjectInfo(cl_mem_info paramName, void *paramValue, size_t *paramValueSizeRet) { cl_int retVal; - size_t srcParamSize = 0; + size_t srcParamSize = GetInfo::invalidSourceSize; void *srcParam = nullptr; cl_bool usesSVMPointer; cl_uint refCnt = 0; @@ -192,11 +192,9 @@ cl_int MemObj::getMemObjectInfo(cl_mem_info paramName, break; } - retVal = changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, srcParam, srcParamSize)); - - if (paramValueSizeRet) { - *paramValueSizeRet = srcParamSize; - } + auto getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, srcParam, srcParamSize); + retVal = changeGetInfoStatusToCLResultType(getInfoStatus); + GetInfo::setParamValueReturnSize(paramValueSizeRet, srcParamSize, getInfoStatus); return retVal; } diff --git a/opencl/source/mem_obj/pipe.cpp b/opencl/source/mem_obj/pipe.cpp index 0f2f427b4c..d3d31d96b4 100644 --- a/opencl/source/mem_obj/pipe.cpp +++ b/opencl/source/mem_obj/pipe.cpp @@ -92,7 +92,7 @@ cl_int Pipe::getPipeInfo(cl_image_info paramName, size_t *paramValueSizeRet) { cl_int retVal; - size_t srcParamSize = 0; + size_t srcParamSize = GetInfo::invalidSourceSize; void *srcParam = nullptr; switch (paramName) { @@ -110,11 +110,9 @@ cl_int Pipe::getPipeInfo(cl_image_info paramName, break; } - retVal = changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, srcParam, srcParamSize)); - - if (paramValueSizeRet) { - *paramValueSizeRet = srcParamSize; - } + auto getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, srcParam, srcParamSize); + retVal = changeGetInfoStatusToCLResultType(getInfoStatus); + GetInfo::setParamValueReturnSize(paramValueSizeRet, srcParamSize, getInfoStatus); return retVal; } diff --git a/opencl/source/platform/platform.cpp b/opencl/source/platform/platform.cpp index 41cee54e74..4bdb26546f 100644 --- a/opencl/source/platform/platform.cpp +++ b/opencl/source/platform/platform.cpp @@ -59,14 +59,15 @@ cl_int Platform::getInfo(cl_platform_info paramName, size_t *paramValueSizeRet) { auto retVal = CL_INVALID_VALUE; const std::string *param = nullptr; - size_t paramSize = 0; + size_t paramSize = GetInfo::invalidSourceSize; uint64_t pVal = 0; + auto getInfoStatus = GetInfoStatus::INVALID_VALUE; switch (paramName) { case CL_PLATFORM_HOST_TIMER_RESOLUTION: pVal = static_cast(this->clDevices[0]->getPlatformHostTimerResolution()); paramSize = sizeof(uint64_t); - retVal = changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, &pVal, paramSize)); + getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, &pVal, paramSize); break; case CL_PLATFORM_PROFILE: param = &platformInfo->profile; @@ -93,12 +94,11 @@ cl_int Platform::getInfo(cl_platform_info paramName, // Case for string parameters if (param) { paramSize = param->length() + 1; - retVal = changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, param->c_str(), paramSize)); + getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, param->c_str(), paramSize); } - if (paramValueSizeRet) { - *paramValueSizeRet = paramSize; - } + retVal = changeGetInfoStatusToCLResultType(getInfoStatus); + GetInfo::setParamValueReturnSize(paramValueSizeRet, paramSize, getInfoStatus); return retVal; } diff --git a/opencl/source/program/get_info.cpp b/opencl/source/program/get_info.cpp index 05b419e31b..83ac9ccb6a 100644 --- a/opencl/source/program/get_info.cpp +++ b/opencl/source/program/get_info.cpp @@ -24,7 +24,7 @@ cl_int Program::getInfo(cl_program_info paramName, size_t paramValueSize, void *paramValue, size_t *paramValueSizeRet) { cl_int retVal = CL_SUCCESS; const void *pSrc = nullptr; - size_t srcSize = 0; + size_t srcSize = GetInfo::invalidSourceSize; size_t retSize = 0; std::string kernelNamesString; cl_device_id device_id = pDevice->getSpecializedDevice(); @@ -149,12 +149,12 @@ cl_int Program::getInfo(cl_program_info paramName, size_t paramValueSize, break; } - retVal = (retVal == CL_SUCCESS) - ? changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, pSrc, srcSize)) - : retVal; - if (paramValueSizeRet) { - *paramValueSizeRet = retSize; + auto getInfoStatus = GetInfoStatus::INVALID_VALUE; + if (retVal == CL_SUCCESS) { + getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, pSrc, srcSize); + retVal = changeGetInfoStatusToCLResultType(getInfoStatus); } + GetInfo::setParamValueReturnSize(paramValueSizeRet, retSize, getInfoStatus); return retVal; } @@ -162,7 +162,7 @@ cl_int Program::getBuildInfo(cl_device_id device, cl_program_build_info paramNam size_t paramValueSize, void *paramValue, size_t *paramValueSizeRet) const { cl_int retVal = CL_SUCCESS; const void *pSrc = nullptr; - size_t srcSize = 0; + size_t srcSize = GetInfo::invalidSourceSize; size_t retSize = 0; cl_device_id device_id = pDevice->getSpecializedDevice(); @@ -210,13 +210,12 @@ cl_int Program::getBuildInfo(cl_device_id device, cl_program_build_info paramNam break; } - retVal = (retVal == CL_SUCCESS) - ? changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, pSrc, srcSize)) - : retVal; - - if (paramValueSizeRet) { - *paramValueSizeRet = retSize; + auto getInfoStatus = GetInfoStatus::INVALID_VALUE; + if (retVal == CL_SUCCESS) { + getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, pSrc, srcSize); + retVal = changeGetInfoStatusToCLResultType(getInfoStatus); } + GetInfo::setParamValueReturnSize(paramValueSizeRet, retSize, getInfoStatus); return retVal; } diff --git a/opencl/source/sampler/sampler.cpp b/opencl/source/sampler/sampler.cpp index bbfd10e7ad..c3f377007d 100644 --- a/opencl/source/sampler/sampler.cpp +++ b/opencl/source/sampler/sampler.cpp @@ -163,7 +163,7 @@ unsigned int Sampler::getSnapWaValue() const { cl_int Sampler::getInfo(cl_sampler_info paramName, size_t paramValueSize, void *paramValue, size_t *paramValueSizeRet) { cl_int retVal; - size_t valueSize = 0; + size_t valueSize = GetInfo::invalidSourceSize; const void *pValue = nullptr; cl_uint refCount = 0; @@ -213,11 +213,9 @@ cl_int Sampler::getInfo(cl_sampler_info paramName, size_t paramValueSize, break; } - retVal = changeGetInfoStatusToCLResultType(::getInfo(paramValue, paramValueSize, pValue, valueSize)); - - if (paramValueSizeRet) { - *paramValueSizeRet = valueSize; - } + auto getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, pValue, valueSize); + retVal = changeGetInfoStatusToCLResultType(getInfoStatus); + GetInfo::setParamValueReturnSize(paramValueSizeRet, valueSize, getInfoStatus); return retVal; } diff --git a/opencl/test/unit_test/api/cl_get_event_profiling_info_tests.inl b/opencl/test/unit_test/api/cl_get_event_profiling_info_tests.inl index 26a44126c8..60987ec423 100644 --- a/opencl/test/unit_test/api/cl_get_event_profiling_info_tests.inl +++ b/opencl/test/unit_test/api/cl_get_event_profiling_info_tests.inl @@ -58,6 +58,24 @@ TEST_F(clEventProfilingTests, GivenInvalidParamNameWhenGettingEventProfilingInfo delete pEvent; } +TEST_F(clEventProfilingTests, GivenInvalidParametersWhenGettingEventProfilingInfoThenValueSizeRetIsNotUpdated) { + Event event{nullptr, 0, 0, 0}; + event.setStatus(CL_COMPLETE); + size_t paramValueSize = sizeof(cl_ulong); + cl_ulong paramValue; + size_t paramValueSizeRet = 0x1234; + cl_int retVal = CL_PROFILING_INFO_NOT_AVAILABLE; + + event.setProfilingEnabled(true); + retVal = clGetEventProfilingInfo(&event, + 0, + paramValueSize, + ¶mValue, + ¶mValueSizeRet); + EXPECT_EQ(CL_INVALID_VALUE, retVal); + EXPECT_EQ(0x1234u, paramValueSizeRet); +} + TEST_F(clEventProfilingTests, GivenInvalidParamValueSizeWhenGettingEventProfilingInfoThenInvalidValueErrorIsReturned) { Event *pEvent = new Event(nullptr, 0, 0, 0); pEvent->setStatus(CL_COMPLETE); diff --git a/opencl/test/unit_test/api/cl_get_image_info_tests.inl b/opencl/test/unit_test/api/cl_get_image_info_tests.inl index efb6d39779..b55567dff9 100644 --- a/opencl/test/unit_test/api/cl_get_image_info_tests.inl +++ b/opencl/test/unit_test/api/cl_get_image_info_tests.inl @@ -80,6 +80,14 @@ TEST_F(clGetImageInfoTests, GivenInvalidParamNameWhenGettingImageInfoThenInvalid ASSERT_EQ(0u, paramRetSize); } +TEST_F(clGetImageInfoTests, GivenInvalidParametersWhenGettingImageInfoThenValueSizeRetIsNotUpdated) { + size_t paramRetSize = 0x1234; + + retVal = clGetImageInfo(image, CL_MEM_SIZE, 0, nullptr, ¶mRetSize); + EXPECT_EQ(CL_INVALID_VALUE, retVal); + EXPECT_EQ(0x1234u, paramRetSize); +} + TEST_F(clGetImageInfoTests, GivenClImageFormatWhenGettingImageInfoThenImageFormatIsReturned) { cl_image_format imgFmtRet; size_t paramRetSize = 0; diff --git a/opencl/test/unit_test/api/cl_get_pipe_info_tests.inl b/opencl/test/unit_test/api/cl_get_pipe_info_tests.inl index a5faa0eb66..0adcd04c27 100644 --- a/opencl/test/unit_test/api/cl_get_pipe_info_tests.inl +++ b/opencl/test/unit_test/api/cl_get_pipe_info_tests.inl @@ -68,6 +68,22 @@ TEST_F(clGetPipeInfoTests, GivenInvalidParamNameWhenGettingPipeInfoThenClInvalid clReleaseMemObject(pipe); } +TEST_F(clGetPipeInfoTests, GivenInvalidParametersWhenGettingPipeInfoThenValueSizeRetIsNotUpdated) { + auto pipe = clCreatePipe(pContext, CL_MEM_READ_WRITE, 1, 20, nullptr, &retVal); + + EXPECT_NE(nullptr, pipe); + EXPECT_EQ(CL_SUCCESS, retVal); + + cl_uint paramValue = 0; + size_t paramValueRetSize = 0x1234; + + retVal = clGetPipeInfo(pipe, CL_MEM_READ_WRITE, sizeof(paramValue), ¶mValue, ¶mValueRetSize); + EXPECT_EQ(CL_INVALID_VALUE, retVal); + EXPECT_EQ(0x1234u, paramValueRetSize); + + clReleaseMemObject(pipe); +} + TEST_F(clGetPipeInfoTests, GivenInvalidMemoryObjectWhenGettingPipeInfoThenClInvalidMemObjectErrorIsReturned) { cl_uint paramValue = 0; diff --git a/opencl/test/unit_test/api/cl_get_platform_info_tests.inl b/opencl/test/unit_test/api/cl_get_platform_info_tests.inl index ef1e61e017..c576670b57 100644 --- a/opencl/test/unit_test/api/cl_get_platform_info_tests.inl +++ b/opencl/test/unit_test/api/cl_get_platform_info_tests.inl @@ -141,6 +141,20 @@ TEST_F(clGetPlatformInfoTests, GivenInvalidParamNameWhenGettingPlatformInfoStrin EXPECT_EQ(CL_INVALID_VALUE, retVal); } +TEST_F(clGetPlatformInfoTests, GivenInvalidParametersWhenGettingPlatformInfoThenValueSizeRetIsNotUpdated) { + char extensions[512]; + retSize = 0x1234; + auto retVal = clGetPlatformInfo( + pPlatform, + 0, // invalid platform info enum + sizeof(extensions), + extensions, + &retSize); + + EXPECT_EQ(CL_INVALID_VALUE, retVal); + EXPECT_EQ(0x1234u, retSize); +} + TEST_F(clGetPlatformInfoTests, GivenInvalidParamSizeWhenGettingPlatformInfoStringThenClInvalidValueErrorIsReturned) { char extensions[512]; auto retVal = clGetPlatformInfo( diff --git a/opencl/test/unit_test/api/cl_intel_accelerator_tests.inl b/opencl/test/unit_test/api/cl_intel_accelerator_tests.inl index e56c0f12a4..64e3f89b65 100644 --- a/opencl/test/unit_test/api/cl_intel_accelerator_tests.inl +++ b/opencl/test/unit_test/api/cl_intel_accelerator_tests.inl @@ -299,7 +299,6 @@ TEST_F(IntelAcceleratorGetInfoTest, GivenShortForDescriptorSizeWhenGettingAccele ¶m_value_size_ret); EXPECT_EQ(CL_INVALID_VALUE, result); - EXPECT_EQ(sizeof(cl_context), param_value_size_ret); } TEST_F(IntelAcceleratorGetInfoTest, GivenZeroForDescriptorSizeGivenLongForDescriptorSizeWhenGettingAcceleratorContextInfoThenCorrectValuesAreReturned) { diff --git a/opencl/test/unit_test/api/cl_intel_motion_estimation.cpp b/opencl/test/unit_test/api/cl_intel_motion_estimation.cpp index 53d676495b..d4a2ac0fde 100644 --- a/opencl/test/unit_test/api/cl_intel_motion_estimation.cpp +++ b/opencl/test/unit_test/api/cl_intel_motion_estimation.cpp @@ -268,7 +268,6 @@ TEST_F(IntelMotionEstimationGetInfoTest, GivenTooShortDescriptorLengthWhenGettin ¶m_value_size_ret); EXPECT_EQ(CL_INVALID_VALUE, result); - EXPECT_EQ(sizeof(cl_motion_estimation_desc_intel), param_value_size_ret); } TEST_F(IntelMotionEstimationGetInfoTest, GivenDescriptorLengthZeroWhenGettingAcceleratorInfoThanClInvalidValueErrorIsReturned) { @@ -280,7 +279,20 @@ TEST_F(IntelMotionEstimationGetInfoTest, GivenDescriptorLengthZeroWhenGettingAcc ¶m_value_size_ret); EXPECT_EQ(CL_INVALID_VALUE, result); - EXPECT_EQ(sizeof(cl_motion_estimation_desc_intel), param_value_size_ret); +} + +TEST_F(IntelMotionEstimationGetInfoTest, GivenInvalidParametersWhenGettingAcceleratorInfoThenValueSizeRetIsNotUpdated) { + param_value_size_ret = 0x1234; + + result = clGetAcceleratorInfoINTEL( + accelerator, + CL_ACCELERATOR_DESCRIPTOR_INTEL, + 0, + &descReturn, + ¶m_value_size_ret); + + EXPECT_EQ(CL_INVALID_VALUE, result); + EXPECT_EQ(0x1234u, param_value_size_ret); } TEST_F(IntelMotionEstimationGetInfoTest, GivenLongerDescriptorLengthWhenGettingAcceleratorInfoThanCorrectDescriptorLengthIsReturned) { @@ -346,7 +358,6 @@ TEST_F(IntelMotionEstimationGetInfoTest, GivenAcceleratorTypeIntelAndTooShortTyp ¶m_value_size_ret); EXPECT_EQ(CL_INVALID_VALUE, result); - EXPECT_EQ(sizeof(cl_accelerator_type_intel), param_value_size_ret); } TEST_F(IntelMotionEstimationGetInfoTest, GivenAcceleratorTypeIntelAndTypeLengthZeroWhenGettingAcceleratorInfoThanClInvalidValueIsReturned) { @@ -358,7 +369,6 @@ TEST_F(IntelMotionEstimationGetInfoTest, GivenAcceleratorTypeIntelAndTypeLengthZ ¶m_value_size_ret); EXPECT_EQ(CL_INVALID_VALUE, result); - EXPECT_EQ(sizeof(cl_accelerator_type_intel), param_value_size_ret); } TEST_F(IntelMotionEstimationGetInfoTest, GivenAcceleratorTypeIntelAndTooLongTypeLengthWhenGettingAcceleratorInfoThanCorrectLengthIsReturned) { diff --git a/opencl/test/unit_test/context/context_get_info_tests.cpp b/opencl/test/unit_test/context/context_get_info_tests.cpp index e00d8a4595..abd655a3c4 100644 --- a/opencl/test/unit_test/context/context_get_info_tests.cpp +++ b/opencl/test/unit_test/context/context_get_info_tests.cpp @@ -47,6 +47,18 @@ TEST_F(ContextGetInfoTest, GivenInvalidParamNameWhenGettingInfoThenInvalidValueE EXPECT_EQ(CL_INVALID_VALUE, retVal); } +TEST_F(ContextGetInfoTest, GivenInvalidParametersWhenGettingContextInfoThenValueSizeRetIsNotUpdated) { + size_t retSize = 0x1234; + + retVal = pContext->getInfo( + 0, + 0, + nullptr, + &retSize); + EXPECT_EQ(CL_INVALID_VALUE, retVal); + EXPECT_EQ(0x1234u, retSize); +} + TEST_F(ContextGetInfoTest, GivenNumDevicesParamNameWhenGettingInfoThenNumberOfDevicesIsReturned) { cl_uint numDevices = 0; size_t retSize = 0; diff --git a/opencl/test/unit_test/device/get_device_info_tests.cpp b/opencl/test/unit_test/device/get_device_info_tests.cpp index a5d58c06d2..5f18c05388 100644 --- a/opencl/test/unit_test/device/get_device_info_tests.cpp +++ b/opencl/test/unit_test/device/get_device_info_tests.cpp @@ -28,6 +28,19 @@ TEST(GetDeviceInfo, GivenInvalidParamsWhenGettingDeviceInfoThenInvalidValueError EXPECT_EQ(CL_INVALID_VALUE, retVal); } +TEST(GetDeviceInfo, GivenInvalidParametersWhenGettingDeviceInfoThenValueSizeRetIsNotUpdated) { + size_t valueSizeRet = 0x1234; + auto device = std::make_unique(MockDevice::createWithNewExecutionEnvironment(nullptr)); + + auto retVal = device->getDeviceInfo( + 0, + 0, + nullptr, + &valueSizeRet); + EXPECT_EQ(CL_INVALID_VALUE, retVal); + EXPECT_EQ(0x1234u, valueSizeRet); +} + HWCMDTEST_F(IGFX_GEN8_CORE, GetDeviceInfoMemCapabilitiesTest, GivenValidParametersWhenGetDeviceInfoIsCalledForBdwPlusThenClSuccessIsReturned) { std::vector params = { diff --git a/opencl/test/unit_test/helpers/get_info_tests.cpp b/opencl/test/unit_test/helpers/get_info_tests.cpp index 2177d7254c..50c4795ba6 100644 --- a/opencl/test/unit_test/helpers/get_info_tests.cpp +++ b/opencl/test/unit_test/helpers/get_info_tests.cpp @@ -13,7 +13,7 @@ TEST(getInfo, GivenSrcSizeLessThanOrEqualDstSizeWhenGettingInfoThenSrcCopiedToDs float dest = 0.0f; float src = 1.0f; - auto retVal = getInfo(&dest, sizeof(dest), &src, sizeof(src)); + auto retVal = GetInfo::getInfo(&dest, sizeof(dest), &src, sizeof(src)); EXPECT_EQ(GetInfoStatus::SUCCESS, retVal); EXPECT_EQ(src, dest); } @@ -22,7 +22,7 @@ TEST(getInfo, GivenSrcSizeGreaterThanEqualDstSizeAndDstNullPtrWhenGettingInfoThe float dest = 0.0f; float src = 1.0f; - auto retVal = getInfo(nullptr, 0, &src, sizeof(src)); + auto retVal = GetInfo::getInfo(nullptr, 0, &src, sizeof(src)); EXPECT_EQ(GetInfoStatus::SUCCESS, retVal); EXPECT_NE(src, dest); } @@ -31,16 +31,16 @@ TEST(getInfo, GivenSrcSizeLessThanOrEqualDstSizeAndDstIsNullPtrWhenGettingInfoTh float dest = 0.0f; float src = 1.0f; - auto retVal = getInfo(nullptr, sizeof(dest), &src, sizeof(src)); + auto retVal = GetInfo::getInfo(nullptr, sizeof(dest), &src, sizeof(src)); EXPECT_EQ(GetInfoStatus::SUCCESS, retVal); EXPECT_NE(src, dest); } -TEST(getInfo, GivenSrcSizeLessThanOrEqualDstSizeAndDstIsNotNullPtrWhenGettingInfoThenInvalidValueIsReturned) { +TEST(getInfo, GivenSrcSizeGreaterThanDstSizeAndDstIsNotNullPtrWhenGettingInfoThenInvalidValueIsReturned) { float dest = 0.0f; float src = 1.0f; - auto retVal = getInfo(&dest, 0, &src, sizeof(src)); + auto retVal = GetInfo::getInfo(&dest, 0, &src, sizeof(src)); EXPECT_EQ(GetInfoStatus::INVALID_VALUE, retVal); EXPECT_NE(src, dest); } @@ -49,20 +49,44 @@ TEST(getInfo, GivenNullSrcPtrWhenGettingInfoThenInvalidValueErrorIsReturned) { float dest = 0.0f; float src = 1.0f; - auto retVal = getInfo(&dest, sizeof(dest), nullptr, sizeof(src)); + auto retVal = GetInfo::getInfo(&dest, sizeof(dest), nullptr, sizeof(src)); EXPECT_EQ(GetInfoStatus::INVALID_VALUE, retVal); EXPECT_NE(src, dest); } -TEST(getInfo, GivenZeroSrcSizeWhenGettingInfoThenInvalidValueErrorIsReturned) { +TEST(getInfo, GivenZeroSrcSizeWhenGettingInfoThenSuccessIsReturned) { float dest = 0.0f; float src = 1.0f; - auto retVal = getInfo(&dest, sizeof(dest), &src, 0); + auto retVal = GetInfo::getInfo(&dest, sizeof(dest), &src, 0); + EXPECT_EQ(GetInfoStatus::SUCCESS, retVal); + EXPECT_NE(src, dest); +} + +TEST(getInfo, GivenInvalidSrcSizeWhenGettingInfoThenInvalidValueErrorIsReturned) { + float dest = 0.0f; + float src = 1.0f; + + auto retVal = GetInfo::getInfo(&dest, sizeof(dest), &src, GetInfo::invalidSourceSize); EXPECT_EQ(GetInfoStatus::INVALID_VALUE, retVal); EXPECT_NE(src, dest); } +TEST(getInfo, GivenInvalidInputWhenSettingParamValueReturnSizeThenNothingHappens) { + size_t paramValueReturnSize = 0u; + + GetInfo::setParamValueReturnSize(nullptr, 1, GetInfoStatus::SUCCESS); + GetInfo::setParamValueReturnSize(¶mValueReturnSize, 1, GetInfoStatus::INVALID_VALUE); + EXPECT_EQ(0u, paramValueReturnSize); +} + +TEST(getInfo, GivenValidInputWhenSettingParamValueReturnSizeThenValueIsUpdated) { + size_t paramValueReturnSize = 0u; + + GetInfo::setParamValueReturnSize(¶mValueReturnSize, 1, GetInfoStatus::SUCCESS); + EXPECT_EQ(1u, paramValueReturnSize); +} + TEST(getInfoHelper, GivenInstanceOfGetInfoHelperAndNullPtrParamsSuccessIsReturned) { GetInfoStatus retVal; GetInfoHelper info(nullptr, 0, nullptr, &retVal); diff --git a/opencl/test/unit_test/kernel/kernel_arg_info_tests.cpp b/opencl/test/unit_test/kernel/kernel_arg_info_tests.cpp index 9966ad9b21..7884655607 100644 --- a/opencl/test/unit_test/kernel/kernel_arg_info_tests.cpp +++ b/opencl/test/unit_test/kernel/kernel_arg_info_tests.cpp @@ -99,6 +99,19 @@ TEST_P(KernelArgInfoTest, WhenQueryingWithNullptrKernelNameTheniReturnNullptr) { EXPECT_EQ(nullptr, kernelInfo); } +TEST_P(KernelArgInfoTest, GivenInvalidParametersWhenGettingKernelArgInfoThenValueSizeRetIsNotUpdated) { + size_t paramValueSizeRet = 0x1234; + + retVal = pKernel->getArgInfo( + 0, + 0, + 0, + nullptr, + ¶mValueSizeRet); + EXPECT_EQ(CL_INVALID_VALUE, retVal); + EXPECT_EQ(0x1234u, paramValueSizeRet); +} + TEST_P(KernelArgInfoTest, getKernelArgAcessQualifier) { cl_kernel_arg_access_qualifier param_value = 0; queryArgInfo(CL_KERNEL_ARG_ACCESS_QUALIFIER, param_value); diff --git a/opencl/test/unit_test/kernel/kernel_tests.cpp b/opencl/test/unit_test/kernel/kernel_tests.cpp index f47614f0d0..8f889767fc 100644 --- a/opencl/test/unit_test/kernel/kernel_tests.cpp +++ b/opencl/test/unit_test/kernel/kernel_tests.cpp @@ -117,6 +117,20 @@ TEST_P(KernelTest, GivenInvalidParamNameWhenGettingInfoThenInvalidValueErrorIsRe EXPECT_EQ(CL_INVALID_VALUE, retVal); } +TEST_P(KernelTest, GivenInvalidParametersWhenGettingInfoThenValueSizeRetIsNotUpdated) { + size_t paramValueSizeRet = 0x1234; + + // get size + retVal = pKernel->getInfo( + 0, + 0, + nullptr, + ¶mValueSizeRet); + + EXPECT_EQ(CL_INVALID_VALUE, retVal); + EXPECT_EQ(0x1234u, paramValueSizeRet); +} + TEST_P(KernelTest, GivenKernelFunctionNameWhenGettingInfoThenKernelFunctionNameIsReturned) { cl_kernel_info paramName = CL_KERNEL_FUNCTION_NAME; size_t paramValueSize = 0; diff --git a/opencl/test/unit_test/mem_obj/get_mem_object_info_tests.cpp b/opencl/test/unit_test/mem_obj/get_mem_object_info_tests.cpp index 8335c6d4aa..2640394e85 100644 --- a/opencl/test/unit_test/mem_obj/get_mem_object_info_tests.cpp +++ b/opencl/test/unit_test/mem_obj/get_mem_object_info_tests.cpp @@ -51,6 +51,19 @@ TEST_F(GetMemObjectInfo, GivenInvalidParamsWhenGettingMemObjectInfoThenInvalidVa EXPECT_EQ(CL_INVALID_VALUE, retVal); } +TEST_F(GetMemObjectInfo, GivenInvalidParametersWhenGettingMemObjectInfoThenValueSizeRetIsNotUpdated) { + auto buffer = std::unique_ptr(BufferHelper<>::create()); + + size_t sizeReturned = 0x1234; + auto retVal = buffer->getMemObjectInfo( + 0, + 0, + nullptr, + &sizeReturned); + EXPECT_EQ(CL_INVALID_VALUE, retVal); + EXPECT_EQ(0x1234u, sizeReturned); +} + TEST_F(GetMemObjectInfo, GivenMemTypeWhenGettingMemObjectInfoThenCorrectValueIsReturned) { auto buffer = std::unique_ptr(BufferHelper<>::create()); diff --git a/opencl/test/unit_test/program/program_tests.cpp b/opencl/test/unit_test/program/program_tests.cpp index fb31c76d6e..1812f427d4 100644 --- a/opencl/test/unit_test/program/program_tests.cpp +++ b/opencl/test/unit_test/program/program_tests.cpp @@ -181,6 +181,19 @@ TEST_P(ProgramFromBinaryTest, GivenNonNullParamValueAndParamValueSizeZeroWhenGet EXPECT_EQ(CL_INVALID_VALUE, retVal); } +TEST_P(ProgramFromBinaryTest, GivenInvalidParametersWhenGettingProgramInfoThenValueSizeRetIsNotUpdated) { + size_t paramValueSizeRet = 0x1234; + auto testBinary = std::make_unique(knownSourceSize); + + retVal = pProgram->getInfo( + CL_PROGRAM_BINARIES, + 0, + &testBinary, + ¶mValueSizeRet); + EXPECT_EQ(CL_INVALID_VALUE, retVal); + EXPECT_EQ(0x1234u, paramValueSizeRet); +} + TEST_P(ProgramFromBinaryTest, GivenInvalidParamWhenGettingProgramBinaryInfoThenInvalidValueErrorIsReturned) { size_t paramValueSizeRet = 0; auto testBinary = std::make_unique(knownSourceSize); @@ -388,6 +401,23 @@ TEST_P(ProgramFromBinaryTest, GivenNullDeviceWhenGettingBuildStatusThenBuildNone EXPECT_EQ(CL_BUILD_NONE, buildStatus); } +TEST_P(ProgramFromBinaryTest, GivenInvalidParametersWhenGettingBuildInfoThenValueSizeRetIsNotUpdated) { + cl_device_id device = pClDevice; + cl_build_status buildStatus = 0; + size_t paramValueSize = sizeof(buildStatus); + size_t paramValueSizeRet = 0x1234; + + retVal = pProgram->getBuildInfo( + device, + 0, + paramValueSize, + &buildStatus, + ¶mValueSizeRet); + + EXPECT_EQ(CL_INVALID_VALUE, retVal); + EXPECT_EQ(0x1234u, paramValueSizeRet); +} + TEST_P(ProgramFromBinaryTest, GivenDefaultDeviceWhenGettingBuildOptionsThenBuildOptionsAreEmpty) { cl_device_id device = pClDevice; size_t paramValueSizeRet = 0u; diff --git a/opencl/test/unit_test/sampler/get_sampler_info_tests.cpp b/opencl/test/unit_test/sampler/get_sampler_info_tests.cpp index 58e6e7b3e2..dbe3dd4e49 100644 --- a/opencl/test/unit_test/sampler/get_sampler_info_tests.cpp +++ b/opencl/test/unit_test/sampler/get_sampler_info_tests.cpp @@ -13,7 +13,7 @@ using namespace NEO; -TEST(GetSamplerInfo, InvalidFlags_returnsError) { +TEST(GetSamplerInfo, GivenInvalidFlagsWhenGettingSamplerInfoThenInvalidValueErrorIsReturnedAndValueSizeRetIsNotUpdated) { MockContext context; auto retVal = CL_INVALID_VALUE; auto normalizedCoords = CL_TRUE; @@ -22,8 +22,11 @@ TEST(GetSamplerInfo, InvalidFlags_returnsError) { auto sampler = Sampler::create(&context, normalizedCoords, addressingMode, filterMode, retVal); - retVal = sampler->getInfo(0, 0, nullptr, nullptr); + size_t valueSizeRet = 0x1234; + + retVal = sampler->getInfo(0, 0, nullptr, &valueSizeRet); EXPECT_EQ(CL_INVALID_VALUE, retVal); + EXPECT_EQ(0x1234u, valueSizeRet); delete sampler; } diff --git a/shared/source/helpers/get_info.h b/shared/source/helpers/get_info.h index b9014eae31..be03f7fef5 100644 --- a/shared/source/helpers/get_info.h +++ b/shared/source/helpers/get_info.h @@ -8,32 +8,45 @@ #pragma once #include "get_info_status.h" -#include - // Need for linux compatibility with memcpy_s #include "shared/source/helpers/string.h" +#include +#include + +namespace GetInfo { + +constexpr size_t invalidSourceSize = std::numeric_limits::max(); + inline GetInfoStatus getInfo(void *destParamValue, size_t destParamValueSize, const void *srcParamValue, size_t srcParamValueSize) { - auto retVal = GetInfoStatus::INVALID_VALUE; - if (srcParamValue && srcParamValueSize) { - if (!destParamValue && !destParamValueSize) { - // Report ok if they're looking for size. - retVal = GetInfoStatus::SUCCESS; - } else if (destParamValue && destParamValueSize >= srcParamValueSize) { - // Report ok if we can copy safely - retVal = GetInfoStatus::SUCCESS; - memcpy_s(destParamValue, destParamValueSize, srcParamValue, srcParamValueSize); - } else if (!destParamValue) { - // Report ok if destParamValue == nullptr and destParamValueSize > 0 - retVal = GetInfoStatus::SUCCESS; - } + if ((srcParamValue == nullptr) || (srcParamValueSize == invalidSourceSize)) { + return GetInfoStatus::INVALID_VALUE; } - return retVal; + if ((srcParamValueSize == 0) || (destParamValue == nullptr)) { + // Report ok if there is nothing to copy or when only size is queried. + return GetInfoStatus::SUCCESS; + } + + if (destParamValueSize < srcParamValueSize) { + return GetInfoStatus::INVALID_VALUE; + } + + // Report ok if we can copy safely. + memcpy_s(destParamValue, destParamValueSize, srcParamValue, srcParamValueSize); + return GetInfoStatus::SUCCESS; } +inline void setParamValueReturnSize(size_t *paramValueSizeRet, size_t newValue, GetInfoStatus getInfoStatus) { + if ((paramValueSizeRet != nullptr) && (getInfoStatus == GetInfoStatus::SUCCESS)) { + *paramValueSizeRet = newValue; + } +} + +} // namespace GetInfo + struct GetInfoHelper { GetInfoHelper(void *dst, size_t dstSize, size_t *retSize, GetInfoStatus *retVal = nullptr) : dst(dst), dstSize(dstSize), retSize(retSize), retVal(retVal) {