1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program EGL Module
3 * ---------------------------------------
4 *
5 * Copyright 2014 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief Extension function pointer query tests.
22 *//*--------------------------------------------------------------------*/
23
24 #include "teglGetProcAddressTests.hpp"
25 #include "teglTestCase.hpp"
26 #include "egluCallLogWrapper.hpp"
27 #include "egluStrUtil.hpp"
28 #include "egluUtil.hpp"
29 #include "eglwLibrary.hpp"
30 #include "eglwEnums.hpp"
31 #include "tcuTestLog.hpp"
32 #include "deSTLUtil.hpp"
33 #include "deStringUtil.hpp"
34
35 namespace deqp
36 {
37 namespace egl
38 {
39
40 namespace
41 {
42
43 #define EGL_MAKE_VERSION(major, minor) (((major) << 12) | (minor))
44
45 using tcu::TestLog;
46 using namespace eglw;
47
48 // Function name strings generated from API headers
49
50 #include "teglGetProcAddressTests.inl"
51
52 struct FunctionNames
53 {
54 int numFunctions;
55 const char *const *functions;
56
FunctionNamesdeqp::egl::__anon71ac69b90111::FunctionNames57 FunctionNames(int numFunctions_, const char *const *functions_) : numFunctions(numFunctions_), functions(functions_)
58 {
59 }
60 };
61
getExtFunctionNames(const std::string & extName)62 FunctionNames getExtFunctionNames(const std::string &extName)
63 {
64 for (int ndx = 0; ndx <= DE_LENGTH_OF_ARRAY(s_extensions); ndx++)
65 {
66 if (extName == s_extensions[ndx].name)
67 return FunctionNames(s_extensions[ndx].numFunctions, s_extensions[ndx].functions);
68 }
69
70 DE_ASSERT(false);
71 return FunctionNames(0, DE_NULL);
72 }
73
74 } // namespace
75
76 // Base class for eglGetProcAddress() test cases
77
78 class GetProcAddressCase : public TestCase, protected eglu::CallLogWrapper
79 {
80 public:
81 GetProcAddressCase(EglTestContext &eglTestCtx, const char *name, const char *description);
82 virtual ~GetProcAddressCase(void);
83
84 void init(void);
85 void deinit(void);
86 IterateResult iterate(void);
87
88 bool isSupported(const std::string &extName);
89
90 virtual void executeTest(void) = 0;
91
92 protected:
93 EGLDisplay m_display;
94 int m_eglVersion;
95
96 private:
97 std::vector<std::string> m_supported;
98 };
99
GetProcAddressCase(EglTestContext & eglTestCtx,const char * name,const char * description)100 GetProcAddressCase::GetProcAddressCase(EglTestContext &eglTestCtx, const char *name, const char *description)
101 : TestCase(eglTestCtx, name, description)
102 , CallLogWrapper(eglTestCtx.getLibrary(), eglTestCtx.getTestContext().getLog())
103 , m_display(EGL_NO_DISPLAY)
104 {
105 }
106
~GetProcAddressCase(void)107 GetProcAddressCase::~GetProcAddressCase(void)
108 {
109 }
110
init(void)111 void GetProcAddressCase::init(void)
112 {
113 try
114 {
115 m_supported = eglu::getClientExtensions(m_eglTestCtx.getLibrary());
116 }
117 catch (const tcu::NotSupportedError &)
118 {
119 // Ignore case where EGL client extensions are not supported
120 // that's okay for these tests.
121 }
122
123 DE_ASSERT(m_display == EGL_NO_DISPLAY);
124
125 m_display = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
126
127 // The EGL_VERSION string is laid out as follows:
128 // major_version.minor_version space vendor_specific_info
129 // Split version from vendor_specific_info
130 std::vector<std::string> tokens = de::splitString(eglQueryString(m_display, EGL_VERSION), ' ');
131 // split version into major & minor
132 std::vector<std::string> values = de::splitString(tokens[0], '.');
133 m_eglVersion = EGL_MAKE_VERSION(atoi(values[0].c_str()), atoi(values[1].c_str()));
134
135 {
136 const std::vector<std::string> displayExtensios =
137 eglu::getDisplayExtensions(m_eglTestCtx.getLibrary(), m_display);
138 m_supported.insert(m_supported.end(), displayExtensios.begin(), displayExtensios.end());
139 }
140
141 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
142 }
143
deinit(void)144 void GetProcAddressCase::deinit(void)
145 {
146 m_eglTestCtx.getLibrary().terminate(m_display);
147 m_display = EGL_NO_DISPLAY;
148 }
149
iterate(void)150 tcu::TestNode::IterateResult GetProcAddressCase::iterate(void)
151 {
152 enableLogging(true);
153
154 executeTest();
155
156 enableLogging(false);
157
158 return STOP;
159 }
160
isSupported(const std::string & extName)161 bool GetProcAddressCase::isSupported(const std::string &extName)
162 {
163 return de::contains(m_supported.begin(), m_supported.end(), extName);
164 }
165
166 // Test by extension
167
168 class GetProcAddressExtensionCase : public GetProcAddressCase
169 {
170 public:
GetProcAddressExtensionCase(EglTestContext & eglTestCtx,const char * name,const char * description,const std::string & extName)171 GetProcAddressExtensionCase(EglTestContext &eglTestCtx, const char *name, const char *description,
172 const std::string &extName)
173 : GetProcAddressCase(eglTestCtx, name, description)
174 , m_extName(extName)
175 {
176 }
177
~GetProcAddressExtensionCase(void)178 virtual ~GetProcAddressExtensionCase(void)
179 {
180 }
181
executeTest(void)182 void executeTest(void)
183 {
184 TestLog &log = m_testCtx.getLog();
185 bool supported = isSupported(m_extName);
186 const FunctionNames funcNames = getExtFunctionNames(m_extName);
187
188 DE_ASSERT(funcNames.numFunctions > 0);
189
190 log << TestLog::Message << m_extName << ": " << (supported ? "supported" : "not supported")
191 << TestLog::EndMessage;
192 log << TestLog::Message << TestLog::EndMessage;
193
194 for (int funcNdx = 0; funcNdx < funcNames.numFunctions; funcNdx++)
195 {
196 const char *funcName = funcNames.functions[funcNdx];
197 void (*funcPtr)(void);
198
199 funcPtr = eglGetProcAddress(funcName);
200 eglu::checkError(eglGetError(), "eglGetProcAddress()", __FILE__, __LINE__);
201
202 if (supported && funcPtr == 0)
203 {
204 log << TestLog::Message << "Fail, received null pointer for supported extension function: " << funcName
205 << TestLog::EndMessage;
206 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Unexpected null pointer");
207 }
208 }
209 }
210
211 private:
212 std::string m_extName;
213 };
214
215 // Test core functions
216
217 class GetProcAddressCoreFunctionsCase : public GetProcAddressCase
218 {
219 public:
220 enum ApiType
221 {
222 EGL14,
223 EGL15,
224 GLES,
225 GLES2,
226 GLES3
227 };
228
GetProcAddressCoreFunctionsCase(EglTestContext & eglTestCtx,const char * name,const char * description,const ApiType apiType)229 GetProcAddressCoreFunctionsCase(EglTestContext &eglTestCtx, const char *name, const char *description,
230 const ApiType apiType)
231 : GetProcAddressCase(eglTestCtx, name, description)
232 , m_apiType(apiType)
233 {
234 }
235
~GetProcAddressCoreFunctionsCase(void)236 virtual ~GetProcAddressCoreFunctionsCase(void)
237 {
238 }
239
RenderableType(ApiType type)240 EGLint RenderableType(ApiType type)
241 {
242 EGLint renderableType = EGL_OPENGL_ES_BIT;
243 switch (type)
244 {
245 case EGL14:
246 case EGL15:
247 case GLES:
248 renderableType = EGL_OPENGL_ES_BIT;
249 break;
250 case GLES2:
251 renderableType = EGL_OPENGL_ES2_BIT;
252 break;
253 case GLES3:
254 renderableType = EGL_OPENGL_ES3_BIT_KHR;
255 break;
256 }
257 return renderableType;
258 }
259
isApiSupported(void)260 bool isApiSupported(void)
261 {
262 EGLint renderableType = EGL_OPENGL_ES_BIT;
263 switch (m_apiType)
264 {
265 case EGL14:
266 return m_eglVersion >= EGL_MAKE_VERSION(1, 4);
267 case EGL15:
268 // With Android Q, EGL 1.5 entry points must have valid
269 // GetProcAddress.
270 return m_eglVersion >= EGL_MAKE_VERSION(1, 5);
271 case GLES:
272 case GLES2:
273 case GLES3:
274 renderableType = RenderableType(m_apiType);
275 break;
276 }
277 return (eglu::getRenderableAPIsMask(m_eglTestCtx.getLibrary(), m_display) & renderableType) == renderableType;
278 }
279
getCoreFunctionNames(EGLint apiType)280 FunctionNames getCoreFunctionNames(EGLint apiType)
281 {
282 switch (apiType)
283 {
284 case EGL14:
285 return FunctionNames(DE_LENGTH_OF_ARRAY(s_EGL14), s_EGL14);
286 case EGL15:
287 return FunctionNames(DE_LENGTH_OF_ARRAY(s_EGL15), s_EGL15);
288 case GLES:
289 return FunctionNames(DE_LENGTH_OF_ARRAY(s_GLES10), s_GLES10);
290 case GLES2:
291 return FunctionNames(DE_LENGTH_OF_ARRAY(s_GLES20), s_GLES20);
292 case GLES3:
293 return FunctionNames(DE_LENGTH_OF_ARRAY(s_GLES30), s_GLES30);
294 default:
295 DE_ASSERT(false);
296 }
297
298 return FunctionNames(0, DE_NULL);
299 }
300
executeTest(void)301 void executeTest(void)
302 {
303 TestLog &log = m_testCtx.getLog();
304 const bool funcPtrSupported = isSupported("EGL_KHR_get_all_proc_addresses");
305 const bool apiSupported = isApiSupported();
306 const FunctionNames funcNames = getCoreFunctionNames(m_apiType);
307
308 log << TestLog::Message
309 << "EGL_KHR_get_all_proc_addresses: " << (funcPtrSupported ? "supported" : "not supported")
310 << TestLog::EndMessage;
311 log << TestLog::Message << TestLog::EndMessage;
312
313 if (!apiSupported)
314 {
315 switch (m_apiType)
316 {
317 case EGL14:
318 log << TestLog::Message << " EGL not supported by any available configuration." << TestLog::EndMessage;
319 break;
320 case EGL15:
321 log << TestLog::Message << " EGL 1.5 not supported by any available configuration."
322 << TestLog::EndMessage;
323 break;
324 case GLES:
325 case GLES2:
326 case GLES3:
327 log << TestLog::Message << eglu::getConfigAttribValueStr(EGL_RENDERABLE_TYPE, RenderableType(m_apiType))
328 << " not supported by any available configuration." << TestLog::EndMessage;
329 break;
330 }
331 log << TestLog::Message << TestLog::EndMessage;
332 }
333
334 for (int funcNdx = 0; funcNdx < funcNames.numFunctions; funcNdx++)
335 {
336 const char *funcName = funcNames.functions[funcNdx];
337 void (*funcPtr)(void);
338
339 funcPtr = eglGetProcAddress(funcName);
340 eglu::checkError(eglGetError(), "eglGetProcAddress()", __FILE__, __LINE__);
341
342 if (apiSupported && funcPtrSupported && (funcPtr == 0))
343 {
344 log << TestLog::Message << "Fail, received null pointer for supported function: " << funcName
345 << TestLog::EndMessage;
346 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Unexpected null pointer");
347 }
348 else if (!apiSupported && (funcPtr != 0))
349 {
350 log << TestLog::Message << "Warning, received non-null value for unsupported function: " << funcName
351 << TestLog::EndMessage;
352 m_testCtx.setTestResult(QP_TEST_RESULT_QUALITY_WARNING, "Non-null value for unsupported function");
353 }
354 }
355 }
356
357 private:
358 const ApiType m_apiType;
359 };
360
GetProcAddressTests(EglTestContext & eglTestCtx)361 GetProcAddressTests::GetProcAddressTests(EglTestContext &eglTestCtx)
362 : TestCaseGroup(eglTestCtx, "get_proc_address", "eglGetProcAddress() tests")
363 {
364 }
365
~GetProcAddressTests(void)366 GetProcAddressTests::~GetProcAddressTests(void)
367 {
368 }
369
init(void)370 void GetProcAddressTests::init(void)
371 {
372 // extensions
373 {
374 tcu::TestCaseGroup *extensionsGroup = new tcu::TestCaseGroup(m_testCtx, "extension", "Test EGL extensions");
375 addChild(extensionsGroup);
376
377 for (int extNdx = 0; extNdx < DE_LENGTH_OF_ARRAY(s_extensions); extNdx++)
378 {
379 const std::string &extName = s_extensions[extNdx].name;
380 std::string testName(extName);
381
382 for (size_t ndx = 0; ndx < extName.length(); ndx++)
383 testName[ndx] = de::toLower(extName[ndx]);
384
385 extensionsGroup->addChild(
386 new GetProcAddressExtensionCase(m_eglTestCtx, testName.c_str(), ("Test " + extName).c_str(), extName));
387 }
388 }
389
390 // core functions
391 {
392 tcu::TestCaseGroup *coreFuncGroup = new tcu::TestCaseGroup(m_testCtx, "core", "Test core functions");
393 addChild(coreFuncGroup);
394
395 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase(m_eglTestCtx, "egl", "Test EGL core functions",
396 GetProcAddressCoreFunctionsCase::EGL14));
397
398 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase(m_eglTestCtx, "egl15", "Test EGL 1.5 functions",
399 GetProcAddressCoreFunctionsCase::EGL15));
400 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase(
401 m_eglTestCtx, "gles", "Test OpenGL ES core functions", GetProcAddressCoreFunctionsCase::GLES));
402 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase(
403 m_eglTestCtx, "gles2", "Test OpenGL ES 2 core functions", GetProcAddressCoreFunctionsCase::GLES2));
404 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase(
405 m_eglTestCtx, "gles3", "Test OpenGL ES 3 core functions", GetProcAddressCoreFunctionsCase::GLES3));
406 }
407 }
408
409 } // namespace egl
410 } // namespace deqp
411