Variable overflow
Cause:
In the clgetdeviceinfo
OpenCL test it is checked that CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE is at least 64KB. However, an int
variable is used for that, while OpenCL specification states that cl_ulong
one shall be considered:
https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/clGetDeviceInfo.html
Consequences:
In some platforms (like AMD) that value can be huge (i.e. 4244635648 (3.953GiB)), overflowing the variable and therefore evaluating as a negative value, giving back a false failed test
Solution:
I suggest just simply applying the correct type. Following a patch produced with git:
diff --git a/tests/cl/api/get-device-info.c b/tests/cl/api/get-device-info.c
index cdfbb265a..c7b6e27c6 100644
--- a/tests/cl/api/get-device-info.c
+++ b/tests/cl/api/get-device-info.c
@@ -59,7 +59,7 @@ piglit_cl_test(const int argc,
size_t param_value_size;
void* param_value;
- int* int_value;
+ cl_ulong* ulong_value;
int num_device_infos = PIGLIT_CL_ENUM_NUM(cl_device_info, env->version);
const cl_device_info *device_infos = PIGLIT_CL_ENUM_ARRAY(cl_device_info);
@@ -154,15 +154,15 @@ piglit_cl_test(const int argc,
* Checks for minimum required values.
*/
- int_value = piglit_cl_get_device_info(env->device_id,
+ ulong_value = piglit_cl_get_device_info(env->device_id,
CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE);
- if (*int_value < 64 * 1024) {
+ if (*ulong_value < 64 * 1024) {
fprintf(stderr, "CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE must be "
"at least 64 KB\n");
piglit_merge_result(&result, PIGLIT_FAIL);
}
- free(int_value);
+ free(ulong_value);
return result;
}