Added test to verify negative result of clSetKernelArg with CL_INVALID_ARG_SIZE and memory object argument (#2450)

Related to #2282, according to work plan from
[here](https://github.com/KhronosGroup/OpenCL-CTS/issues/2282#issuecomment-3069182773)
This commit is contained in:
Marcin Hajder
2025-09-09 17:44:35 +02:00
committed by GitHub
parent 1aeca1360b
commit a0bd81d574

View File

@@ -87,6 +87,14 @@ const char *sample_two_kernel_program[] = {
"\n" "\n"
"}\n" }; "}\n" };
const char *sample_mem_obj_size_test_kernel = R"(
__kernel void mem_obj_size_test(__global int *src, __global int *dst)
{
size_t tid = get_global_id(0);
dst[tid] = src[tid];
}
)";
const char *sample_local_size_test_kernel = R"( const char *sample_local_size_test_kernel = R"(
__kernel void local_size_test(__local int *src, __global int *dst) __kernel void local_size_test(__local int *src, __global int *dst)
{ {
@@ -726,6 +734,45 @@ REGISTER_TEST(negative_set_immutable_memory_to_writeable_kernel_arg)
return TEST_PASS; return TEST_PASS;
} }
REGISTER_TEST(negative_invalid_arg_mem_obj)
{
cl_int error = CL_SUCCESS;
clProgramWrapper program;
clKernelWrapper mem_obj_arg_kernel;
// Setup the test
error =
create_single_kernel_helper(context, &program, nullptr, 1,
&sample_mem_obj_size_test_kernel, nullptr);
test_error(error, "Unable to build test program");
mem_obj_arg_kernel = clCreateKernel(program, "mem_obj_size_test", &error);
test_error(error,
"Unable to get mem_obj_size_test kernel for built program");
std::vector<cl_uchar> mem_data(256, 0);
clMemWrapper buffer = clCreateBuffer(
context, CL_MEM_USE_HOST_PTR, mem_data.size(), mem_data.data(), &error);
test_error(error, "clCreateBuffer failed");
// Run the test - CL_INVALID_ARG_SIZE
error = clSetKernelArg(mem_obj_arg_kernel, 0, sizeof(cl_mem) * 2, &buffer);
test_failure_error_ret(
error, CL_INVALID_ARG_SIZE,
"clSetKernelArg is supposed to fail with CL_INVALID_ARG_SIZE when "
"argument is a memory object and arg_size > sizeof(cl_mem)",
TEST_FAIL);
error = clSetKernelArg(mem_obj_arg_kernel, 0, sizeof(cl_mem) / 2, &buffer);
test_failure_error_ret(
error, CL_INVALID_ARG_SIZE,
"clSetKernelArg is supposed to fail with CL_INVALID_ARG_SIZE when "
"argument is a memory object and arg_size < sizeof(cl_mem)",
TEST_FAIL);
return TEST_PASS;
}
REGISTER_TEST(negative_invalid_kernel) REGISTER_TEST(negative_invalid_kernel)
{ {
cl_int error = CL_SUCCESS; cl_int error = CL_SUCCESS;