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 bool supportsPBuffer (const eglu::CandidateConfig& c)
96 return (c.get(EGL_SURFACE_TYPE) & EGL_PBUFFER_BIT) == EGL_PBUFFER_BIT;
99 eglw::EGLConfig getConfig (const eglw::Library& egl, eglw::EGLDisplay display)
101 eglu::FilterList filters;
102 filters << isES2Renderable;
103 filters << supportsPBuffer;
104 return eglu::chooseSingleConfig(egl, display, filters);
107 tcu::TestCase::IterateResult MultiContextTest::iterate (void)
109 const deUint32 seed = m_sharing == SHARING_SHARED ? 2498541716u : 8825414;
110 const size_t maxContextCount = 128;
111 const size_t minContextCount = 32;
112 const eglw::EGLint attribList[] =
114 EGL_CONTEXT_CLIENT_VERSION, 2,
117 const eglw::EGLint pbufferAttribList[] =
124 TestLog& log = m_testCtx.getLog();
125 tcu::ResultCollector resultCollector (log);
126 de::Random rng (seed);
128 const eglw::Library& egl = m_eglTestCtx.getLibrary();
129 const eglu::UniqueDisplay display (egl, eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay()));
130 const eglw::EGLConfig config = getConfig(egl, *display);
132 const eglu::UniqueSurface surface (egl, *display, m_use != USE_NONE ? egl.createPbufferSurface(*display, config, pbufferAttribList) : EGL_NO_SURFACE);
133 EGLU_CHECK_MSG(egl, "Failed to create pbuffer.");
135 std::vector<eglw::EGLContext> contexts;
138 contexts.reserve(maxContextCount);
140 log << TestLog::Message << "Trying to create " << maxContextCount << (m_sharing == SHARING_SHARED ? " shared " : " ") << "contexts." << TestLog::EndMessage;
141 log << TestLog::Message << "Requiring that at least " << minContextCount << " contexts can be created." << TestLog::EndMessage;
143 if (m_use == USE_CLEAR)
144 m_eglTestCtx.initGLFunctions(&gl, glu::ApiType::es(2,0));
146 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
150 for (size_t contextCount = 0; contextCount < maxContextCount; contextCount++)
152 const eglw::EGLContext sharedContext = (m_sharing == SHARING_SHARED && contextCount > 0 ? contexts[rng.getUint32() % (deUint32)contextCount] : EGL_NO_CONTEXT);
153 const eglw::EGLContext context = egl.createContext(*display, config, sharedContext, attribList);
154 const eglw::EGLint error = egl.getError();
156 if (context == EGL_NO_CONTEXT || error != EGL_SUCCESS)
158 log << TestLog::Message << "Got error after creating " << contextCount << " contexts." << TestLog::EndMessage;
160 if (error == EGL_BAD_ALLOC)
162 if (contextCount < minContextCount)
163 resultCollector.fail("Couldn't create the minimum number of contexts required.");
165 log << TestLog::Message << "Got EGL_BAD_ALLOC." << TestLog::EndMessage;
168 resultCollector.fail("eglCreateContext() produced error that is not EGL_BAD_ALLOC: " + eglu::getErrorStr(error).toString());
170 if (context != EGL_NO_CONTEXT)
171 resultCollector.fail("eglCreateContext() produced error, but context is not EGL_NO_CONTEXT");
177 contexts.push_back(context);
179 if (m_use == USE_MAKECURRENT || m_use == USE_CLEAR)
181 const eglw::EGLBoolean result = egl.makeCurrent(*display, *surface, *surface, context);
182 const eglw::EGLint makeCurrentError = egl.getError();
184 if (!result || makeCurrentError != EGL_SUCCESS)
186 log << TestLog::Message << "Failed to make " << (contextCount + 1) << "th context current: " << eglu::getErrorStr(makeCurrentError) << TestLog::EndMessage;
187 resultCollector.fail("Failed to make context current");
191 else if (m_use == USE_CLEAR)
193 gl.clearColor(0.25f, 0.75f, 0.50f, 1.00f);
194 gl.clear(GL_COLOR_BUFFER_BIT);
196 GLU_CHECK_GLW_MSG(gl, "Failed to clear color.");
202 for (size_t contextNdx = 0; contextNdx < contexts.size(); contextNdx++)
204 EGLU_CHECK_CALL(egl, destroyContext(*display, contexts[contextNdx]));
205 contexts[contextNdx] = EGL_NO_CONTEXT;
208 if (m_use == USE_MAKECURRENT || m_use == USE_CLEAR)
209 EGLU_CHECK_CALL(egl, makeCurrent(*display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
213 for (size_t contextNdx = 0; contextNdx < contexts.size(); contextNdx++)
215 if (contexts[contextNdx] != EGL_NO_CONTEXT)
216 EGLU_CHECK_CALL(egl, destroyContext(*display, contexts[contextNdx]));
219 if (m_use == USE_MAKECURRENT || m_use == USE_CLEAR)
220 EGLU_CHECK_CALL(egl, makeCurrent(*display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
225 resultCollector.setTestContextResult(m_testCtx);
231 TestCaseGroup* createMultiContextTests (EglTestContext& eglTestCtx)
233 de::MovePtr<TestCaseGroup> group (new TestCaseGroup(eglTestCtx, "multicontext", "EGL multi context tests."));
235 group->addChild(new MultiContextTest(eglTestCtx, MultiContextTest::SHARING_NONE, MultiContextTest::USE_NONE, "non_shared", "Create multiple non-shared contexts."));
236 group->addChild(new MultiContextTest(eglTestCtx, MultiContextTest::SHARING_SHARED, MultiContextTest::USE_NONE, "shared", "Create multiple shared contexts."));
238 group->addChild(new MultiContextTest(eglTestCtx, MultiContextTest::SHARING_NONE, MultiContextTest::USE_MAKECURRENT, "non_shared_make_current", "Create multiple non-shared contexts."));
239 group->addChild(new MultiContextTest(eglTestCtx, MultiContextTest::SHARING_SHARED, MultiContextTest::USE_MAKECURRENT, "shared_make_current", "Create multiple shared contexts."));
241 group->addChild(new MultiContextTest(eglTestCtx, MultiContextTest::SHARING_NONE, MultiContextTest::USE_CLEAR, "non_shared_clear", "Create multiple non-shared contexts."));
242 group->addChild(new MultiContextTest(eglTestCtx, MultiContextTest::SHARING_SHARED, MultiContextTest::USE_CLEAR, "shared_clear", "Create multiple shared contexts."));
244 return group.release();