Skip to content

Commit c9a8f9b

Browse files
GlSharingFunction tests update
Add mock of opengl32.dll to check that sharing functions are loaded Change-Id: I361707ee9a506e84db51d4fa9c98823db2550fae
1 parent 711d67a commit c9a8f9b

17 files changed

+713
-438
lines changed

runtime/helpers/string_helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2018 Intel Corporation
2+
* Copyright (C) 2017-2019 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*

runtime/os_interface/windows/gl/gl_sharing_win.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ bool GLSharingFunctions::isGlSharingEnabled() {
7070
return oglLibAvailable;
7171
}
7272

73-
bool GLSharingFunctions::isOpenGlExtensionSupported(const char *pExtensionString) {
73+
bool GLSharingFunctions::isOpenGlExtensionSupported(const unsigned char *pExtensionString) {
7474
bool LoadedNull = (glGetStringi == nullptr) || (glGetIntegerv == nullptr);
7575
if (LoadedNull) {
7676
return false;
@@ -79,8 +79,8 @@ bool GLSharingFunctions::isOpenGlExtensionSupported(const char *pExtensionString
7979
cl_int NumberOfExtensions = 0;
8080
glGetIntegerv(GL_NUM_EXTENSIONS, &NumberOfExtensions);
8181
for (cl_int i = 0; i < NumberOfExtensions; i++) {
82-
const char *pString = reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i));
83-
if (strcmp(pString, pExtensionString) == 0) {
82+
std::basic_string<unsigned char> pString = glGetStringi(GL_EXTENSIONS, i);
83+
if (pString == pExtensionString) {
8484
return true;
8585
}
8686
}
@@ -89,30 +89,35 @@ bool GLSharingFunctions::isOpenGlExtensionSupported(const char *pExtensionString
8989

9090
bool GLSharingFunctions::isOpenGlSharingSupported() {
9191

92-
const char *Vendor = reinterpret_cast<const char *>(glGetString(GL_VENDOR));
93-
if ((Vendor == nullptr) || (strcmp(Vendor, "Intel") != 0)) {
92+
std::basic_string<unsigned char> Vendor = glGetString(GL_VENDOR);
93+
const unsigned char intelVendor[] = "Intel";
94+
95+
if ((Vendor.empty()) || (Vendor != intelVendor)) {
9496
return false;
9597
}
96-
97-
const char *Version = reinterpret_cast<const char *>(glGetString(GL_VERSION));
98-
if (Version == nullptr) {
98+
std::basic_string<unsigned char> Version = glGetString(GL_VERSION);
99+
if (Version.empty()) {
99100
return false;
100101
}
101102

102103
bool IsOpenGLES = false;
103-
if (strstr(Version, "OpenGL ES") != NULL) {
104+
const unsigned char versionES[] = "OpenGL ES";
105+
if (Version.find(versionES) != std::string::npos) {
104106
IsOpenGLES = true;
105107
}
106108

107109
if (IsOpenGLES == true) {
108-
if (strstr(Version, "OpenGL ES 1.") != NULL) {
109-
if (isOpenGlExtensionSupported("GL_OES_framebuffer_object") == false) {
110+
const unsigned char versionES1[] = "OpenGL ES 1.";
111+
if (Version.find(versionES1) != std::string::npos) {
112+
const unsigned char supportGLOES[] = "GL_OES_framebuffer_object";
113+
if (isOpenGlExtensionSupported(supportGLOES) == false) {
110114
return false;
111115
}
112116
}
113117
} else {
114118
if (Version[0] < '3') {
115-
if (isOpenGlExtensionSupported("GL_EXT_framebuffer_object") == false) {
119+
const unsigned char supportGLEXT[] = "GL_EXT_framebuffer_object";
120+
if (isOpenGlExtensionSupported(supportGLEXT) == false) {
116121
return false;
117122
}
118123
}

runtime/sharings/gl/gl_sharing.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ class GLSharingFunctions : public SharingFunctions {
163163
}
164164

165165
void createBackupContext();
166-
bool isOpenGlExtensionSupported(const char *pExtensionString);
166+
167+
bool isOpenGlExtensionSupported(const unsigned char *pExtentionString);
167168
bool isOpenGlSharingSupported();
168169

169170
std::mutex mutex;

unit_tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ option(SHOW_VERBOSE_UTESTS_RESULTS "Use the default/verbose test output" ON)
130130

131131
if(NOT SHOW_VERBOSE_UTESTS_RESULTS)
132132
set(IGDRCL_TESTS_LISTENER_OPTION "--disable_default_listener")
133+
else()
134+
set(IGDRCL_TESTS_LISTENER_OPTION "--enable_default_listener")
133135
endif()
134136

135137
target_include_directories(igdrcl_tests PRIVATE

unit_tests/command_queue/gl/enqueue_kernel_gl_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018 Intel Corporation
2+
* Copyright (C) 2018-2019 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -29,7 +29,7 @@ TEST_F(EnqueueKernelTest, givenKernelWithSharedObjArgsWhenEnqueueIsCalledThenRes
2929
auto nonSharedBuffer = new MockBuffer;
3030
MockGlSharing glSharing;
3131
glSharing.uploadDataToBufferInfo(1, 0);
32-
pContext->setSharingFunctions(new GlSharingFunctionsMock());
32+
pContext->setSharingFunctions(glSharing.sharingFunctions.release());
3333
auto retVal = CL_SUCCESS;
3434
auto sharedBuffer = GlBuffer::createSharedGlBuffer(pContext, CL_MEM_READ_WRITE, 1, &retVal);
3535
auto sharedMem = static_cast<cl_mem>(sharedBuffer);
Lines changed: 8 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018 Intel Corporation
2+
* Copyright (C) 2018-2019 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -9,20 +9,6 @@
99
#include "unit_tests/mocks/gl/mock_gl_sharing.h"
1010

1111
namespace OCLRT {
12-
int GLSetSharedOCLContextStateCalled = 0;
13-
int GLAcquireSharedBufferCalled = 0;
14-
int GLAcquireSharedRenderBufferCalled = 0;
15-
int GLAcquireSharedTextureCalled = 0;
16-
int GLReleaseSharedBufferCalled = 0;
17-
int GLReleaseSharedRenderBufferCalled = 0;
18-
int GLReleaseSharedTextureCalled = 0;
19-
int GLGetCurrentContextCalled = 0;
20-
int GLGetCurrentDisplayCalled = 0;
21-
int GLMakeCurrentCalled = 0;
22-
int GLDeleteContextCalled = 0;
23-
int WGLCreateContextCalled = 0;
24-
int WGLShareListsCalled = 0;
25-
int WGLDeleteContextCalled = 0;
2612
int EGLCreateContextCalled = 0;
2713
int EGLChooseConfigCalled = 0;
2814
int EGLDeleteContextCalled = 0;
@@ -31,50 +17,16 @@ int GlxQueryContextCalled = 0;
3117
int GlxCreateNewContextCalled = 0;
3218
int GlxDeleteContextCalled = 0;
3319
int GlxIsDirectCalled = 0;
34-
int GLRetainSyncCalled = 0;
35-
int GLReleaseSyncCalled = 0;
36-
int GLGetSyncivCalled = 0;
37-
38-
CL_GL_BUFFER_INFO bufferInfoInput = {0};
39-
CL_GL_BUFFER_INFO bufferInfoOutput = {0};
40-
CL_GL_RESOURCE_INFO textureInfoInput = {0};
41-
CL_GL_RESOURCE_INFO textureInfoOutput = {0};
4220
EGLBkpContextParams eglBkpContextParams = {0};
4321
GLXBkpContextParams glxBkpContextParams = {0};
44-
GLMockReturnedValues glMockReturnedValues = {0};
4522

4623
void GlSharingFunctionsMock::initMembers() {
47-
GLSetSharedOCLContextState = mockGLSetSharedOCLContextState;
48-
GLAcquireSharedBuffer = mockGLAcquireSharedBuffer;
49-
GLAcquireSharedRenderBuffer = mockGLAcquireSharedRenderBuffer;
50-
GLAcquireSharedTexture = mockGLAcquireSharedTexture;
51-
GLReleaseSharedBuffer = mockGLReleaseSharedBuffer;
52-
GLReleaseSharedRenderBuffer = mockGLReleaseSharedRenderBuffer;
53-
GLReleaseSharedTexture = mockGLReleaseSharedTexture;
54-
GLGetCurrentContext = mockGLGetCurrentContext;
55-
GLGetCurrentDisplay = mockGLGetCurrentDisplay;
56-
this->wglMakeCurrent = mockWGLMakeCurrent;
57-
GLReleaseSync = mockGlReleaseSync;
58-
GLRetainSync = mockGlRetainSync;
59-
GLGetSynciv = mockGlGetSynciv;
60-
pfnWglCreateContext = mockWGlCreateContext;
61-
pfnWglShareLists = mockWGlShareLists;
62-
pfnWglDeleteContext = mockWGLDeleteContext;
63-
64-
GLSetSharedOCLContextStateCalled = 0;
65-
GLAcquireSharedBufferCalled = 0;
66-
GLAcquireSharedRenderBufferCalled = 0;
67-
GLAcquireSharedTextureCalled = 0;
68-
GLReleaseSharedBufferCalled = 0;
69-
GLReleaseSharedRenderBufferCalled = 0;
70-
GLReleaseSharedTextureCalled = 0;
71-
GLGetCurrentContextCalled = 0;
72-
GLGetCurrentDisplayCalled = 0;
73-
GLMakeCurrentCalled = 0;
74-
GLDeleteContextCalled = 0;
75-
WGLCreateContextCalled = 0;
76-
WGLShareListsCalled = 0;
77-
WGLDeleteContextCalled = 0;
24+
GLSharingFunctions::initGLFunctions();
25+
glDllHelper dllParam;
26+
dllParam.setGLSetSharedOCLContextStateReturnedValue(1u);
27+
dllParam.resetParam("");
28+
dllParam.loadTexture({0});
29+
dllParam.loadBuffer({0});
7830
EGLChooseConfigCalled = 0;
7931
EGLCreateContextCalled = 0;
8032
EGLDeleteContextCalled = 0;
@@ -83,23 +35,15 @@ void GlSharingFunctionsMock::initMembers() {
8335
GlxCreateNewContextCalled = 0;
8436
GlxDeleteContextCalled = 0;
8537
GlxIsDirectCalled = 0;
86-
GLRetainSyncCalled = 0;
87-
GLReleaseSyncCalled = 0;
88-
GLGetSyncivCalled = 0;
89-
memset(&bufferInfoInput, 0, sizeof(CL_GL_BUFFER_INFO));
90-
memset(&bufferInfoOutput, 0, sizeof(CL_GL_BUFFER_INFO));
91-
memset(&textureInfoInput, 0, sizeof(CL_GL_RESOURCE_INFO));
92-
memset(&textureInfoOutput, 0, sizeof(CL_GL_RESOURCE_INFO));
9338
memset(&eglBkpContextParams, 0, sizeof(EGLBkpContextParams));
9439
memset(&glxBkpContextParams, 0, sizeof(GLXBkpContextParams));
95-
memset(&glMockReturnedValues, 0, sizeof(GLMockReturnedValues));
9640
}
9741

9842
GlSharingFunctionsMock::GlSharingFunctionsMock() {
9943
initMembers();
10044
}
10145

10246
MockGlSharing::MockGlSharing(GLType glhdcType, GLContext glhglrcHandle, GLContext glhglrcHandleBkpCtx, GLDisplay glhdcHandle) {
103-
m_sharingFunctions.setHandles(glhdcType, glhglrcHandle, glhglrcHandleBkpCtx, glhdcHandle);
47+
sharingFunctions->setHandles(glhdcType, glhglrcHandle, glhglrcHandleBkpCtx, glhdcHandle);
10448
}
10549
} // namespace OCLRT

0 commit comments

Comments
 (0)