Debian Codegraph @

opencl/test/unit_test/sharings/gl/windows/gl_sharing_enable_tests.cpp

raw
1 /*
2 * Copyright (C) 2018-2021 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #include "shared/test/common/fixtures/memory_management_fixture.h"
9
10 #include "opencl/source/sharings/gl/windows/win_enable_gl.h"
11 #include "opencl/test/unit_test/mocks/mock_context.h"
12
13 #include "gtest/gtest.h"
14
15 using namespace NEO;
16
17 class GlSharingEnablerTests : public ::testing::Test {
18 public:
19 void SetUp() override {
20 factory.reset(new GlSharingBuilderFactory());
21 ASSERT_NE(nullptr, factory.get());
22 }
23
24 std::unique_ptr<GlSharingBuilderFactory> factory;
25 };
26
27 TEST_F(GlSharingEnablerTests, givenGlFactoryWhenAskedThenExtensionsAreReturned) {
28 auto ext = factory->getExtensions(nullptr);
29 EXPECT_GT(ext.length(), 0u);
30 EXPECT_STRNE("", ext.c_str());
31 }
32
33 TEST_F(GlSharingEnablerTests, givenGlFactoryWhenAskedThenGlobalIcdIsConfigured) {
34 class IcdRestore {
35 public:
36 IcdRestore() { icdSnapshot = icdGlobalDispatchTable; }
37 ~IcdRestore() { icdGlobalDispatchTable = icdSnapshot; }
38 decltype(icdGlobalDispatchTable) icdSnapshot;
39 };
40 // we play with global table, so first save state then restore it with use of RAII
41 IcdRestore icdRestore;
42 // clear ICD table
43 icdGlobalDispatchTable.clCreateFromGLBuffer = nullptr;
44 icdGlobalDispatchTable.clCreateFromGLTexture = nullptr;
45 icdGlobalDispatchTable.clCreateFromGLTexture2D = nullptr;
46 icdGlobalDispatchTable.clCreateFromGLTexture3D = nullptr;
47 icdGlobalDispatchTable.clCreateFromGLRenderbuffer = nullptr;
48 icdGlobalDispatchTable.clGetGLObjectInfo = nullptr;
49 icdGlobalDispatchTable.clGetGLTextureInfo = nullptr;
50 icdGlobalDispatchTable.clEnqueueAcquireGLObjects = nullptr;
51 icdGlobalDispatchTable.clEnqueueReleaseGLObjects = nullptr;
52 icdGlobalDispatchTable.clCreateEventFromGLsyncKHR = nullptr;
53 icdGlobalDispatchTable.clGetGLContextInfoKHR = nullptr;
54
55 factory->fillGlobalDispatchTable();
56 EXPECT_NE(nullptr, icdGlobalDispatchTable.clCreateFromGLBuffer);
57 EXPECT_NE(nullptr, icdGlobalDispatchTable.clCreateFromGLTexture);
58 EXPECT_NE(nullptr, icdGlobalDispatchTable.clCreateFromGLTexture2D);
59 EXPECT_NE(nullptr, icdGlobalDispatchTable.clCreateFromGLTexture3D);
60 EXPECT_NE(nullptr, icdGlobalDispatchTable.clCreateFromGLRenderbuffer);
61 EXPECT_NE(nullptr, icdGlobalDispatchTable.clGetGLObjectInfo);
62 EXPECT_NE(nullptr, icdGlobalDispatchTable.clGetGLTextureInfo);
63 EXPECT_NE(nullptr, icdGlobalDispatchTable.clEnqueueAcquireGLObjects);
64 EXPECT_NE(nullptr, icdGlobalDispatchTable.clEnqueueReleaseGLObjects);
65 EXPECT_NE(nullptr, icdGlobalDispatchTable.clCreateEventFromGLsyncKHR);
66 EXPECT_NE(nullptr, icdGlobalDispatchTable.clGetGLContextInfoKHR);
67 }
68
69 TEST_F(GlSharingEnablerTests, givenGlFactoryWhenAskedThenBuilderIsCreated) {
70 auto builder = factory->createContextBuilder();
71 EXPECT_NE(nullptr, builder);
72 }
73
74 TEST_F(GlSharingEnablerTests, givenGlBuilderWhenUnknownPropertyThenFalseIsReturned) {
75 auto builder = factory->createContextBuilder();
76 ASSERT_NE(nullptr, builder);
77
78 cl_context_properties property = CL_CONTEXT_PLATFORM;
79 cl_context_properties value;
80 auto res = builder->processProperties(property, value);
81 EXPECT_FALSE(res);
82 }
83
84 TEST_F(GlSharingEnablerTests, givenGlBuilderWhenInvalidPropertyThenFalseIsReturned) {
85 auto builder = factory->createContextBuilder();
86 ASSERT_NE(nullptr, builder);
87
88 cl_context_properties property = CL_CGL_SHAREGROUP_KHR;
89 cl_context_properties value;
90 auto res = builder->processProperties(property, value);
91 EXPECT_FALSE(res);
92 }
93
94 TEST_F(GlSharingEnablerTests, givenGlBuilderWhenValidPropertyThenTrueIsReturned) {
95 cl_context_properties props[] = {CL_GL_CONTEXT_KHR, CL_WGL_HDC_KHR, CL_GLX_DISPLAY_KHR, CL_EGL_DISPLAY_KHR};
96 for (auto currProperty : props) {
97 auto builder = factory->createContextBuilder();
98 ASSERT_NE(nullptr, builder);
99
100 cl_context_properties property = currProperty;
101 cl_context_properties value = 0x10000;
102 auto res = builder->processProperties(property, value);
103 EXPECT_TRUE(res);
104
105 // repeat to check if we don't allocate twice
106 auto prevAllocations = MemoryManagement::numAllocations.load();
107 res = builder->processProperties(property, value);
108 EXPECT_TRUE(res);
109 auto currAllocations = MemoryManagement::numAllocations.load();
110 EXPECT_EQ(prevAllocations, currAllocations);
111 }
112 }
113
114 TEST_F(GlSharingEnablerTests, givenGlBuilderWhenNoPropertiesThenFinalizerReturnsTrue) {
115 auto builder = factory->createContextBuilder();
116 ASSERT_NE(nullptr, builder);
117
118 MockContext context;
119 int32_t errcodeRet = CL_SUCCESS;
120 auto res = builder->finalizeProperties(context, errcodeRet);
121 EXPECT_TRUE(res);
122 EXPECT_EQ(CL_SUCCESS, errcodeRet);
123 }
124
125 TEST_F(GlSharingEnablerTests, givenGlBuilderWhenInvalidPropertiesThenFinalizerReturnsTrue) {
126 auto builder = factory->createContextBuilder();
127 ASSERT_NE(nullptr, builder);
128
129 cl_context_properties property = CL_CONTEXT_PLATFORM;
130 cl_context_properties value;
131 auto res = builder->processProperties(property, value);
132 EXPECT_FALSE(res);
133
134 MockContext context;
135 int32_t errcodeRet = CL_SUCCESS;
136 res = builder->finalizeProperties(context, errcodeRet);
137 EXPECT_TRUE(res);
138 EXPECT_EQ(CL_SUCCESS, errcodeRet);
139 }
140
141 TEST_F(GlSharingEnablerTests, givenGlBuilderWhenNullHandleThenFinalizerReturnsTrueAndNoSharingRegistered) {
142 auto builder = factory->createContextBuilder();
143 ASSERT_NE(nullptr, builder);
144
145 cl_context_properties property = CL_GL_CONTEXT_KHR;
146 cl_context_properties value = 0x0;
147 auto res = builder->processProperties(property, value);
148 EXPECT_TRUE(res);
149
150 MockContext context;
151 int32_t errcodeRet = CL_SUCCESS;
152 res = builder->finalizeProperties(context, errcodeRet);
153 EXPECT_TRUE(res);
154 EXPECT_EQ(CL_SUCCESS, errcodeRet);
155
156 auto sharing = context.getSharing<GLSharingFunctions>();
157 EXPECT_EQ(nullptr, sharing);
158 }
159
160 TEST_F(GlSharingEnablerTests, givenGlBuilderWhenHandleThenFinalizerReturnsTrueAndSharingIsRegistered) {
161 auto builder = factory->createContextBuilder();
162 ASSERT_NE(nullptr, builder);
163
164 cl_context_properties property = CL_GL_CONTEXT_KHR;
165 cl_context_properties value = 0x1000;
166 auto res = builder->processProperties(property, value);
167 EXPECT_TRUE(res);
168
169 MockContext context;
170 int32_t errcodeRet = CL_SUCCESS;
171 res = builder->finalizeProperties(context, errcodeRet);
172 EXPECT_TRUE(res);
173 EXPECT_EQ(CL_SUCCESS, errcodeRet);
174
175 auto sharing = context.getSharing<GLSharingFunctions>();
176 EXPECT_NE(nullptr, sharing);
177 }