From a28927694781649bc7d708b434ef876d5be36500 Mon Sep 17 00:00:00 2001 From: Kamil Goras Date: Fri, 5 Apr 2024 14:08:27 +0200 Subject: [PATCH 1/4] Added negative tests for clCommandBarrierWithWaitListKHR --- .../cl_khr_command_buffer/CMakeLists.txt | 1 + .../extensions/cl_khr_command_buffer/main.cpp | 8 +- .../negative_command_buffer_barrier.cpp | 239 ++++++++++++++++++ .../extensions/cl_khr_command_buffer/procs.h | 19 ++ 4 files changed, 266 insertions(+), 1 deletion(-) create mode 100644 test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_barrier.cpp diff --git a/test_conformance/extensions/cl_khr_command_buffer/CMakeLists.txt b/test_conformance/extensions/cl_khr_command_buffer/CMakeLists.txt index 8a4a116a93..ef9ab850e6 100644 --- a/test_conformance/extensions/cl_khr_command_buffer/CMakeLists.txt +++ b/test_conformance/extensions/cl_khr_command_buffer/CMakeLists.txt @@ -16,6 +16,7 @@ set(${MODULE_NAME}_SOURCES command_buffer_test_barrier.cpp command_buffer_test_event_info.cpp command_buffer_finalize.cpp + negative_command_buffer_barrier.cpp ) set_gnulike_module_compile_flags("-Wno-sign-compare") diff --git a/test_conformance/extensions/cl_khr_command_buffer/main.cpp b/test_conformance/extensions/cl_khr_command_buffer/main.cpp index 4ecb080650..66995c88bd 100644 --- a/test_conformance/extensions/cl_khr_command_buffer/main.cpp +++ b/test_conformance/extensions/cl_khr_command_buffer/main.cpp @@ -63,7 +63,13 @@ test_definition test_list[] = { ADD_TEST(event_info_context), ADD_TEST(event_info_reference_count), ADD_TEST(finalize_invalid), - ADD_TEST(finalize_empty) + ADD_TEST(finalize_empty), + ADD_TEST(negative_command_buffer_barrier_not_null_queue), + ADD_TEST(negative_command_buffer_barrier_invalid_command_buffer), + ADD_TEST(negative_command_buffer_barrier_context_not_same_with_queue), + ADD_TEST(negative_command_buffer_barrier_buffer_finalized), + ADD_TEST(negative_command_buffer_barrier_mutable_handle_not_null), + ADD_TEST(negative_command_buffer_barrier_sync_points_null_or_num_zero) }; int main(int argc, const char *argv[]) diff --git a/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_barrier.cpp b/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_barrier.cpp new file mode 100644 index 0000000000..87291485b6 --- /dev/null +++ b/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_barrier.cpp @@ -0,0 +1,239 @@ +// +// 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 "basic_command_buffer.h" +#include "procs.h" +#include + +//-------------------------------------------------------------------------- +namespace { + +// CL_INVALID_COMMAND_QUEUE if command_queue is not NULL. +struct CommandBufferBarrierNotNullQueue : public BasicCommandBufferTest +{ + using BasicCommandBufferTest::BasicCommandBufferTest; + + cl_int Run() override + { + cl_int error = clCommandBarrierWithWaitListKHR( + command_buffer, queue, 0, nullptr, nullptr, nullptr); + + test_failure_error_ret(error, CL_INVALID_COMMAND_QUEUE, + "clCommandBarrierWithWaitListKHR should return " + "CL_INVALID_COMMAND_QUEUE", + TEST_FAIL); + + return CL_SUCCESS; + } +}; + +// CL_INVALID_COMMAND_BUFFER_KHR if command_buffer is not a valid +// command-buffer. +struct CommandBufferBarrierInvalidCommandBuffer : public BasicCommandBufferTest +{ + using BasicCommandBufferTest::BasicCommandBufferTest; + + cl_int Run() override + { + cl_int error = clCommandBarrierWithWaitListKHR( + nullptr, queue, 0, nullptr, nullptr, nullptr); + + test_failure_error_ret(error, CL_INVALID_COMMAND_BUFFER_KHR, + "clCommandBarrierWithWaitListKHR should return " + "CL_INVALID_COMMAND_BUFFER_KHR", + TEST_FAIL); + + return CL_SUCCESS; + } +}; + +// CL_INVALID_CONTEXT if the context associated with command_queue and +// command_buffer is not the same. +struct CommandBufferBarrierContextNotSameWithQueue + : public BasicCommandBufferTest +{ + using BasicCommandBufferTest::BasicCommandBufferTest; + + cl_int Run() override + { + // cl_int error; + + // clContextWrapper new_context = + // clCreateContext(0, 1, &device, nullptr, nullptr, &error); + // test_error(error, "Failed to create context"); + // clCommandQueueWrapper queue1 = + // clCreateCommandQueue(new_context, device, 0, &error); + // test_error(error, "clCreateCommandQueue failed"); + + // std::vector queues; + // queues.push_back(queue); + // queues.push_back(queue1); + // command_buffer = clCreateCommandBufferKHR(2, queues.data(), 0, + // &error); + + // error = clCommandBarrierWithWaitListKHR(command_buffer, + // queue1, 0, + // nullptr, nullptr, + // nullptr); + + // test_failure_error_ret(error, CL_INVALID_CONTEXT, + // "clCommandBarrierWithWaitListKHR should + // return " "CL_INVALID_CONTEXT", + // TEST_FAIL); + + return CL_SUCCESS; + } +}; + +// CL_INVALID_OPERATION if command_buffer has been finalized. +struct CommandBufferBarrierBufferFinalized : public BasicCommandBufferTest +{ + using BasicCommandBufferTest::BasicCommandBufferTest; + + cl_int Run() override + { + cl_int error = clFinalizeCommandBufferKHR(command_buffer); + test_error(error, "clFinalizeCommandBufferKHR failed"); + + error = clCommandBarrierWithWaitListKHR(command_buffer, nullptr, 0, + nullptr, nullptr, nullptr); + + test_failure_error_ret(error, CL_INVALID_OPERATION, + "clCommandBarrierWithWaitListKHR should return " + "CL_INVALID_OPERATION", + TEST_FAIL); + + return CL_SUCCESS; + } +}; + +// CL_INVALID_VALUE if mutable_handle is not NULL. +struct CommandBufferBarrierMutableHandleNotNull : public BasicCommandBufferTest +{ + using BasicCommandBufferTest::BasicCommandBufferTest; + + cl_int Run() override + { + cl_mutable_command_khr mutable_handle; + + cl_int error = clCommandBarrierWithWaitListKHR( + command_buffer, nullptr, 0, nullptr, nullptr, &mutable_handle); + + test_failure_error_ret(error, CL_INVALID_VALUE, + "clCommandBarrierWithWaitListKHR should return " + "CL_INVALID_VALUE", + TEST_FAIL); + + return CL_SUCCESS; + } +}; + +// CL_INVALID_SYNC_POINT_WAIT_LIST_KHR if sync_point_wait_list is NULL and +// num_sync_points_in_wait_list is > 0, or sync_point_wait_list is not NULL and +// num_sync_points_in_wait_list is 0, or if synchronization-point objects in +// sync_point_wait_list are not valid synchronization-points. +struct CommandBufferBarrierSyncPointsNullOrNumZero + : public BasicCommandBufferTest +{ + using BasicCommandBufferTest::BasicCommandBufferTest; + + cl_int Run() override + { + cl_int error = clCommandBarrierWithWaitListKHR( + command_buffer, nullptr, 1, nullptr, nullptr, nullptr); + + test_failure_error_ret(error, CL_INVALID_SYNC_POINT_WAIT_LIST_KHR, + "clCommandBarrierWithWaitListKHR should return " + "CL_INVALID_SYNC_POINT_WAIT_LIST_KHR", + TEST_FAIL); + + cl_sync_point_khr point = 1; + std::vector sync_points; + sync_points.push_back(point); + + error = clCommandBarrierWithWaitListKHR( + command_buffer, nullptr, 0, sync_points.data(), nullptr, nullptr); + + test_failure_error_ret(error, CL_INVALID_SYNC_POINT_WAIT_LIST_KHR, + "clCommandBarrierWithWaitListKHR should return " + "CL_INVALID_SYNC_POINT_WAIT_LIST_KHR", + TEST_FAIL); + + cl_sync_point_khr* invalid_point = nullptr; + std::vector invalid_sync_points; + invalid_sync_points.push_back(invalid_point); + + error = clCommandBarrierWithWaitListKHR(command_buffer, nullptr, 1, + *invalid_sync_points.data(), + nullptr, nullptr); + + test_failure_error_ret(error, CL_INVALID_SYNC_POINT_WAIT_LIST_KHR, + "clCommandBarrierWithWaitListKHR should return " + "CL_INVALID_SYNC_POINT_WAIT_LIST_KHR", + TEST_FAIL); + + return CL_SUCCESS; + } +}; +}; + +int test_negative_command_buffer_barrier_not_null_queue(cl_device_id device, + cl_context context, + cl_command_queue queue, + int num_elements) +{ + return MakeAndRunTest( + device, context, queue, num_elements); +} + +int test_negative_command_buffer_barrier_invalid_command_buffer( + cl_device_id device, cl_context context, cl_command_queue queue, + int num_elements) +{ + return MakeAndRunTest( + device, context, queue, num_elements); +} + +int test_negative_command_buffer_barrier_context_not_same_with_queue( + cl_device_id device, cl_context context, cl_command_queue queue, + int num_elements) +{ + return MakeAndRunTest( + device, context, queue, num_elements); +} + +int test_negative_command_buffer_barrier_buffer_finalized( + cl_device_id device, cl_context context, cl_command_queue queue, + int num_elements) +{ + return MakeAndRunTest( + device, context, queue, num_elements); +} + +int test_negative_command_buffer_barrier_mutable_handle_not_null( + cl_device_id device, cl_context context, cl_command_queue queue, + int num_elements) +{ + return MakeAndRunTest( + device, context, queue, num_elements); +} + +int test_negative_command_buffer_barrier_sync_points_null_or_num_zero( + cl_device_id device, cl_context context, cl_command_queue queue, + int num_elements) +{ + return MakeAndRunTest( + device, context, queue, num_elements); +} diff --git a/test_conformance/extensions/cl_khr_command_buffer/procs.h b/test_conformance/extensions/cl_khr_command_buffer/procs.h index ce121ceacc..b541393802 100644 --- a/test_conformance/extensions/cl_khr_command_buffer/procs.h +++ b/test_conformance/extensions/cl_khr_command_buffer/procs.h @@ -140,5 +140,24 @@ extern int test_finalize_invalid(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements); extern int test_finalize_empty(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements); +// Command-buffer negative tests +extern int test_negative_command_buffer_barrier_not_null_queue( + cl_device_id device, cl_context context, cl_command_queue queue, + int num_elements); +extern int test_negative_command_buffer_barrier_invalid_command_buffer( + cl_device_id device, cl_context context, cl_command_queue queue, + int num_elements); +extern int test_negative_command_buffer_barrier_context_not_same_with_queue( + cl_device_id device, cl_context context, cl_command_queue queue, + int num_elements); +extern int test_negative_command_buffer_barrier_buffer_finalized( + cl_device_id device, cl_context context, cl_command_queue queue, + int num_elements); +extern int test_negative_command_buffer_barrier_mutable_handle_not_null( + cl_device_id device, cl_context context, cl_command_queue queue, + int num_elements); +extern int test_negative_command_buffer_barrier_sync_points_null_or_num_zero( + cl_device_id device, cl_context context, cl_command_queue queue, + int num_elements); #endif // CL_KHR_COMMAND_BUFFER_PROCS_H From 49d3e3c595b36fc511e070a6b583a4decc79a3b9 Mon Sep 17 00:00:00 2001 From: Kamil Goras Date: Tue, 9 Apr 2024 07:51:57 +0200 Subject: [PATCH 2/4] Removed test with CL_INVALID_CONTEXT (issue #1147) --- .../extensions/cl_khr_command_buffer/main.cpp | 1 - .../negative_command_buffer_barrier.cpp | 46 ------------------- .../extensions/cl_khr_command_buffer/procs.h | 3 -- 3 files changed, 50 deletions(-) diff --git a/test_conformance/extensions/cl_khr_command_buffer/main.cpp b/test_conformance/extensions/cl_khr_command_buffer/main.cpp index 66995c88bd..ef35792b6d 100644 --- a/test_conformance/extensions/cl_khr_command_buffer/main.cpp +++ b/test_conformance/extensions/cl_khr_command_buffer/main.cpp @@ -66,7 +66,6 @@ test_definition test_list[] = { ADD_TEST(finalize_empty), ADD_TEST(negative_command_buffer_barrier_not_null_queue), ADD_TEST(negative_command_buffer_barrier_invalid_command_buffer), - ADD_TEST(negative_command_buffer_barrier_context_not_same_with_queue), ADD_TEST(negative_command_buffer_barrier_buffer_finalized), ADD_TEST(negative_command_buffer_barrier_mutable_handle_not_null), ADD_TEST(negative_command_buffer_barrier_sync_points_null_or_num_zero) diff --git a/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_barrier.cpp b/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_barrier.cpp index 87291485b6..2e516fa19c 100644 --- a/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_barrier.cpp +++ b/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_barrier.cpp @@ -59,44 +59,6 @@ struct CommandBufferBarrierInvalidCommandBuffer : public BasicCommandBufferTest } }; -// CL_INVALID_CONTEXT if the context associated with command_queue and -// command_buffer is not the same. -struct CommandBufferBarrierContextNotSameWithQueue - : public BasicCommandBufferTest -{ - using BasicCommandBufferTest::BasicCommandBufferTest; - - cl_int Run() override - { - // cl_int error; - - // clContextWrapper new_context = - // clCreateContext(0, 1, &device, nullptr, nullptr, &error); - // test_error(error, "Failed to create context"); - // clCommandQueueWrapper queue1 = - // clCreateCommandQueue(new_context, device, 0, &error); - // test_error(error, "clCreateCommandQueue failed"); - - // std::vector queues; - // queues.push_back(queue); - // queues.push_back(queue1); - // command_buffer = clCreateCommandBufferKHR(2, queues.data(), 0, - // &error); - - // error = clCommandBarrierWithWaitListKHR(command_buffer, - // queue1, 0, - // nullptr, nullptr, - // nullptr); - - // test_failure_error_ret(error, CL_INVALID_CONTEXT, - // "clCommandBarrierWithWaitListKHR should - // return " "CL_INVALID_CONTEXT", - // TEST_FAIL); - - return CL_SUCCESS; - } -}; - // CL_INVALID_OPERATION if command_buffer has been finalized. struct CommandBufferBarrierBufferFinalized : public BasicCommandBufferTest { @@ -206,14 +168,6 @@ int test_negative_command_buffer_barrier_invalid_command_buffer( device, context, queue, num_elements); } -int test_negative_command_buffer_barrier_context_not_same_with_queue( - cl_device_id device, cl_context context, cl_command_queue queue, - int num_elements) -{ - return MakeAndRunTest( - device, context, queue, num_elements); -} - int test_negative_command_buffer_barrier_buffer_finalized( cl_device_id device, cl_context context, cl_command_queue queue, int num_elements) diff --git a/test_conformance/extensions/cl_khr_command_buffer/procs.h b/test_conformance/extensions/cl_khr_command_buffer/procs.h index b541393802..bd131261ce 100644 --- a/test_conformance/extensions/cl_khr_command_buffer/procs.h +++ b/test_conformance/extensions/cl_khr_command_buffer/procs.h @@ -147,9 +147,6 @@ extern int test_negative_command_buffer_barrier_not_null_queue( extern int test_negative_command_buffer_barrier_invalid_command_buffer( cl_device_id device, cl_context context, cl_command_queue queue, int num_elements); -extern int test_negative_command_buffer_barrier_context_not_same_with_queue( - cl_device_id device, cl_context context, cl_command_queue queue, - int num_elements); extern int test_negative_command_buffer_barrier_buffer_finalized( cl_device_id device, cl_context context, cl_command_queue queue, int num_elements); From 4fe39bc1c9a4408404254dc055f5d1027da1b918 Mon Sep 17 00:00:00 2001 From: Kamil Goras Date: Wed, 8 May 2024 11:17:02 +0200 Subject: [PATCH 3/4] Added minor correction --- .../negative_command_buffer_barrier.cpp | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_barrier.cpp b/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_barrier.cpp index 2e516fa19c..56f3a797d5 100644 --- a/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_barrier.cpp +++ b/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_barrier.cpp @@ -113,33 +113,39 @@ struct CommandBufferBarrierSyncPointsNullOrNumZero cl_int Run() override { + cl_sync_point_khr invalid_point = 0; + std::vector invalid_sync_points; + invalid_sync_points.push_back(&invalid_point); + cl_int error = clCommandBarrierWithWaitListKHR( - command_buffer, nullptr, 1, nullptr, nullptr, nullptr); + command_buffer, nullptr, 1, *invalid_sync_points.data(), nullptr, + nullptr); test_failure_error_ret(error, CL_INVALID_SYNC_POINT_WAIT_LIST_KHR, "clCommandBarrierWithWaitListKHR should return " "CL_INVALID_SYNC_POINT_WAIT_LIST_KHR", TEST_FAIL); - cl_sync_point_khr point = 1; - std::vector sync_points; - sync_points.push_back(point); - error = clCommandBarrierWithWaitListKHR( - command_buffer, nullptr, 0, sync_points.data(), nullptr, nullptr); + error = clCommandBarrierWithWaitListKHR(command_buffer, nullptr, 1, + nullptr, nullptr, nullptr); test_failure_error_ret(error, CL_INVALID_SYNC_POINT_WAIT_LIST_KHR, "clCommandBarrierWithWaitListKHR should return " "CL_INVALID_SYNC_POINT_WAIT_LIST_KHR", TEST_FAIL); - cl_sync_point_khr* invalid_point = nullptr; - std::vector invalid_sync_points; - invalid_sync_points.push_back(invalid_point); - error = clCommandBarrierWithWaitListKHR(command_buffer, nullptr, 1, - *invalid_sync_points.data(), - nullptr, nullptr); + cl_sync_point_khr point; + error = + clCommandCopyBufferKHR(command_buffer, nullptr, in_mem, out_mem, 0, + 0, data_size(), 0, nullptr, &point, nullptr); + test_error(error, "clCommandCopyBufferKHR failed"); + std::vector sync_points; + sync_points.push_back(point); + + error = clCommandBarrierWithWaitListKHR( + command_buffer, nullptr, 0, sync_points.data(), nullptr, nullptr); test_failure_error_ret(error, CL_INVALID_SYNC_POINT_WAIT_LIST_KHR, "clCommandBarrierWithWaitListKHR should return " From 15a077b0cd9ef4a5250fb861cccdd7bc4e8536f6 Mon Sep 17 00:00:00 2001 From: Kamil Goras Date: Wed, 8 May 2024 12:40:40 +0200 Subject: [PATCH 4/4] Removed vectors for sync points --- .../extensions/cl_khr_command_buffer/CMakeLists.txt | 2 +- .../negative_command_buffer_barrier.cpp | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/test_conformance/extensions/cl_khr_command_buffer/CMakeLists.txt b/test_conformance/extensions/cl_khr_command_buffer/CMakeLists.txt index 678655aa59..fd85a68ca9 100644 --- a/test_conformance/extensions/cl_khr_command_buffer/CMakeLists.txt +++ b/test_conformance/extensions/cl_khr_command_buffer/CMakeLists.txt @@ -15,7 +15,7 @@ set(${MODULE_NAME}_SOURCES command_buffer_test_copy.cpp command_buffer_test_barrier.cpp command_buffer_test_event_info.cpp - command_buffer_finalize.cpp + command_buffer_finalize.cpp negative_command_buffer_finalize.cpp negative_command_buffer_retain_release.cpp negative_command_buffer_create.cpp diff --git a/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_barrier.cpp b/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_barrier.cpp index 56f3a797d5..14f828cd5d 100644 --- a/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_barrier.cpp +++ b/test_conformance/extensions/cl_khr_command_buffer/negative_command_buffer_barrier.cpp @@ -114,12 +114,9 @@ struct CommandBufferBarrierSyncPointsNullOrNumZero cl_int Run() override { cl_sync_point_khr invalid_point = 0; - std::vector invalid_sync_points; - invalid_sync_points.push_back(&invalid_point); cl_int error = clCommandBarrierWithWaitListKHR( - command_buffer, nullptr, 1, *invalid_sync_points.data(), nullptr, - nullptr); + command_buffer, nullptr, 1, &invalid_point, nullptr, nullptr); test_failure_error_ret(error, CL_INVALID_SYNC_POINT_WAIT_LIST_KHR, "clCommandBarrierWithWaitListKHR should return " @@ -141,11 +138,9 @@ struct CommandBufferBarrierSyncPointsNullOrNumZero clCommandCopyBufferKHR(command_buffer, nullptr, in_mem, out_mem, 0, 0, data_size(), 0, nullptr, &point, nullptr); test_error(error, "clCommandCopyBufferKHR failed"); - std::vector sync_points; - sync_points.push_back(point); - error = clCommandBarrierWithWaitListKHR( - command_buffer, nullptr, 0, sync_points.data(), nullptr, nullptr); + error = clCommandBarrierWithWaitListKHR(command_buffer, nullptr, 0, + &point, nullptr, nullptr); test_failure_error_ret(error, CL_INVALID_SYNC_POINT_WAIT_LIST_KHR, "clCommandBarrierWithWaitListKHR should return "