Skip to content

Commit

Permalink
Test CL_COMMAND_BUFFER_CONTEXT_KHR (#1697)
Browse files Browse the repository at this point in the history
Test coverage for spec PR KhronosGroup/OpenCL-Docs#899
which introduces a new cl_khr_command_buffer query for the cl_context
  • Loading branch information
EwanC committed Jun 28, 2023
1 parent 56974a5 commit 75aca34
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum class CombufInfoTestMode
CITM_REF_COUNT,
CITM_STATE,
CITM_PROP_ARRAY,
CITM_CONTEXT,
};

namespace {
Expand All @@ -38,6 +39,7 @@ namespace {
// -test case for CL_COMMAND_BUFFER_REFERENCE_COUNT_KHR query
// -test case for CL_COMMAND_BUFFER_STATE_KHR query
// -test case for CL_COMMAND_BUFFER_PROPERTIES_ARRAY_KHR query
// -test case for CL_COMMAND_BUFFER_CONTEXT_KHR query

template <CombufInfoTestMode test_mode>
struct CommandBufferGetCommandBufferInfo : public BasicCommandBufferTest
Expand Down Expand Up @@ -70,6 +72,10 @@ struct CommandBufferGetCommandBufferInfo : public BasicCommandBufferTest
error = RunPropArrayInfoTest();
test_error(error, "RunPropArrayInfoTest failed");
break;
case CombufInfoTestMode::CITM_CONTEXT:
error = RunContextInfoTest();
test_error(error, "RunContextInfoTest failed");
break;
}

return CL_SUCCESS;
Expand Down Expand Up @@ -323,6 +329,46 @@ struct CommandBufferGetCommandBufferInfo : public BasicCommandBufferTest
return TEST_FAIL;
}

cl_int RunContextInfoTest()
{
cl_int error = TEST_PASS;

// record command buffers
error = RecordCommandBuffer();
test_error(error, "RecordCommandBuffer failed");

size_t ret_value_size = 0;
error = clGetCommandBufferInfoKHR(command_buffer,
CL_COMMAND_BUFFER_CONTEXT_KHR, 0,
nullptr, &ret_value_size);
test_error(error, "clGetCommandBufferInfoKHR failed");

test_assert_error(
ret_value_size == sizeof(cl_context),
"Unexpected result of CL_COMMAND_BUFFER_CONTEXT_KHR query!");

cl_context ret_context = nullptr;
error = clGetCommandBufferInfoKHR(
command_buffer, CL_COMMAND_BUFFER_CONTEXT_KHR, sizeof(cl_context),
&ret_context, nullptr);
test_error(error, "clGetCommandBufferInfoKHR failed");
test_assert_error(
ret_context != nullptr,
"Unexpected result of CL_COMMAND_BUFFER_CONTEXT_KHR query!");

cl_context expected_context = nullptr;
error =
clGetCommandQueueInfo(queue, CL_QUEUE_CONTEXT, sizeof(cl_context),
&expected_context, nullptr);
test_error(error, "clGetCommandQueueInfo failed");

test_assert_error(
ret_context == expected_context,
"Unexpected result of CL_COMMAND_BUFFER_CONTEXT_KHR query!");

return TEST_PASS;
}

const cl_int pattern = 0xE;
};

Expand Down Expand Up @@ -360,3 +406,11 @@ int test_info_prop_array(cl_device_id device, cl_context context,
CommandBufferGetCommandBufferInfo<CombufInfoTestMode::CITM_PROP_ARRAY>>(
device, context, queue, num_elements);
}

int test_info_context(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements)
{
return MakeAndRunTest<
CommandBufferGetCommandBufferInfo<CombufInfoTestMode::CITM_CONTEXT>>(
device, context, queue, num_elements);
}
1 change: 1 addition & 0 deletions test_conformance/extensions/cl_khr_command_buffer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ test_definition test_list[] = {
ADD_TEST(info_ref_count),
ADD_TEST(info_state),
ADD_TEST(info_prop_array),
ADD_TEST(info_context),
ADD_TEST(basic_profiling),
ADD_TEST(simultaneous_profiling),
ADD_TEST(regular_wait_for_command_buffer),
Expand Down
2 changes: 2 additions & 0 deletions test_conformance/extensions/cl_khr_command_buffer/procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ extern int test_info_state(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_info_prop_array(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_info_context(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_basic_set_kernel_arg(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_pending_set_kernel_arg(cl_device_id device, cl_context context,
Expand Down

0 comments on commit 75aca34

Please sign in to comment.