Skip to content

Conversation

@MichaelRizkalla-arm
Copy link
Contributor

@MichaelRizkalla-arm MichaelRizkalla-arm commented Aug 19, 2025

This PR adds negative tests for the following API functions:

  • clCreateContext
  • clCreateContextFromType
  • clRetainContext
  • clReleaseContext
  • clSetContextDestructorCallback

Also, define a new macro test_object_failure_ret to test for an expected error code and the returned object is NULL as a result of a failure.

@MichaelRizkalla-arm MichaelRizkalla-arm changed the title Add negative tests for context and device API functions Add negative tests for context API functions Aug 19, 2025
@MichaelRizkalla-arm MichaelRizkalla-arm force-pushed the negative_ctx_and_device_tests branch from 9b2681e to 2147c7e Compare August 19, 2025 08:25
@MichaelRizkalla-arm MichaelRizkalla-arm force-pushed the negative_ctx_and_device_tests branch from 2147c7e to d99404d Compare August 26, 2025 10:48
Copy link
Contributor

@EwanC EwanC left a comment

Choose a reason for hiding this comment

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

Looking good, but have a few minor comments

TEST_FAIL);

cl_context_properties invalid_value{ -1 };
props[0] = CL_CONTEXT_INTEROP_USER_SYNC;
Copy link
Contributor

Choose a reason for hiding this comment

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

we could enter this control flow if get_device_cl_version(device) returns Version(1,1) but CL_CONTEXT_INTEROP_USER_SYNC isn't added to the spec until version 1.2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the branch condition to >= Version(1, 2).

"not one of the supported values\"",
TEST_FAIL);

err = clGetContextInfo(context, CL_CONTEXT_REFERENCE_COUNT, 0, &param_value,
Copy link
Contributor

Choose a reason for hiding this comment

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

using a non-zero value, e.g sizeof(cl_uint) - 1 would be a marginally stronger test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

ctx = clCreateContext(props, 1, &device, nullptr, nullptr, &err);
test_object_failure_ret(
ctx, err, CL_INVALID_PROPERTY,
"clCreateContext should return CL_INVALID_PROPERTY when: \"the "
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this provide extra coverage that the first check for this case on line 41 doesn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's been removed.

This change adds negative tests to `cl_context`-related APIs:
- clCreateContext
- clCreateContextFromType
- clRetainContext
- clReleaseContext
- clSetContextDestructorCallback

It also adds a verification macro: `test_object_failure_ret`. It
verifies that an expected error code is returned and the CL object is
`NULL`.

Signed-off-by: Michael Rizkalla <michael.rizkalla@arm.com>
@MichaelRizkalla-arm MichaelRizkalla-arm force-pushed the negative_ctx_and_device_tests branch from d99404d to 536a8dd Compare December 3, 2025 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants