From 7b0f4ee861728810853277c84f5796a20ad21c35 Mon Sep 17 00:00:00 2001 From: Marcin Hajder Date: Tue, 16 Jul 2024 17:08:28 +0200 Subject: [PATCH] Added new cl_khr_semaphore tests to verify clReleaseSemaphoreKHR/clRetainSemaphoreKHR negative results (#1976) According to work plan from issue #1691 Co-authored-by: Ben Ashbaugh --- .../cl_khr_semaphore/CMakeLists.txt | 1 + .../extensions/cl_khr_semaphore/main.cpp | 2 + .../extensions/cl_khr_semaphore/procs.h | 8 ++ ...est_semaphores_negative_release_retain.cpp | 89 +++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 test_conformance/extensions/cl_khr_semaphore/test_semaphores_negative_release_retain.cpp diff --git a/test_conformance/extensions/cl_khr_semaphore/CMakeLists.txt b/test_conformance/extensions/cl_khr_semaphore/CMakeLists.txt index 2ef34d324..5ebda6f2f 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_release_retain.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 f19c5abf2..721562458 100644 --- a/test_conformance/extensions/cl_khr_semaphore/main.cpp +++ b/test_conformance/extensions/cl_khr_semaphore/main.cpp @@ -47,6 +47,8 @@ test_definition test_list[] = { Version(1, 2)), ADD_TEST_VERSION(semaphores_negative_wait_invalid_event_status, Version(1, 2)), + ADD_TEST_VERSION(semaphores_negative_release, Version(1, 2)), + ADD_TEST_VERSION(semaphores_negative_retain, Version(1, 2)), }; const int test_num = ARRAY_SIZE(test_list); diff --git a/test_conformance/extensions/cl_khr_semaphore/procs.h b/test_conformance/extensions/cl_khr_semaphore/procs.h index 1ca219591..cbe3993db 100644 --- a/test_conformance/extensions/cl_khr_semaphore/procs.h +++ b/test_conformance/extensions/cl_khr_semaphore/procs.h @@ -71,3 +71,11 @@ extern int test_semaphores_negative_wait_invalid_event_wait_list( extern int test_semaphores_negative_wait_invalid_event_status( cl_device_id device, cl_context context, cl_command_queue queue, int num_elements); +extern int test_semaphores_negative_release(cl_device_id device, + cl_context context, + cl_command_queue queue, + int num_elements); +extern int test_semaphores_negative_retain(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_release_retain.cpp b/test_conformance/extensions/cl_khr_semaphore/test_semaphores_negative_release_retain.cpp new file mode 100644 index 000000000..ea6139de2 --- /dev/null +++ b/test_conformance/extensions/cl_khr_semaphore/test_semaphores_negative_release_retain.cpp @@ -0,0 +1,89 @@ +// +// 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" +#include +#include +#include +#include + +namespace { + +// sema_object is not a valid semaphore object + +struct ReleaseInvalidSemaphore : public SemaphoreTestBase +{ + ReleaseInvalidSemaphore(cl_device_id device, cl_context context, + cl_command_queue queue) + : SemaphoreTestBase(device, context, queue) + {} + + cl_int Run() override + { + // Release invalid semaphore + cl_int err = CL_SUCCESS; + err = clReleaseSemaphoreKHR(nullptr); + if (err != CL_INVALID_SEMAPHORE_KHR) + { + log_error("Unexpected clReleaseSemaphoreKHR result, expected " + "CL_INVALID_SEMAPHORE_KHR, get %s\n", + IGetErrorString(err)); + return TEST_FAIL; + } + + return TEST_PASS; + } +}; + +struct RetainInvalidSemaphore : public SemaphoreTestBase +{ + RetainInvalidSemaphore(cl_device_id device, cl_context context, + cl_command_queue queue) + : SemaphoreTestBase(device, context, queue) + {} + + cl_int Run() override + { + // Release invalid semaphore + cl_int err = CL_SUCCESS; + err = clRetainSemaphoreKHR(nullptr); + if (err != CL_INVALID_SEMAPHORE_KHR) + { + log_error("Unexpected clRetainSemaphoreKHR result, expected " + "CL_INVALID_SEMAPHORE_KHR, get %s\n", + IGetErrorString(err)); + return TEST_FAIL; + } + + return TEST_PASS; + } +}; + +} + +int test_semaphores_negative_release(cl_device_id device, cl_context context, + cl_command_queue queue, int num_elements) +{ + return MakeAndRunTest(device, context, queue); +} + +int test_semaphores_negative_retain(cl_device_id device, cl_context context, + cl_command_queue queue, int num_elements) +{ + return MakeAndRunTest(device, context, queue); +}