From c9a8f9b1bed02e994849b9f337d993da89406a65 Mon Sep 17 00:00:00 2001 From: Katarzyna Cencelewska Date: Mon, 28 Jan 2019 08:27:26 +0100 Subject: [PATCH] GlSharingFunction tests update Add mock of opengl32.dll to check that sharing functions are loaded Change-Id: I361707ee9a506e84db51d4fa9c98823db2550fae --- runtime/helpers/string_helpers.h | 2 +- .../windows/gl/gl_sharing_win.cpp | 29 +- runtime/sharings/gl/gl_sharing.h | 3 +- unit_tests/CMakeLists.txt | 2 + .../gl/enqueue_kernel_gl_tests.cpp | 4 +- unit_tests/mocks/gl/mock_gl_sharing.cpp | 72 +--- unit_tests/mocks/gl/mock_gl_sharing.h | 208 +++-------- unit_tests/mocks/gl/mock_opengl32.cpp | 332 +++++++++++++++++- unit_tests/mocks/gl/mock_opengl32.def | 36 +- unit_tests/mocks/mock_context.cpp | 4 + unit_tests/mocks/mock_context.h | 1 + .../os_interface/windows/gl/gl_dll_helper.h | 57 ++- .../windows/gl/gl_os_sharing_tests.cpp | 9 +- .../gl/gl_create_from_texture_tests.cpp | 11 +- .../sharings/gl/gl_reused_buffers_tests.cpp | 27 +- unit_tests/sharings/gl/gl_sharing_tests.cpp | 273 +++++++------- unit_tests/sharings/gl/gl_texture_tests.cpp | 85 ++--- 17 files changed, 715 insertions(+), 440 deletions(-) diff --git a/runtime/helpers/string_helpers.h b/runtime/helpers/string_helpers.h index 900f7b9d3b..0965fd5d5e 100644 --- a/runtime/helpers/string_helpers.h +++ b/runtime/helpers/string_helpers.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * diff --git a/runtime/os_interface/windows/gl/gl_sharing_win.cpp b/runtime/os_interface/windows/gl/gl_sharing_win.cpp index cf02441f42..eb90878ec7 100644 --- a/runtime/os_interface/windows/gl/gl_sharing_win.cpp +++ b/runtime/os_interface/windows/gl/gl_sharing_win.cpp @@ -70,7 +70,7 @@ bool GLSharingFunctions::isGlSharingEnabled() { return oglLibAvailable; } -bool GLSharingFunctions::isOpenGlExtensionSupported(const char *pExtensionString) { +bool GLSharingFunctions::isOpenGlExtensionSupported(const unsigned char *pExtensionString) { bool LoadedNull = (glGetStringi == nullptr) || (glGetIntegerv == nullptr); if (LoadedNull) { return false; @@ -79,8 +79,8 @@ bool GLSharingFunctions::isOpenGlExtensionSupported(const char *pExtensionString cl_int NumberOfExtensions = 0; glGetIntegerv(GL_NUM_EXTENSIONS, &NumberOfExtensions); for (cl_int i = 0; i < NumberOfExtensions; i++) { - const char *pString = reinterpret_cast(glGetStringi(GL_EXTENSIONS, i)); - if (strcmp(pString, pExtensionString) == 0) { + std::basic_string pString = glGetStringi(GL_EXTENSIONS, i); + if (pString == pExtensionString) { return true; } } @@ -89,30 +89,35 @@ bool GLSharingFunctions::isOpenGlExtensionSupported(const char *pExtensionString bool GLSharingFunctions::isOpenGlSharingSupported() { - const char *Vendor = reinterpret_cast(glGetString(GL_VENDOR)); - if ((Vendor == nullptr) || (strcmp(Vendor, "Intel") != 0)) { + std::basic_string Vendor = glGetString(GL_VENDOR); + const unsigned char intelVendor[] = "Intel"; + + if ((Vendor.empty()) || (Vendor != intelVendor)) { return false; } - - const char *Version = reinterpret_cast(glGetString(GL_VERSION)); - if (Version == nullptr) { + std::basic_string Version = glGetString(GL_VERSION); + if (Version.empty()) { return false; } bool IsOpenGLES = false; - if (strstr(Version, "OpenGL ES") != NULL) { + const unsigned char versionES[] = "OpenGL ES"; + if (Version.find(versionES) != std::string::npos) { IsOpenGLES = true; } if (IsOpenGLES == true) { - if (strstr(Version, "OpenGL ES 1.") != NULL) { - if (isOpenGlExtensionSupported("GL_OES_framebuffer_object") == false) { + const unsigned char versionES1[] = "OpenGL ES 1."; + if (Version.find(versionES1) != std::string::npos) { + const unsigned char supportGLOES[] = "GL_OES_framebuffer_object"; + if (isOpenGlExtensionSupported(supportGLOES) == false) { return false; } } } else { if (Version[0] < '3') { - if (isOpenGlExtensionSupported("GL_EXT_framebuffer_object") == false) { + const unsigned char supportGLEXT[] = "GL_EXT_framebuffer_object"; + if (isOpenGlExtensionSupported(supportGLEXT) == false) { return false; } } diff --git a/runtime/sharings/gl/gl_sharing.h b/runtime/sharings/gl/gl_sharing.h index fd1837a627..e14f974d2a 100644 --- a/runtime/sharings/gl/gl_sharing.h +++ b/runtime/sharings/gl/gl_sharing.h @@ -163,7 +163,8 @@ class GLSharingFunctions : public SharingFunctions { } void createBackupContext(); - bool isOpenGlExtensionSupported(const char *pExtensionString); + + bool isOpenGlExtensionSupported(const unsigned char *pExtentionString); bool isOpenGlSharingSupported(); std::mutex mutex; diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt index 8cd4c4fba4..4b852de05f 100644 --- a/unit_tests/CMakeLists.txt +++ b/unit_tests/CMakeLists.txt @@ -130,6 +130,8 @@ option(SHOW_VERBOSE_UTESTS_RESULTS "Use the default/verbose test output" ON) if(NOT SHOW_VERBOSE_UTESTS_RESULTS) set(IGDRCL_TESTS_LISTENER_OPTION "--disable_default_listener") +else() + set(IGDRCL_TESTS_LISTENER_OPTION "--enable_default_listener") endif() target_include_directories(igdrcl_tests PRIVATE diff --git a/unit_tests/command_queue/gl/enqueue_kernel_gl_tests.cpp b/unit_tests/command_queue/gl/enqueue_kernel_gl_tests.cpp index 1c17709a6a..7451d775d9 100644 --- a/unit_tests/command_queue/gl/enqueue_kernel_gl_tests.cpp +++ b/unit_tests/command_queue/gl/enqueue_kernel_gl_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Intel Corporation + * Copyright (C) 2018-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -29,7 +29,7 @@ TEST_F(EnqueueKernelTest, givenKernelWithSharedObjArgsWhenEnqueueIsCalledThenRes auto nonSharedBuffer = new MockBuffer; MockGlSharing glSharing; glSharing.uploadDataToBufferInfo(1, 0); - pContext->setSharingFunctions(new GlSharingFunctionsMock()); + pContext->setSharingFunctions(glSharing.sharingFunctions.release()); auto retVal = CL_SUCCESS; auto sharedBuffer = GlBuffer::createSharedGlBuffer(pContext, CL_MEM_READ_WRITE, 1, &retVal); auto sharedMem = static_cast(sharedBuffer); diff --git a/unit_tests/mocks/gl/mock_gl_sharing.cpp b/unit_tests/mocks/gl/mock_gl_sharing.cpp index 33a01d79f5..81b24e0b4b 100644 --- a/unit_tests/mocks/gl/mock_gl_sharing.cpp +++ b/unit_tests/mocks/gl/mock_gl_sharing.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Intel Corporation + * Copyright (C) 2018-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -9,20 +9,6 @@ #include "unit_tests/mocks/gl/mock_gl_sharing.h" namespace OCLRT { -int GLSetSharedOCLContextStateCalled = 0; -int GLAcquireSharedBufferCalled = 0; -int GLAcquireSharedRenderBufferCalled = 0; -int GLAcquireSharedTextureCalled = 0; -int GLReleaseSharedBufferCalled = 0; -int GLReleaseSharedRenderBufferCalled = 0; -int GLReleaseSharedTextureCalled = 0; -int GLGetCurrentContextCalled = 0; -int GLGetCurrentDisplayCalled = 0; -int GLMakeCurrentCalled = 0; -int GLDeleteContextCalled = 0; -int WGLCreateContextCalled = 0; -int WGLShareListsCalled = 0; -int WGLDeleteContextCalled = 0; int EGLCreateContextCalled = 0; int EGLChooseConfigCalled = 0; int EGLDeleteContextCalled = 0; @@ -31,50 +17,16 @@ int GlxQueryContextCalled = 0; int GlxCreateNewContextCalled = 0; int GlxDeleteContextCalled = 0; int GlxIsDirectCalled = 0; -int GLRetainSyncCalled = 0; -int GLReleaseSyncCalled = 0; -int GLGetSyncivCalled = 0; - -CL_GL_BUFFER_INFO bufferInfoInput = {0}; -CL_GL_BUFFER_INFO bufferInfoOutput = {0}; -CL_GL_RESOURCE_INFO textureInfoInput = {0}; -CL_GL_RESOURCE_INFO textureInfoOutput = {0}; EGLBkpContextParams eglBkpContextParams = {0}; GLXBkpContextParams glxBkpContextParams = {0}; -GLMockReturnedValues glMockReturnedValues = {0}; void GlSharingFunctionsMock::initMembers() { - GLSetSharedOCLContextState = mockGLSetSharedOCLContextState; - GLAcquireSharedBuffer = mockGLAcquireSharedBuffer; - GLAcquireSharedRenderBuffer = mockGLAcquireSharedRenderBuffer; - GLAcquireSharedTexture = mockGLAcquireSharedTexture; - GLReleaseSharedBuffer = mockGLReleaseSharedBuffer; - GLReleaseSharedRenderBuffer = mockGLReleaseSharedRenderBuffer; - GLReleaseSharedTexture = mockGLReleaseSharedTexture; - GLGetCurrentContext = mockGLGetCurrentContext; - GLGetCurrentDisplay = mockGLGetCurrentDisplay; - this->wglMakeCurrent = mockWGLMakeCurrent; - GLReleaseSync = mockGlReleaseSync; - GLRetainSync = mockGlRetainSync; - GLGetSynciv = mockGlGetSynciv; - pfnWglCreateContext = mockWGlCreateContext; - pfnWglShareLists = mockWGlShareLists; - pfnWglDeleteContext = mockWGLDeleteContext; - - GLSetSharedOCLContextStateCalled = 0; - GLAcquireSharedBufferCalled = 0; - GLAcquireSharedRenderBufferCalled = 0; - GLAcquireSharedTextureCalled = 0; - GLReleaseSharedBufferCalled = 0; - GLReleaseSharedRenderBufferCalled = 0; - GLReleaseSharedTextureCalled = 0; - GLGetCurrentContextCalled = 0; - GLGetCurrentDisplayCalled = 0; - GLMakeCurrentCalled = 0; - GLDeleteContextCalled = 0; - WGLCreateContextCalled = 0; - WGLShareListsCalled = 0; - WGLDeleteContextCalled = 0; + GLSharingFunctions::initGLFunctions(); + glDllHelper dllParam; + dllParam.setGLSetSharedOCLContextStateReturnedValue(1u); + dllParam.resetParam(""); + dllParam.loadTexture({0}); + dllParam.loadBuffer({0}); EGLChooseConfigCalled = 0; EGLCreateContextCalled = 0; EGLDeleteContextCalled = 0; @@ -83,16 +35,8 @@ void GlSharingFunctionsMock::initMembers() { GlxCreateNewContextCalled = 0; GlxDeleteContextCalled = 0; GlxIsDirectCalled = 0; - GLRetainSyncCalled = 0; - GLReleaseSyncCalled = 0; - GLGetSyncivCalled = 0; - memset(&bufferInfoInput, 0, sizeof(CL_GL_BUFFER_INFO)); - memset(&bufferInfoOutput, 0, sizeof(CL_GL_BUFFER_INFO)); - memset(&textureInfoInput, 0, sizeof(CL_GL_RESOURCE_INFO)); - memset(&textureInfoOutput, 0, sizeof(CL_GL_RESOURCE_INFO)); memset(&eglBkpContextParams, 0, sizeof(EGLBkpContextParams)); memset(&glxBkpContextParams, 0, sizeof(GLXBkpContextParams)); - memset(&glMockReturnedValues, 0, sizeof(GLMockReturnedValues)); } GlSharingFunctionsMock::GlSharingFunctionsMock() { @@ -100,6 +44,6 @@ GlSharingFunctionsMock::GlSharingFunctionsMock() { } MockGlSharing::MockGlSharing(GLType glhdcType, GLContext glhglrcHandle, GLContext glhglrcHandleBkpCtx, GLDisplay glhdcHandle) { - m_sharingFunctions.setHandles(glhdcType, glhglrcHandle, glhglrcHandleBkpCtx, glhdcHandle); + sharingFunctions->setHandles(glhdcType, glhglrcHandle, glhglrcHandleBkpCtx, glhdcHandle); } } // namespace OCLRT diff --git a/unit_tests/mocks/gl/mock_gl_sharing.h b/unit_tests/mocks/gl/mock_gl_sharing.h index 8aa6d020ad..1e1a1acd6b 100644 --- a/unit_tests/mocks/gl/mock_gl_sharing.h +++ b/unit_tests/mocks/gl/mock_gl_sharing.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Intel Corporation + * Copyright (C) 2018-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -11,6 +11,7 @@ #include "runtime/gmm_helper/gmm_helper.h" #include "runtime/sharings/gl/gl_sharing.h" #include "public/cl_gl_private_intel.h" +#include "unit_tests/os_interface/windows/gl/gl_dll_helper.h" namespace OCLRT { struct EGLBkpContextParams { @@ -36,19 +37,6 @@ struct GLMockReturnedValues { }; extern int GLSetSharedOCLContextStateCalled; -extern int GLAcquireSharedBufferCalled; -extern int GLAcquireSharedRenderBufferCalled; -extern int GLAcquireSharedTextureCalled; -extern int GLReleaseSharedBufferCalled; -extern int GLReleaseSharedRenderBufferCalled; -extern int GLReleaseSharedTextureCalled; -extern int GLGetCurrentContextCalled; -extern int GLGetCurrentDisplayCalled; -extern int GLMakeCurrentCalled; -extern int GLDeleteContextCalled; -extern int WGLCreateContextCalled; -extern int WGLShareListsCalled; -extern int WGLDeleteContextCalled; extern int EGLCreateContextCalled; extern int EGLDeleteContextCalled; extern int EGLChooseConfigCalled; @@ -57,16 +45,8 @@ extern int GlxQueryContextCalled; extern int GlxCreateNewContextCalled; extern int GlxDeleteContextCalled; extern int GlxIsDirectCalled; -extern int GLRetainSyncCalled; -extern int GLReleaseSyncCalled; -extern int GLGetSyncivCalled; -extern CL_GL_BUFFER_INFO bufferInfoInput; -extern CL_GL_BUFFER_INFO bufferInfoOutput; -extern CL_GL_RESOURCE_INFO textureInfoInput; -extern CL_GL_RESOURCE_INFO textureInfoOutput; extern EGLBkpContextParams eglBkpContextParams; extern GLXBkpContextParams glxBkpContextParams; -extern GLMockReturnedValues glMockReturnedValues; namespace glTextureTargets { static const unsigned int supportedTargets[] = { @@ -91,118 +71,35 @@ static const unsigned int supportedTargets[] = { class GlSharingFunctionsMock : public GLSharingFunctions { + void initMembers(); + + public: static GLboolean OSAPI mockGLSetSharedOCLContextState(GLDisplay, GLContext, GLboolean, GLvoid *pBufferInfo) { GLSetSharedOCLContextStateCalled++; return (GLboolean)1; }; - static GLboolean OSAPI mockGLAcquireSharedBuffer(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { - auto pBufferInfo = (CL_GL_BUFFER_INFO *)pResourceInfo; - bufferInfoInput = *pBufferInfo; - pBufferInfo->bufferSize = bufferInfoOutput.bufferSize; - pBufferInfo->globalShareHandle = bufferInfoOutput.globalShareHandle; - pBufferInfo->pGmmResInfo = bufferInfoOutput.pGmmResInfo; - pBufferInfo->bufferOffset = bufferInfoOutput.bufferOffset; - GLAcquireSharedBufferCalled++; - return (GLboolean)1; - }; - static GLboolean OSAPI mockGLAcquireSharedRenderBuffer(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { - auto pTextureInfo = (CL_GL_RESOURCE_INFO *)pResourceInfo; - textureInfoInput = *pTextureInfo; - pTextureInfo->globalShareHandle = textureInfoOutput.globalShareHandle; - pTextureInfo->pGmmResInfo = textureInfoOutput.pGmmResInfo; - pTextureInfo->glInternalFormat = GL_RGBA8; - GLAcquireSharedRenderBufferCalled++; - return (GLboolean)1; - }; - static GLboolean OSAPI mockGLAcquireSharedTexture(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { - auto pTextureInfo = (CL_GL_RESOURCE_INFO *)pResourceInfo; - textureInfoInput = *pTextureInfo; - pTextureInfo->globalShareHandle = textureInfoOutput.globalShareHandle; - pTextureInfo->globalShareHandleMCS = textureInfoOutput.globalShareHandleMCS; - if (pTextureInfo->target == GL_TEXTURE_BUFFER) { - // size and width for texture buffer are queried from textureInfo - not from gmm - pTextureInfo->textureBufferSize = textureInfoOutput.textureBufferSize; - pTextureInfo->textureBufferWidth = textureInfoOutput.textureBufferWidth; - } - pTextureInfo->pGmmResInfo = textureInfoOutput.pGmmResInfo; - pTextureInfo->glInternalFormat = textureInfoOutput.glInternalFormat ? textureInfoOutput.glInternalFormat : GL_RGBA8; - pTextureInfo->glHWFormat = textureInfoOutput.glHWFormat; - pTextureInfo->textureBufferOffset = textureInfoOutput.textureBufferOffset; - pTextureInfo->numberOfSamples = textureInfoOutput.numberOfSamples; - GLAcquireSharedTextureCalled++; - return (GLboolean)1; - }; - static GLboolean OSAPI mockGLReleaseSharedTexture(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { - textureInfoInput = *static_cast(pResourceInfo); - GLReleaseSharedTextureCalled++; - return (GLboolean)1; - }; - static GLboolean OSAPI mockGLReleaseSharedRenderBuffer(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { - textureInfoInput = *static_cast(pResourceInfo); - GLReleaseSharedRenderBufferCalled++; - return (GLboolean)1; - }; - static GLboolean OSAPI mockGLReleaseSharedBuffer(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { - bufferInfoInput = *static_cast(pResourceInfo); - GLReleaseSharedBufferCalled++; - return (GLboolean)1; - }; - static GLContext OSAPI mockGLGetCurrentContext() { - GLGetCurrentContextCalled++; - return glMockReturnedValues.currentContext; - }; - static GLDisplay OSAPI mockGLGetCurrentDisplay() { - GLGetCurrentDisplayCalled++; - return glMockReturnedValues.currentDisplay; - }; - static BOOL OSAPI mockWGLMakeCurrent(HDC, HGLRC context) { - GLMakeCurrentCalled++; - glMockReturnedValues.madeCurrentContext = context; - if (glMockReturnedValues.forceMakeCurrentCallFail) { - if (glMockReturnedValues.failsCounter < glMockReturnedValues.numberOfCallFails) { - glMockReturnedValues.failsCounter++; - return GL_FALSE; - } - } - return (GLboolean)1; - }; - - static GLContext OSAPI mockWGlCreateContext(GLDisplay hdcHandle) { - WGLCreateContextCalled++; - return (GLContext)0x101; - } - static int OSAPI mockWGlShareLists(GLContext contextHandle, GLContext backupContextHandle) { - WGLShareListsCalled++; - return 1; - } - - static BOOL OSAPI mockWGLDeleteContext(HGLRC context) { - WGLDeleteContextCalled++; - GLDeleteContextCalled++; - return (GLboolean)1; - } - - static GLboolean OSAPI mockGlRetainSync(GLDisplay HDCHandle, GLContext ContextHandle, GLContext BackupContextHandle, - GLvoid *pSyncInfo) { - GLRetainSyncCalled++; - GL_CL_SYNC_INFO *syncInfo = (GL_CL_SYNC_INFO *)(pSyncInfo); - syncInfo->pSync = (void *)0x123; - return GL_TRUE; - } - static GLboolean OSAPI mockGlReleaseSync(GLDisplay HDCHandle, GLContext ContextHandle, GLContext BackupContextHandle, - GLvoid *pSync) { - GLReleaseSyncCalled++; - return GL_TRUE; - } - static void OSAPI mockGlGetSynciv(GLvoid *pSync, GLenum pname, GLint *value) { - GLGetSyncivCalled++; - *value = glMockReturnedValues.syncivRetVal; - } - void initMembers(); - - public: ~GlSharingFunctionsMock() override = default; + using GLSharingFunctions::GLAcquireSharedBuffer; + using GLSharingFunctions::GLAcquireSharedRenderBuffer; + using GLSharingFunctions::GLAcquireSharedTexture; + using GLSharingFunctions::GLGetCurrentContext; + using GLSharingFunctions::GLGetCurrentDisplay; + using GLSharingFunctions::glGetIntegerv; + using GLSharingFunctions::glGetString; + using GLSharingFunctions::glGetStringi; + using GLSharingFunctions::GLGetSynciv; + using GLSharingFunctions::GLReleaseSharedBuffer; + using GLSharingFunctions::GLReleaseSharedRenderBuffer; + using GLSharingFunctions::GLReleaseSharedTexture; + using GLSharingFunctions::GLReleaseSync; + using GLSharingFunctions::GLRetainSync; + using GLSharingFunctions::GLSetSharedOCLContextState; + using GLSharingFunctions::pfnWglCreateContext; + using GLSharingFunctions::pfnWglDeleteContext; + using GLSharingFunctions::pfnWglShareLists; + using GLSharingFunctions::wglMakeCurrent; + using GLSharingFunctions::glArbEventMapping; using GLSharingFunctions::GLContextHandle; using GLSharingFunctions::GLDeviceHandle; @@ -236,20 +133,24 @@ class MockGlSharing { public: MockGlSharing() {} MockGlSharing(GLType GLHDCType, GLContext GLHGLRCHandle, GLContext GLHGLRCHandleBkpCtx, GLDisplay GLHDCHandle); - void uploadDataToBufferInfo() { bufferInfoOutput = m_bufferInfoOutput; } + void uploadDataToBufferInfo() { + dllParam->loadBuffer(m_bufferInfoOutput); + } void uploadDataToBufferInfo(unsigned int sharedHandle, int bufferOffset) { m_bufferInfoOutput.globalShareHandle = sharedHandle; m_bufferInfoOutput.bufferOffset = bufferOffset; - bufferInfoOutput = m_bufferInfoOutput; + dllParam->loadBuffer(m_bufferInfoOutput); + } + void uploadDataToTextureInfo() { + dllParam->loadTexture(m_textureInfoOutput); } - void uploadDataToTextureInfo() { textureInfoOutput = m_textureInfoOutput; } void uploadDataToTextureInfo(unsigned int sharedHandle) { m_textureInfoOutput.globalShareHandle = sharedHandle; - textureInfoOutput = m_textureInfoOutput; + dllParam->loadTexture(m_textureInfoOutput); } void uploadTextureBufferOffsetToTextureInfo(int texBufOffset) { m_textureInfoOutput.textureBufferOffset = texBufOffset; - textureInfoOutput = m_textureInfoOutput; + dllParam->loadTexture(m_textureInfoOutput); } void overrideGetCurrentValues(GLContext ctx, GLDisplay display, bool forceMakeCurrentFail = false, int numberOfFails = 0) { glMockReturnedValues.currentContext = ctx; @@ -257,54 +158,35 @@ class MockGlSharing { glMockReturnedValues.forceMakeCurrentCallFail = forceMakeCurrentFail; glMockReturnedValues.numberOfCallFails = numberOfFails; glMockReturnedValues.failsCounter = 0; + dllParam->setGlMockReturnedValues(glMockReturnedValues); + } + void setGetSyncivReturnValue(int val) { + glMockReturnedValues.syncivRetVal = val; + dllParam->setGlMockReturnedValues(glMockReturnedValues); } - void setGetSyncivReturnValue(int val) { glMockReturnedValues.syncivRetVal = val; } - - GlSharingFunctionsMock m_sharingFunctions; + std::unique_ptr sharingFunctions = std::make_unique(); + std::unique_ptr dllParam = std::make_unique(); CL_GL_RESOURCE_INFO m_clGlResourceInfo = {0}; GL_CL_RESOURCE_INFO m_glClResourceInfo = {0}; CL_GL_BUFFER_INFO m_bufferInfoOutput = {0}; CL_GL_RESOURCE_INFO m_textureInfoOutput = {0}; + GLMockReturnedValues glMockReturnedValues = {0}; }; class MockGLSharingFunctions : public GLSharingFunctions { public: - static const char *arrayStringi[2]; - static const char *arrayString[2]; - static GLboolean GLSetSharedOCLContextStateReturnedValue; static bool SharingEnabled; - static const GLubyte *OSAPI glGetStringTest(GLenum name) { - if (name == GL_VENDOR) - return (const GLubyte *)arrayString[0]; - if (name == GL_VERSION) - return (const GLubyte *)arrayString[1]; - return nullptr; - }; - static const GLubyte *OSAPI glGetStringiTest(GLenum name, GLuint index) { return (const GLubyte *)arrayStringi[index]; }; + static void OSAPI glGetIntegervTest(GLenum pname, GLint *data) { if (pname == GL_NUM_EXTENSIONS) *data = 2; }; - static GLboolean OSAPI GLSetSharedOCLContextStateTest(GLDisplay HDCHandle, GLContext ContextHandle, GLboolean State, - GLvoid *pContextInfo) { - ((ContextInfo *)pContextInfo)->ContextHandle = 1; - ((ContextInfo *)pContextInfo)->DeviceHandle = 2; - return GLSetSharedOCLContextStateReturnedValue; - } using GLSharingFunctions::glGetIntegerv; using GLSharingFunctions::glGetString; - + std::unique_ptr dllParam = std::make_unique(); MockGLSharingFunctions() { - glGetString = (PFNglGetString)glGetStringTest; - glGetStringi = (PFNglGetStringi)glGetStringiTest; - glGetIntegerv = (PFNglGetIntegerv)glGetIntegervTest; - GLSetSharedOCLContextState = (PFNOGLSetSharedOCLContextStateINTEL)GLSetSharedOCLContextStateTest; - arrayStringi[0] = "GL_OES_framebuffer_object"; - arrayStringi[1] = "GL_EXT_framebuffer_object"; - arrayString[0] = "Intel"; - arrayString[1] = "4.0"; - GLSetSharedOCLContextStateReturnedValue = 1; + GLSharingFunctions::initGLFunctions(); MockGLSharingFunctions::SharingEnabled = 1; } }; diff --git a/unit_tests/mocks/gl/mock_opengl32.cpp b/unit_tests/mocks/gl/mock_opengl32.cpp index 5de8c914da..7eba8367c7 100644 --- a/unit_tests/mocks/gl/mock_opengl32.cpp +++ b/unit_tests/mocks/gl/mock_opengl32.cpp @@ -5,23 +5,333 @@ * */ +#define _GDI32_ //It causes that definitions of functions are not loaded from dll in file wingdi.h because they are in this file. + #include #include "unit_tests/helpers/windows/mock_function.h" +#include "unit_tests/mocks/gl/mock_gl_sharing.h" #include "GL/gl.h" -#undef wglGetProcAddress -#pragma warning(disable : 4273) - extern "C" { const char *glString = "Intel"; const char *glVersion = "4.0"; -const unsigned char *_stdcall glGetString(unsigned int name) { +const char *arrayStringi[2]{"GL_OES_framebuffer_object", "GL_EXT_framebuffer_object"}; +int GLAcquireSharedBufferCalled = 0; +int GLAcquireSharedRenderBufferCalled = 0; +int GLAcquireSharedTextureCalled = 0; +int GLDeleteContextCalled = 0; +int GLGetCurrentContextCalled = 0; +int GLGetCurrentDisplayCalled = 0; +int GLGetSyncivCalled = 0; +int GLMakeCurrentCalled = 0; +int GLReleaseSharedBufferCalled = 0; +int GLReleaseSharedRenderBufferCalled = 0; +int GLReleaseSharedTextureCalled = 0; +int GLReleaseSyncCalled = 0; +int GLRetainSyncCalled = 0; +int WGLCreateContextCalled = 0; +int WGLDeleteContextCalled = 0; +int WGLShareListsCalled = 0; +CL_GL_BUFFER_INFO bufferInfoInput = {0}; +CL_GL_BUFFER_INFO bufferInfoOutput = {0}; +CL_GL_RESOURCE_INFO textureInfoInput = {0}; +CL_GL_RESOURCE_INFO textureInfoOutput = {0}; +OCLRT::GLMockReturnedValues glMockReturnedValues = {0}; +GLboolean GLSetSharedOCLContextStateReturnedValue = 1u; + +const unsigned char *WINAPI glGetString(unsigned int name) { if (name == GL_VENDOR) return reinterpret_cast(glString); if (name == GL_VERSION) return reinterpret_cast(glVersion); return reinterpret_cast(""); }; +GLboolean WINAPI wglSetSharedOCLContextStateINTELMock(HDC HDCHandle, HGLRC ContextHandle, unsigned char State, + void *pContextInfo) { + ((OCLRT::ContextInfo *)pContextInfo)->ContextHandle = 1; + ((OCLRT::ContextInfo *)pContextInfo)->DeviceHandle = 2; + return GLSetSharedOCLContextStateReturnedValue; +}; +GLboolean WINAPI mockGLAcquireSharedBuffer(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { + + auto pBufferInfo = (CL_GL_BUFFER_INFO *)pResourceInfo; + bufferInfoInput = *pBufferInfo; + pBufferInfo->bufferSize = bufferInfoOutput.bufferSize; + pBufferInfo->globalShareHandle = bufferInfoOutput.globalShareHandle; + pBufferInfo->pGmmResInfo = bufferInfoOutput.pGmmResInfo; + pBufferInfo->bufferOffset = bufferInfoOutput.bufferOffset; + GLAcquireSharedBufferCalled++; + return (GLboolean)1; +}; +GLboolean WINAPI mockGLReleaseSharedBuffer(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { + bufferInfoInput = *static_cast(pResourceInfo); + GLReleaseSharedBufferCalled++; + return (GLboolean)1; +}; +GLboolean WINAPI mockGLAcquireSharedRenderBuffer(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { + auto pTextureInfo = (CL_GL_RESOURCE_INFO *)pResourceInfo; + textureInfoInput = *pTextureInfo; + pTextureInfo->globalShareHandle = textureInfoOutput.globalShareHandle; + pTextureInfo->pGmmResInfo = textureInfoOutput.pGmmResInfo; + pTextureInfo->glInternalFormat = GL_RGBA8; + GLAcquireSharedRenderBufferCalled++; + return (GLboolean)1; +}; +GLboolean WINAPI mockGLReleaseSharedRenderBuffer(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { + textureInfoInput = *static_cast(pResourceInfo); + GLReleaseSharedRenderBufferCalled++; + return (GLboolean)1; +}; +GLboolean WINAPI mockGLAcquireSharedTexture(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { + auto pTextureInfo = (CL_GL_RESOURCE_INFO *)pResourceInfo; + textureInfoInput = *pTextureInfo; + pTextureInfo->globalShareHandle = textureInfoOutput.globalShareHandle; + pTextureInfo->globalShareHandleMCS = textureInfoOutput.globalShareHandleMCS; + if (pTextureInfo->target == GL_TEXTURE_BUFFER) { + // size and width for texture buffer are queried from textureInfo - not from gmm + pTextureInfo->textureBufferSize = textureInfoOutput.textureBufferSize; + pTextureInfo->textureBufferWidth = textureInfoOutput.textureBufferWidth; + } + pTextureInfo->pGmmResInfo = textureInfoOutput.pGmmResInfo; + pTextureInfo->glInternalFormat = textureInfoOutput.glInternalFormat ? textureInfoOutput.glInternalFormat : GL_RGBA8; + pTextureInfo->glHWFormat = textureInfoOutput.glHWFormat; + pTextureInfo->textureBufferOffset = textureInfoOutput.textureBufferOffset; + pTextureInfo->numberOfSamples = textureInfoOutput.numberOfSamples; + GLAcquireSharedTextureCalled++; + return (GLboolean)1; +}; +GLboolean WINAPI mockGLReleaseSharedTexture(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { + textureInfoInput = *static_cast(pResourceInfo); + GLReleaseSharedTextureCalled++; + return (GLboolean)1; +}; +GLboolean WINAPI mockGlRetainSync(GLDisplay HDCHandle, GLContext ContextHandle, GLContext BackupContextHandle, + GLvoid *pSyncInfo) { + GLRetainSyncCalled++; + GL_CL_SYNC_INFO *syncInfo = (GL_CL_SYNC_INFO *)(pSyncInfo); + syncInfo->pSync = (void *)0x123; + return GL_TRUE; +}; +GLboolean WINAPI mockGlReleaseSync(GLDisplay HDCHandle, GLContext ContextHandle, GLContext BackupContextHandle, + GLvoid *pSync) { + GLReleaseSyncCalled++; + return GL_TRUE; +}; +void WINAPI mockGlGetSynciv(GLvoid *pSync, GLenum pname, GLint *value) { + GLGetSyncivCalled++; + *value = glMockReturnedValues.syncivRetVal; +}; +const unsigned char *_stdcall glGetStringiMock(unsigned int name, unsigned int index) { return reinterpret_cast(arrayStringi[index]); }; +GLDisplay WINAPI mockGLGetCurrentDisplay() { + GLGetCurrentDisplayCalled++; + return glMockReturnedValues.currentDisplay; +}; +PROC WINAPI wglGetProcAddress(LPCSTR name) { + if (strcmp(name, "wglSetSharedOCLContextStateINTEL") == 0) { + return reinterpret_cast(*wglSetSharedOCLContextStateINTELMock); + } + if (strcmp(name, "wglAcquireSharedBufferINTEL") == 0) { + return reinterpret_cast(*mockGLAcquireSharedBuffer); + } + if (strcmp(name, "wglReleaseSharedBufferINTEL") == 0) { + return reinterpret_cast(*mockGLReleaseSharedBuffer); + } + if (strcmp(name, "wglAcquireSharedRenderBufferINTEL") == 0) { + return reinterpret_cast(*mockGLAcquireSharedRenderBuffer); + } + if (strcmp(name, "wglReleaseSharedRenderBufferINTEL") == 0) { + return reinterpret_cast(*mockGLReleaseSharedRenderBuffer); + } + if (strcmp(name, "wglAcquireSharedTextureINTEL") == 0) { + return reinterpret_cast(*mockGLAcquireSharedTexture); + } + if (strcmp(name, "wglReleaseSharedTextureINTEL") == 0) { + return reinterpret_cast(*mockGLReleaseSharedTexture); + } + if (strcmp(name, "wglRetainSyncINTEL") == 0) { + return reinterpret_cast(*mockGlRetainSync); + } + if (strcmp(name, "wglReleaseSyncINTEL") == 0) { + return reinterpret_cast(*mockGlReleaseSync); + } + if (strcmp(name, "wglGetSyncivINTEL") == 0) { + return reinterpret_cast(*mockGlGetSynciv); + } + if (strcmp(name, "glGetStringi") == 0) { + return reinterpret_cast(*glGetStringiMock); + } + return nullptr; +} +HGLRC WINAPI wglGetCurrentContext() { + GLGetCurrentContextCalled++; + return glMockReturnedValues.currentContext; +}; +HDC WINAPI wglGetCurrentDC() { return mockGLGetCurrentDisplay(); }; +HGLRC WINAPI wglCreateContext(HDC Arg1) { + WGLCreateContextCalled++; + return (GLContext)0x101; +}; +BOOL WINAPI wglDeleteContext(HGLRC Arg1) { + WGLDeleteContextCalled++; + GLDeleteContextCalled++; + return (GLboolean)1; +}; +void WINAPI glGetIntegerv(GLenum pname, GLint *params) { return OCLRT::MockGLSharingFunctions::glGetIntegervTest(pname, params); }; +BOOL WINAPI wglShareLists(HGLRC arg1, HGLRC arg2) { + WGLShareListsCalled++; + return 1; +}; + +BOOL WINAPI wglMakeCurrent(HDC arg1, HGLRC arg2) { + GLMakeCurrentCalled++; + glMockReturnedValues.madeCurrentContext = arg2; + if (glMockReturnedValues.forceMakeCurrentCallFail) { + if (glMockReturnedValues.failsCounter < glMockReturnedValues.numberOfCallFails) { + glMockReturnedValues.failsCounter++; + return GL_FALSE; + } + } + return (GLboolean)1; +}; +void *WINAPI mockLoader(const char *name) { + if (strcmp(name, "realFunction") == 0) { + return *realFunction; + } + return nullptr; +}; +void resetParam(const char *name) { + if (strcmp(name, "GLAcquireSharedBufferCalled") == 0) { + GLAcquireSharedBufferCalled = 0; + } + if (strcmp(name, "GLAcquireSharedRenderBufferCalled") == 0) { + GLAcquireSharedRenderBufferCalled = 0; + } + if (strcmp(name, "GLAcquireSharedTextureCalled") == 0) { + GLAcquireSharedTextureCalled = 0; + } + if (strcmp(name, "GLDeleteContextCalled") == 0) { + GLDeleteContextCalled = 0; + } + if (strcmp(name, "GLGetCurrentContextCalled") == 0) { + GLGetCurrentContextCalled = 0; + } + if (strcmp(name, "GLGetCurrentDisplayCalled") == 0) { + GLGetCurrentDisplayCalled = 0; + } + if (strcmp(name, "GLGetSyncivCalled") == 0) { + GLGetSyncivCalled = 0; + } + if (strcmp(name, "GLMakeCurrentCalled") == 0) { + GLMakeCurrentCalled = 0; + } + if (strcmp(name, "GLReleaseSharedBufferCalled") == 0) { + GLReleaseSharedBufferCalled = 0; + } + if (strcmp(name, "GLReleaseSharedRenderBufferCalled") == 0) { + GLReleaseSharedRenderBufferCalled = 0; + } + if (strcmp(name, "GLReleaseSharedTextureCalled") == 0) { + GLReleaseSharedTextureCalled = 0; + } + if (strcmp(name, "GLReleaseSyncCalled") == 0) { + GLReleaseSyncCalled = 0; + } + if (strcmp(name, "GLRetainSyncCalled") == 0) { + GLRetainSyncCalled = 0; + } + if (strcmp(name, "WGLCreateContextCalled") == 0) { + WGLCreateContextCalled = 0; + } + if (strcmp(name, "WGLDeleteContextCalled") == 0) { + WGLDeleteContextCalled = 0; + } + if (strcmp(name, "WGLShareListsCalled") == 0) { + WGLShareListsCalled = 0; + } + if (strcmp(name, "") == 0) { + GLAcquireSharedBufferCalled = 0; + GLAcquireSharedRenderBufferCalled = 0; + GLAcquireSharedTextureCalled = 0; + GLDeleteContextCalled = 0; + GLGetCurrentContextCalled = 0; + GLGetCurrentDisplayCalled = 0; + GLGetSyncivCalled = 0; + GLMakeCurrentCalled = 0; + GLReleaseSharedBufferCalled = 0; + GLReleaseSharedRenderBufferCalled = 0; + GLReleaseSharedTextureCalled = 0; + GLReleaseSyncCalled = 0; + GLRetainSyncCalled = 0; + WGLCreateContextCalled = 0; + WGLDeleteContextCalled = 0; + WGLShareListsCalled = 0; + } +}; +int getParam(const char *name) { + if (strcmp(name, "GLAcquireSharedBufferCalled") == 0) { + return GLAcquireSharedBufferCalled; + } + if (strcmp(name, "GLAcquireSharedRenderBufferCalled") == 0) { + return GLAcquireSharedRenderBufferCalled; + } + if (strcmp(name, "GLAcquireSharedTextureCalled") == 0) { + return GLAcquireSharedTextureCalled; + } + if (strcmp(name, "GLDeleteContextCalled") == 0) { + return GLDeleteContextCalled; + } + if (strcmp(name, "GLGetCurrentContextCalled") == 0) { + return GLGetCurrentContextCalled; + } + if (strcmp(name, "GLGetCurrentDisplayCalled") == 0) { + return GLGetCurrentDisplayCalled; + } + if (strcmp(name, "GLGetSyncivCalled") == 0) { + return GLGetSyncivCalled; + } + if (strcmp(name, "GLMakeCurrentCalled") == 0) { + return GLMakeCurrentCalled; + } + if (strcmp(name, "GLReleaseSharedBufferCalled") == 0) { + return GLReleaseSharedBufferCalled; + } + if (strcmp(name, "GLReleaseSharedRenderBufferCalled") == 0) { + return GLReleaseSharedRenderBufferCalled; + } + if (strcmp(name, "GLReleaseSharedTextureCalled") == 0) { + return GLReleaseSharedTextureCalled; + } + if (strcmp(name, "GLReleaseSyncCalled") == 0) { + return GLReleaseSyncCalled; + } + if (strcmp(name, "GLRetainSyncCalled") == 0) { + return GLRetainSyncCalled; + } + if (strcmp(name, "WGLCreateContextCalled") == 0) { + return WGLCreateContextCalled; + } + if (strcmp(name, "WGLDeleteContextCalled") == 0) { + return WGLDeleteContextCalled; + } + if (strcmp(name, "WGLShareListsCalled") == 0) { + return WGLShareListsCalled; + } + return 0; +}; +CL_GL_BUFFER_INFO getBufferInfo() { return bufferInfoInput; }; +CL_GL_RESOURCE_INFO getTextureInfo() { return textureInfoInput; }; +void memParam() { + memset(&bufferInfoInput, 0, sizeof(CL_GL_BUFFER_INFO)); + memset(&bufferInfoOutput, 0, sizeof(CL_GL_BUFFER_INFO)); + memset(&textureInfoInput, 0, sizeof(CL_GL_RESOURCE_INFO)); + memset(&textureInfoOutput, 0, sizeof(CL_GL_RESOURCE_INFO)); + memset(&glMockReturnedValues, 0, sizeof(GLMockReturnedValues)); +}; +void loadBuffer(CL_GL_BUFFER_INFO buff) { bufferInfoOutput = buff; }; +void loadTexture(CL_GL_RESOURCE_INFO texture) { textureInfoOutput = texture; }; +OCLRT::GLMockReturnedValues getGlMockReturnedValues() { return glMockReturnedValues; }; +void setGlMockReturnedValues(OCLRT::GLMockReturnedValues value) { glMockReturnedValues = value; }; +void setGetSyncivReturnValue(int val) { glMockReturnedValues.syncivRetVal = val; } void glSetString(const char *name, unsigned int var) { if (var == GL_VENDOR) { glString = name; @@ -29,15 +339,7 @@ void glSetString(const char *name, unsigned int var) { glVersion = name; } }; - -PROC WINAPI wglGetProcAddress(LPCSTR name) { - return nullptr; -} - -void *__stdcall mockLoader(const char *name) { - if (strcmp(name, "realFunction") == 0) { - return *realFunction; - } - return nullptr; -} +void glSetStringi(const char *name, unsigned int index) { arrayStringi[index] = name; }; +void setGLSetSharedOCLContextStateReturnedValue(GLboolean value) { GLSetSharedOCLContextStateReturnedValue = static_cast(value); }; +GLboolean getGLSetSharedOCLContextStateReturnedValue() { return GLSetSharedOCLContextStateReturnedValue; }; } diff --git a/unit_tests/mocks/gl/mock_opengl32.def b/unit_tests/mocks/gl/mock_opengl32.def index e57f2660fb..ed4fbdec74 100644 --- a/unit_tests/mocks/gl/mock_opengl32.def +++ b/unit_tests/mocks/gl/mock_opengl32.def @@ -18,9 +18,41 @@ ; ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR ; OTHER DEALINGS IN THE SOFTWARE. -LIBRARY "gdi32_mock" +LIBRARY "mock_opengl32" EXPORTS glGetString wglGetProcAddress glSetString -mockLoader \ No newline at end of file +mockLoader +glGetStringiMock +wglSetSharedOCLContextStateINTELMock +wglGetCurrentContext +wglGetCurrentDC +glGetIntegerv +wglCreateContext +wglDeleteContext +wglShareLists +wglMakeCurrent +glSetString +glSetStringi +mockGLAcquireSharedBuffer +resetParam +getParam +loadBuffer +getBufferInfo +memParam +setGLSetSharedOCLContextStateReturnedValue +getGLSetSharedOCLContextStateReturnedValue +mockGLAcquireSharedRenderBuffer +mockGLReleaseSharedBuffer +mockGLReleaseSharedRenderBuffer +mockGLReleaseSharedTexture +mockGLAcquireSharedTexture +loadTexture +getTextureInfo +mockGLGetCurrentDisplay +setGlMockReturnedValues +getGlMockReturnedValues +mockGlRetainSync +mockGlReleaseSync +mockGlGetSynciv \ No newline at end of file diff --git a/unit_tests/mocks/mock_context.cpp b/unit_tests/mocks/mock_context.cpp index 2e52983fbd..5c89abbe60 100644 --- a/unit_tests/mocks/mock_context.cpp +++ b/unit_tests/mocks/mock_context.cpp @@ -81,6 +81,10 @@ void MockContext::releaseSharingFunctions(SharingType sharing) { this->sharingFunctions[sharing].release(); } +void MockContext::resetSharingFunctions(SharingType sharing) { + this->sharingFunctions[sharing].reset(); +} + void MockContext::registerSharingWithId(SharingFunctions *sharing, SharingType sharingId) { this->sharingFunctions[sharingId].reset(sharing); } diff --git a/unit_tests/mocks/mock_context.h b/unit_tests/mocks/mock_context.h index 95daaf7fc7..ee9e1c1b34 100644 --- a/unit_tests/mocks/mock_context.h +++ b/unit_tests/mocks/mock_context.h @@ -30,6 +30,7 @@ class MockContext : public Context { void setSharingFunctions(SharingFunctions *sharingFunctions); void setContextType(ContextType contextType); void releaseSharingFunctions(SharingType sharing); + void resetSharingFunctions(SharingType sharing); void registerSharingWithId(SharingFunctions *sharing, SharingType sharingId); cl_bool peekPreferD3dSharedResources() { return preferD3dSharedResources; } diff --git a/unit_tests/os_interface/windows/gl/gl_dll_helper.h b/unit_tests/os_interface/windows/gl/gl_dll_helper.h index 30d55c0c8f..2a216b581d 100644 --- a/unit_tests/os_interface/windows/gl/gl_dll_helper.h +++ b/unit_tests/os_interface/windows/gl/gl_dll_helper.h @@ -8,13 +8,28 @@ #pragma once #include "runtime/os_interface/os_library.h" #include "Gl/gl.h" +#include "public/cl_gl_private_intel.h" using namespace OCLRT; namespace Os { extern const char *openglDllName; } +namespace OCLRT { +struct GLMockReturnedValues; +} + +using GLString = void (*)(const char *, unsigned int); +using GLSharedOCLContext = void (*)(GLboolean); +using glBoolean = GLboolean (*)(); +using Void = void (*)(const char *); +using Int = int (*)(const char *); +using BufferParam = void (*)(CL_GL_BUFFER_INFO); +using TextureParam = void (*)(CL_GL_RESOURCE_INFO); +using BuffInfo = CL_GL_BUFFER_INFO (*)(); +using TextureInfo = CL_GL_RESOURCE_INFO (*)(); +using GLMockValue = GLMockReturnedValues (*)(); +using setGLMockValue = void (*)(GLMockReturnedValues); -typedef void (*GLString)(const char *, unsigned int); struct glDllHelper { public: glDllHelper() { @@ -22,15 +37,53 @@ struct glDllHelper { if (glDllLoad) { glSetString = (*glDllLoad)["glSetString"]; UNRECOVERABLE_IF(glSetString == nullptr); + glSetStringi = (*glDllLoad)["glSetStringi"]; + UNRECOVERABLE_IF(glSetStringi == nullptr); + setGLSetSharedOCLContextStateReturnedValue = (*glDllLoad)["setGLSetSharedOCLContextStateReturnedValue"]; + UNRECOVERABLE_IF(setGLSetSharedOCLContextStateReturnedValue == nullptr); + getGLSetSharedOCLContextStateReturnedValue = (*glDllLoad)["getGLSetSharedOCLContextStateReturnedValue"]; + UNRECOVERABLE_IF(getGLSetSharedOCLContextStateReturnedValue == nullptr); + resetParam = (*glDllLoad)["resetParam"]; + UNRECOVERABLE_IF(resetParam == nullptr); + getParam = (*glDllLoad)["getParam"]; + UNRECOVERABLE_IF(getParam == nullptr); + loadBuffer = (*glDllLoad)["loadBuffer"]; + UNRECOVERABLE_IF(loadBuffer == nullptr); + getBufferInfo = (*glDllLoad)["getBufferInfo"]; + UNRECOVERABLE_IF(getBufferInfo == nullptr); + getTextureInfo = (*glDllLoad)["getTextureInfo"]; + UNRECOVERABLE_IF(getTextureInfo == nullptr); + Void memParam = (*glDllLoad)["memParam"]; + UNRECOVERABLE_IF(memParam == nullptr); + loadTexture = (*glDllLoad)["loadTexture"]; + UNRECOVERABLE_IF(loadTexture == nullptr); + getGlMockReturnedValues = (*glDllLoad)["getGlMockReturnedValues"]; + UNRECOVERABLE_IF(getGlMockReturnedValues == nullptr); + setGlMockReturnedValues = (*glDllLoad)["setGlMockReturnedValues"]; + UNRECOVERABLE_IF(setGlMockReturnedValues == nullptr); } } ~glDllHelper() { if (glDllLoad) { glSetString("Intel", GL_VENDOR); glSetString("4.0", GL_VERSION); + glSetStringi("GL_OES_framebuffer_object", 0); + glSetStringi("GL_EXT_framebuffer_object", 1); } } - GLString glSetString = nullptr; + GLString glSetString; + GLString glSetStringi; + GLSharedOCLContext setGLSetSharedOCLContextStateReturnedValue; + glBoolean getGLSetSharedOCLContextStateReturnedValue; + Void resetParam; + Int getParam; + + BufferParam loadBuffer; + TextureParam loadTexture; + BuffInfo getBufferInfo; + TextureInfo getTextureInfo; + GLMockValue getGlMockReturnedValues; + setGLMockValue setGlMockReturnedValues; private: std::unique_ptr glDllLoad; diff --git a/unit_tests/os_interface/windows/gl/gl_os_sharing_tests.cpp b/unit_tests/os_interface/windows/gl/gl_os_sharing_tests.cpp index d026e6d62c..6af63850f8 100644 --- a/unit_tests/os_interface/windows/gl/gl_os_sharing_tests.cpp +++ b/unit_tests/os_interface/windows/gl/gl_os_sharing_tests.cpp @@ -52,11 +52,12 @@ TEST(glSharingBasicTest, GivenSharingFunctionsWhenItIsConstructedThenBackupConte GLContext GLHGLRCHandle = 0; GLDisplay GLHDCHandle = 0; int32_t expectedContextAttrs[3] = {0}; + glDllHelper dllHelper; auto glSharingFunctions = new GlSharingFunctionsMock(GLHDCType, GLHGLRCHandle, GLHGLRCHandle, GLHDCHandle); - EXPECT_EQ(1, WGLCreateContextCalled); - EXPECT_EQ(1, WGLShareListsCalled); + EXPECT_EQ(1, dllHelper.getParam("WGLCreateContextCalled")); + EXPECT_EQ(1, dllHelper.getParam("WGLShareListsCalled")); EXPECT_EQ(0, EGLChooseConfigCalled); EXPECT_EQ(0, EGLCreateContextCalled); EXPECT_EQ(0, GlxChooseFBConfigCalled); @@ -71,8 +72,8 @@ TEST(glSharingBasicTest, GivenSharingFunctionsWhenItIsConstructedThenBackupConte EXPECT_EQ(0, glxBkpContextParams.queryAttribute); EXPECT_EQ(0, glxBkpContextParams.renderType); delete glSharingFunctions; - EXPECT_EQ(1, WGLDeleteContextCalled); - EXPECT_EQ(1, GLDeleteContextCalled); + EXPECT_EQ(1, dllHelper.getParam("WGLDeleteContextCalled")); + EXPECT_EQ(1, dllHelper.getParam("GLDeleteContextCalled")); } struct GlArbSyncEventOsTest : public ::testing::Test { diff --git a/unit_tests/sharings/gl/gl_create_from_texture_tests.cpp b/unit_tests/sharings/gl/gl_create_from_texture_tests.cpp index 1d9b06db7b..99fb76d5f4 100644 --- a/unit_tests/sharings/gl/gl_create_from_texture_tests.cpp +++ b/unit_tests/sharings/gl/gl_create_from_texture_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Intel Corporation + * Copyright (C) 2018-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -43,8 +43,7 @@ class CreateFromGlTexture : public ::testing::Test { void SetUp() override { imgDesc = {}; imgInfo = {}; - glSharing = new MockGlSharing; - clContext.setSharingFunctions(&glSharing->m_sharingFunctions); + clContext.setSharingFunctions(glSharing->sharingFunctions.release()); ASSERT_FALSE(overrideCommandStreamReceiverCreation); clContext.setMemoryManager(&tempMM); } @@ -79,7 +78,7 @@ class CreateFromGlTexture : public ::testing::Test { std::unique_ptr mcsGmm; TempMM tempMM; MockContext clContext; - MockGlSharing *glSharing; + std::unique_ptr glSharing = std::make_unique(); cl_int retVal; static const unsigned int mcsHandle = 0xFF; }; @@ -135,9 +134,9 @@ TEST_P(CreateFromGlTextureTestsWithParams, givenAllTextureSpecificParamsWhenCrea ASSERT_EQ(CL_SUCCESS, retVal); if (target == GL_RENDERBUFFER_EXT) { - EXPECT_EQ(1, GLAcquireSharedRenderBufferCalled); + EXPECT_EQ(1, glSharing->dllParam->getParam("GLAcquireSharedRenderBufferCalled")); } else { - EXPECT_EQ(1, GLAcquireSharedTextureCalled); + EXPECT_EQ(1, glSharing->dllParam->getParam("GLAcquireSharedTextureCalled")); } EXPECT_EQ(GmmHelper::getCubeFaceIndex(target), glImage->getCubeFaceIndex()); diff --git a/unit_tests/sharings/gl/gl_reused_buffers_tests.cpp b/unit_tests/sharings/gl/gl_reused_buffers_tests.cpp index e0ce53ac1b..e20a70d5ad 100644 --- a/unit_tests/sharings/gl/gl_reused_buffers_tests.cpp +++ b/unit_tests/sharings/gl/gl_reused_buffers_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Intel Corporation + * Copyright (C) 2018-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -19,11 +19,13 @@ using namespace OCLRT; struct GlReusedBufferTests : public ::testing::Test { void SetUp() override { glSharingFunctions = new GlSharingFunctionsMock(); + context.setSharingFunctions(glSharingFunctions); graphicsAllocationsForGlBufferReuse = &glSharingFunctions->graphicsAllocationsForGlBufferReuse; } GlSharingFunctionsMock *glSharingFunctions = nullptr; + MockContext context; std::vector> *graphicsAllocationsForGlBufferReuse = nullptr; @@ -90,7 +92,10 @@ TEST_F(GlReusedBufferTests, givenMultipleBuffersWithReusedAllocationWhenCreating } TEST_F(GlReusedBufferTests, givenGlobalShareHandleChangedWhenAcquiringSharedBufferThenChangeGraphicsAllocation) { + std::unique_ptr dllParam = std::make_unique(); + CL_GL_BUFFER_INFO bufferInfoOutput = dllParam->getBufferInfo(); bufferInfoOutput.globalShareHandle = 40; + dllParam->loadBuffer(bufferInfoOutput); auto clBuffer = std::unique_ptr(GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, bufferId1, &retVal)); auto glBuffer = clBuffer->peekSharingHandler(); auto oldGraphicsAllocation = clBuffer->getGraphicsAllocation(); @@ -98,6 +103,7 @@ TEST_F(GlReusedBufferTests, givenGlobalShareHandleChangedWhenAcquiringSharedBuff ASSERT_EQ(40, oldGraphicsAllocation->peekSharedHandle()); bufferInfoOutput.globalShareHandle = 41; + dllParam->loadBuffer(bufferInfoOutput); glBuffer->acquire(clBuffer.get()); auto newGraphicsAllocation = clBuffer->getGraphicsAllocation(); @@ -118,8 +124,11 @@ TEST_F(GlReusedBufferTests, givenGlobalShareHandleDidNotChangeWhenAcquiringShare GlBuffer::resolveGraphicsAllocationChange(currentSharedHandle, updateData); } }; - + std::unique_ptr dllParam = std::make_unique(); + CL_GL_BUFFER_INFO bufferInfoOutput = dllParam->getBufferInfo(); bufferInfoOutput.globalShareHandle = 40; + + dllParam->loadBuffer(bufferInfoOutput); auto clBuffer = std::unique_ptr(GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, bufferId1, &retVal)); auto glBuffer = new MyGlBuffer(context.getSharing(), bufferId1); clBuffer->setSharingHandler(glBuffer); @@ -140,20 +149,26 @@ TEST_F(GlReusedBufferTests, givenGlobalShareHandleChangedWhenAcquiringSharedBuff GlBuffer::resolveGraphicsAllocationChange(currentSharedHandle, updateData); } }; - + std::unique_ptr dllParam = std::make_unique(); + CL_GL_BUFFER_INFO bufferInfoOutput = dllParam->getBufferInfo(); bufferInfoOutput.globalShareHandle = 40; + dllParam->loadBuffer(bufferInfoOutput); auto clBuffer = std::unique_ptr(GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, bufferId1, &retVal)); auto glBuffer = new MyGlBuffer(context.getSharing(), bufferId1); clBuffer->setSharingHandler(glBuffer); bufferInfoOutput.globalShareHandle = 41; + dllParam->loadBuffer(bufferInfoOutput); glBuffer->acquire(clBuffer.get()); glBuffer->release(clBuffer.get()); } TEST_F(GlReusedBufferTests, givenMultipleBuffersAndGlobalShareHandleChangedWhenAcquiringSharedBufferDeleteOldGfxAllocationFromReuseVector) { + std::unique_ptr dllParam = std::make_unique(); + CL_GL_BUFFER_INFO bufferInfoOutput = dllParam->getBufferInfo(); bufferInfoOutput.globalShareHandle = 40; + dllParam->loadBuffer(bufferInfoOutput); auto clBuffer1 = std::unique_ptr(GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, bufferId1, &retVal)); auto clBuffer2 = std::unique_ptr(GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, bufferId1, &retVal)); auto graphicsAllocation1 = clBuffer1->getGraphicsAllocation(); @@ -163,6 +178,7 @@ TEST_F(GlReusedBufferTests, givenMultipleBuffersAndGlobalShareHandleChangedWhenA ASSERT_EQ(1, graphicsAllocationsForGlBufferReuse->size()); bufferInfoOutput.globalShareHandle = 41; + dllParam->loadBuffer(bufferInfoOutput); clBuffer1->peekSharingHandler()->acquire(clBuffer1.get()); auto newGraphicsAllocation = clBuffer1->getGraphicsAllocation(); EXPECT_EQ(1, graphicsAllocationsForGlBufferReuse->size()); @@ -181,11 +197,16 @@ TEST_F(GlReusedBufferTests, givenGraphicsAllocationCreationReturnsNullptrWhenAcq auto suceedingMemoryManager = context.getMemoryManager(); auto failingMemoryManager = std::unique_ptr(new FailingMemoryManager()); + std::unique_ptr dllParam = std::make_unique(); + CL_GL_BUFFER_INFO bufferInfoOutput = dllParam->getBufferInfo(); bufferInfoOutput.globalShareHandle = 40; + + dllParam->loadBuffer(bufferInfoOutput); auto clBuffer = std::unique_ptr(GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, bufferId1, &retVal)); auto glBuffer = clBuffer->peekSharingHandler(); bufferInfoOutput.globalShareHandle = 41; + dllParam->loadBuffer(bufferInfoOutput); context.setMemoryManager(failingMemoryManager.get()); auto result = glBuffer->acquire(clBuffer.get()); diff --git a/unit_tests/sharings/gl/gl_sharing_tests.cpp b/unit_tests/sharings/gl/gl_sharing_tests.cpp index 24237763e4..21240e0662 100644 --- a/unit_tests/sharings/gl/gl_sharing_tests.cpp +++ b/unit_tests/sharings/gl/gl_sharing_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Intel Corporation + * Copyright (C) 2018-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -34,15 +34,12 @@ using namespace OCLRT; bool MockGLSharingFunctions::SharingEnabled = false; -const char *MockGLSharingFunctions::arrayStringi[2] = {"GL_OES_framebuffer_object", "GL_EXT_framebuffer_object"}; -const char *MockGLSharingFunctions::arrayString[2] = {"Intel", "4.0"}; -GLboolean MockGLSharingFunctions::GLSetSharedOCLContextStateReturnedValue = 1; class glSharingTests : public ::testing::Test { public: void SetUp() override { - mockGlSharing = new MockGlSharing; - context.setSharingFunctions(&mockGlSharing->m_sharingFunctions); + mockGlSharingFunctions = mockGlSharing->sharingFunctions.release(); + context.setSharingFunctions(mockGlSharingFunctions); mockGlSharing->m_bufferInfoOutput.globalShareHandle = bufferId; mockGlSharing->m_bufferInfoOutput.bufferSize = 4096u; @@ -50,12 +47,9 @@ class glSharingTests : public ::testing::Test { ASSERT_FALSE(overrideCommandStreamReceiverCreation); } - void TearDown() override { - context.releaseSharingFunctions(SharingType::CLGL_SHARING); - delete mockGlSharing; - } MockContext context; - MockGlSharing *mockGlSharing; + std::unique_ptr mockGlSharing = std::make_unique(); + GlSharingFunctionsMock *mockGlSharingFunctions; unsigned int bufferId = 1u; }; @@ -67,19 +61,20 @@ TEST_F(glSharingTests, givenGlMockWhenItIsCreatedThenNonZeroObjectIsReturned) { TEST_F(glSharingTests, givenGLSharingFunctionsWhenAskedForIdThenClGlSharingIdIsReturned) { auto v = SharingType::CLGL_SHARING; - EXPECT_EQ(v, mockGlSharing->m_sharingFunctions.getId()); + EXPECT_EQ(v, mockGlSharingFunctions->getId()); } TEST_F(glSharingTests, givenMockGlWhenGlBufferIsCreatedThenMemObjectHasGlHandler) { auto retVal = CL_SUCCESS; auto glBuffer = GlBuffer::createSharedGlBuffer(&context, CL_MEM_READ_WRITE, bufferId, &retVal); + EXPECT_NE(nullptr, glBuffer); EXPECT_NE(nullptr, glBuffer->getGraphicsAllocation()); EXPECT_EQ(CL_SUCCESS, retVal); EXPECT_EQ(4096u, glBuffer->getGraphicsAllocation()->getUnderlyingBufferSize()); - EXPECT_EQ(1, GLAcquireSharedBufferCalled); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLAcquireSharedBufferCalled")); - EXPECT_EQ(bufferId, bufferInfoInput.bufferName); + EXPECT_EQ(bufferId, mockGlSharing->dllParam->getBufferInfo().bufferName); EXPECT_EQ(4096u, glBuffer->getSize()); size_t flagsExpected = CL_MEM_READ_WRITE; EXPECT_EQ(flagsExpected, glBuffer->getFlags()); @@ -88,7 +83,7 @@ TEST_F(glSharingTests, givenMockGlWhenGlBufferIsCreatedThenMemObjectHasGlHandler ASSERT_NE(nullptr, handler); auto glHandler = static_cast(handler); - EXPECT_EQ(glHandler->peekFunctionsHandler(), &mockGlSharing->m_sharingFunctions); + EXPECT_EQ(glHandler->peekFunctionsHandler(), mockGlSharingFunctions); delete glBuffer; } @@ -126,7 +121,7 @@ TEST_F(glSharingTests, givenContextWhenClCreateFromGlBufferIsCalledThenBufferIsR } TEST_F(glSharingTests, givenContextWithoutSharingWhenClCreateFromGlBufferIsCalledThenErrorIsReturned) { - context.releaseSharingFunctions(CLGL_SHARING); + context.resetSharingFunctions(CLGL_SHARING); auto retVal = CL_SUCCESS; auto glBuffer = clCreateFromGLBuffer(&context, 0, bufferId, &retVal); ASSERT_EQ(CL_INVALID_CONTEXT, retVal); @@ -138,7 +133,7 @@ GLboolean OSAPI mockGLAcquireSharedBuffer(GLDisplay, GLContext, GLContext, GLvoi }; TEST_F(glSharingTests, givenContextWithSharingWhenClCreateFromGlBufferIsCalledWithIncorrectThenErrorIsReturned) { - mockGlSharing->m_sharingFunctions.setGLAcquireSharedBufferMock(mockGLAcquireSharedBuffer); + mockGlSharingFunctions->setGLAcquireSharedBufferMock(mockGLAcquireSharedBuffer); auto retVal = CL_SUCCESS; auto glBuffer = clCreateFromGLBuffer(&context, 0, bufferId, &retVal); ASSERT_EQ(CL_INVALID_GL_OBJECT, retVal); @@ -164,7 +159,8 @@ TEST_F(glSharingTests, givenContextAnd32BitAddressingWhenClCreateFromGlBufferIsC TEST_F(glSharingTests, givenGlClBufferWhenAskedForCLGLGetInfoThenIdAndTypeIsReturned) { auto retVal = CL_SUCCESS; auto glBuffer = clCreateFromGLBuffer(&context, 0, bufferId, &retVal); - EXPECT_EQ(1, GLAcquireSharedBufferCalled); + + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLAcquireSharedBufferCalled")); cl_gl_object_type objectType = 0u; cl_GLuint objectId = 0u; @@ -207,7 +203,7 @@ TEST_F(glSharingTests, givenClBufferWhenAskedForCLGLGetInfoThenErrorIsReturned) TEST_F(glSharingTests, givenClGLBufferWhenItIsAcquiredThenAcuqireCountIsIncremented) { auto retVal = CL_SUCCESS; auto glBuffer = clCreateFromGLBuffer(&context, 0, bufferId, &retVal); - EXPECT_EQ(1, GLAcquireSharedBufferCalled); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLAcquireSharedBufferCalled")); auto memObject = castToObject(glBuffer); EXPECT_FALSE(memObject->isMemObjZeroCopy()); @@ -216,8 +212,8 @@ TEST_F(glSharingTests, givenClGLBufferWhenItIsAcquiredThenAcuqireCountIsIncremen auto currentGraphicsAllocation = memObject->getGraphicsAllocation(); memObject->peekSharingHandler()->acquire(memObject); - EXPECT_EQ(2, GLAcquireSharedBufferCalled); - EXPECT_EQ(1, GLGetCurrentContextCalled); + EXPECT_EQ(2, mockGlSharing->dllParam->getParam("GLAcquireSharedBufferCalled")); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLGetCurrentContextCalled")); auto currentGraphicsAllocation2 = memObject->getGraphicsAllocation(); @@ -233,16 +229,16 @@ TEST_F(glSharingTests, givenClGLBufferWhenItIsAcquiredTwiceThenAcuqireIsNotCalle auto memObject = castToObject(glBuffer); memObject->peekSharingHandler()->acquire(memObject); - EXPECT_EQ(2, GLAcquireSharedBufferCalled); - EXPECT_EQ(1, GLGetCurrentContextCalled); + EXPECT_EQ(2, mockGlSharing->dllParam->getParam("GLAcquireSharedBufferCalled")); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLGetCurrentContextCalled")); memObject->peekSharingHandler()->acquire(memObject); - EXPECT_EQ(2, GLAcquireSharedBufferCalled); - EXPECT_EQ(1, GLGetCurrentContextCalled); + EXPECT_EQ(2, mockGlSharing->dllParam->getParam("GLAcquireSharedBufferCalled")); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLGetCurrentContextCalled")); memObject->peekSharingHandler()->release(memObject); memObject->peekSharingHandler()->release(memObject); - EXPECT_EQ(1, GLGetCurrentContextCalled); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLGetCurrentContextCalled")); retVal = clReleaseMemObject(glBuffer); EXPECT_EQ(CL_SUCCESS, retVal); @@ -274,14 +270,14 @@ TEST_F(glSharingTests, givenClGLBufferWhenItIsAcquiredTwiceAfterReleaseThenAcuqi auto memObject = castToObject(glBuffer); memObject->peekSharingHandler()->acquire(memObject); - EXPECT_EQ(2, GLAcquireSharedBufferCalled); - EXPECT_EQ(1, GLGetCurrentContextCalled); + EXPECT_EQ(2, mockGlSharing->dllParam->getParam("GLAcquireSharedBufferCalled")); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLGetCurrentContextCalled")); memObject->peekSharingHandler()->release(memObject); memObject->peekSharingHandler()->acquire(memObject); - EXPECT_EQ(3, GLAcquireSharedBufferCalled); - EXPECT_EQ(2, GLGetCurrentContextCalled); + EXPECT_EQ(3, mockGlSharing->dllParam->getParam("GLAcquireSharedBufferCalled")); + EXPECT_EQ(2, mockGlSharing->dllParam->getParam("GLGetCurrentContextCalled")); retVal = clReleaseMemObject(glBuffer); EXPECT_EQ(CL_SUCCESS, retVal); @@ -295,11 +291,11 @@ TEST_F(glSharingTests, givenClGLBufferWhenItIsAcquireCountIsDecrementedToZeroThe sharingHandler->acquire(buffer.get()); sharingHandler->release(buffer.get()); - EXPECT_EQ(0, GLReleaseSharedBufferCalled); + EXPECT_EQ(0, mockGlSharing->dllParam->getParam("GLReleaseSharedBufferCalled")); sharingHandler->release(buffer.get()); - EXPECT_EQ(1, GLReleaseSharedBufferCalled); - EXPECT_EQ(bufferId, bufferInfoInput.bufferName); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLReleaseSharedBufferCalled")); + EXPECT_EQ(bufferId, mockGlSharing->dllParam->getBufferInfo().bufferName); } TEST_F(glSharingTests, givenClGLBufferWhenItIsAcquiredWithDifferentOffsetThenGraphicsAllocationContainsLatestOffsetValue) { @@ -331,10 +327,10 @@ TEST_F(glSharingTests, givenHwCommandQueueWhenAcquireIsCalledThenAcquireCountIsI auto buffer = castToObject(glBuffer); EXPECT_EQ(0u, buffer->acquireCount); - EXPECT_EQ(1, GLAcquireSharedBufferCalled); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLAcquireSharedBufferCalled")); retVal = clEnqueueAcquireGLObjects(commandQueue, 1, &glBuffer, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(2, GLAcquireSharedBufferCalled); + EXPECT_EQ(2, mockGlSharing->dllParam->getParam("GLAcquireSharedBufferCalled")); EXPECT_EQ(1u, buffer->acquireCount); retVal = clEnqueueReleaseGLObjects(commandQueue, 1, &glBuffer, 0, nullptr, nullptr); @@ -343,7 +339,7 @@ TEST_F(glSharingTests, givenHwCommandQueueWhenAcquireIsCalledThenAcquireCountIsI retVal = clEnqueueAcquireGLObjects(commandQueue, 1, &glBuffer, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(3, GLAcquireSharedBufferCalled); + EXPECT_EQ(3, mockGlSharing->dllParam->getParam("GLAcquireSharedBufferCalled")); EXPECT_EQ(1u, buffer->acquireCount); retVal = clReleaseCommandQueue(commandQueue); @@ -361,7 +357,7 @@ TEST_F(glSharingTests, givenHwCommandQueueWhenAcquireIsCalledWithIncorrectWaitli auto buffer = castToObject(glBuffer); EXPECT_EQ(0u, buffer->acquireCount); - EXPECT_EQ(1, GLAcquireSharedBufferCalled); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLAcquireSharedBufferCalled")); retVal = clEnqueueAcquireGLObjects(commandQueue, 0, &glBuffer, 1, nullptr, nullptr); EXPECT_EQ(CL_INVALID_EVENT_WAIT_LIST, retVal); @@ -499,7 +495,7 @@ TEST_F(glSharingTests, givenHwCommandQueueWhenReleaseIsCalledWithIncorrectWaitli auto buffer = castToObject(glBuffer); EXPECT_EQ(0u, buffer->acquireCount); - EXPECT_EQ(1, GLAcquireSharedBufferCalled); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLAcquireSharedBufferCalled")); retVal = clEnqueueAcquireGLObjects(commandQueue, 1, &glBuffer, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); @@ -525,11 +521,11 @@ TEST_F(glSharingTests, givenContextWithoutSharingWhenAcquireIsCalledThenErrorIsR EXPECT_EQ(0u, buffer->acquireCount); context.releaseSharingFunctions(CLGL_SHARING); - - EXPECT_EQ(1, GLAcquireSharedBufferCalled); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLAcquireSharedBufferCalled")); retVal = clEnqueueAcquireGLObjects(commandQueue, 1, &glBuffer, 0, nullptr, nullptr); EXPECT_EQ(CL_INVALID_CONTEXT, retVal); + context.setSharingFunctions(mockGlSharingFunctions); retVal = clReleaseCommandQueue(commandQueue); EXPECT_EQ(CL_SUCCESS, retVal); retVal = clReleaseMemObject(glBuffer); @@ -545,17 +541,17 @@ TEST_F(glSharingTests, givenContextWithoutSharingWhenReleaseIsCalledThenErrorIsR auto buffer = castToObject(glBuffer); EXPECT_EQ(0u, buffer->acquireCount); - EXPECT_EQ(1, GLAcquireSharedBufferCalled); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLAcquireSharedBufferCalled")); retVal = clEnqueueAcquireGLObjects(commandQueue, 1, &glBuffer, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(2, GLAcquireSharedBufferCalled); + EXPECT_EQ(2, mockGlSharing->dllParam->getParam("GLAcquireSharedBufferCalled")); EXPECT_EQ(1u, buffer->acquireCount); context.releaseSharingFunctions(CLGL_SHARING); - retVal = clEnqueueReleaseGLObjects(commandQueue, 1, &glBuffer, 0, nullptr, nullptr); EXPECT_EQ(CL_INVALID_CONTEXT, retVal); + context.setSharingFunctions(mockGlSharingFunctions); retVal = clReleaseCommandQueue(commandQueue); EXPECT_EQ(CL_SUCCESS, retVal); retVal = clReleaseMemObject(glBuffer); @@ -618,54 +614,58 @@ TEST_F(glSharingTests, givenMockGLWhenFunctionsAreCalledThenCallsAreReceived) { auto glContext = (GLContext)1; mockGlSharing->overrideGetCurrentValues(glContext, glDisplay); - EXPECT_EQ(1u, mockGlSharing->m_sharingFunctions.setSharedOCLContextState()); - EXPECT_EQ(1u, mockGlSharing->m_sharingFunctions.acquireSharedBufferINTEL(ptrToStruct)); - EXPECT_EQ(1u, mockGlSharing->m_sharingFunctions.acquireSharedRenderBuffer(ptrToStruct)); - EXPECT_EQ(1u, mockGlSharing->m_sharingFunctions.acquireSharedTexture(ptrToStruct)); - EXPECT_EQ(1u, mockGlSharing->m_sharingFunctions.releaseSharedBufferINTEL(ptrToStruct)); - EXPECT_EQ(1u, mockGlSharing->m_sharingFunctions.releaseSharedRenderBuffer(ptrToStruct)); - EXPECT_EQ(1u, mockGlSharing->m_sharingFunctions.releaseSharedTexture(ptrToStruct)); - EXPECT_EQ(glContext, mockGlSharing->m_sharingFunctions.getCurrentContext()); - EXPECT_EQ(glDisplay, mockGlSharing->m_sharingFunctions.getCurrentDisplay()); - EXPECT_EQ(1u, mockGlSharing->m_sharingFunctions.makeCurrent(glContext, glDisplay)); + EXPECT_EQ(1u, mockGlSharingFunctions->setSharedOCLContextState()); + EXPECT_EQ(1u, mockGlSharingFunctions->acquireSharedBufferINTEL(ptrToStruct)); + EXPECT_EQ(1u, mockGlSharingFunctions->acquireSharedRenderBuffer(ptrToStruct)); + EXPECT_EQ(1u, mockGlSharingFunctions->acquireSharedTexture(ptrToStruct)); + EXPECT_EQ(1u, mockGlSharingFunctions->releaseSharedBufferINTEL(ptrToStruct)); + EXPECT_EQ(1u, mockGlSharingFunctions->releaseSharedRenderBuffer(ptrToStruct)); + EXPECT_EQ(1u, mockGlSharingFunctions->releaseSharedTexture(ptrToStruct)); + EXPECT_EQ(glContext, mockGlSharingFunctions->getCurrentContext()); + EXPECT_EQ(glDisplay, mockGlSharingFunctions->getCurrentDisplay()); + EXPECT_EQ(1u, mockGlSharingFunctions->makeCurrent(glContext, glDisplay)); - EXPECT_EQ(1, GLSetSharedOCLContextStateCalled); - EXPECT_EQ(1, GLAcquireSharedBufferCalled); - EXPECT_EQ(1, GLAcquireSharedRenderBufferCalled); - EXPECT_EQ(1, GLAcquireSharedTextureCalled); - EXPECT_EQ(1, GLReleaseSharedBufferCalled); - EXPECT_EQ(1, GLReleaseSharedRenderBufferCalled); - EXPECT_EQ(1, GLReleaseSharedTextureCalled); - EXPECT_EQ(1, GLGetCurrentContextCalled); - EXPECT_EQ(1, GLGetCurrentDisplayCalled); - EXPECT_EQ(1, GLMakeCurrentCalled); + EXPECT_EQ(1, mockGlSharing->dllParam->getGLSetSharedOCLContextStateReturnedValue()); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLAcquireSharedBufferCalled")); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLAcquireSharedRenderBufferCalled")); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLAcquireSharedTextureCalled")); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLReleaseSharedBufferCalled")); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLReleaseSharedRenderBufferCalled")); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLReleaseSharedTextureCalled")); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLGetCurrentContextCalled")); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLGetCurrentDisplayCalled")); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLMakeCurrentCalled")); } TEST(glSharingBasicTest, GivenSharingFunctionsWhenItIsConstructedThenOglContextFunctionIsCalled) { GLType GLHDCType = 0; GLContext GLHGLRCHandle = 0; GLDisplay GLHDCHandle = 0; + glDllHelper getDllParam; GlSharingFunctionsMock glSharingFunctions(GLHDCType, GLHGLRCHandle, GLHGLRCHandle, GLHDCHandle); - EXPECT_EQ(1, GLSetSharedOCLContextStateCalled); + EXPECT_EQ(1, getDllParam.getGLSetSharedOCLContextStateReturnedValue()); } TEST(glSharingBasicTest, givenInvalidExtensionNameWhenCheckGLExtensionSupportedThenReturnFalse) { GLSharingFunctions glSharingFunctions; - bool RetVal = glSharingFunctions.isOpenGlExtensionSupported("InvalidExtensionName"); + const unsigned char invalidExtension[] = "InvalidExtensionName"; + bool RetVal = glSharingFunctions.isOpenGlExtensionSupported(invalidExtension); EXPECT_FALSE(RetVal); } TEST(glSharingBasicTest, givenglGetIntegervIsNullWhenCheckGLExtensionSupportedThenReturnFalse) { MockGLSharingFunctions glSharingFunctions; glSharingFunctions.glGetIntegerv = nullptr; - bool RetVal = glSharingFunctions.isOpenGlExtensionSupported("InvalidExtensionName"); + const unsigned char invalidExtension[] = "InvalidExtensionName"; + bool RetVal = glSharingFunctions.isOpenGlExtensionSupported(invalidExtension); EXPECT_FALSE(RetVal); } TEST(glSharingBasicTest, givenValidExtensionNameWhenCheckGLExtensionSupportedThenReturnTrue) { MockGLSharingFunctions glSharingFunctions; - bool RetVal = glSharingFunctions.isOpenGlExtensionSupported("GL_OES_framebuffer_object"); + const unsigned char supportGLOES[] = "GL_OES_framebuffer_object"; + bool RetVal = glSharingFunctions.isOpenGlExtensionSupported(supportGLOES); EXPECT_TRUE(RetVal); } @@ -677,7 +677,7 @@ TEST(glSharingBasicTest, givenWhenCheckGLSharingSupportedThenReturnTrue) { TEST(glSharingBasicTest, givenVendorisNullWhenCheckGLSharingSupportedThenReturnFalse) { auto invalidGetStringFcn = [](GLenum name) { - return (const GLubyte *)nullptr; + return (const GLubyte *)""; }; MockGLSharingFunctions glSharingFunctions; @@ -690,10 +690,10 @@ TEST(glSharingBasicTest, givenVendorisNullWhenCheckGLSharingSupportedThenReturnF TEST(glSharingBasicTest, givenVersionisNullWhenCheckGLSharingSupportedThenReturnFalse) { MockGLSharingFunctions glSharingFunctions; - glSharingFunctions.arrayString[1] = nullptr; // version returns null + glSharingFunctions.dllParam->glSetString("", GL_VERSION); // version returns null bool RetVal = glSharingFunctions.isOpenGlSharingSupported(); EXPECT_FALSE(RetVal); - glSharingFunctions.arrayString[0] = "Int.."; + glSharingFunctions.dllParam->glSetString("Int..", GL_VENDOR); RetVal = glSharingFunctions.isOpenGlSharingSupported(); EXPECT_FALSE(RetVal); } @@ -701,40 +701,66 @@ TEST(glSharingBasicTest, givenVersionisNullWhenCheckGLSharingSupportedThenReturn TEST(glSharingBasicTest, givenVersionisGlesWhenCheckGLSharingSupportedThenReturnFalse) { MockGLSharingFunctions glSharingFunctions; - glSharingFunctions.arrayString[1] = "OpenGL ES"; + glSharingFunctions.dllParam->glSetString("OpenGL ES", GL_VERSION); bool RetVal = glSharingFunctions.isOpenGlSharingSupported(); EXPECT_TRUE(RetVal); - glSharingFunctions.arrayString[1] = "OpenGL ES 1."; + glSharingFunctions.dllParam->glSetString("OpenGL ES 1.", GL_VERSION); RetVal = glSharingFunctions.isOpenGlSharingSupported(); EXPECT_TRUE(RetVal); - glSharingFunctions.arrayString[1] = "2.0"; + glSharingFunctions.dllParam->glSetString("2.0", GL_VERSION); RetVal = glSharingFunctions.isOpenGlSharingSupported(); EXPECT_TRUE(RetVal); - glSharingFunctions.arrayStringi[1] = "GL_EXT_framebuffer_o..."; + glSharingFunctions.dllParam->glSetStringi("GL_EXT_framebuffer_o...", 1); RetVal = glSharingFunctions.isOpenGlSharingSupported(); EXPECT_FALSE(RetVal); - glSharingFunctions.arrayStringi[1] = "GL_EXT_framebuffer_object"; + glSharingFunctions.dllParam->glSetStringi("GL_EXT_framebuffer_object", 1); RetVal = glSharingFunctions.isOpenGlSharingSupported(); EXPECT_TRUE(RetVal); - glSharingFunctions.arrayString[1] = "OpenGL ES 1."; - glSharingFunctions.arrayStringi[0] = "GL_OES_framebuffer_o..."; + glSharingFunctions.dllParam->glSetString("OpenGL ES 1.", GL_VERSION); + glSharingFunctions.dllParam->glSetStringi("GL_OES_framebuffer_o...", 0); RetVal = glSharingFunctions.isOpenGlSharingSupported(); EXPECT_FALSE(RetVal); } TEST(glSharingBasicTest, givensetSharedOCLContextStateWhenCallThenCorrectValue) { MockGLSharingFunctions glSharingFunctions; - glSharingFunctions.GLSetSharedOCLContextStateReturnedValue = 0u; + glSharingFunctions.dllParam->setGLSetSharedOCLContextStateReturnedValue(0u); EXPECT_EQ(0u, glSharingFunctions.setSharedOCLContextState()); - glSharingFunctions.GLSetSharedOCLContextStateReturnedValue = 1u; + glSharingFunctions.dllParam->setGLSetSharedOCLContextStateReturnedValue(1u); EXPECT_EQ(1u, glSharingFunctions.setSharedOCLContextState()); } +TEST(glSharingBasicTest, givenGlSharingFunctionsWhenItIsConstructedThenFunctionsAreLoaded) { + GLType GLHDCType = 0; + GLContext GLHGLRCHandle = 0; + GLDisplay GLHDCHandle = 0; + GlSharingFunctionsMock glSharingFunctions(GLHDCType, GLHGLRCHandle, GLHGLRCHandle, GLHDCHandle); + + EXPECT_NE(nullptr, glSharingFunctions.GLGetCurrentContext); + EXPECT_NE(nullptr, glSharingFunctions.GLGetCurrentDisplay); + EXPECT_NE(nullptr, glSharingFunctions.glGetString); + EXPECT_NE(nullptr, glSharingFunctions.glGetIntegerv); + EXPECT_NE(nullptr, glSharingFunctions.pfnWglCreateContext); + EXPECT_NE(nullptr, glSharingFunctions.pfnWglDeleteContext); + EXPECT_NE(nullptr, glSharingFunctions.pfnWglShareLists); + EXPECT_NE(nullptr, glSharingFunctions.wglMakeCurrent); + EXPECT_NE(nullptr, glSharingFunctions.GLSetSharedOCLContextState); + EXPECT_NE(nullptr, glSharingFunctions.GLAcquireSharedBuffer); + EXPECT_NE(nullptr, glSharingFunctions.GLReleaseSharedBuffer); + EXPECT_NE(nullptr, glSharingFunctions.GLAcquireSharedRenderBuffer); + EXPECT_NE(nullptr, glSharingFunctions.GLReleaseSharedRenderBuffer); + EXPECT_NE(nullptr, glSharingFunctions.GLAcquireSharedTexture); + EXPECT_NE(nullptr, glSharingFunctions.GLReleaseSharedTexture); + EXPECT_NE(nullptr, glSharingFunctions.GLRetainSync); + EXPECT_NE(nullptr, glSharingFunctions.GLReleaseSync); + EXPECT_NE(nullptr, glSharingFunctions.GLGetSynciv); + EXPECT_NE(nullptr, glSharingFunctions.glGetStringi); +} TEST_F(glSharingTests, givenContextWhenCreateFromSharedBufferThenSharedImageIsReturned) { auto retVal = CL_SUCCESS; auto glBuffer = clCreateFromGLBuffer(&context, 0, bufferId, &retVal); @@ -836,7 +862,7 @@ TEST(APIclCreateEventFromGLsyncKHR, givenInvalidContexWhenCreateThenReturnError) } TEST_F(glSharingTests, givenContextWithoutSharingWhenCreateEventFromGLThenErrorIsReturned) { - context.releaseSharingFunctions(CLGL_SHARING); + context.resetSharingFunctions(CLGL_SHARING); cl_int retVal = CL_SUCCESS; cl_GLsync sync = {0}; auto event = clCreateEventFromGLsyncKHR(&context, sync, &retVal); @@ -853,24 +879,24 @@ TEST(glSharingContextSwitch, givenContextOrBkpContextHandleAsCurrentWhenSwitchAt mockGlSharing.overrideGetCurrentValues(context, display); { - GLContextGuard guard(mockGlSharing.m_sharingFunctions); - EXPECT_TRUE(glMockReturnedValues.currentContext == context); - EXPECT_TRUE(glMockReturnedValues.currentDisplay == display); + GLContextGuard guard(*mockGlSharing.sharingFunctions); + EXPECT_TRUE(mockGlSharing.dllParam->getGlMockReturnedValues().currentContext == context); + EXPECT_TRUE(mockGlSharing.dllParam->getGlMockReturnedValues().currentDisplay == display); } - EXPECT_EQ(0, GLMakeCurrentCalled); - EXPECT_EQ(1, GLGetCurrentContextCalled); - EXPECT_EQ(1, GLGetCurrentDisplayCalled); + EXPECT_EQ(0, mockGlSharing.dllParam->getParam("GLMakeCurrentCalled")); + EXPECT_EQ(1, mockGlSharing.dllParam->getParam("GLGetCurrentContextCalled")); + EXPECT_EQ(1, mockGlSharing.dllParam->getParam("GLGetCurrentDisplayCalled")); mockGlSharing.overrideGetCurrentValues(bkpContext, display); { - GLContextGuard guard(mockGlSharing.m_sharingFunctions); - EXPECT_EQ(0, GLMakeCurrentCalled); - EXPECT_TRUE(glMockReturnedValues.currentContext == bkpContext); + GLContextGuard guard(*mockGlSharing.sharingFunctions); + EXPECT_EQ(0, mockGlSharing.dllParam->getParam("GLMakeCurrentCalled")); + EXPECT_TRUE(mockGlSharing.dllParam->getGlMockReturnedValues().currentContext == bkpContext); } - EXPECT_EQ(1, GLMakeCurrentCalled); // destructor - EXPECT_TRUE(glMockReturnedValues.madeCurrentContext == bkpContext); + EXPECT_EQ(1, mockGlSharing.dllParam->getParam("GLMakeCurrentCalled")); // destructor + EXPECT_TRUE(mockGlSharing.dllParam->getGlMockReturnedValues().madeCurrentContext == bkpContext); } TEST(glSharingContextSwitch, givenUnknownCurrentContextAndNoFailsOnCallWhenSwitchAttemptedThenMakeSwitchToCtxHandle) { @@ -883,13 +909,13 @@ TEST(glSharingContextSwitch, givenUnknownCurrentContextAndNoFailsOnCallWhenSwitc mockGlSharing.overrideGetCurrentValues(unknownContext, display, false); { - GLContextGuard guard(mockGlSharing.m_sharingFunctions); - EXPECT_TRUE(glMockReturnedValues.currentContext == unknownContext); - EXPECT_EQ(1, GLMakeCurrentCalled); - EXPECT_TRUE(glMockReturnedValues.madeCurrentContext == context); + GLContextGuard guard(*mockGlSharing.sharingFunctions); + EXPECT_TRUE(mockGlSharing.dllParam->getGlMockReturnedValues().currentContext == unknownContext); + EXPECT_EQ(1, mockGlSharing.dllParam->getParam("GLMakeCurrentCalled")); + EXPECT_TRUE(mockGlSharing.dllParam->getGlMockReturnedValues().madeCurrentContext == context); } - EXPECT_EQ(2, GLMakeCurrentCalled); // destructor - EXPECT_TRUE(glMockReturnedValues.madeCurrentContext == unknownContext); + EXPECT_EQ(2, mockGlSharing.dllParam->getParam("GLMakeCurrentCalled")); // destructor + EXPECT_TRUE(mockGlSharing.dllParam->getGlMockReturnedValues().madeCurrentContext == unknownContext); } TEST(glSharingContextSwitch, givenUnknownCurrentContextAndOneFailOnCallWhenSwitchAttemptedThenMakeSwitchToBkpCtxHandle) { @@ -902,13 +928,13 @@ TEST(glSharingContextSwitch, givenUnknownCurrentContextAndOneFailOnCallWhenSwitc mockGlSharing.overrideGetCurrentValues(unknownContext, display, true, 1); { - GLContextGuard guard(mockGlSharing.m_sharingFunctions); - EXPECT_TRUE(glMockReturnedValues.currentContext == unknownContext); - EXPECT_EQ(2, GLMakeCurrentCalled); - EXPECT_TRUE(glMockReturnedValues.madeCurrentContext == bkpContext); + GLContextGuard guard(*mockGlSharing.sharingFunctions); + EXPECT_TRUE(mockGlSharing.dllParam->getGlMockReturnedValues().currentContext == unknownContext); + EXPECT_EQ(2, mockGlSharing.dllParam->getParam("GLMakeCurrentCalled")); + EXPECT_TRUE(mockGlSharing.dllParam->getGlMockReturnedValues().madeCurrentContext == bkpContext); } - EXPECT_EQ(3, GLMakeCurrentCalled); // destructor - EXPECT_TRUE(glMockReturnedValues.madeCurrentContext == unknownContext); + EXPECT_EQ(3, mockGlSharing.dllParam->getParam("GLMakeCurrentCalled")); // destructor + EXPECT_TRUE(mockGlSharing.dllParam->getGlMockReturnedValues().madeCurrentContext == unknownContext); } TEST(glSharingContextSwitch, givenUnknownCurrentContextAndMultipleFailOnCallWhenSwitchAttemptedThenMakeSwitchToBkpCtxHandleUntilSuccess) { @@ -921,13 +947,13 @@ TEST(glSharingContextSwitch, givenUnknownCurrentContextAndMultipleFailOnCallWhen mockGlSharing.overrideGetCurrentValues(unknownContext, display, true, 5); { - GLContextGuard guard(mockGlSharing.m_sharingFunctions); - EXPECT_TRUE(glMockReturnedValues.currentContext == unknownContext); - EXPECT_EQ(6, GLMakeCurrentCalled); - EXPECT_TRUE(glMockReturnedValues.madeCurrentContext == bkpContext); + GLContextGuard guard(*mockGlSharing.sharingFunctions); + EXPECT_TRUE(mockGlSharing.dllParam->getGlMockReturnedValues().currentContext == unknownContext); + EXPECT_EQ(6, mockGlSharing.dllParam->getParam("GLMakeCurrentCalled")); + EXPECT_TRUE(mockGlSharing.dllParam->getGlMockReturnedValues().madeCurrentContext == bkpContext); } - EXPECT_EQ(7, GLMakeCurrentCalled); // destructor - EXPECT_TRUE(glMockReturnedValues.madeCurrentContext == unknownContext); + EXPECT_EQ(7, mockGlSharing.dllParam->getParam("GLMakeCurrentCalled")); // destructor + EXPECT_TRUE(mockGlSharing.dllParam->getGlMockReturnedValues().madeCurrentContext == unknownContext); } TEST(glSharingContextSwitch, givenZeroCurrentContextWhenSwitchAttemptedThenMakeSwitchToBkpCtxHandle) { @@ -941,20 +967,21 @@ TEST(glSharingContextSwitch, givenZeroCurrentContextWhenSwitchAttemptedThenMakeS mockGlSharing.overrideGetCurrentValues(zeroContext, display, false); { - GLContextGuard guard(mockGlSharing.m_sharingFunctions); - EXPECT_TRUE(glMockReturnedValues.currentContext == zeroContext); - EXPECT_EQ(1, GLMakeCurrentCalled); - EXPECT_TRUE(glMockReturnedValues.madeCurrentContext == bkpContext); + GLContextGuard guard(*mockGlSharing.sharingFunctions); + EXPECT_TRUE(mockGlSharing.dllParam->getGlMockReturnedValues().currentContext == zeroContext); + EXPECT_EQ(1, mockGlSharing.dllParam->getParam("GLMakeCurrentCalled")); + EXPECT_TRUE(mockGlSharing.dllParam->getGlMockReturnedValues().madeCurrentContext == bkpContext); } - EXPECT_EQ(2, GLMakeCurrentCalled); // destructor - EXPECT_TRUE(glMockReturnedValues.madeCurrentContext == zeroContext); + EXPECT_EQ(2, mockGlSharing.dllParam->getParam("GLMakeCurrentCalled")); // destructor + EXPECT_TRUE(mockGlSharing.dllParam->getGlMockReturnedValues().madeCurrentContext == zeroContext); } TEST(glSharingContextSwitch, givenSharingFunctionsWhenGlDeleteContextIsNotPresentThenItIsNotCalled) { - auto glSharingFunctions = new MockGLSharingFunctions(); - auto currentGlDeleteContextCalledCount = GLDeleteContextCalled; + auto glSharingFunctions = new GLSharingFunctions(); + glDllHelper dllParam; + auto currentGlDeleteContextCalledCount = dllParam.getParam("GLDeleteContextCalled"); delete glSharingFunctions; - EXPECT_EQ(currentGlDeleteContextCalledCount, GLDeleteContextCalled); + EXPECT_EQ(currentGlDeleteContextCalledCount, dllParam.getParam("GLDeleteContextCalled")); } HWTEST_F(glSharingTests, givenSyncObjectWhenCreateEventIsCalledThenCreateGLSyncObj) { @@ -971,12 +998,12 @@ HWTEST_F(glSharingTests, givenSyncObjectWhenCreateEventIsCalledThenCreateGLSyncO EXPECT_TRUE(eventObj->peekExecutionStatus() == CL_SUBMITTED); EXPECT_EQ(Event::eventNotReady, eventObj->taskLevel); EXPECT_EQ(Event::eventNotReady, eventObj->getTaskLevel()); - EXPECT_EQ(1, GLRetainSyncCalled); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLRetainSyncCalled")); eventObj->setStatus(CL_COMPLETE); EXPECT_EQ(0u, eventObj->getTaskLevel()); clReleaseEvent(event); - EXPECT_EQ(1, GLReleaseSyncCalled); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLReleaseSyncCalled")); } HWTEST_F(glSharingTests, givenEventCreatedFromFenceObjectWhenItIsPassedToAcquireThenItsStatusIsUpdated) { @@ -1016,13 +1043,13 @@ TEST_F(glSharingTests, givenSyncEventWhenUpdateExecutionStatusIsCalledThenGLGetS mockGlSharing->setGetSyncivReturnValue(GL_UNSIGNALED); syncEvent->updateExecutionStatus(); - EXPECT_EQ(1, GLGetSyncivCalled); + EXPECT_EQ(1, mockGlSharing->dllParam->getParam("GLGetSyncivCalled")); EXPECT_TRUE(syncEvent->updateEventAndReturnCurrentStatus() == CL_SUBMITTED); - EXPECT_EQ(2, GLGetSyncivCalled); // updateExecutionStatus called in peekExecutionStatus + EXPECT_EQ(2, mockGlSharing->dllParam->getParam("GLGetSyncivCalled")); // updateExecutionStatus called in peekExecutionStatus mockGlSharing->setGetSyncivReturnValue(GL_SIGNALED); syncEvent->updateExecutionStatus(); - EXPECT_EQ(3, GLGetSyncivCalled); + EXPECT_EQ(3, mockGlSharing->dllParam->getParam("GLGetSyncivCalled")); EXPECT_TRUE(syncEvent->peekExecutionStatus() == CL_COMPLETE); delete syncEvent; diff --git a/unit_tests/sharings/gl/gl_texture_tests.cpp b/unit_tests/sharings/gl/gl_texture_tests.cpp index d6c29e6d27..8b974b6efb 100644 --- a/unit_tests/sharings/gl/gl_texture_tests.cpp +++ b/unit_tests/sharings/gl/gl_texture_tests.cpp @@ -52,14 +52,14 @@ class GlSharingTextureTests : public ::testing::Test { imgDesc.image_type = CL_MEM_OBJECT_IMAGE1D; imgDesc.image_width = 10; auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - glSharing = new MockGlSharing; tempMM = new TempMM(executionEnvironment); executionEnvironment.memoryManager.reset(tempMM); device.reset(MockDevice::create(*platformDevices, &executionEnvironment, 0)); clContext = std::make_unique(device.get()); - clContext->setSharingFunctions(&glSharing->m_sharingFunctions); + mockGlSharingFunctions = glSharing->sharingFunctions.release(); + clContext->setSharingFunctions(mockGlSharingFunctions); ASSERT_FALSE(overrideCommandStreamReceiverCreation); tempMM->forceGmm = MockGmm::queryImgParams(imgInfo); @@ -68,11 +68,6 @@ class GlSharingTextureTests : public ::testing::Test { textureId = 1; } - void TearDown() override { - clContext->releaseSharingFunctions(SharingType::CLGL_SHARING); - delete glSharing; - } - void setUnifiedAuxSurf() { tempMM->useForcedGmm = true; auto mockGmmResInfo = reinterpret_cast<::testing::NiceMock *>(tempMM->forceGmm->gmmResourceInfo.get()); @@ -84,7 +79,8 @@ class GlSharingTextureTests : public ::testing::Test { TempMM *tempMM; std::unique_ptr device; std::unique_ptr clContext; - MockGlSharing *glSharing; + std::unique_ptr glSharing = std::make_unique(); + GlSharingFunctionsMock *mockGlSharingFunctions; size_t textureSize; unsigned int textureId; }; @@ -101,16 +97,16 @@ TEST_F(GlSharingTextureTests, givenMockGlWhen1dGlTextureIsCreatedThenMemObjectHa ASSERT_NE(nullptr, glTexture); EXPECT_NE(nullptr, glTexture->getGraphicsAllocation()); EXPECT_EQ(textureSize, glTexture->getGraphicsAllocation()->getUnderlyingBufferSize()); - EXPECT_EQ(1, GLAcquireSharedTextureCalled); + EXPECT_EQ(1, glSharing->dllParam->getParam("GLAcquireSharedTextureCalled")); EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(textureId, textureInfoInput.name); + EXPECT_EQ(textureId, glSharing->dllParam->getTextureInfo().name); //input auto handler = glTexture->peekSharingHandler(); ASSERT_NE(nullptr, handler); auto glHandler = static_cast(handler); - EXPECT_EQ(glHandler->peekFunctionsHandler(), &glSharing->m_sharingFunctions); + EXPECT_EQ(glHandler->peekFunctionsHandler(), mockGlSharingFunctions); delete glTexture; } @@ -139,23 +135,25 @@ TEST_F(GlSharingTextureTests, givenMockGlWhenGlTextureIsCreatedFromWrongHandleTh GLboolean OSAPI mockGLAcquireSharedTexture(GLDisplay, GLContext, GLContext, GLvoid *pResourceInfo) { auto pTextureInfo = (CL_GL_RESOURCE_INFO *)pResourceInfo; - textureInfoInput = *pTextureInfo; - pTextureInfo->globalShareHandle = textureInfoOutput.globalShareHandle; - pTextureInfo->globalShareHandleMCS = textureInfoOutput.globalShareHandleMCS; + glDllHelper dllParam; + pTextureInfo->globalShareHandle = dllParam.getTextureInfo().globalShareHandle; + pTextureInfo->globalShareHandleMCS = dllParam.getTextureInfo().globalShareHandleMCS; + if (pTextureInfo->target == GL_TEXTURE_BUFFER) { // size and width for texture buffer are queried from textureInfo - not from gmm - pTextureInfo->textureBufferSize = textureInfoOutput.textureBufferSize; - pTextureInfo->textureBufferWidth = textureInfoOutput.textureBufferWidth; + pTextureInfo->textureBufferSize = dllParam.getTextureInfo().textureBufferSize; + pTextureInfo->textureBufferWidth = dllParam.getTextureInfo().textureBufferWidth; } - pTextureInfo->pGmmResInfo = textureInfoOutput.pGmmResInfo; + pTextureInfo->pGmmResInfo = dllParam.getTextureInfo().pGmmResInfo; pTextureInfo->glInternalFormat = 99999; - pTextureInfo->glHWFormat = textureInfoOutput.glHWFormat; - pTextureInfo->textureBufferOffset = textureInfoOutput.textureBufferOffset; + pTextureInfo->glHWFormat = dllParam.getTextureInfo().glHWFormat; + pTextureInfo->textureBufferOffset = dllParam.getTextureInfo().textureBufferOffset; + dllParam.loadTexture(*pTextureInfo); return (GLboolean)1; }; TEST_F(GlSharingTextureTests, givenMockGlWhenGlTextureIsCreatedFromIncorrectFormatThenErrorAndNoTextureIsReturned) { - glSharing->m_sharingFunctions.setGLAcquireSharedTextureMock(mockGLAcquireSharedTexture); + mockGlSharingFunctions->setGLAcquireSharedTextureMock(mockGLAcquireSharedTexture); auto retVal = CL_SUCCESS; auto glTexture = GlTexture::createSharedGlTexture(clContext.get(), (cl_mem_flags)0, GL_TEXTURE_1D, 0, textureId, &retVal); @@ -176,16 +174,16 @@ TEST_F(GlSharingTextureTests, givenMockGlWhenRenderBufferTextureIsCreatedThenMem ASSERT_NE(nullptr, glTexture); EXPECT_NE(nullptr, glTexture->getGraphicsAllocation()); EXPECT_EQ(textureSize, glTexture->getGraphicsAllocation()->getUnderlyingBufferSize()); - EXPECT_EQ(1, GLAcquireSharedRenderBufferCalled); + EXPECT_EQ(1, glSharing->dllParam->getParam("GLAcquireSharedRenderBufferCalled")); EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(textureId, textureInfoInput.name); + EXPECT_EQ(textureId, glSharing->dllParam->getTextureInfo().name); auto handler = glTexture->peekSharingHandler(); ASSERT_NE(nullptr, handler); auto glHandler = static_cast(handler); - EXPECT_EQ(glHandler->peekFunctionsHandler(), &glSharing->m_sharingFunctions); + EXPECT_EQ(glHandler->peekFunctionsHandler(), mockGlSharingFunctions); delete glTexture; } @@ -255,7 +253,7 @@ TEST_F(GlSharingTextureTests, givenContextAnd1dTextureWhenClCreateFromGlTextureI TEST_F(GlSharingTextureTests, givenContextWithoutSharingAnd1dTextureWhenClCreateFromGlTextureIsCalledThenErrorIsReturned) { tempMM->useForcedGmm = false; - clContext->releaseSharingFunctions(CLGL_SHARING); + clContext->resetSharingFunctions(CLGL_SHARING); cl_int retVal = CL_INVALID_GL_OBJECT; auto glImage = clCreateFromGLTexture(clContext.get(), 0, GL_TEXTURE_1D, 0, textureId, &retVal); ASSERT_EQ(CL_INVALID_CONTEXT, retVal); @@ -274,7 +272,7 @@ TEST_F(GlSharingTextureTests, givenContextAndRenderBufferTextureWhenClCreateFrom TEST_F(GlSharingTextureTests, givenContextWithoutSharingAndRenderBufferTextureWhenClCreateFromGlTextureIsCalledThenErrorIsReturned) { tempMM->useForcedGmm = false; - clContext->releaseSharingFunctions(CLGL_SHARING); + clContext->resetSharingFunctions(CLGL_SHARING); cl_int retVal = CL_INVALID_GL_OBJECT; auto glImage = clCreateFromGLRenderbuffer(clContext.get(), 0, textureId, &retVal); ASSERT_EQ(CL_INVALID_CONTEXT, retVal); @@ -319,7 +317,7 @@ TEST_F(GlSharingTextureTests, givenHwCommandQueueAndGlTextureWhenItIsCreatedWith TEST_F(GlSharingTextureTests, givenContextWithoutSharingAndGlTextureWhenItIsCreatedWithClCreateFromGlTexture2dThenErrorIsReturned) { tempMM->useForcedGmm = false; - clContext->releaseSharingFunctions(CLGL_SHARING); + clContext->resetSharingFunctions(CLGL_SHARING); auto retVal = CL_SUCCESS; auto glImage = clCreateFromGLTexture2D(clContext.get(), 0, GL_TEXTURE_2D, 0, textureId, &retVal); ASSERT_EQ(CL_INVALID_CONTEXT, retVal); @@ -346,7 +344,7 @@ TEST_F(GlSharingTextureTests, givenHwCommandQueueAndGlTextureWhenItIsCreatedWith TEST_F(GlSharingTextureTests, givenContextWithoutSharingAndGlTextureWhenItIsCreatedWithClCreateFromGlTexture3dThenErrorIsReturned) { tempMM->useForcedGmm = false; - clContext->releaseSharingFunctions(CLGL_SHARING); + clContext->resetSharingFunctions(CLGL_SHARING); auto retVal = CL_SUCCESS; auto glImage = clCreateFromGLTexture3D(clContext.get(), 0, GL_TEXTURE_3D, 0, textureId, &retVal); ASSERT_EQ(CL_INVALID_CONTEXT, retVal); @@ -362,17 +360,17 @@ TEST_F(GlSharingTextureTests, givenHwCommandQueueAndGlTextureWhenAcquireIsCalled auto glImage = clCreateFromGLTexture(clContext.get(), 0, GL_TEXTURE_1D, 0, textureId, &retVal); - EXPECT_EQ(1, GLAcquireSharedTextureCalled); + EXPECT_EQ(1, glSharing->dllParam->getParam("GLAcquireSharedTextureCalled")); retVal = clEnqueueAcquireGLObjects(commandQueue, 1, &glImage, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(2, GLAcquireSharedTextureCalled); + EXPECT_EQ(2, glSharing->dllParam->getParam("GLAcquireSharedTextureCalled")); retVal = clEnqueueReleaseGLObjects(commandQueue, 1, &glImage, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); retVal = clEnqueueAcquireGLObjects(commandQueue, 1, &glImage, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(3, GLAcquireSharedTextureCalled); + EXPECT_EQ(3, glSharing->dllParam->getParam("GLAcquireSharedTextureCalled")); retVal = clReleaseCommandQueue(commandQueue); EXPECT_EQ(CL_SUCCESS, retVal); @@ -425,17 +423,17 @@ TEST_F(GlSharingTextureTests, givenHwCommandQueueAndGlRenderBufferWhenAcquireIsC auto glImage = clCreateFromGLRenderbuffer(clContext.get(), 0, textureId, &retVal); - EXPECT_EQ(1, GLAcquireSharedRenderBufferCalled); + EXPECT_EQ(1, glSharing->dllParam->getParam("GLAcquireSharedRenderBufferCalled")); retVal = clEnqueueAcquireGLObjects(commandQueue, 1, &glImage, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(2, GLAcquireSharedRenderBufferCalled); + EXPECT_EQ(2, glSharing->dllParam->getParam("GLAcquireSharedRenderBufferCalled")); retVal = clEnqueueReleaseGLObjects(commandQueue, 1, &glImage, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); retVal = clEnqueueAcquireGLObjects(commandQueue, 1, &glImage, 0, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); - EXPECT_EQ(3, GLAcquireSharedRenderBufferCalled); + EXPECT_EQ(3, glSharing->dllParam->getParam("GLAcquireSharedRenderBufferCalled")); retVal = clReleaseCommandQueue(commandQueue); EXPECT_EQ(CL_SUCCESS, retVal); @@ -451,12 +449,12 @@ TEST_F(GlSharingTextureTests, givenSharedGlTextureWhenItIsAcquireCountIsDecremen sharingHandler->acquire(image.get()); sharingHandler->release(image.get()); - EXPECT_EQ(0, GLReleaseSharedTextureCalled); + EXPECT_EQ(0, glSharing->dllParam->getParam("GLReleaseSharedTextureCalled")); sharingHandler->release(image.get()); - EXPECT_EQ(1, GLReleaseSharedTextureCalled); - EXPECT_EQ(0, GLReleaseSharedRenderBufferCalled); - EXPECT_EQ(textureId, textureInfoInput.name); + EXPECT_EQ(1, glSharing->dllParam->getParam("GLReleaseSharedTextureCalled")); + EXPECT_EQ(0, glSharing->dllParam->getParam("GLReleaseSharedRenderBufferCalled")); + EXPECT_EQ(textureId, glSharing->dllParam->getTextureInfo().name); } TEST_F(GlSharingTextureTests, givenSharedRenderBufferWhenItIsAcquireCountIsDecrementedToZeroThenCallReleaseFunction) { @@ -467,12 +465,12 @@ TEST_F(GlSharingTextureTests, givenSharedRenderBufferWhenItIsAcquireCountIsDecre sharingHandler->acquire(image.get()); sharingHandler->release(image.get()); - EXPECT_EQ(0, GLReleaseSharedRenderBufferCalled); + EXPECT_EQ(0, glSharing->dllParam->getParam("GLReleaseSharedRenderBufferCalled")); sharingHandler->release(image.get()); - EXPECT_EQ(1, GLReleaseSharedRenderBufferCalled); - EXPECT_EQ(0, GLReleaseSharedTextureCalled); - EXPECT_EQ(textureId, textureInfoInput.name); + EXPECT_EQ(1, glSharing->dllParam->getParam("GLReleaseSharedRenderBufferCalled")); + EXPECT_EQ(0, glSharing->dllParam->getParam("GLReleaseSharedTextureCalled")); + EXPECT_EQ(textureId, glSharing->dllParam->getTextureInfo().name); } TEST_F(GlSharingTextureTests, givenMultisampleTextureWithMoreThanOneSampleWhenAskedForNumSamplesThenReturnCorrectValue) { @@ -520,7 +518,10 @@ TEST_F(GlSharingTextureTests, givenTextureWithZeroSamplesWhenAskedForNumSamplesT TEST_F(GlSharingTextureTests, givenMockGlWhenGlTextureIsCreatedFromFormatNotIncludedInSurfaceFormatsThenErrorAndNoTextureIsReturned) { cl_int retVal = CL_SUCCESS; - textureInfoOutput.glInternalFormat = GL_SRGB8_ALPHA8; + auto textureInfoOutput = std::make_unique(); + textureInfoOutput->glInternalFormat = GL_SRGB8_ALPHA8; + glSharing->dllParam->loadTexture(*textureInfoOutput); + auto glTexture = GlTexture::createSharedGlTexture(clContext.get(), CL_MEM_WRITE_ONLY, GL_SRGB8_ALPHA8, 0, textureId, &retVal); EXPECT_EQ(nullptr, glTexture);