Negative tests for commandCopyImage[ToBuffer]KHR (#1943)

According to description
https://github.com/KhronosGroup/OpenCL-CTS/issues/1668
This commit is contained in:
Kamil-Goras-Mobica
2024-05-21 17:40:08 +02:00
committed by GitHub
parent 88a707dd13
commit 9500c30492
4 changed files with 447 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ set(${MODULE_NAME}_SOURCES
command_buffer_test_event_info.cpp
command_buffer_finalize.cpp
negative_command_buffer_finalize.cpp
negative_command_buffer_copy_image.cpp
negative_command_buffer_retain_release.cpp
negative_command_buffer_create.cpp
negative_command_nd_range_kernel.cpp

View File

@@ -64,6 +64,7 @@ test_definition test_list[] = {
ADD_TEST(event_info_reference_count),
ADD_TEST(finalize_invalid),
ADD_TEST(finalize_empty),
// Command-buffer negative tests
ADD_TEST(negative_retain_command_buffer_invalid_command_buffer),
ADD_TEST(negative_release_command_buffer_invalid_command_buffer),
ADD_TEST(negative_finalize_command_buffer_invalid_command_buffer),
@@ -91,6 +92,12 @@ test_definition test_list[] = {
ADD_TEST(negative_get_command_buffer_info_state),
ADD_TEST(negative_get_command_buffer_info_prop_array),
ADD_TEST(negative_get_command_buffer_info_context),
ADD_TEST(negative_command_buffer_copy_image_queue_not_null),
ADD_TEST(negative_command_buffer_copy_image_context_not_same),
ADD_TEST(negative_command_buffer_copy_image_sync_points_null_or_num_zero),
ADD_TEST(negative_command_buffer_copy_image_invalid_command_buffer),
ADD_TEST(negative_command_buffer_copy_image_finalized_command_buffer),
ADD_TEST(negative_command_buffer_copy_image_mutable_handle_not_null),
ADD_TEST(negative_command_buffer_barrier_not_null_queue),
ADD_TEST(negative_command_buffer_barrier_invalid_command_buffer),
ADD_TEST(negative_command_buffer_barrier_buffer_finalized),

View File

@@ -0,0 +1,421 @@
//
// 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 <vector>
//--------------------------------------------------------------------------
struct CommandCopyBaseTest : BasicCommandBufferTest
{
CommandCopyBaseTest(cl_device_id device, cl_context context,
cl_command_queue queue)
: BasicCommandBufferTest(device, context, queue)
{}
cl_int SetUp(int elements) override
{
cl_int error = BasicCommandBufferTest::SetUp(elements);
test_error(error, "BasicCommandBufferTest::SetUp failed");
src_image = create_image_2d(context, CL_MEM_READ_ONLY, &formats, 512,
512, 0, NULL, &error);
test_error(error, "create_image_2d failed");
dst_image = create_image_2d(context, CL_MEM_WRITE_ONLY, &formats, 512,
512, 0, NULL, &error);
test_error(error, "create_image_2d failed");
return CL_SUCCESS;
}
bool Skip() override
{
cl_bool image_support;
cl_int error =
clGetDeviceInfo(device, CL_DEVICE_IMAGE_SUPPORT,
sizeof(image_support), &image_support, nullptr);
test_error(error, "clGetDeviceInfo for CL_DEVICE_IMAGE_SUPPORT failed");
return (!image_support || BasicCommandBufferTest::Skip());
}
protected:
clMemWrapper src_image;
clMemWrapper dst_image;
const cl_image_format formats = { CL_RGBA, CL_UNSIGNED_INT8 };
const size_t origin[3] = { 0, 0, 0 };
const size_t region[3] = { 512, 512, 1 };
};
namespace {
// CL_INVALID_COMMAND_QUEUE if command_queue is not NULL.
struct CommandBufferCopyImageQueueNotNull : public CommandCopyBaseTest
{
using CommandCopyBaseTest::CommandCopyBaseTest;
cl_int Run() override
{
cl_int error = clCommandCopyImageKHR(command_buffer, queue, src_image,
dst_image, origin, origin, region,
0, nullptr, nullptr, nullptr);
test_failure_error_ret(error, CL_INVALID_COMMAND_QUEUE,
"clCommandCopyImageKHR should return "
"CL_INVALID_COMMAND_QUEUE",
TEST_FAIL);
error = clCommandCopyImageToBufferKHR(command_buffer, queue, src_image,
dst_image, origin, region, 0, 0,
nullptr, nullptr, nullptr);
test_failure_error_ret(error, CL_INVALID_COMMAND_QUEUE,
"clCommandCopyImageToBufferKHR should return "
"CL_INVALID_COMMAND_QUEUE",
TEST_FAIL);
return CL_SUCCESS;
}
bool Skip() override
{
return CommandCopyBaseTest::Skip()
|| is_extension_available(device,
"cl_khr_command_buffer_multi_device");
}
};
// CL_INVALID_CONTEXT if the context associated with command_queue,
// command_buffer, src_image, and dst_image are not the same.
struct CommandBufferCopyImageContextNotSame : public CommandCopyBaseTest
{
using CommandCopyBaseTest::CommandCopyBaseTest;
cl_int Run() override
{
cl_int error = clCommandCopyImageKHR(
command_buffer, nullptr, src_image_ctx, dst_image, origin, origin,
region, 0, 0, nullptr, nullptr);
test_failure_error_ret(error, CL_INVALID_CONTEXT,
"clCommandCopyImageKHR should return "
"CL_INVALID_CONTEXT",
TEST_FAIL);
error = clCommandCopyImageToBufferKHR(
command_buffer, nullptr, src_image_ctx, dst_image, origin, region,
0, 0, nullptr, nullptr, nullptr);
test_failure_error_ret(error, CL_INVALID_CONTEXT,
"clCommandCopyImageToBufferKHR should return "
"CL_INVALID_CONTEXT",
TEST_FAIL);
error = clCommandCopyImageKHR(command_buffer, nullptr, src_image,
dst_image_ctx, origin, origin, region, 0,
nullptr, nullptr, nullptr);
test_failure_error_ret(error, CL_INVALID_CONTEXT,
"clCommandCopyImageKHR should return "
"CL_INVALID_CONTEXT",
TEST_FAIL);
error = clCommandCopyImageToBufferKHR(
command_buffer, nullptr, src_image, dst_image_ctx, origin, region,
0, 0, nullptr, nullptr, nullptr);
test_failure_error_ret(error, CL_INVALID_CONTEXT,
"clCommandCopyImageToBufferKHR should return "
"CL_INVALID_CONTEXT",
TEST_FAIL);
command_buffer = clCreateCommandBufferKHR(1, &queue1, 0, &error);
test_error(error, "clCreateCommandBufferKHR failed");
error = clCommandCopyImageKHR(command_buffer, nullptr, src_image,
dst_image, origin, origin, region, 0,
nullptr, nullptr, nullptr);
test_failure_error_ret(error, CL_INVALID_CONTEXT,
"clCommandCopyImageKHR should return "
"CL_INVALID_CONTEXT",
TEST_FAIL);
error = clCommandCopyImageToBufferKHR(
command_buffer, nullptr, src_image, dst_image, origin, region, 0, 0,
nullptr, nullptr, nullptr);
test_failure_error_ret(error, CL_INVALID_CONTEXT,
"clCommandCopyImageToBufferKHR should return "
"CL_INVALID_CONTEXT",
TEST_FAIL);
return CL_SUCCESS;
}
cl_int SetUp(int elements) override
{
cl_int error = CommandCopyBaseTest::SetUp(elements);
test_error(error, "BasicCommandBufferTest::SetUp failed");
context1 = clCreateContext(0, 1, &device, nullptr, nullptr, &error);
test_error(error, "Failed to create context");
src_image_ctx = create_image_2d(context1, CL_MEM_READ_ONLY, &formats,
512, 512, 0, NULL, &error);
test_error(error, "create_image_2d failed");
dst_image_ctx = create_image_2d(context1, CL_MEM_WRITE_ONLY, &formats,
512, 512, 0, NULL, &error);
test_error(error, "create_image_2d failed");
queue1 = clCreateCommandQueue(context1, device, 0, &error);
test_error(error, "clCreateCommandQueue failed");
return CL_SUCCESS;
}
clContextWrapper context1;
clCommandQueueWrapper queue1;
clMemWrapper src_image_ctx;
clMemWrapper dst_image_ctx;
};
// 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 CommandBufferCopySyncPointsNullOrNumZero : public CommandCopyBaseTest
{
using CommandCopyBaseTest::CommandCopyBaseTest;
cl_int Run() override
{
cl_sync_point_khr invalid_point = 0;
cl_int error = clCommandCopyImageKHR(
command_buffer, nullptr, src_image, dst_image, origin, origin,
region, 1, &invalid_point, nullptr, nullptr);
test_failure_error_ret(error, CL_INVALID_SYNC_POINT_WAIT_LIST_KHR,
"clCommandCopyImageKHR should return "
"CL_INVALID_SYNC_POINT_WAIT_LIST_KHR",
TEST_FAIL);
error = clCommandCopyImageToBufferKHR(
command_buffer, nullptr, src_image, dst_image, origin, region, 0, 1,
&invalid_point, nullptr, nullptr);
test_failure_error_ret(error, CL_INVALID_SYNC_POINT_WAIT_LIST_KHR,
"clCommandCopyImageToBufferKHR should return "
"CL_INVALID_SYNC_POINT_WAIT_LIST_KHR",
TEST_FAIL);
error = clCommandCopyImageKHR(command_buffer, nullptr, src_image,
dst_image, origin, origin, region, 1,
nullptr, nullptr, nullptr);
test_failure_error_ret(error, CL_INVALID_SYNC_POINT_WAIT_LIST_KHR,
"clCommandCopyImageKHR should return "
"CL_INVALID_SYNC_POINT_WAIT_LIST_KHR",
TEST_FAIL);
error = clCommandCopyImageToBufferKHR(
command_buffer, nullptr, src_image, dst_image, origin, region, 0, 1,
nullptr, nullptr, nullptr);
test_failure_error_ret(error, CL_INVALID_SYNC_POINT_WAIT_LIST_KHR,
"clCommandCopyImageToBufferKHR should return "
"CL_INVALID_SYNC_POINT_WAIT_LIST_KHR",
TEST_FAIL);
cl_sync_point_khr point;
error = clCommandBarrierWithWaitListKHR(command_buffer, nullptr, 0,
nullptr, &point, nullptr);
test_error(error, "clCommandBarrierWithWaitListKHR failed");
error = clCommandCopyImageKHR(command_buffer, nullptr, src_image,
dst_image, origin, origin, region, 0,
&point, nullptr, nullptr);
test_failure_error_ret(error, CL_INVALID_SYNC_POINT_WAIT_LIST_KHR,
"clCommandCopyImageKHR should return "
"CL_INVALID_SYNC_POINT_WAIT_LIST_KHR",
TEST_FAIL);
error = clCommandCopyImageToBufferKHR(
command_buffer, nullptr, src_image, dst_image, origin, region, 0, 0,
&point, nullptr, nullptr);
test_failure_error_ret(error, CL_INVALID_SYNC_POINT_WAIT_LIST_KHR,
"clCommandCopyImageToBufferKHR should return "
"CL_INVALID_SYNC_POINT_WAIT_LIST_KHR",
TEST_FAIL);
return CL_SUCCESS;
}
};
// CL_INVALID_COMMAND_BUFFER_KHR if command_buffer is not a valid
// command-buffer.
struct CommandBufferCopyImageInvalidCommandBuffer : public CommandCopyBaseTest
{
using CommandCopyBaseTest::CommandCopyBaseTest;
cl_int Run() override
{
cl_int error = clCommandCopyImageKHR(nullptr, nullptr, src_image,
dst_image, origin, origin, region,
0, nullptr, nullptr, nullptr);
test_failure_error_ret(error, CL_INVALID_COMMAND_BUFFER_KHR,
"clCommandCopyImageKHR should return "
"CL_INVALID_COMMAND_BUFFER_KHR",
TEST_FAIL);
error = clCommandCopyImageToBufferKHR(nullptr, nullptr, src_image,
dst_image, origin, region, 0, 0,
nullptr, nullptr, nullptr);
test_failure_error_ret(error, CL_INVALID_COMMAND_BUFFER_KHR,
"clCommandCopyImageToBufferKHR should return "
"CL_INVALID_COMMAND_BUFFER_KHR",
TEST_FAIL);
return CL_SUCCESS;
}
};
// CL_INVALID_OPERATION if command_buffer has been finalized.
struct CommandBufferCopyImageFinalizedCommandBuffer : public CommandCopyBaseTest
{
using CommandCopyBaseTest::CommandCopyBaseTest;
cl_int Run() override
{
cl_int error = clFinalizeCommandBufferKHR(command_buffer);
test_error(error, "clFinalizeCommandBufferKHR failed");
error = clCommandCopyImageKHR(command_buffer, nullptr, src_image,
dst_image, origin, origin, region, 0,
nullptr, nullptr, nullptr);
test_failure_error_ret(error, CL_INVALID_OPERATION,
"clCommandCopyImageKHR should return "
"CL_INVALID_OPERATION",
TEST_FAIL);
error = clCommandCopyImageToBufferKHR(
command_buffer, nullptr, src_image, dst_image, origin, region, 0, 0,
nullptr, nullptr, nullptr);
test_failure_error_ret(error, CL_INVALID_OPERATION,
"clCommandCopyImageToBufferKHR should return "
"CL_INVALID_OPERATION",
TEST_FAIL);
return CL_SUCCESS;
}
};
// CL_INVALID_VALUE if mutable_handle is not NULL.
struct CommandBufferCopyImageMutableHandleNotNull : public CommandCopyBaseTest
{
using CommandCopyBaseTest::CommandCopyBaseTest;
cl_int Run() override
{
cl_mutable_command_khr mutable_handle;
cl_int error = clCommandCopyImageKHR(
command_buffer, nullptr, src_image, dst_image, origin, origin,
region, 0, nullptr, nullptr, &mutable_handle);
test_failure_error_ret(error, CL_INVALID_VALUE,
"clCommandCopyImageKHR should return "
"CL_INVALID_VALUE",
TEST_FAIL);
error = clCommandCopyImageToBufferKHR(
command_buffer, nullptr, src_image, dst_image, origin, region, 0, 0,
nullptr, nullptr, &mutable_handle);
test_failure_error_ret(error, CL_INVALID_VALUE,
"clCommandCopyImageToBufferKHR should return "
"CL_INVALID_VALUE",
TEST_FAIL);
return CL_SUCCESS;
}
};
}
int test_negative_command_buffer_copy_image_queue_not_null(
cl_device_id device, cl_context context, cl_command_queue queue,
int num_elements)
{
return MakeAndRunTest<CommandBufferCopyImageQueueNotNull>(
device, context, queue, num_elements);
}
int test_negative_command_buffer_copy_image_context_not_same(
cl_device_id device, cl_context context, cl_command_queue queue,
int num_elements)
{
return MakeAndRunTest<CommandBufferCopyImageContextNotSame>(
device, context, queue, num_elements);
}
int test_negative_command_buffer_copy_image_sync_points_null_or_num_zero(
cl_device_id device, cl_context context, cl_command_queue queue,
int num_elements)
{
return MakeAndRunTest<CommandBufferCopySyncPointsNullOrNumZero>(
device, context, queue, num_elements);
}
int test_negative_command_buffer_copy_image_invalid_command_buffer(
cl_device_id device, cl_context context, cl_command_queue queue,
int num_elements)
{
return MakeAndRunTest<CommandBufferCopyImageInvalidCommandBuffer>(
device, context, queue, num_elements);
}
int test_negative_command_buffer_copy_image_finalized_command_buffer(
cl_device_id device, cl_context context, cl_command_queue queue,
int num_elements)
{
return MakeAndRunTest<CommandBufferCopyImageFinalizedCommandBuffer>(
device, context, queue, num_elements);
}
int test_negative_command_buffer_copy_image_mutable_handle_not_null(
cl_device_id device, cl_context context, cl_command_queue queue,
int num_elements)
{
return MakeAndRunTest<CommandBufferCopyImageMutableHandleNotNull>(
device, context, queue, num_elements);
}

View File

@@ -256,6 +256,24 @@ extern int
test_negative_enqueue_command_buffer_num_queues_not_zero_different_while_buffer_creation(
cl_device_id device, cl_context context, cl_command_queue queue,
int num_elements);
extern int test_negative_command_buffer_copy_image_queue_not_null(
cl_device_id device, cl_context context, cl_command_queue queue,
int num_elements);
extern int test_negative_command_buffer_copy_image_context_not_same(
cl_device_id device, cl_context context, cl_command_queue queue,
int num_elements);
extern int test_negative_command_buffer_copy_image_sync_points_null_or_num_zero(
cl_device_id device, cl_context context, cl_command_queue queue,
int num_elements);
extern int test_negative_command_buffer_copy_image_invalid_command_buffer(
cl_device_id device, cl_context context, cl_command_queue queue,
int num_elements);
extern int test_negative_command_buffer_copy_image_finalized_command_buffer(
cl_device_id device, cl_context context, cl_command_queue queue,
int num_elements);
extern int test_negative_command_buffer_copy_image_mutable_handle_not_null(
cl_device_id device, cl_context context, cl_command_queue queue,
int num_elements);
extern int test_negative_enqueue_command_buffer_not_valid_queue_in_queues(
cl_device_id device, cl_context context, cl_command_queue queue,
int num_elements);