From 550bec5711c73e138a1108abc55a1645ef57afea Mon Sep 17 00:00:00 2001 From: piotr-wozniak-mobica <127202485+piotr-wozniak-mobica@users.noreply.github.com> Date: Tue, 12 Sep 2023 17:55:49 +0200 Subject: [PATCH] UT for getObjectInfo (#234) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * UT for getObjectInfo * Fixes for UT getObjectInfo * Changes after review --------- Co-authored-by: piotr-wozniak-mobica <“piotr.wozniak@mobica.com”> --- tests/CMakeLists.txt | 16 +++++++++----- tests/test_openclhpp.cpp | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 826b1e65..0a1dc05d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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) @@ -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) diff --git a/tests/test_openclhpp.cpp b/tests/test_openclhpp.cpp index 607bed5c..7748e664 100644 --- a/tests/test_openclhpp.cpp +++ b/tests/test_openclhpp.cpp @@ -13,6 +13,7 @@ extern "C" #include #include "Mockcl.h" #include "Mockcl_ext.h" +#include "Mockcl_gl.h" #include #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) @@ -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"