forked from KhronosGroup/OpenCL-CTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable narrowing errors for more directories
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
Showing
17 changed files
with
361 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), ¶m_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), ¶m_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, ¶m_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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.