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"
46 // Function name strings generated from API headers
48 #include "teglGetProcAddressTests.inl"
53 const char* const* functions;
55 FunctionNames (int numFunctions_, const char* const* functions_)
56 : numFunctions (numFunctions_)
57 , functions (functions_)
62 FunctionNames getExtFunctionNames (const std::string& extName)
64 for (int ndx = 0; ndx <= DE_LENGTH_OF_ARRAY(s_extensions); ndx++)
66 if (extName == s_extensions[ndx].name)
67 return FunctionNames(s_extensions[ndx].numFunctions, s_extensions[ndx].functions);
71 return FunctionNames(0, DE_NULL);
74 FunctionNames getCoreFunctionNames (EGLint apiBit)
78 case 0: return FunctionNames(DE_LENGTH_OF_ARRAY(s_EGL14), s_EGL14);
79 case EGL_OPENGL_ES_BIT: return FunctionNames(DE_LENGTH_OF_ARRAY(s_GLES10), s_GLES10);
80 case EGL_OPENGL_ES2_BIT: return FunctionNames(DE_LENGTH_OF_ARRAY(s_GLES20), s_GLES20);
81 case EGL_OPENGL_ES3_BIT_KHR: return FunctionNames(DE_LENGTH_OF_ARRAY(s_GLES30), s_GLES30);
86 return FunctionNames(0, DE_NULL);
91 // Base class for eglGetProcAddress() test cases
93 class GetProcAddressCase : public TestCase, protected eglu::CallLogWrapper
96 GetProcAddressCase (EglTestContext& eglTestCtx, const char* name, const char* description);
97 virtual ~GetProcAddressCase (void);
101 IterateResult iterate (void);
103 bool isSupported (const std::string& extName);
105 virtual void executeTest (void) = 0;
108 EGLDisplay m_display;
111 std::vector<std::string> m_supported;
114 GetProcAddressCase::GetProcAddressCase (EglTestContext& eglTestCtx, const char* name, const char* description)
115 : TestCase (eglTestCtx, name, description)
116 , CallLogWrapper (eglTestCtx.getLibrary(), eglTestCtx.getTestContext().getLog())
117 , m_display (EGL_NO_DISPLAY)
121 GetProcAddressCase::~GetProcAddressCase (void)
125 void GetProcAddressCase::init (void)
129 m_supported = eglu::getClientExtensions(m_eglTestCtx.getLibrary());
131 catch (const eglu::Error& error)
133 // EGL_BAD_DISPLAY is generated if client extensions are not supported.
134 if (error.getError() != EGL_BAD_DISPLAY)
138 DE_ASSERT(m_display == EGL_NO_DISPLAY);
140 m_display = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
143 const std::vector<std::string> displayExtensios = eglu::getDisplayExtensions(m_eglTestCtx.getLibrary(), m_display);
144 m_supported.insert(m_supported.end(), displayExtensios.begin(), displayExtensios.end());
147 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
150 void GetProcAddressCase::deinit (void)
152 m_eglTestCtx.getLibrary().terminate(m_display);
153 m_display = EGL_NO_DISPLAY;
156 tcu::TestNode::IterateResult GetProcAddressCase::iterate (void)
162 enableLogging(false);
167 bool GetProcAddressCase::isSupported (const std::string& extName)
169 return de::contains(m_supported.begin(), m_supported.end(), extName);
174 class GetProcAddressExtensionCase : public GetProcAddressCase
177 GetProcAddressExtensionCase (EglTestContext& eglTestCtx, const char* name, const char* description, const std::string& extName)
178 : GetProcAddressCase (eglTestCtx, name, description)
179 , m_extName (extName)
183 virtual ~GetProcAddressExtensionCase (void)
187 void executeTest (void)
189 TestLog& log = m_testCtx.getLog();
190 bool supported = isSupported(m_extName);
191 const FunctionNames funcNames = getExtFunctionNames(m_extName);
193 DE_ASSERT(funcNames.numFunctions > 0);
195 log << TestLog::Message << m_extName << ": " << (supported ? "supported" : "not supported") << TestLog::EndMessage;
196 log << TestLog::Message << TestLog::EndMessage;
198 for (int funcNdx = 0; funcNdx < funcNames.numFunctions; funcNdx++)
200 const char* funcName = funcNames.functions[funcNdx];
201 void (*funcPtr)(void);
203 funcPtr = eglGetProcAddress(funcName);
204 eglu::checkError(eglGetError(), "eglGetProcAddress()", __FILE__, __LINE__);
206 if (supported && funcPtr == 0)
208 log << TestLog::Message << "Fail, received null pointer for supported extension function: " << funcName << TestLog::EndMessage;
209 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Unexpected null pointer");
215 std::string m_extName;
218 // Test core functions
220 class GetProcAddressCoreFunctionsCase : public GetProcAddressCase
223 GetProcAddressCoreFunctionsCase (EglTestContext& eglTestCtx, const char* name, const char* description, const EGLint apiBit)
224 : GetProcAddressCase (eglTestCtx, name, description)
229 virtual ~GetProcAddressCoreFunctionsCase (void)
233 void executeTest (void)
235 TestLog& log = m_testCtx.getLog();
236 const bool funcPtrSupported = isSupported("EGL_KHR_get_all_proc_addresses");
237 const bool apiSupported = (eglu::getRenderableAPIsMask(m_eglTestCtx.getLibrary(), m_display) & m_apiBit) == m_apiBit;
238 const FunctionNames funcNames = getCoreFunctionNames(m_apiBit);
240 log << TestLog::Message << "EGL_KHR_get_all_proc_addresses: " << (funcPtrSupported ? "supported" : "not supported") << TestLog::EndMessage;
241 log << TestLog::Message << TestLog::EndMessage;
245 log << TestLog::Message << eglu::getConfigAttribValueStr(EGL_RENDERABLE_TYPE, m_apiBit) << " not supported by any available configuration." << TestLog::EndMessage;
246 log << TestLog::Message << TestLog::EndMessage;
249 for (int funcNdx = 0; funcNdx < funcNames.numFunctions; funcNdx++)
251 const char* funcName = funcNames.functions[funcNdx];
252 void (*funcPtr)(void);
254 funcPtr = eglGetProcAddress(funcName);
255 eglu::checkError(eglGetError(), "eglGetProcAddress()", __FILE__, __LINE__);
257 if (apiSupported && funcPtrSupported && (funcPtr == 0))
259 log << TestLog::Message << "Fail, received null pointer for supported function: " << funcName << TestLog::EndMessage;
260 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Unexpected null pointer");
262 else if (!apiSupported && (funcPtr != 0))
264 log << TestLog::Message << "Warning, received non-null value for unsupported function: " << funcName << TestLog::EndMessage;
265 m_testCtx.setTestResult(QP_TEST_RESULT_QUALITY_WARNING, "Non-null value for unsupported function");
271 const EGLint m_apiBit;
274 GetProcAddressTests::GetProcAddressTests (EglTestContext& eglTestCtx)
275 : TestCaseGroup(eglTestCtx, "get_proc_address", "eglGetProcAddress() tests")
279 GetProcAddressTests::~GetProcAddressTests (void)
283 void GetProcAddressTests::init (void)
287 tcu::TestCaseGroup* extensionsGroup = new tcu::TestCaseGroup(m_testCtx, "extension", "Test EGL extensions");
288 addChild(extensionsGroup);
290 for (int extNdx = 0; extNdx < DE_LENGTH_OF_ARRAY(s_extensions); extNdx++)
292 const std::string& extName = s_extensions[extNdx].name;
293 std::string testName (extName);
295 for (size_t ndx = 0; ndx < extName.length(); ndx++)
296 testName[ndx] = de::toLower(extName[ndx]);
298 extensionsGroup->addChild(new GetProcAddressExtensionCase(m_eglTestCtx, testName.c_str(), ("Test " + extName).c_str(), extName));
304 tcu::TestCaseGroup* coreFuncGroup = new tcu::TestCaseGroup(m_testCtx, "core", "Test core functions");
305 addChild(coreFuncGroup);
307 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase (m_eglTestCtx, "egl", "Test EGL core functions", 0));
308 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase (m_eglTestCtx, "gles", "Test OpenGL ES core functions", EGL_OPENGL_ES_BIT));
309 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase (m_eglTestCtx, "gles2", "Test OpenGL ES 2 core functions", EGL_OPENGL_ES2_BIT));
310 coreFuncGroup->addChild(new GetProcAddressCoreFunctionsCase (m_eglTestCtx, "gles3", "Test OpenGL ES 3 core functions", EGL_OPENGL_ES3_BIT_KHR));