1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program EGL Module
3 * ---------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Extension function pointer query tests.
22 *//*--------------------------------------------------------------------*/
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"
43 #define EGL_MAKE_VERSION(major, minor) (((major) << 12) | (minor))
48 // Function name strings generated from API headers
50 #include "teglGetProcAddressTests.inl"
55 const char* const* functions;
57 FunctionNames (int numFunctions_, const char* const* functions_)
58 : numFunctions (numFunctions_)
59 , functions (functions_)
64 FunctionNames getExtFunctionNames (const std::string& extName)
66 for (int ndx = 0; ndx <= DE_LENGTH_OF_ARRAY(s_extensions); ndx++)
68 if (extName == s_extensions[ndx].name)
69 return FunctionNames(s_extensions[ndx].numFunctions, s_extensions[ndx].functions);
73 return FunctionNames(0, DE_NULL);
78 // Base class for eglGetProcAddress() test cases
80 class GetProcAddressCase : public TestCase, protected eglu::CallLogWrapper
83 GetProcAddressCase (EglTestContext& eglTestCtx, const char* name, const char* description);
84 virtual ~GetProcAddressCase (void);
88 IterateResult iterate (void);
90 bool isSupported (const std::string& extName);
92 virtual void executeTest (void) = 0;
99 std::vector<std::string> m_supported;
102 GetProcAddressCase::GetProcAddressCase (EglTestContext& eglTestCtx, const char* name, const char* description)
103 : TestCase (eglTestCtx, name, description)
104 , CallLogWrapper (eglTestCtx.getLibrary(), eglTestCtx.getTestContext().getLog())
105 , m_display (EGL_NO_DISPLAY)
109 GetProcAddressCase::~GetProcAddressCase (void)
113 void GetProcAddressCase::init (void)
117 m_supported = eglu::getClientExtensions(m_eglTestCtx.getLibrary());
119 catch (const tcu::NotSupportedError& error)
121 // Ignore case where EGL client extensions are not supported
122 // that's okay for these tests.
125 DE_ASSERT(m_display == EGL_NO_DISPLAY);
127 m_display = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
129 // The EGL_VERSION string is laid out as follows:
130 // major_version.minor_version space vendor_specific_info
131 // Split version from vendor_specific_info
132 std::vector<std::string> tokens = de::splitString(eglQueryString(m_display, EGL_VERSION), ' ');
133 // split version into major & minor
134 std::vector<std::string> values = de::splitString(tokens[0], '.');
135 m_eglVersion = EGL_MAKE_VERSION(atoi(values[0].c_str()), atoi(values[1].c_str()));
138 const std::vector<std::string> displayExtensios = eglu::getDisplayExtensions(m_eglTestCtx.getLibrary(), m_display);
139 m_supported.insert(m_supported.end(), displayExtensios.begin(), displayExtensios.end());
142 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
145 void GetProcAddressCase::deinit (void)
147 m_eglTestCtx.getLibrary().terminate(m_display);
148 m_display = EGL_NO_DISPLAY;
151 tcu::TestNode::IterateResult GetProcAddressCase::iterate (void)
157 enableLogging(false);
162 bool GetProcAddressCase::isSupported (const std::string& extName)
164 return de::contains(m_supported.begin(), m_supported.end(), extName);
169 class GetProcAddressExtensionCase : public GetProcAddressCase
172 GetProcAddressExtensionCase (EglTestContext& eglTestCtx, const char* name, const char* description, const std::string& extName)
173 : GetProcAddressCase (eglTestCtx, name, description)
174 , m_extName (extName)
178 virtual ~GetProcAddressExtensionCase (void)
182 void executeTest (void)
184 TestLog& log = m_testCtx.getLog();
185 bool supported = isSupported(m_extName);
186 const FunctionNames funcNames = getExtFunctionNames(m_extName);
188 DE_ASSERT(funcNames.numFunctions > 0);
190 log << TestLog::Message << m_extName << ": " << (supported ? "supported" : "not supported") << TestLog::EndMessage;
191 log << TestLog::Message << TestLog::EndMessage;
193 for (int funcNdx = 0; funcNdx < funcNames.numFunctions; funcNdx++)
195 const char* funcName = funcNames.functions[funcNdx];
196 void (*funcPtr)(void);
198 funcPtr = eglGetProcAddress(funcName);
199 eglu::checkError(eglGetError(), "eglGetProcAddress()", __FILE__, __LINE__);
201 if (supported && funcPtr == 0)
203 log << TestLog::Message << "Fail, received null pointer for supported extension function: " << funcName << TestLog::EndMessage;
204 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Unexpected null pointer");
210 std::string m_extName;
213 // Test core functions
215 class GetProcAddressCoreFunctionsCase : public GetProcAddressCase
227 GetProcAddressCoreFunctionsCase (EglTestContext& eglTestCtx, const char* name, const char* description, const ApiType apiType)
228 : GetProcAddressCase (eglTestCtx, name, description)
229 , m_apiType (apiType)
233 virtual ~GetProcAddressCoreFunctionsCase (void)
237 EGLint RenderableType (ApiType type)
239 EGLint renderableType = EGL_OPENGL_ES_BIT;
244 renderableType = EGL_OPENGL_ES_BIT;
247 renderableType = EGL_OPENGL_ES2_BIT;
250 renderableType = EGL_OPENGL_ES3_BIT_KHR;
253 return renderableType;
256 bool isApiSupported (void)
258 EGLint renderableType = EGL_OPENGL_ES_BIT;
261 if (m_eglVersion >= EGL_MAKE_VERSION(1, 4)) return true;
265 // With Android Q, EGL 1.5 entry points must have valid
267 if (m_eglVersion >= EGL_MAKE_VERSION(1, 5)) return true;
273 renderableType = RenderableType(m_apiType);
276 return (eglu::getRenderableAPIsMask(m_eglTestCtx.getLibrary(), m_display) & renderableType) == renderableType;
279 FunctionNames getCoreFunctionNames (EGLint apiType)
283 case EGL14: return FunctionNames(DE_LENGTH_OF_ARRAY(s_EGL14), s_EGL14);
284 case EGL15: return FunctionNames(DE_LENGTH_OF_ARRAY(s_EGL15), s_EGL15);
285 case GLES : return FunctionNames(DE_LENGTH_OF_ARRAY(s_GLES10), s_GLES10);
286 case GLES2: return FunctionNames(DE_LENGTH_OF_ARRAY(s_GLES20), s_GLES20);
287 case GLES3: return FunctionNames(DE_LENGTH_OF_ARRAY(s_GLES30), s_GLES30);
292 return FunctionNames(0, DE_NULL);
295 void executeTest (void)
297 TestLog& log = m_testCtx.getLog();
298 const bool funcPtrSupported = isSupported("EGL_KHR_get_all_proc_addresses");
299 const bool apiSupported = isApiSupported();
300 const FunctionNames funcNames = getCoreFunctionNames(m_apiType);
302 log << TestLog::Message << "EGL_KHR_get_all_proc_addresses: " << (funcPtrSupported ? "supported" : "not supported") << TestLog::EndMessage;
303 log << TestLog::Message << TestLog::EndMessage;
310 log << TestLog::Message << " EGL not supported by any available configuration." << TestLog::EndMessage;
313 log << TestLog::Message << " EGL 1.5 not supported by any available configuration." << TestLog::EndMessage;
318 log << TestLog::Message << eglu::getConfigAttribValueStr(EGL_RENDERABLE_TYPE, RenderableType(m_apiType)) << " not supported by any available configuration." << TestLog::EndMessage;
321 log << TestLog::Message << TestLog::EndMessage;
324 for (int funcNdx = 0; funcNdx < funcNames.numFunctions; funcNdx++)
326 const char* funcName = funcNames.functions[funcNdx];
327 void (*funcPtr)(void);
329 funcPtr = eglGetProcAddress(funcName);
330 eglu::checkError(eglGetError(), "eglGetProcAddress()", __FILE__, __LINE__);
332 if (apiSupported && funcPtrSupported && (funcPtr == 0))
334 log << TestLog::Message << "Fail, received null pointer for supported function: " << funcName << TestLog::EndMessage;
335 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Unexpected null pointer");
337 else if (!apiSupported && (funcPtr != 0))
339 log << TestLog::Message << "Warning, received non-null value for unsupported function: " << funcName << TestLog::EndMessage;
340 m_testCtx.setTestResult(QP_TEST_RESULT_QUALITY_WARNING, "Non-null value for unsupported function");
346 const ApiType m_apiType;
349 GetProcAddressTests::GetProcAddressTests (EglTestContext& eglTestCtx)
350 : TestCaseGroup(eglTestCtx, "get_proc_address", "eglGetProcAddress() tests")
354 GetProcAddressTests::~GetProcAddressTests (void)
358 void GetProcAddressTests::init (void)
362 tcu::TestCaseGroup* extensionsGroup = new tcu::TestCaseGroup(m_testCtx, "extension", "Test EGL extensions");
363 addChild(extensionsGroup);
365 for (int extNdx = 0; extNdx < DE_LENGTH_OF_ARRAY(s_extensions); extNdx++)
367 const std::string& extName = s_extensions[extNdx].name;
368 std::string testName (extName);
370 for (size_t ndx = 0; ndx < extName.length(); ndx++)
371 testName[ndx] = de::toLower(extName[ndx]);
373 extensionsGroup->addChild(new GetProcAddressExtensionCase(m_eglTestCtx, testName.c_str(), ("Test " + extName).c_str(), extName));
379 tcu::TestCaseGroup* coreFuncGroup = new tcu::TestCaseGroup(m_testCtx, "core", "Test core functions");
380 addChild(coreFuncGroup);
382 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase (m_eglTestCtx, "egl", "Test EGL core functions", GetProcAddressCoreFunctionsCase::EGL14));
384 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase (m_eglTestCtx, "egl15", "Test EGL 1.5 functions", GetProcAddressCoreFunctionsCase::EGL15));
385 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase (m_eglTestCtx, "gles", "Test OpenGL ES core functions", GetProcAddressCoreFunctionsCase::GLES));
386 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase (m_eglTestCtx, "gles2", "Test OpenGL ES 2 core functions", GetProcAddressCoreFunctionsCase::GLES2));
387 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase (m_eglTestCtx, "gles3", "Test OpenGL ES 3 core functions", GetProcAddressCoreFunctionsCase::GLES3));