From c1af7c33014fdb32a9dd2b53699edadc46f4ffb6 Mon Sep 17 00:00:00 2001 From: Marcin Hajder Date: Tue, 9 Jul 2024 17:46:37 +0200 Subject: [PATCH] Added new tests to verify negative results of clGetSemaphoreInfoKHR (#1981) According to work plan from issue #1691 --- .../cl_khr_semaphore/CMakeLists.txt | 1 + .../extensions/cl_khr_semaphore/main.cpp | 3 + .../extensions/cl_khr_semaphore/procs.h | 6 + .../test_semaphores_negative_getinfo.cpp | 130 ++++++++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 test_conformance/extensions/cl_khr_semaphore/test_semaphores_negative_getinfo.cpp diff --git a/test_conformance/extensions/cl_khr_semaphore/CMakeLists.txt b/test_conformance/extensions/cl_khr_semaphore/CMakeLists.txt index 5618ebd6..2ef34d32 100644 --- a/test_conformance/extensions/cl_khr_semaphore/CMakeLists.txt +++ b/test_conformance/extensions/cl_khr_semaphore/CMakeLists.txt @@ -3,6 +3,7 @@ set(MODULE_NAME CL_KHR_SEMAPHORE) set(${MODULE_NAME}_SOURCES main.cpp test_semaphores.cpp + test_semaphores_negative_getinfo.cpp test_semaphores_negative_wait.cpp semaphore_base.h ) diff --git a/test_conformance/extensions/cl_khr_semaphore/main.cpp b/test_conformance/extensions/cl_khr_semaphore/main.cpp index dc360ab6..f19c5abf 100644 --- a/test_conformance/extensions/cl_khr_semaphore/main.cpp +++ b/test_conformance/extensions/cl_khr_semaphore/main.cpp @@ -35,6 +35,9 @@ test_definition test_list[] = { ADD_TEST_VERSION(semaphores_multi_wait, Version(1, 2)), ADD_TEST_VERSION(semaphores_queries, Version(1, 2)), ADD_TEST_VERSION(semaphores_import_export_fd, Version(1, 2)), + ADD_TEST_VERSION(semaphores_negative_get_info_invalid_semaphore, + Version(1, 2)), + ADD_TEST_VERSION(semaphores_negative_get_info_invalid_value, Version(1, 2)), ADD_TEST_VERSION(semaphores_negative_wait_invalid_command_queue, Version(1, 2)), ADD_TEST_VERSION(semaphores_negative_wait_invalid_value, Version(1, 2)), diff --git a/test_conformance/extensions/cl_khr_semaphore/procs.h b/test_conformance/extensions/cl_khr_semaphore/procs.h index 9fb17458..1ca21959 100644 --- a/test_conformance/extensions/cl_khr_semaphore/procs.h +++ b/test_conformance/extensions/cl_khr_semaphore/procs.h @@ -45,6 +45,12 @@ extern int test_semaphores_import_export_fd(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); +extern int test_semaphores_negative_get_info_invalid_semaphore( + cl_device_id device, cl_context context, cl_command_queue queue, + int num_elements); +extern int test_semaphores_negative_get_info_invalid_value( + cl_device_id device, cl_context context, cl_command_queue queue, + int num_elements); extern int test_semaphores_negative_wait_invalid_command_queue( cl_device_id device, cl_context context, cl_command_queue queue, int num_elements); diff --git a/test_conformance/extensions/cl_khr_semaphore/test_semaphores_negative_getinfo.cpp b/test_conformance/extensions/cl_khr_semaphore/test_semaphores_negative_getinfo.cpp new file mode 100644 index 00000000..0cf8bb0f --- /dev/null +++ b/test_conformance/extensions/cl_khr_semaphore/test_semaphores_negative_getinfo.cpp @@ -0,0 +1,130 @@ +// +// Copyright (c) 2024 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 "semaphore_base.h" + +#include "harness/errorHelpers.h" + +namespace { + +// sema_object is not a valid semaphore. + +struct GetInfoInvalidSemaphore : public SemaphoreTestBase +{ + GetInfoInvalidSemaphore(cl_device_id device, cl_context context, + cl_command_queue queue) + : SemaphoreTestBase(device, context, queue) + {} + + cl_int Run() override + { + // Wait semaphore + cl_semaphore_type_khr type = 0; + size_t ret_size = 0; + cl_int err = clGetSemaphoreInfoKHR(nullptr, CL_SEMAPHORE_TYPE_KHR, + sizeof(cl_semaphore_type_khr), &type, + &ret_size); + test_failure_error(err, CL_INVALID_SEMAPHORE_KHR, + "Unexpected clGetSemaphoreInfoKHR return"); + + return CL_SUCCESS; + } +}; + +// 1) param_name is not one of the attribute defined in the Semaphore Queries +// table + +// 2) param_value_size is less than the size of Return Type of the corresponding +// param_name attribute as defined in the Semaphore Queries table. + +struct GetInfoInvalidValue : public SemaphoreTestBase +{ + GetInfoInvalidValue(cl_device_id device, cl_context context, + cl_command_queue queue) + : SemaphoreTestBase(device, context, queue) + {} + + cl_int Run() override + { + // Create semaphore + cl_semaphore_properties_khr sema_props[] = { + static_cast(CL_SEMAPHORE_TYPE_KHR), + static_cast( + CL_SEMAPHORE_TYPE_BINARY_KHR), + static_cast( + CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR), + (cl_semaphore_properties_khr)device, + CL_SEMAPHORE_DEVICE_HANDLE_LIST_END_KHR, + 0 + }; + + cl_int err = CL_SUCCESS; + semaphore = + clCreateSemaphoreWithPropertiesKHR(context, sema_props, &err); + test_error(err, "Could not create semaphore"); + + // (1) + cl_semaphore_info_khr param_name = ~0; + err = clGetSemaphoreInfoKHR(semaphore, param_name, 0, nullptr, nullptr); + test_failure_error(err, CL_INVALID_VALUE, + "Unexpected clGetSemaphoreInfoKHR return"); + + // (2) + size_t size = 0; + err = clGetSemaphoreInfoKHR(semaphore, CL_SEMAPHORE_PROPERTIES_KHR, 0, + nullptr, &size); + test_error(err, "Could not query semaphore"); + + // make sure that first test provides too small param size + if (size != sizeof(sema_props)) + test_fail("Error: expected size %d, returned %d", + sizeof(sema_props), size); + + // first test with non-zero property size but not enough + cl_semaphore_properties_khr ret_props = 0; + err = clGetSemaphoreInfoKHR(semaphore, CL_SEMAPHORE_PROPERTIES_KHR, + sizeof(ret_props), &ret_props, nullptr); + test_failure_error(err, CL_INVALID_VALUE, + "Unexpected clGetSemaphoreInfoKHR return"); + + // second test with zero property size + cl_semaphore_type_khr type = 0; + err = clGetSemaphoreInfoKHR(semaphore, CL_SEMAPHORE_TYPE_KHR, 0, &type, + nullptr); + test_failure_error(err, CL_INVALID_VALUE, + "Unexpected clGetSemaphoreInfoKHR return"); + + return CL_SUCCESS; + } +}; + +} + +int test_semaphores_negative_get_info_invalid_semaphore(cl_device_id device, + cl_context context, + cl_command_queue queue, + int num_elements) +{ + return MakeAndRunTest(device, context, queue); +} + +int test_semaphores_negative_get_info_invalid_value(cl_device_id device, + cl_context context, + cl_command_queue queue, + int num_elements) +{ + return MakeAndRunTest(device, context, queue); +}