mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
Convert some if-else chains to switch statements (#1730)
All of these if-else chains compare against enums, which is better done using switch statements. This helps avoid some `-Wsometimes-uninitialized` warnings of variables that are assigned inside the switch. Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
This commit is contained in:
committed by
GitHub
parent
4f62adf1ca
commit
957e3b3985
@@ -79,20 +79,30 @@ int check_image(cl_command_queue queue, cl_mem mem) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == CL_MEM_OBJECT_BUFFER) {
|
switch (type)
|
||||||
log_error("Expected image object, not buffer.\n");
|
{
|
||||||
return -1;
|
case CL_MEM_OBJECT_BUFFER:
|
||||||
} else if (type == CL_MEM_OBJECT_IMAGE2D) {
|
log_error("Expected image object, not buffer.\n");
|
||||||
error = clGetImageInfo(mem, CL_IMAGE_WIDTH, sizeof(width), &width, NULL);
|
|
||||||
if (error) {
|
|
||||||
print_error(error, "clGetMemObjectInfo failed for CL_IMAGE_WIDTH.");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
case CL_MEM_OBJECT_IMAGE2D:
|
||||||
error = clGetImageInfo(mem, CL_IMAGE_HEIGHT, sizeof(height), &height, NULL);
|
error = clGetImageInfo(mem, CL_IMAGE_WIDTH, sizeof(width), &width,
|
||||||
if (error) {
|
NULL);
|
||||||
print_error(error, "clGetMemObjectInfo failed for CL_IMAGE_HEIGHT.");
|
if (error)
|
||||||
return -1;
|
{
|
||||||
}
|
print_error(error,
|
||||||
|
"clGetMemObjectInfo failed for CL_IMAGE_WIDTH.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
error = clGetImageInfo(mem, CL_IMAGE_HEIGHT, sizeof(height),
|
||||||
|
&height, NULL);
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
print_error(error,
|
||||||
|
"clGetMemObjectInfo failed for CL_IMAGE_HEIGHT.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default: log_error("unexpected object type"); return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -64,16 +64,21 @@ static int test_setargs_and_execution(cl_command_queue queue, cl_kernel kernel,
|
|||||||
cl_int status;
|
cl_int status;
|
||||||
const char *typestr;
|
const char *typestr;
|
||||||
|
|
||||||
if (type == NON_NULL_PATH) {
|
switch (type)
|
||||||
status = clSetKernelArg(kernel, 0, sizeof(cl_mem), &test_buf);
|
{
|
||||||
typestr = "non-NULL";
|
case NON_NULL_PATH:
|
||||||
} else if (type == ADDROF_NULL_PATH) {
|
status = clSetKernelArg(kernel, 0, sizeof(cl_mem), &test_buf);
|
||||||
test_buf = NULL;
|
typestr = "non-NULL";
|
||||||
status = clSetKernelArg(kernel, 0, sizeof(cl_mem), &test_buf);
|
break;
|
||||||
typestr = "&NULL";
|
case ADDROF_NULL_PATH:
|
||||||
} else if (type == NULL_PATH) {
|
test_buf = NULL;
|
||||||
status = clSetKernelArg(kernel, 0, sizeof(cl_mem), NULL);
|
status = clSetKernelArg(kernel, 0, sizeof(cl_mem), &test_buf);
|
||||||
typestr = "NULL";
|
typestr = "&NULL";
|
||||||
|
break;
|
||||||
|
case NULL_PATH:
|
||||||
|
status = clSetKernelArg(kernel, 0, sizeof(cl_mem), NULL);
|
||||||
|
typestr = "NULL";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_info("Testing setKernelArgs with %s buffer.\n", typestr);
|
log_info("Testing setKernelArgs with %s buffer.\n", typestr);
|
||||||
|
|||||||
@@ -41,60 +41,52 @@ int test_image_type( cl_device_id device, cl_context context, cl_command_queue q
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( testMethod == k1D )
|
switch (testMethod)
|
||||||
{
|
{
|
||||||
name = "1D -> 1D";
|
case k1D:
|
||||||
imageType = CL_MEM_OBJECT_IMAGE1D;
|
name = "1D -> 1D";
|
||||||
}
|
imageType = CL_MEM_OBJECT_IMAGE1D;
|
||||||
else if( testMethod == k2D )
|
break;
|
||||||
{
|
case k2D:
|
||||||
name = "2D -> 2D";
|
name = "2D -> 2D";
|
||||||
imageType = CL_MEM_OBJECT_IMAGE2D;
|
imageType = CL_MEM_OBJECT_IMAGE2D;
|
||||||
}
|
break;
|
||||||
else if( testMethod == k3D )
|
case k3D:
|
||||||
{
|
name = "3D -> 3D";
|
||||||
name = "3D -> 3D";
|
imageType = CL_MEM_OBJECT_IMAGE3D;
|
||||||
imageType = CL_MEM_OBJECT_IMAGE3D;
|
break;
|
||||||
}
|
case k1DArray:
|
||||||
else if( testMethod == k1DArray )
|
name = "1D array -> 1D array";
|
||||||
{
|
imageType = CL_MEM_OBJECT_IMAGE1D_ARRAY;
|
||||||
name = "1D array -> 1D array";
|
break;
|
||||||
imageType = CL_MEM_OBJECT_IMAGE1D_ARRAY;
|
case k2DArray:
|
||||||
}
|
name = "2D array -> 2D array";
|
||||||
else if( testMethod == k2DArray )
|
imageType = CL_MEM_OBJECT_IMAGE2D_ARRAY;
|
||||||
{
|
break;
|
||||||
name = "2D array -> 2D array";
|
case k2DTo3D:
|
||||||
imageType = CL_MEM_OBJECT_IMAGE2D_ARRAY;
|
name = "2D -> 3D";
|
||||||
}
|
imageType = CL_MEM_OBJECT_IMAGE3D;
|
||||||
else if( testMethod == k2DTo3D )
|
break;
|
||||||
{
|
case k3DTo2D:
|
||||||
name = "2D -> 3D";
|
name = "3D -> 2D";
|
||||||
imageType = CL_MEM_OBJECT_IMAGE3D;
|
imageType = CL_MEM_OBJECT_IMAGE3D;
|
||||||
}
|
break;
|
||||||
else if( testMethod == k3DTo2D )
|
case k2DArrayTo2D:
|
||||||
{
|
name = "2D array -> 2D";
|
||||||
name = "3D -> 2D";
|
imageType = CL_MEM_OBJECT_IMAGE2D_ARRAY;
|
||||||
imageType = CL_MEM_OBJECT_IMAGE3D;
|
break;
|
||||||
}
|
case k2DTo2DArray:
|
||||||
else if( testMethod == k2DArrayTo2D )
|
name = "2D -> 2D array";
|
||||||
{
|
imageType = CL_MEM_OBJECT_IMAGE2D_ARRAY;
|
||||||
name = "2D array -> 2D";
|
break;
|
||||||
imageType = CL_MEM_OBJECT_IMAGE2D_ARRAY;
|
case k2DArrayTo3D:
|
||||||
}
|
name = "2D array -> 3D";
|
||||||
else if( testMethod == k2DTo2DArray )
|
imageType = CL_MEM_OBJECT_IMAGE3D;
|
||||||
{
|
break;
|
||||||
name = "2D -> 2D array";
|
case k3DTo2DArray:
|
||||||
imageType = CL_MEM_OBJECT_IMAGE2D_ARRAY;
|
name = "3D -> 2D array";
|
||||||
}
|
imageType = CL_MEM_OBJECT_IMAGE3D;
|
||||||
else if( testMethod == k2DArrayTo3D )
|
break;
|
||||||
{
|
|
||||||
name = "2D array -> 3D";
|
|
||||||
imageType = CL_MEM_OBJECT_IMAGE3D;
|
|
||||||
}
|
|
||||||
else if( testMethod == k3DTo2DArray )
|
|
||||||
{
|
|
||||||
name = "3D -> 2D array";
|
|
||||||
imageType = CL_MEM_OBJECT_IMAGE3D;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(gTestMipmaps)
|
if(gTestMipmaps)
|
||||||
|
|||||||
@@ -33,35 +33,34 @@ int test_image_type( cl_device_id device, cl_context context, cl_command_queue q
|
|||||||
cl_mem_object_type imageType;
|
cl_mem_object_type imageType;
|
||||||
test_func test_fn;
|
test_func test_fn;
|
||||||
|
|
||||||
if ( testMethod == k1D )
|
switch (testMethod)
|
||||||
{
|
{
|
||||||
name = "1D Image Fill";
|
case k1D:
|
||||||
imageType = CL_MEM_OBJECT_IMAGE1D;
|
name = "1D Image Fill";
|
||||||
test_fn = &test_fill_image_set_1D;
|
imageType = CL_MEM_OBJECT_IMAGE1D;
|
||||||
}
|
test_fn = &test_fill_image_set_1D;
|
||||||
else if ( testMethod == k2D )
|
break;
|
||||||
{
|
case k2D:
|
||||||
name = "2D Image Fill";
|
name = "2D Image Fill";
|
||||||
imageType = CL_MEM_OBJECT_IMAGE2D;
|
imageType = CL_MEM_OBJECT_IMAGE2D;
|
||||||
test_fn = &test_fill_image_set_2D;
|
test_fn = &test_fill_image_set_2D;
|
||||||
}
|
break;
|
||||||
else if ( testMethod == k1DArray )
|
case k1DArray:
|
||||||
{
|
name = "1D Image Array Fill";
|
||||||
name = "1D Image Array Fill";
|
imageType = CL_MEM_OBJECT_IMAGE1D_ARRAY;
|
||||||
imageType = CL_MEM_OBJECT_IMAGE1D_ARRAY;
|
test_fn = &test_fill_image_set_1D_array;
|
||||||
test_fn = &test_fill_image_set_1D_array;
|
break;
|
||||||
}
|
case k2DArray:
|
||||||
else if ( testMethod == k2DArray )
|
name = "2D Image Array Fill";
|
||||||
{
|
imageType = CL_MEM_OBJECT_IMAGE2D_ARRAY;
|
||||||
name = "2D Image Array Fill";
|
test_fn = &test_fill_image_set_2D_array;
|
||||||
imageType = CL_MEM_OBJECT_IMAGE2D_ARRAY;
|
break;
|
||||||
test_fn = &test_fill_image_set_2D_array;
|
case k3D:
|
||||||
}
|
name = "3D Image Fill";
|
||||||
else if ( testMethod == k3D )
|
imageType = CL_MEM_OBJECT_IMAGE3D;
|
||||||
{
|
test_fn = &test_fill_image_set_3D;
|
||||||
name = "3D Image Fill";
|
break;
|
||||||
imageType = CL_MEM_OBJECT_IMAGE3D;
|
default: log_error("Unhandled method\n"); return -1;
|
||||||
test_fn = &test_fill_image_set_3D;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log_info( "Running %s tests...\n", name );
|
log_info( "Running %s tests...\n", name );
|
||||||
|
|||||||
Reference in New Issue
Block a user