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&)
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 return m_eglVersion >= EGL_MAKE_VERSION(1, 4);
263 // With Android Q, EGL 1.5 entry points must have valid
265 return m_eglVersion >= EGL_MAKE_VERSION(1, 5);
269 renderableType = RenderableType(m_apiType);
272 return (eglu::getRenderableAPIsMask(m_eglTestCtx.getLibrary(), m_display) & renderableType) == renderableType;
275 FunctionNames getCoreFunctionNames (EGLint apiType)
279 case EGL14: return FunctionNames(DE_LENGTH_OF_ARRAY(s_EGL14), s_EGL14);
280 case EGL15: return FunctionNames(DE_LENGTH_OF_ARRAY(s_EGL15), s_EGL15);
281 case GLES : return FunctionNames(DE_LENGTH_OF_ARRAY(s_GLES10), s_GLES10);
282 case GLES2: return FunctionNames(DE_LENGTH_OF_ARRAY(s_GLES20), s_GLES20);
283 case GLES3: return FunctionNames(DE_LENGTH_OF_ARRAY(s_GLES30), s_GLES30);
288 return FunctionNames(0, DE_NULL);
291 void executeTest (void)
293 TestLog& log = m_testCtx.getLog();
294 const bool funcPtrSupported = isSupported("EGL_KHR_get_all_proc_addresses");
295 const bool apiSupported = isApiSupported();
296 const FunctionNames funcNames = getCoreFunctionNames(m_apiType);
298 log << TestLog::Message << "EGL_KHR_get_all_proc_addresses: " << (funcPtrSupported ? "supported" : "not supported") << TestLog::EndMessage;
299 log << TestLog::Message << TestLog::EndMessage;
306 log << TestLog::Message << " EGL not supported by any available configuration." << TestLog::EndMessage;
309 log << TestLog::Message << " EGL 1.5 not supported by any available configuration." << TestLog::EndMessage;
314 log << TestLog::Message << eglu::getConfigAttribValueStr(EGL_RENDERABLE_TYPE, RenderableType(m_apiType)) << " not supported by any available configuration." << TestLog::EndMessage;
317 log << TestLog::Message << TestLog::EndMessage;
320 for (int funcNdx = 0; funcNdx < funcNames.numFunctions; funcNdx++)
322 const char* funcName = funcNames.functions[funcNdx];
323 void (*funcPtr)(void);
325 funcPtr = eglGetProcAddress(funcName);
326 eglu::checkError(eglGetError(), "eglGetProcAddress()", __FILE__, __LINE__);
328 if (apiSupported && funcPtrSupported && (funcPtr == 0))
330 log << TestLog::Message << "Fail, received null pointer for supported function: " << funcName << TestLog::EndMessage;
331 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Unexpected null pointer");
333 else if (!apiSupported && (funcPtr != 0))
335 log << TestLog::Message << "Warning, received non-null value for unsupported function: " << funcName << TestLog::EndMessage;
336 m_testCtx.setTestResult(QP_TEST_RESULT_QUALITY_WARNING, "Non-null value for unsupported function");
342 const ApiType m_apiType;
345 GetProcAddressTests::GetProcAddressTests (EglTestContext& eglTestCtx)
346 : TestCaseGroup(eglTestCtx, "get_proc_address", "eglGetProcAddress() tests")
350 GetProcAddressTests::~GetProcAddressTests (void)
354 void GetProcAddressTests::init (void)
358 tcu::TestCaseGroup* extensionsGroup = new tcu::TestCaseGroup(m_testCtx, "extension", "Test EGL extensions");
359 addChild(extensionsGroup);
361 for (int extNdx = 0; extNdx < DE_LENGTH_OF_ARRAY(s_extensions); extNdx++)
363 const std::string& extName = s_extensions[extNdx].name;
364 std::string testName (extName);
366 for (size_t ndx = 0; ndx < extName.length(); ndx++)
367 testName[ndx] = de::toLower(extName[ndx]);
369 extensionsGroup->addChild(new GetProcAddressExtensionCase(m_eglTestCtx, testName.c_str(), ("Test " + extName).c_str(), extName));
375 tcu::TestCaseGroup* coreFuncGroup = new tcu::TestCaseGroup(m_testCtx, "core", "Test core functions");
376 addChild(coreFuncGroup);
378 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase (m_eglTestCtx, "egl", "Test EGL core functions", GetProcAddressCoreFunctionsCase::EGL14));
380 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase (m_eglTestCtx, "egl15", "Test EGL 1.5 functions", GetProcAddressCoreFunctionsCase::EGL15));
381 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase (m_eglTestCtx, "gles", "Test OpenGL ES core functions", GetProcAddressCoreFunctionsCase::GLES));
382 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase (m_eglTestCtx, "gles2", "Test OpenGL ES 2 core functions", GetProcAddressCoreFunctionsCase::GLES2));
383 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase (m_eglTestCtx, "gles3", "Test OpenGL ES 3 core functions", GetProcAddressCoreFunctionsCase::GLES3));