Skip to content

Commit

Permalink
UT for getObjectInfo (KhronosGroup#234)
Browse files Browse the repository at this point in the history
* UT for getObjectInfo

* Fixes for UT getObjectInfo

* Changes after review

---------

Co-authored-by: piotr-wozniak-mobica <“piotr.wozniak@mobica.com”>
  • Loading branch information
piotr-wozniak-mobica and piotr-wozniak-mobica authored Sep 12, 2023
1 parent c8c5a9b commit 550bec5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
16 changes: 11 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,35 @@ endif()
# End of workaround

add_custom_command(
OUTPUT stripped/cl.h stripped/cl_ext.h
OUTPUT stripped/cl.h stripped/cl_ext.h stripped/cl_gl.h
COMMAND ${CMAKE_COMMAND} -E make_directory stripped
COMMAND ${CMAKE_COMMAND} -E make_directory mocks
COMMAND ${CMAKE_COMMAND} -D INPUT="${OPENCL_HEADERS_INTERFACE_INCLUDE_DIRECTORIES}/CL/cl.h" -D OUTPUT="stripped/cl.h" -P ${CMAKE_CURRENT_SOURCE_DIR}/strip_defines.cmake
COMMAND ${CMAKE_COMMAND} -D INPUT="${OPENCL_HEADERS_INTERFACE_INCLUDE_DIRECTORIES}/CL/cl_ext.h" -D OUTPUT="stripped/cl_ext.h" -P ${CMAKE_CURRENT_SOURCE_DIR}/strip_defines.cmake
COMMENT "Stripping defines from cl.h and cl_ext.h"
COMMAND ${CMAKE_COMMAND} -D INPUT="${OPENCL_HEADERS_INTERFACE_INCLUDE_DIRECTORIES}/CL/cl_gl.h" -D OUTPUT="stripped/cl_gl.h" -P ${CMAKE_CURRENT_SOURCE_DIR}/strip_defines.cmake
COMMENT "Stripping defines from cl.h, cl_ext.h and cl_gl.h"
DEPENDS ${OPENCL_HEADERS_INTERFACE_INCLUDE_DIRECTORIES}/CL/cl.h strip_defines.cmake)

add_custom_target(
strip_cl_defines ALL
DEPENDS stripped/cl.h
DEPENDS stripped/cl_ext.h
DEPENDS stripped/cl_gl.h
SOURCES strip_defines.cmake)

add_custom_command(
OUTPUT mocks/Mockcl.c mocks/Mockcl.h mocks/Mockcl_ext.c mocks/Mockcl_ext.h
OUTPUT mocks/Mockcl.c mocks/Mockcl.h mocks/Mockcl_ext.c mocks/Mockcl_ext.h mocks/Mockcl_gl.c mocks/Mockcl_gl.h
COMMAND ${RUBY_EXECUTABLE} ${CMOCK_DIR}/lib/cmock.rb -o${CMAKE_CURRENT_SOURCE_DIR}/cmock.yml stripped/cl.h
COMMAND ${RUBY_EXECUTABLE} ${CMOCK_DIR}/lib/cmock.rb -o${CMAKE_CURRENT_SOURCE_DIR}/cmock.yml stripped/cl_ext.h
COMMAND ${RUBY_EXECUTABLE} ${CMOCK_DIR}/lib/cmock.rb -o${CMAKE_CURRENT_SOURCE_DIR}/cmock.yml stripped/cl_gl.h
COMMENT "Generating mocks"
DEPENDS stripped/cl.h stripped/cl_ext.h cmock.yml)
DEPENDS stripped/cl.h stripped/cl_ext.h stripped/cl_gl.h cmock.yml)

add_custom_target(
mock_cl_header ALL
DEPENDS mocks/Mockcl.c mocks/Mockcl.h
DEPENDS mocks/Mockcl_ext.c mocks/Mockcl_ext.h
DEPENDS mocks/Mockcl_gl.c mocks/Mockcl_gl.h
SOURCES cmock.yml)

add_dependencies(mock_cl_header strip_cl_defines)
Expand Down Expand Up @@ -103,13 +107,15 @@ endif()
set(TEST_HEADERS
${PROJECT_SOURCE_DIR}/include/CL/opencl.hpp
mocks/Mockcl.h
mocks/Mockcl_ext.h)
mocks/Mockcl_ext.h
mocks/Mockcl_gl.h)

set(TEST_SOURCES
${CMAKE_CURRENT_BINARY_DIR}/test_openclhpp_Runner.c
test_openclhpp.cpp
${CMAKE_CURRENT_BINARY_DIR}/mocks/Mockcl.c
${CMAKE_CURRENT_BINARY_DIR}/mocks/Mockcl_ext.c
${CMAKE_CURRENT_BINARY_DIR}/mocks/Mockcl_gl.c
${CMOCK_DIR}/src/cmock.c
${UNITY_DIR}/src/unity.c)

Expand Down
46 changes: 46 additions & 0 deletions tests/test_openclhpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extern "C"
#include <cmock.h>
#include "Mockcl.h"
#include "Mockcl_ext.h"
#include "Mockcl_gl.h"
#include <string.h>

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
Expand Down Expand Up @@ -4471,4 +4472,49 @@ void testTemplateGetImageRequirementsInfo(void)
void testTemplateGetImageRequirementsInfo() {}
#endif // cl_ext_image_requirements_info

static cl_mem clCreateFromGLBuffer_testgetObjectInfo(cl_context context,
cl_mem_flags flags,
cl_GLuint bufobj,
cl_int *errcode_ret,
int num_calls)
{
TEST_ASSERT_EQUAL(0, bufobj);
TEST_ASSERT_EQUAL_PTR(make_context(0), context);
TEST_ASSERT_EQUAL(0, flags);
if (errcode_ret)
*errcode_ret = CL_SUCCESS;
return make_mem(0);
}

static cl_int clGetGLObjectInfo_testgetObjectInfo(cl_mem memobj,
cl_gl_object_type *type,
cl_GLuint *gl_object_name,
int num)
{
TEST_ASSERT_EQUAL(memobj, make_mem(0));
*type = CL_GL_OBJECT_BUFFER;

*gl_object_name = 0;
return CL_SUCCESS;
}

void testgetObjectInfo() {
cl_mem_flags flags = 0;
cl_int err = 0;
cl_GLuint bufobj = 0;
cl_mem memobj = make_mem(0);
cl_gl_object_type type = CL_GL_OBJECT_TEXTURE2D_ARRAY;
clGetGLObjectInfo_StubWithCallback(clGetGLObjectInfo_testgetObjectInfo);
clCreateFromGLBuffer_StubWithCallback(
clCreateFromGLBuffer_testgetObjectInfo);
clReleaseMemObject_ExpectAndReturn(make_mem(0), CL_SUCCESS);
cl::BufferGL buffer(contextPool[0], flags, bufobj, &err);

TEST_ASSERT_EQUAL_PTR(make_mem(0), buffer());
TEST_ASSERT_EQUAL(CL_SUCCESS, err);

TEST_ASSERT_EQUAL(buffer.getObjectInfo(&type, &bufobj), CL_SUCCESS);
TEST_ASSERT_EQUAL(type, CL_GL_OBJECT_BUFFER);
TEST_ASSERT_EQUAL(bufobj, 0);
}
} // extern "C"

0 comments on commit 550bec5

Please sign in to comment.