Skip to content

Add negative tests for creating memory objects with CL_MEM_KERNEL_READ_AND_WRITE - #2867

Open
shajder wants to merge 3 commits into
KhronosGroup:mainfrom
shajder:negative_mem_object_create_buffer
Open

shajder wants to merge 3 commits into
KhronosGroup:mainfrom
shajder:negative_mem_object_create_buffer

Conversation

@shajder

@shajder shajder commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Ref #2791

Checks that clCreateBuffer, clCreateBufferWithProperties, clCreateImage and clCreateImageWithProperties return CL_INVALID_VALUE when CL_MEM_KERNEL_READ_AND_WRITE is set in flags.

[run-test: test_api negative_create_buffer negative_create_buffer_with_properties negative_create_image negative_create_image_with_properties]

@rjodinchr rjodinchr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change Fixes #2791 to Ref #2791 in the PR description so the issue isn't closed automatically when this merges? There is still work left to do for #2791 (for example, covering clCreateSubBuffer, and possibly clCreateImage2D / clCreateImage3D or clCreatePipe).

Comment thread test_conformance/api/CMakeLists.txt Resolved
@shajder

shajder commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Could you change Fixes #2791 to Ref #2791 in the PR description so the issue isn't closed automatically when this merges? There is still work left to do for #2791 (for example, covering clCreateSubBuffer, and possibly clCreateImage2D / clCreateImage3D or clCreatePipe).

Changed as requested. clCreateSubBuffer has no generic CL_INVALID_VALUE for invalid flags in the spec, so I presume it would need a spec change first.

Comment on lines +135 to +142
if (error != CL_INVALID_VALUE || buffer != nullptr)
{
log_error("%s(flags: 0x%llx) with CL_MEM_KERNEL_READ_AND_WRITE, "
"expected CL_INVALID_VALUE, got %s\n",
api_name, (unsigned long long)flags,
IGetErrorString(error));
return TEST_FAIL;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: if a driver sets error to CL_INVALID_VALUE but returns a non-null cl_mem, this message (and the one in test_create_image below) will print expected CL_INVALID_VALUE, got CL_INVALID_VALUE. Could we also print the returned handle (e.g., expected NULL and CL_INVALID_VALUE, got %p and %s) or use test_object_failure_ret?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@rjodinchr

Copy link
Copy Markdown
Collaborator

Could you change Fixes #2791 to Ref #2791 in the PR description so the issue isn't closed automatically when this merges? There is still work left to do for #2791 (for example, covering clCreateSubBuffer, and possibly clCreateImage2D / clCreateImage3D or clCreatePipe).

Changed as requested. clCreateSubBuffer has no generic CL_INVALID_VALUE for invalid flags in the spec, so I presume it would need a spec change first.

Good catch! Indeed, clCreateSubBuffer is missing the generic "CL_INVALID_VALUE if values specified in flags are not valid" bullet in the spec even though the Memory Flags table says CL_MEM_KERNEL_READ_AND_WRITE must not be used to create a memory object. We should open an issue in OpenCL-Docs to clarify clCreateSubBuffer.

In that case, this PR looks good to me as-is (and feel free to re-add Fixes #2791 or we can close #2791 once merged and track clCreateSubBuffer after the spec is updated).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants