Skip to content

Commit

Permalink
Enable narrowing errors for more directories
Browse files Browse the repository at this point in the history
Moves -Wno-narrowing down to only run on suites with
many narrowing errors.

Includes some quick fixes for one-off errors this caused.

Contributes KhronosGroup#787

Signed-off-by: Ellen Norris-Thompson <ellen.norris-thompson@arm.com>
  • Loading branch information
ellnor01 committed Feb 5, 2021
1 parent 39dd7a2 commit 1282bca
Show file tree
Hide file tree
Showing 17 changed files with 361 additions and 26 deletions.
4 changes: 0 additions & 4 deletions test_conformance/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# Remember current source directory (`test_conformance').
set( CLConf_Install_Base_Dir "${CMAKE_CURRENT_SOURCE_DIR}" )

if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang")
add_cxx_flag_if_supported(-Wno-narrowing)
endif()

set(HARNESS_LIB harness)

add_subdirectory( allocations )
Expand Down
300 changes: 300 additions & 0 deletions test_conformance/api/negative_context.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
//
// Copyright (c) 2020 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "testBase.h"

/* Negative Tests for clCreateContext */
int test_negative_create_context(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{
// clCreateContext returns CL_INVALID_PLATFORM when:
// "an invalid platform object is used with the CL_CONTEXT_PLATFORM
// property" using a nullptr
cl_context_properties props[3] = {
CL_CONTEXT_PLATFORM, reinterpret_cast<cl_context_properties>(nullptr), 0
};
bool failed_tests =
negative_object_test(clCreateContext, CL_INVALID_PLATFORM, props, 1,
&deviceID, nullptr, nullptr);

// clCreateContext returns CL_INVALID_PLATFORM when:
// "an invalid platform object is used with the CL_CONTEXT_PLATFORM
// property" using a a valid object that is NOT a platform
props[1] = reinterpret_cast<cl_context_properties>(context);
failed_tests |= negative_object_test(clCreateContext, CL_INVALID_PLATFORM,
props, 1, &deviceID, nullptr, nullptr);

if (get_device_cl_version(deviceID) >= Version(1, 1))
{
// clCreateContext return CL_INVALID_PROPERTY when: "context property
// name in properties is not a supported property name"
props[0] = reinterpret_cast<cl_context_properties>("INVALID_PROPERTY");

props[1] = reinterpret_cast<cl_context_properties>(nullptr);
failed_tests |=
negative_object_test(clCreateContext, CL_INVALID_PROPERTY, props, 1,
&deviceID, nullptr, nullptr);
// clCreateContext return CL_INVALID_PROPERTY when: "the value specified
// for a supported property name is not valid"
cl_context_properties invalid_value{ -1 };
props[0] = CL_CONTEXT_INTEROP_USER_SYNC;
props[1] = reinterpret_cast<cl_context_properties>(invalid_value);
failed_tests |=
negative_object_test(clCreateContext, CL_INVALID_PROPERTY, props, 1,
&deviceID, nullptr, nullptr);
// clCreateContext return CL_INVALID_PROPERTY when: "the same property
// name is specified more than once"
cl_bool property_value = CL_FALSE;
cl_context_properties duplicated_property[7] = {
CL_CONTEXT_INTEROP_USER_SYNC,
(cl_context_properties)property_value,
CL_CONTEXT_INTEROP_USER_SYNC,
(cl_context_properties)property_value,
CL_CONTEXT_INTEROP_USER_SYNC,
(cl_context_properties)property_value,
0
};
failed_tests |= negative_object_test(
clCreateContext, CL_INVALID_PROPERTY, duplicated_property, 1,
&deviceID, nullptr, nullptr);
}
// clCreateContext return CL_INVALID_VALUE when: "devices is NULL"
failed_tests |= negative_object_test(clCreateContext, CL_INVALID_VALUE,
nullptr, 1, nullptr, nullptr, nullptr);
// clCreateContext return CL_INVALID_VALUE when: "num_devices is equal to
// zero"
failed_tests |=
negative_object_test(clCreateContext, CL_INVALID_VALUE, nullptr, 0,
&deviceID, nullptr, nullptr);
// clCreateContext return CL_INVALID_VALUE when: "pfn_notify is NULL but
// user_data is not NULL"
int user_data = 1; // Arbitrary non-NULL value
failed_tests |=
negative_object_test(clCreateContext, CL_INVALID_VALUE, nullptr, 1,
&deviceID, nullptr, &user_data);
// clCreateContext return CL_INVALID_DEVICE when: "any device in devices is
// not a valid device" using a device set to nullptr
cl_device_id invalid_device = nullptr;
failed_tests |=
negative_object_test(clCreateContext, CL_INVALID_DEVICE, nullptr, 1,
&invalid_device, nullptr, nullptr);
// clCreateContext return CL_INVALID_DEVICE when: "any device in devices is
// not a valid device" using a pointer to a valid object that is NOT a
// device
failed_tests |= negative_object_test(
clCreateContext, CL_INVALID_DEVICE, nullptr, 1,
reinterpret_cast<cl_device_id*>(&context), nullptr, nullptr);
return failed_tests ? TEST_FAIL : TEST_PASS;
}

/* Negative Tests for clCreateContextFromType */

// clCreateContextFromType returns CL_DEVICE_NOT_AVAILABLE when: "no devices
// that match device_type and property values specified in properties are
// currently available"
static test_status test_cl_device_not_found(cl_platform_id platform,
cl_device_id deviceID)
{
cl_device_id devices = nullptr;
cl_int err = CL_SUCCESS;
std::vector<cl_device_type> device_types = { CL_DEVICE_TYPE_CPU,
CL_DEVICE_TYPE_GPU,
CL_DEVICE_TYPE_ACCELERATOR };
if (get_device_cl_version(deviceID) >= Version(1, 2))
{
device_types.push_back(CL_DEVICE_TYPE_CUSTOM);
}
for (auto type : device_types)
{
clContextWrapper context =
clCreateContextFromType(nullptr, type, nullptr, nullptr, &err);
if (err != CL_SUCCESS)
{
break;
}
if (type == device_types.back())
{
return TEST_SKIP;
}
}

test_failure_error_ret(err, CL_DEVICE_NOT_FOUND, "clCreateContextFromType",
TEST_FAIL);
return TEST_PASS;
}

int test_negative_create_context_from_type(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements)
{
cl_platform_id platform = getPlatformFromDevice(deviceID);

// clCreateContext returns CL_INVALID_PLATFORM when: "an
// invalid platform object is used with the CL_CONTEXT_PLATFORM property"
// using a nullptr
cl_context_properties props[5] = {
CL_CONTEXT_PLATFORM, reinterpret_cast<cl_context_properties>(nullptr),
0, 0, 0
};
bool failed_tests =
negative_object_test(clCreateContextFromType, CL_INVALID_PLATFORM,
props, CL_DEVICE_TYPE_DEFAULT, nullptr, nullptr);

// clCreateContext returns CL_INVALID_PLATFORM when: "an
// invalid platform object is used with the CL_CONTEXT_PLATFORM property"
// using a valid object that is NOT a platform
failed_tests |=
negative_object_test(clCreateContextFromType, CL_INVALID_PLATFORM,
props, CL_DEVICE_TYPE_DEFAULT, nullptr, nullptr);
if (get_device_cl_version(deviceID) >= Version(1, 1))
{
// clCreateContext return CL_INVALID_PROPERTY when: "context property
// name in properties is not a supported property name"
props[1] = reinterpret_cast<cl_context_properties>(platform);
props[2] = reinterpret_cast<cl_context_properties>("INVALID_PROPERTY");
props[3] = reinterpret_cast<cl_context_properties>(nullptr);

failed_tests |= negative_object_test(
clCreateContextFromType, CL_INVALID_PROPERTY, props,
CL_DEVICE_TYPE_DEFAULT, nullptr, nullptr);
// clCreateContext return CL_INVALID_PROPERTY when: "the value specified
// for a supported property name is not valid"
cl_context_properties invalid_value{ -1 };
props[2] = CL_CONTEXT_INTEROP_USER_SYNC;
props[3] = reinterpret_cast<cl_context_properties>(invalid_value);
failed_tests |= negative_object_test(
clCreateContextFromType, CL_INVALID_PROPERTY, props,
CL_DEVICE_TYPE_DEFAULT, nullptr, nullptr);
// clCreateContext return CL_INVALID_PROPERTY when: "the same property
// name is specified more than once"
props[2] = CL_CONTEXT_PLATFORM;
props[3] = reinterpret_cast<cl_context_properties>(platform);
failed_tests |= negative_object_test(
clCreateContextFromType, CL_INVALID_PROPERTY, props,
CL_DEVICE_TYPE_DEFAULT, nullptr, nullptr);
}
// clCreateContext return CL_INVALID_VALUE when: "pfn_notify is NULL but
// user_data is not NULL"
int user_data = 1; // Arbitrary non-NULL value
failed_tests |=
negative_object_test(clCreateContextFromType, CL_INVALID_VALUE, nullptr,
CL_DEVICE_TYPE_DEFAULT, nullptr, &user_data);
// clCreateContextFromType returns CL_INVALID_DEVICE_TYPE when: "device_type
// is not a valid value"
cl_device_type INVALID_DEVICE_TYPE = 0;
failed_tests |=
negative_object_test(clCreateContextFromType, CL_INVALID_DEVICE_TYPE,
nullptr, INVALID_DEVICE_TYPE, nullptr, nullptr);
failed_tests |= (TEST_FAIL == test_cl_device_not_found(platform, deviceID));
return failed_tests ? TEST_FAIL : TEST_PASS;
}

/* Negative Tests for clRetainContext */
int test_negative_retain_context(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{
// clRetainContext returns CL_INVALID_CONTEXT when: "context is not a valid
// OpenCL context" using a nullptr
bool failed_tests =
negative_test(clRetainContext, CL_INVALID_CONTEXT, nullptr);

// clRetainContext returns CL_INVALID_CONTEXT when: "context is not a valid
// OpenCL context" using a valid object which is NOT a context
failed_tests |= negative_test(clRetainContext, CL_INVALID_CONTEXT,
reinterpret_cast<cl_context>(deviceID));

return failed_tests ? TEST_FAIL : TEST_PASS;
}

/* Negative Tests for clReleaseContext */
int test_negative_release_context(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{
// clReleaseContext returns CL_INVALID_CONTEXT when: "context is not a valid
// OpenCL context" using a nullptr
bool failed_tests =
negative_test(clReleaseContext, CL_INVALID_CONTEXT, nullptr);

// clReleaseContext returns CL_INVALID_CONTEXT when: "context is not a valid
// OpenCL context" using a valid object which is NOT a context
failed_tests |= negative_test(clReleaseContext, CL_INVALID_CONTEXT,
reinterpret_cast<cl_context>(deviceID));

return failed_tests ? TEST_FAIL : TEST_PASS;
}

/* Negative Tests for clGetContextInfo */
int test_negative_get_context_info(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{

// clGetContextInfo returns CL_INVALID_CONTEXT when: "context is not a valid
// context" using a nullptr
cl_uint param_value = 0;
bool failed_tests = negative_test(
clGetContextInfo, CL_INVALID_CONTEXT, nullptr,
CL_CONTEXT_REFERENCE_COUNT, sizeof(param_value), &param_value, nullptr);

// clGetContextInfo returns CL_INVALID_CONTEXT when: "context is not a valid
// context" using a valid object which is NOT a context
failed_tests = negative_test(clGetContextInfo, CL_INVALID_CONTEXT,
reinterpret_cast<cl_context>(deviceID),
CL_CONTEXT_REFERENCE_COUNT,
sizeof(param_value), &param_value, nullptr);

// clGetContextInfo returns CL_INVALID_VALUE when: "param_name is not one of
// the supported values"
cl_context_info INVALID_PARAM_VALUE = 0;
failed_tests |= negative_test(clGetContextInfo, CL_INVALID_VALUE, context,
INVALID_PARAM_VALUE, 0, nullptr, nullptr);

// clGetContextInfo returns CL_INVALID_VALUE when: "size in bytes specified
// by param_value_size is < size of return type and param_value is not a
// NULL value"
failed_tests |=
negative_test(clGetContextInfo, CL_INVALID_VALUE, context,
CL_CONTEXT_REFERENCE_COUNT, 0, &param_value, nullptr);

return failed_tests ? TEST_FAIL : TEST_PASS;
}

/* Negative Tests for clSetContextDestructorCallback */
static void CL_CALLBACK callback(cl_context context, void* user_data) {}

int test_negative_set_context_destructor_callback(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements)
{
// clSetContextDestructorCallback returns CL_INVALID_CONTEXT when: "context
// is not a valid context" using a nullptr
bool failed_tests =
negative_test(clSetContextDestructorCallback, CL_INVALID_CONTEXT,
nullptr, callback, nullptr);

// clSetContextDestructorCallback returns CL_INVALID_CONTEXT when: "context
// is not a valid context" using a valid object which is NOT a device
failed_tests |= negative_test(
clSetContextDestructorCallback, CL_INVALID_CONTEXT,
reinterpret_cast<cl_context>(deviceID), callback, nullptr);

// clSetContextDestructorCallback returns CL_INVALID_VALUE when: "pfn_notify
// is NULL"
failed_tests |= negative_test(clSetContextDestructorCallback,
CL_INVALID_VALUE, context, nullptr, nullptr);

return failed_tests ? TEST_FAIL : TEST_PASS;
}
2 changes: 1 addition & 1 deletion test_conformance/api/test_queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ int sampler_param_test(cl_sampler sampler, cl_sampler_info param_name,
return 0;
}

static cl_int normalized_coord_values[] = { CL_TRUE, CL_FALSE };
static cl_bool normalized_coord_values[] = { CL_TRUE, CL_FALSE };
static cl_addressing_mode addressing_mode_values[] = {
CL_ADDRESS_NONE, CL_ADDRESS_CLAMP_TO_EDGE, CL_ADDRESS_CLAMP,
CL_ADDRESS_REPEAT, CL_ADDRESS_MIRRORED_REPEAT
Expand Down
11 changes: 9 additions & 2 deletions test_conformance/atomics/test_atomics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,8 +1011,15 @@ cl_long test_atomic_and_result_long( size_t size, cl_long *startRefValues, size_

int test_atomic_and(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
{
TestFns set = { 0xffffffff, 0xffffffffffffffffLL, test_bitwise_num_results,
test_atomic_and_result_int, NULL, NULL, test_atomic_and_result_long, NULL, NULL };
TestFns set = { (int)0xffffffff,
(long long)0xffffffffffffffffLL,
test_bitwise_num_results,
test_atomic_and_result_int,
NULL,
NULL,
test_atomic_and_result_long,
NULL,
NULL };

if( test_atomic_function_set( deviceID, context, queue, num_elements, atom_and_core, set, true, /*matchGroupSize*/ false, /*usingAtomicPrefix*/ false ) != 0 )
return -1;
Expand Down
4 changes: 4 additions & 0 deletions test_conformance/basic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
set(MODULE_NAME BASIC)

if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang")
add_cxx_flag_if_supported(-Wno-narrowing)
endif()

set(${MODULE_NAME}_SOURCES
main.cpp
test_fpmath_float.cpp test_fpmath_float2.cpp test_fpmath_float4.cpp
Expand Down
4 changes: 4 additions & 0 deletions test_conformance/compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
set(MODULE_NAME COMPILER)

if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang")
add_cxx_flag_if_supported(-Wno-narrowing)
endif()

set(${MODULE_NAME}_SOURCES
main.cpp
test_build_helpers.cpp
Expand Down
10 changes: 5 additions & 5 deletions test_conformance/computeinfo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ typedef struct
} device_info;

device_info device_infos[] = {
{ CL_DEVICE_TYPE_DEFAULT, "CL_DEVICE_TYPE_DEFAULT", -1, NULL },
{ CL_DEVICE_TYPE_CPU, "CL_DEVICE_TYPE_CPU", -1, NULL },
{ CL_DEVICE_TYPE_GPU, "CL_DEVICE_TYPE_GPU", -1, NULL },
{ CL_DEVICE_TYPE_ACCELERATOR, "CL_DEVICE_TYPE_ACCELERATOR", -1, NULL },
{ CL_DEVICE_TYPE_ALL, "CL_DEVICE_TYPE_ALL", -1, NULL },
{ CL_DEVICE_TYPE_DEFAULT, "CL_DEVICE_TYPE_DEFAULT", 0, NULL },
{ CL_DEVICE_TYPE_CPU, "CL_DEVICE_TYPE_CPU", 0, NULL },
{ CL_DEVICE_TYPE_GPU, "CL_DEVICE_TYPE_GPU", 0, NULL },
{ CL_DEVICE_TYPE_ACCELERATOR, "CL_DEVICE_TYPE_ACCELERATOR", 0, NULL },
{ CL_DEVICE_TYPE_ALL, "CL_DEVICE_TYPE_ALL", 0, NULL },
};

// config types
Expand Down
4 changes: 4 additions & 0 deletions test_conformance/conversions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
set(MODULE_NAME CONVERSIONS)

if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang")
add_cxx_flag_if_supported(-Wno-narrowing)
endif()

set (${MODULE_NAME}_SOURCES
Sleep.cpp test_conversions.cpp basic_test_conversions.cpp
)
Expand Down
2 changes: 1 addition & 1 deletion test_conformance/device_execution/execute_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ int test_execute_block(cl_device_id device, cl_context context, cl_command_queue
size_t ret_len;
cl_int n, err_ret, res = 0;
clCommandQueueWrapper dev_queue;
cl_int kernel_results[MAX_GWS] = {0xDEADBEEF};
cl_int kernel_results[MAX_GWS] = { (cl_int)0xDEADBEEF };

size_t max_local_size = 1;
err_ret = clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(max_local_size), &max_local_size, &ret_len);
Expand Down
Loading

0 comments on commit 1282bca

Please sign in to comment.