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 Simple Context construction test.
22 *//*--------------------------------------------------------------------*/
24 #include "teglCreateContextTests.hpp"
25 #include "teglSimpleConfigCase.hpp"
26 #include "egluStrUtil.hpp"
27 #include "egluUtil.hpp"
28 #include "egluUnique.hpp"
29 #include "eglwLibrary.hpp"
30 #include "eglwEnums.hpp"
31 #include "tcuTestLog.hpp"
32 #include "deSTLUtil.hpp"
43 static const EGLint s_es1Attrs[] = { EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE };
44 static const EGLint s_es2Attrs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
45 static const EGLint s_es3Attrs[] = { EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_NONE };
52 const EGLint* ctxAttrs;
55 { "OpenGL", EGL_OPENGL_API, EGL_OPENGL_BIT, DE_NULL },
56 { "OpenGL ES 1", EGL_OPENGL_ES_API, EGL_OPENGL_ES_BIT, s_es1Attrs },
57 { "OpenGL ES 2", EGL_OPENGL_ES_API, EGL_OPENGL_ES2_BIT, s_es2Attrs },
58 { "OpenGL ES 3", EGL_OPENGL_ES_API, EGL_OPENGL_ES3_BIT_KHR, s_es3Attrs },
59 { "OpenVG", EGL_OPENVG_API, EGL_OPENVG_BIT, DE_NULL }
62 class CreateContextCase : public SimpleConfigCase
65 CreateContextCase (EglTestContext& eglTestCtx, const char* name, const char* description, const eglu::FilterList& filters);
66 ~CreateContextCase (void);
68 void executeForConfig (EGLDisplay display, EGLConfig config);
71 CreateContextCase::CreateContextCase (EglTestContext& eglTestCtx, const char* name, const char* description, const eglu::FilterList& filters)
72 : SimpleConfigCase(eglTestCtx, name, description, filters)
76 CreateContextCase::~CreateContextCase (void)
80 void CreateContextCase::executeForConfig (EGLDisplay display, EGLConfig config)
82 const Library& egl = m_eglTestCtx.getLibrary();
83 TestLog& log = m_testCtx.getLog();
84 EGLint id = eglu::getConfigAttribInt(egl, display, config, EGL_CONFIG_ID);
85 EGLint apiBits = eglu::getConfigAttribInt(egl, display, config, EGL_RENDERABLE_TYPE);
87 for (int apiNdx = 0; apiNdx < (int)DE_LENGTH_OF_ARRAY(s_apis); apiNdx++)
89 if ((apiBits & s_apis[apiNdx].apiBit) == 0)
90 continue; // Not supported API
92 log << TestLog::Message << "Creating " << s_apis[apiNdx].name << " context with config ID " << id << TestLog::EndMessage;
93 EGLU_CHECK_MSG(egl, "init");
95 EGLU_CHECK_CALL(egl, bindAPI(s_apis[apiNdx].api));
97 EGLContext context = egl.createContext(display, config, EGL_NO_CONTEXT, s_apis[apiNdx].ctxAttrs);
98 EGLenum err = egl.getError();
100 if (context == EGL_NO_CONTEXT || err != EGL_SUCCESS)
102 log << TestLog::Message << " Fail, context: " << tcu::toHex(context) << ", error: " << eglu::getErrorName(err) << TestLog::EndMessage;
103 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Failed to create context");
108 EGLU_CHECK_CALL(egl, destroyContext(display, context));
109 log << TestLog::Message << " Pass" << TestLog::EndMessage;
114 class CreateContextNoConfigCase : public TestCase
117 CreateContextNoConfigCase (EglTestContext& eglTestCtx)
118 : TestCase(eglTestCtx, "no_config", "EGL_KHR_no_config_context")
122 IterateResult iterate (void)
124 const eglw::Library& egl = m_eglTestCtx.getLibrary();
125 const eglu::UniqueDisplay display (egl, eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay(), DE_NULL));
126 tcu::TestLog& log = m_testCtx.getLog();
128 if (!eglu::hasExtension(egl, *display, "EGL_KHR_no_config_context"))
129 TCU_THROW(NotSupportedError, "EGL_KHR_no_config_context is not supported");
131 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "pass");
133 for (int apiNdx = 0; apiNdx < (int)DE_LENGTH_OF_ARRAY(s_apis); apiNdx++)
135 const EGLenum api = s_apis[apiNdx].api;
137 if (egl.bindAPI(api) == EGL_FALSE)
139 TCU_CHECK(egl.getError() == EGL_BAD_PARAMETER);
140 log << TestLog::Message << "eglBindAPI(" << eglu::getAPIStr(api) << ") failed, skipping" << TestLog::EndMessage;
144 log << TestLog::Message << "Creating " << s_apis[apiNdx].name << " context" << TestLog::EndMessage;
146 const EGLContext context = egl.createContext(*display, (EGLConfig)0, EGL_NO_CONTEXT, s_apis[apiNdx].ctxAttrs);
147 const EGLenum err = egl.getError();
149 if (context == EGL_NO_CONTEXT || err != EGL_SUCCESS)
151 log << TestLog::Message << " Fail, context: " << tcu::toHex(context) << ", error: " << eglu::getErrorName(err) << TestLog::EndMessage;
152 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Failed to create context");
157 EGLU_CHECK_CALL(egl, destroyContext(*display, context));
158 log << TestLog::Message << " Pass" << TestLog::EndMessage;
166 CreateContextTests::CreateContextTests (EglTestContext& eglTestCtx)
167 : TestCaseGroup(eglTestCtx, "create_context", "Basic eglCreateContext() tests")
171 CreateContextTests::~CreateContextTests (void)
175 void CreateContextTests::init (void)
177 vector<NamedFilterList> filterLists;
178 getDefaultFilterLists(filterLists, eglu::FilterList());
180 for (vector<NamedFilterList>::iterator i = filterLists.begin(); i != filterLists.end(); i++)
181 addChild(new CreateContextCase(m_eglTestCtx, i->getName(), i->getDescription(), *i));
183 addChild(new CreateContextNoConfigCase(m_eglTestCtx));