1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program EGL Module
3 * ---------------------------------------
5 * Copyright 2016 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 EGL multi context tests
22 *//*--------------------------------------------------------------------*/
24 #include "teglMultiContextTests.hpp"
26 #include "egluUtil.hpp"
27 #include "egluUnique.hpp"
28 #include "egluStrUtil.hpp"
29 #include "egluConfigFilter.hpp"
31 #include "eglwLibrary.hpp"
32 #include "eglwEnums.hpp"
34 #include "gluDefs.hpp"
36 #include "glwFunctions.hpp"
37 #include "glwEnums.hpp"
39 #include "tcuResultCollector.hpp"
40 #include "tcuTestLog.hpp"
42 #include "deRandom.hpp"
55 class MultiContextTest : public TestCase
73 MultiContextTest (EglTestContext& eglTestCtx, Sharing sharing, Use use, const char* name, const char* description);
75 IterateResult iterate (void);
78 const Sharing m_sharing;
82 MultiContextTest::MultiContextTest (EglTestContext& eglTestCtx, Sharing sharing, Use use, const char* name, const char* description)
83 : TestCase (eglTestCtx, name, description)
89 bool isES2Renderable (const eglu::CandidateConfig& c)
91 return (c.get(EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT) == EGL_OPENGL_ES2_BIT;
94 eglw::EGLConfig getConfig (const eglw::Library& egl, eglw::EGLDisplay display)
96 eglu::FilterList filters;
97 filters << isES2Renderable;
98 return eglu::chooseSingleConfig(egl, display, filters);
101 tcu::TestCase::IterateResult MultiContextTest::iterate (void)
103 const deUint32 seed = m_sharing == SHARING_SHARED ? 2498541716u : 8825414;
104 const size_t maxContextCount = 128;
105 const size_t minContextCount = 32;
106 const eglw::EGLint attribList[] =
108 EGL_CONTEXT_CLIENT_VERSION, 2,
111 const eglw::EGLint pbufferAttribList[] =
118 TestLog& log = m_testCtx.getLog();
119 tcu::ResultCollector resultCollector (log);
120 de::Random rng (seed);
122 const eglw::Library& egl = m_eglTestCtx.getLibrary();
123 const eglu::UniqueDisplay display (egl, eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay()));
124 const eglw::EGLConfig config = getConfig(egl, *display);
126 const eglu::UniqueSurface surface (egl, *display, m_use != USE_NONE ? egl.createPbufferSurface(*display, config, pbufferAttribList) : EGL_NO_SURFACE);
127 EGLU_CHECK_MSG(egl, "Failed to create pbuffer.");
129 std::vector<eglw::EGLContext> contexts;
132 contexts.reserve(maxContextCount);
134 log << TestLog::Message << "Trying to create " << maxContextCount << (m_sharing == SHARING_SHARED ? " shared " : " ") << "contexts." << TestLog::EndMessage;
135 log << TestLog::Message << "Requiring that at least " << minContextCount << " contexts can be created." << TestLog::EndMessage;
137 if (m_use == USE_CLEAR)
138 m_eglTestCtx.initGLFunctions(&gl, glu::ApiType::es(2,0));
140 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
144 for (size_t contextCount = 0; contextCount < maxContextCount; contextCount++)
146 const eglw::EGLContext sharedContext = (m_sharing == SHARING_SHARED && contextCount > 0 ? contexts[rng.getUint32() % (deUint32)contextCount] : EGL_NO_CONTEXT);
147 const eglw::EGLContext context = egl.createContext(*display, config, sharedContext, attribList);
148 const eglw::EGLint error = egl.getError();
150 if (context == EGL_NO_CONTEXT || error != EGL_SUCCESS)
152 log << TestLog::Message << "Got error after creating " << contextCount << " contexts." << TestLog::EndMessage;
154 if (error == EGL_BAD_ALLOC)
156 if (contextCount < minContextCount)
157 resultCollector.fail("Couldn't create the minimum number of contexts required.");
159 log << TestLog::Message << "Got EGL_BAD_ALLOC." << TestLog::EndMessage;
162 resultCollector.fail("eglCreateContext() produced error that is not EGL_BAD_ALLOC: " + eglu::getErrorStr(error).toString());
164 if (context != EGL_NO_CONTEXT)
165 resultCollector.fail("eglCreateContext() produced error, but context is not EGL_NO_CONTEXT");
171 contexts.push_back(context);
173 if (m_use == USE_MAKECURRENT || m_use == USE_CLEAR)
175 const eglw::EGLBoolean result = egl.makeCurrent(*display, *surface, *surface, context);
176 const eglw::EGLint makeCurrentError = egl.getError();
178 if (!result || makeCurrentError != EGL_SUCCESS)
180 log << TestLog::Message << "Failed to make " << (contextCount + 1) << "th context current: " << eglu::getErrorStr(makeCurrentError) << TestLog::EndMessage;
181 resultCollector.fail("Failed to make context current");
185 else if (m_use == USE_CLEAR)
187 gl.clearColor(0.25f, 0.75f, 0.50f, 1.00f);
188 gl.clear(GL_COLOR_BUFFER_BIT);
190 GLU_CHECK_GLW_MSG(gl, "Failed to clear color.");
196 for (size_t contextNdx = 0; contextNdx < contexts.size(); contextNdx++)
198 EGLU_CHECK_CALL(egl, destroyContext(*display, contexts[contextNdx]));
199 contexts[contextNdx] = EGL_NO_CONTEXT;
202 if (m_use == USE_MAKECURRENT || m_use == USE_CLEAR)
203 EGLU_CHECK_CALL(egl, makeCurrent(*display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
207 for (size_t contextNdx = 0; contextNdx < contexts.size(); contextNdx++)
209 if (contexts[contextNdx] != EGL_NO_CONTEXT)
210 EGLU_CHECK_CALL(egl, destroyContext(*display, contexts[contextNdx]));
213 if (m_use == USE_MAKECURRENT || m_use == USE_CLEAR)
214 EGLU_CHECK_CALL(egl, makeCurrent(*display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
219 resultCollector.setTestContextResult(m_testCtx);
225 TestCaseGroup* createMultiContextTests (EglTestContext& eglTestCtx)
227 de::MovePtr<TestCaseGroup> group (new TestCaseGroup(eglTestCtx, "multicontext", "EGL multi context tests."));
229 group->addChild(new MultiContextTest(eglTestCtx, MultiContextTest::SHARING_NONE, MultiContextTest::USE_NONE, "non_shared", "Create multiple non-shared contexts."));
230 group->addChild(new MultiContextTest(eglTestCtx, MultiContextTest::SHARING_SHARED, MultiContextTest::USE_NONE, "shared", "Create multiple shared contexts."));
232 group->addChild(new MultiContextTest(eglTestCtx, MultiContextTest::SHARING_NONE, MultiContextTest::USE_MAKECURRENT, "non_shared_make_current", "Create multiple non-shared contexts."));
233 group->addChild(new MultiContextTest(eglTestCtx, MultiContextTest::SHARING_SHARED, MultiContextTest::USE_MAKECURRENT, "shared_make_current", "Create multiple shared contexts."));
235 group->addChild(new MultiContextTest(eglTestCtx, MultiContextTest::SHARING_NONE, MultiContextTest::USE_CLEAR, "non_shared_clear", "Create multiple non-shared contexts."));
236 group->addChild(new MultiContextTest(eglTestCtx, MultiContextTest::SHARING_SHARED, MultiContextTest::USE_CLEAR, "shared_clear", "Create multiple shared contexts."));
238 return group.release();