Skip to content

Commit

Permalink
Negative test for returning command-buffer mutable handle
Browse files Browse the repository at this point in the history
See KhronosGroup/OpenCL-Docs#1043
which clarifies that implementations are expected to return
`CL_INVALID_VALUE` when an output command-handle is used
without a layered extension supporting it.
  • Loading branch information
EwanC committed Jan 16, 2024
1 parent f924273 commit 3b0f458
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,62 @@ struct InterleavedEnqueueTest : public BasicCommandBufferTest
}
};

// Test correct error code is returned from invalid usage of a returned
// command handle from a command appending entry-point.
struct InvalidCommandHandleTest : public BasicCommandBufferTest
{
using BasicCommandBufferTest::BasicCommandBufferTest;

cl_int SetUp(int elements) override
{
mutable_dispatch_support = is_extension_available(
device, "cl_khr_command_buffer_mutable_dispatch");

return BasicCommandBufferTest::SetUp(elements);
}

cl_int Run() override
{
cl_mutable_command_khr kernel_command = nullptr;
cl_int error = clCommandNDRangeKernelKHR(
command_buffer, nullptr, nullptr, kernel, 1, nullptr, &num_elements,
nullptr, 0, nullptr, nullptr, &kernel_command);

if (mutable_dispatch_support)
{
test_error(error, "clCommandNDRangeKernelKHRfailed");
}
else
{
test_failure_error_ret(error, CL_INVALID_VALUE,
"clCommandNDRangeKernelKHR should return "
"CL_INVALID_VALUE when an "
"output mutable handle is passed without "
"any layered extensions.",
TEST_FAIL);
}

const cl_int pattern = 42;
cl_mutable_command_khr fill_command = nullptr;
error = clCommandFillBufferKHR(
command_buffer, nullptr, in_mem, &pattern, sizeof(cl_int), 0,
sizeof(cl_int), 0, nullptr, nullptr, &fill_command);

test_failure_error_ret(
error, CL_INVALID_VALUE,
"clCommandFillBufferKHR should return CL_INVALID_VALUE when an "
"output mutable handle is passed without any layered extensions.",
TEST_FAIL);

return CL_SUCCESS;
}

bool Skip() override { return BasicCommandBufferTest::Skip(); }

bool mutable_dispatch_support = false;
};


} // anonymous namespace

int test_single_ndrange(cl_device_id device, cl_context context,
Expand Down Expand Up @@ -448,3 +504,10 @@ int test_explicit_flush(cl_device_id device, cl_context context,
return MakeAndRunTest<ExplicitFlushTest>(device, context, queue,
num_elements);
}

int test_invalid_command_handle(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements)
{
return MakeAndRunTest<InvalidCommandHandleTest>(device, context, queue,
num_elements);
}
3 changes: 2 additions & 1 deletion test_conformance/extensions/cl_khr_command_buffer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ 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(invalid_command_handle)
};

int main(int argc, const char *argv[])
Expand Down
4 changes: 4 additions & 0 deletions test_conformance/extensions/cl_khr_command_buffer/procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,8 @@ extern int test_finalize_invalid(cl_device_id device, cl_context context,
extern int test_finalize_empty(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements);

extern int test_invalid_command_handle(cl_device_id device, cl_context context,
cl_command_queue queue,
int num_elements);

#endif // CL_KHR_COMMAND_BUFFER_PROCS_H

0 comments on commit 3b0f458

Please sign in to comment.