mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
Refactor buffer ReadWrite and Copy tests (#2259)
This change refactors the following tests to use RAII to clean-up
allocated resources on exit, and adds additional changes as mentioned
below:
- test_arrayreadwrite
- Allow different `cl_mem_flags` to be passed to the test.
- test_bufferreadwriterect:
- Allow different `cl_mem_flags` to be passed to the test.
- Customisable copy, read and write functions.
- test_buffer_copy
- Fill the destination buffer with `invalid_ptr` instead of `out_ptr` if
created with `CL_MEM_(USE/COPY)_HOST_PTR`.
- test_buffer_partial_copy
- Fill the destination buffer with `invalid_ptr` instead of `out_ptr` if
created with `CL_MEM_(USE/COPY)_HOST_PTR`.
---------
Signed-off-by: Michael Rizkalla <michael.rizkalla@arm.com>
This commit is contained in:
@@ -342,8 +342,21 @@ void CL_CALLBACK mem_obj_destructor_callback( cl_mem, void *data )
|
||||
free( data );
|
||||
}
|
||||
|
||||
// This is the main test function for the conformance test.
|
||||
REGISTER_TEST(bufferreadwriterect)
|
||||
using test_fn = int (*)(size_t, size_t[3], size_t[3], size_t, size_t[3],
|
||||
size_t[3]);
|
||||
struct TestFunctions
|
||||
{
|
||||
test_fn copy;
|
||||
test_fn read;
|
||||
test_fn write;
|
||||
};
|
||||
|
||||
static int test_bufferreadwriterect_impl(cl_device_id device,
|
||||
cl_context context,
|
||||
cl_command_queue queue,
|
||||
int num_elements,
|
||||
cl_map_flags buffer_flags,
|
||||
const TestFunctions& test_functions)
|
||||
{
|
||||
gQueue = queue;
|
||||
cl_int err;
|
||||
@@ -434,7 +447,8 @@ REGISTER_TEST(bufferreadwriterect)
|
||||
memcpy(backing[i], verify[i], size_bytes);
|
||||
|
||||
// Create the CL buffer.
|
||||
buffer[i] = clCreateBuffer (context, CL_MEM_USE_HOST_PTR | CL_MEM_READ_WRITE, size_bytes, backing[i], &err);
|
||||
buffer[i] =
|
||||
clCreateBuffer(context, buffer_flags, size_bytes, backing[i], &err);
|
||||
CL_EXIT_ERROR(err,"clCreateBuffer failed for buffer %u", i);
|
||||
|
||||
// Make sure buffer is cleaned up appropriately if we encounter an error in the rest of the calls.
|
||||
@@ -499,7 +513,8 @@ REGISTER_TEST(bufferreadwriterect)
|
||||
doffset[0], doffset[1], doffset[2], sregion[0],
|
||||
sregion[1], sregion[2],
|
||||
sregion[0] * sregion[1] * sregion[2]);
|
||||
if ((err = copy_region(src, soffset, sregion, dst, doffset, dregion)))
|
||||
if ((err = test_functions.copy(src, soffset, sregion, dst,
|
||||
doffset, dregion)))
|
||||
return err;
|
||||
break;
|
||||
case 1:
|
||||
@@ -509,7 +524,8 @@ REGISTER_TEST(bufferreadwriterect)
|
||||
doffset[0], doffset[1], doffset[2], sregion[0],
|
||||
sregion[1], sregion[2],
|
||||
sregion[0] * sregion[1] * sregion[2]);
|
||||
if ((err = read_verify_region(src, soffset, sregion, dst, doffset, dregion)))
|
||||
if ((err = test_functions.read(src, soffset, sregion, dst,
|
||||
doffset, dregion)))
|
||||
return err;
|
||||
break;
|
||||
case 2:
|
||||
@@ -519,7 +535,8 @@ REGISTER_TEST(bufferreadwriterect)
|
||||
doffset[0], doffset[1], doffset[2], sregion[0],
|
||||
sregion[1], sregion[2],
|
||||
sregion[0] * sregion[1] * sregion[2]);
|
||||
if ((err = write_region(src, soffset, sregion, dst, doffset, dregion)))
|
||||
if ((err = test_functions.write(src, soffset, sregion, dst,
|
||||
doffset, dregion)))
|
||||
return err;
|
||||
break;
|
||||
}
|
||||
@@ -562,3 +579,15 @@ REGISTER_TEST(bufferreadwriterect)
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
// This is the main test function for the conformance test.
|
||||
REGISTER_TEST(bufferreadwriterect)
|
||||
{
|
||||
TestFunctions test_functions;
|
||||
test_functions.copy = copy_region;
|
||||
test_functions.read = read_verify_region;
|
||||
test_functions.write = write_region;
|
||||
return test_bufferreadwriterect_impl(
|
||||
device, context, queue, num_elements,
|
||||
CL_MEM_USE_HOST_PTR | CL_MEM_READ_WRITE, test_functions);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user