1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program EGL Module
3*35238bceSAndroid Build Coastguard Worker * ---------------------------------------
4*35238bceSAndroid Build Coastguard Worker *
5*35238bceSAndroid Build Coastguard Worker * Copyright 2016 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker *
7*35238bceSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker *
11*35238bceSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker *
13*35238bceSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker *
19*35238bceSAndroid Build Coastguard Worker *//*!
20*35238bceSAndroid Build Coastguard Worker * \file
21*35238bceSAndroid Build Coastguard Worker * \brief EGL thread clean up tests
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker
24*35238bceSAndroid Build Coastguard Worker #include "teglThreadCleanUpTests.hpp"
25*35238bceSAndroid Build Coastguard Worker
26*35238bceSAndroid Build Coastguard Worker #include "egluUtil.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "egluUnique.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "egluConfigFilter.hpp"
29*35238bceSAndroid Build Coastguard Worker
30*35238bceSAndroid Build Coastguard Worker #include "eglwLibrary.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "eglwEnums.hpp"
32*35238bceSAndroid Build Coastguard Worker
33*35238bceSAndroid Build Coastguard Worker #include "tcuMaybe.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
35*35238bceSAndroid Build Coastguard Worker
36*35238bceSAndroid Build Coastguard Worker #include "deThread.hpp"
37*35238bceSAndroid Build Coastguard Worker
38*35238bceSAndroid Build Coastguard Worker namespace deqp
39*35238bceSAndroid Build Coastguard Worker {
40*35238bceSAndroid Build Coastguard Worker namespace egl
41*35238bceSAndroid Build Coastguard Worker {
42*35238bceSAndroid Build Coastguard Worker namespace
43*35238bceSAndroid Build Coastguard Worker {
44*35238bceSAndroid Build Coastguard Worker
45*35238bceSAndroid Build Coastguard Worker using namespace eglw;
46*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
47*35238bceSAndroid Build Coastguard Worker
isES2Renderable(const eglu::CandidateConfig & c)48*35238bceSAndroid Build Coastguard Worker bool isES2Renderable(const eglu::CandidateConfig &c)
49*35238bceSAndroid Build Coastguard Worker {
50*35238bceSAndroid Build Coastguard Worker return (c.get(EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT) == EGL_OPENGL_ES2_BIT;
51*35238bceSAndroid Build Coastguard Worker }
52*35238bceSAndroid Build Coastguard Worker
isPBuffer(const eglu::CandidateConfig & c)53*35238bceSAndroid Build Coastguard Worker bool isPBuffer(const eglu::CandidateConfig &c)
54*35238bceSAndroid Build Coastguard Worker {
55*35238bceSAndroid Build Coastguard Worker return (c.surfaceType() & EGL_PBUFFER_BIT) == EGL_PBUFFER_BIT;
56*35238bceSAndroid Build Coastguard Worker }
57*35238bceSAndroid Build Coastguard Worker
58*35238bceSAndroid Build Coastguard Worker class Thread : public de::Thread
59*35238bceSAndroid Build Coastguard Worker {
60*35238bceSAndroid Build Coastguard Worker public:
Thread(const Library & egl,EGLDisplay display,EGLSurface surface,EGLContext context,EGLConfig config,tcu::Maybe<eglu::Error> & error)61*35238bceSAndroid Build Coastguard Worker Thread(const Library &egl, EGLDisplay display, EGLSurface surface, EGLContext context, EGLConfig config,
62*35238bceSAndroid Build Coastguard Worker tcu::Maybe<eglu::Error> &error)
63*35238bceSAndroid Build Coastguard Worker : m_egl(egl)
64*35238bceSAndroid Build Coastguard Worker , m_display(display)
65*35238bceSAndroid Build Coastguard Worker , m_surface(surface)
66*35238bceSAndroid Build Coastguard Worker , m_context(context)
67*35238bceSAndroid Build Coastguard Worker , m_config(config)
68*35238bceSAndroid Build Coastguard Worker , m_error(error)
69*35238bceSAndroid Build Coastguard Worker {
70*35238bceSAndroid Build Coastguard Worker }
71*35238bceSAndroid Build Coastguard Worker
testContext(EGLContext context)72*35238bceSAndroid Build Coastguard Worker void testContext(EGLContext context)
73*35238bceSAndroid Build Coastguard Worker {
74*35238bceSAndroid Build Coastguard Worker if (m_surface != EGL_NO_SURFACE)
75*35238bceSAndroid Build Coastguard Worker {
76*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_MSG(m_egl, "eglCreateContext");
77*35238bceSAndroid Build Coastguard Worker m_egl.makeCurrent(m_display, m_surface, m_surface, context);
78*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_MSG(m_egl, "eglMakeCurrent");
79*35238bceSAndroid Build Coastguard Worker }
80*35238bceSAndroid Build Coastguard Worker else
81*35238bceSAndroid Build Coastguard Worker {
82*35238bceSAndroid Build Coastguard Worker const EGLint attribs[] = {EGL_WIDTH, 32, EGL_HEIGHT, 32, EGL_NONE};
83*35238bceSAndroid Build Coastguard Worker const eglu::UniqueSurface surface(m_egl, m_display,
84*35238bceSAndroid Build Coastguard Worker m_egl.createPbufferSurface(m_display, m_config, attribs));
85*35238bceSAndroid Build Coastguard Worker
86*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_MSG(m_egl, "eglCreateContext");
87*35238bceSAndroid Build Coastguard Worker m_egl.makeCurrent(m_display, *surface, *surface, context);
88*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_MSG(m_egl, "eglMakeCurrent");
89*35238bceSAndroid Build Coastguard Worker }
90*35238bceSAndroid Build Coastguard Worker }
91*35238bceSAndroid Build Coastguard Worker
run(void)92*35238bceSAndroid Build Coastguard Worker void run(void)
93*35238bceSAndroid Build Coastguard Worker {
94*35238bceSAndroid Build Coastguard Worker try
95*35238bceSAndroid Build Coastguard Worker {
96*35238bceSAndroid Build Coastguard Worker const EGLint attribList[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
97*35238bceSAndroid Build Coastguard Worker
98*35238bceSAndroid Build Coastguard Worker m_egl.bindAPI(EGL_OPENGL_ES_API);
99*35238bceSAndroid Build Coastguard Worker
100*35238bceSAndroid Build Coastguard Worker if (m_context == EGL_NO_CONTEXT)
101*35238bceSAndroid Build Coastguard Worker {
102*35238bceSAndroid Build Coastguard Worker const eglu::UniqueContext context(m_egl, m_display,
103*35238bceSAndroid Build Coastguard Worker m_egl.createContext(m_display, m_config, EGL_NO_CONTEXT, attribList));
104*35238bceSAndroid Build Coastguard Worker
105*35238bceSAndroid Build Coastguard Worker testContext(*context);
106*35238bceSAndroid Build Coastguard Worker }
107*35238bceSAndroid Build Coastguard Worker else
108*35238bceSAndroid Build Coastguard Worker {
109*35238bceSAndroid Build Coastguard Worker testContext(m_context);
110*35238bceSAndroid Build Coastguard Worker }
111*35238bceSAndroid Build Coastguard Worker }
112*35238bceSAndroid Build Coastguard Worker catch (const eglu::Error &error)
113*35238bceSAndroid Build Coastguard Worker {
114*35238bceSAndroid Build Coastguard Worker m_error = error;
115*35238bceSAndroid Build Coastguard Worker }
116*35238bceSAndroid Build Coastguard Worker
117*35238bceSAndroid Build Coastguard Worker m_egl.releaseThread();
118*35238bceSAndroid Build Coastguard Worker }
119*35238bceSAndroid Build Coastguard Worker
120*35238bceSAndroid Build Coastguard Worker private:
121*35238bceSAndroid Build Coastguard Worker const Library &m_egl;
122*35238bceSAndroid Build Coastguard Worker const EGLDisplay m_display;
123*35238bceSAndroid Build Coastguard Worker const EGLSurface m_surface;
124*35238bceSAndroid Build Coastguard Worker const EGLContext m_context;
125*35238bceSAndroid Build Coastguard Worker const EGLConfig m_config;
126*35238bceSAndroid Build Coastguard Worker tcu::Maybe<eglu::Error> &m_error;
127*35238bceSAndroid Build Coastguard Worker };
128*35238bceSAndroid Build Coastguard Worker
129*35238bceSAndroid Build Coastguard Worker class ThreadCleanUpTest : public TestCase
130*35238bceSAndroid Build Coastguard Worker {
131*35238bceSAndroid Build Coastguard Worker public:
132*35238bceSAndroid Build Coastguard Worker enum ContextType
133*35238bceSAndroid Build Coastguard Worker {
134*35238bceSAndroid Build Coastguard Worker CONTEXTTYPE_SINGLE = 0,
135*35238bceSAndroid Build Coastguard Worker CONTEXTTYPE_MULTI
136*35238bceSAndroid Build Coastguard Worker };
137*35238bceSAndroid Build Coastguard Worker
138*35238bceSAndroid Build Coastguard Worker enum SurfaceType
139*35238bceSAndroid Build Coastguard Worker {
140*35238bceSAndroid Build Coastguard Worker SURFACETYPE_SINGLE = 0,
141*35238bceSAndroid Build Coastguard Worker SURFACETYPE_MULTI
142*35238bceSAndroid Build Coastguard Worker };
143*35238bceSAndroid Build Coastguard Worker
testCaseName(ContextType contextType,SurfaceType surfaceType)144*35238bceSAndroid Build Coastguard Worker static std::string testCaseName(ContextType contextType, SurfaceType surfaceType)
145*35238bceSAndroid Build Coastguard Worker {
146*35238bceSAndroid Build Coastguard Worker std::string name;
147*35238bceSAndroid Build Coastguard Worker
148*35238bceSAndroid Build Coastguard Worker if (contextType == CONTEXTTYPE_SINGLE)
149*35238bceSAndroid Build Coastguard Worker name += "single_context_";
150*35238bceSAndroid Build Coastguard Worker else
151*35238bceSAndroid Build Coastguard Worker name += "multi_context_";
152*35238bceSAndroid Build Coastguard Worker
153*35238bceSAndroid Build Coastguard Worker if (surfaceType == SURFACETYPE_SINGLE)
154*35238bceSAndroid Build Coastguard Worker name += "single_surface";
155*35238bceSAndroid Build Coastguard Worker else
156*35238bceSAndroid Build Coastguard Worker name += "multi_surface";
157*35238bceSAndroid Build Coastguard Worker
158*35238bceSAndroid Build Coastguard Worker return name;
159*35238bceSAndroid Build Coastguard Worker }
160*35238bceSAndroid Build Coastguard Worker
ThreadCleanUpTest(EglTestContext & eglTestCtx,ContextType contextType,SurfaceType surfaceType)161*35238bceSAndroid Build Coastguard Worker ThreadCleanUpTest(EglTestContext &eglTestCtx, ContextType contextType, SurfaceType surfaceType)
162*35238bceSAndroid Build Coastguard Worker : TestCase(eglTestCtx, testCaseName(contextType, surfaceType).c_str(), "Simple thread context clean up test")
163*35238bceSAndroid Build Coastguard Worker , m_contextType(contextType)
164*35238bceSAndroid Build Coastguard Worker , m_surfaceType(surfaceType)
165*35238bceSAndroid Build Coastguard Worker , m_iterCount(250)
166*35238bceSAndroid Build Coastguard Worker , m_iterNdx(0)
167*35238bceSAndroid Build Coastguard Worker , m_display(EGL_NO_DISPLAY)
168*35238bceSAndroid Build Coastguard Worker , m_config(0)
169*35238bceSAndroid Build Coastguard Worker , m_surface(EGL_NO_SURFACE)
170*35238bceSAndroid Build Coastguard Worker , m_context(EGL_NO_CONTEXT)
171*35238bceSAndroid Build Coastguard Worker {
172*35238bceSAndroid Build Coastguard Worker }
173*35238bceSAndroid Build Coastguard Worker
~ThreadCleanUpTest(void)174*35238bceSAndroid Build Coastguard Worker ~ThreadCleanUpTest(void)
175*35238bceSAndroid Build Coastguard Worker {
176*35238bceSAndroid Build Coastguard Worker deinit();
177*35238bceSAndroid Build Coastguard Worker }
178*35238bceSAndroid Build Coastguard Worker
init(void)179*35238bceSAndroid Build Coastguard Worker void init(void)
180*35238bceSAndroid Build Coastguard Worker {
181*35238bceSAndroid Build Coastguard Worker const Library &egl = m_eglTestCtx.getLibrary();
182*35238bceSAndroid Build Coastguard Worker
183*35238bceSAndroid Build Coastguard Worker m_display = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
184*35238bceSAndroid Build Coastguard Worker
185*35238bceSAndroid Build Coastguard Worker {
186*35238bceSAndroid Build Coastguard Worker eglu::FilterList filters;
187*35238bceSAndroid Build Coastguard Worker filters << isES2Renderable << isPBuffer;
188*35238bceSAndroid Build Coastguard Worker m_config = eglu::chooseSingleConfig(egl, m_display, filters);
189*35238bceSAndroid Build Coastguard Worker }
190*35238bceSAndroid Build Coastguard Worker
191*35238bceSAndroid Build Coastguard Worker if (m_contextType == CONTEXTTYPE_SINGLE)
192*35238bceSAndroid Build Coastguard Worker {
193*35238bceSAndroid Build Coastguard Worker const EGLint attribList[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
194*35238bceSAndroid Build Coastguard Worker
195*35238bceSAndroid Build Coastguard Worker egl.bindAPI(EGL_OPENGL_ES_API);
196*35238bceSAndroid Build Coastguard Worker
197*35238bceSAndroid Build Coastguard Worker m_context = egl.createContext(m_display, m_config, EGL_NO_CONTEXT, attribList);
198*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_MSG(egl, "Failed to create context");
199*35238bceSAndroid Build Coastguard Worker }
200*35238bceSAndroid Build Coastguard Worker
201*35238bceSAndroid Build Coastguard Worker if (m_surfaceType == SURFACETYPE_SINGLE)
202*35238bceSAndroid Build Coastguard Worker {
203*35238bceSAndroid Build Coastguard Worker const EGLint attribs[] = {EGL_WIDTH, 32, EGL_HEIGHT, 32, EGL_NONE};
204*35238bceSAndroid Build Coastguard Worker
205*35238bceSAndroid Build Coastguard Worker m_surface = egl.createPbufferSurface(m_display, m_config, attribs);
206*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_MSG(egl, "Failed to create surface");
207*35238bceSAndroid Build Coastguard Worker }
208*35238bceSAndroid Build Coastguard Worker }
209*35238bceSAndroid Build Coastguard Worker
deinit(void)210*35238bceSAndroid Build Coastguard Worker void deinit(void)
211*35238bceSAndroid Build Coastguard Worker {
212*35238bceSAndroid Build Coastguard Worker const Library &egl = m_eglTestCtx.getLibrary();
213*35238bceSAndroid Build Coastguard Worker
214*35238bceSAndroid Build Coastguard Worker if (m_surface != EGL_NO_SURFACE)
215*35238bceSAndroid Build Coastguard Worker {
216*35238bceSAndroid Build Coastguard Worker egl.destroySurface(m_display, m_surface);
217*35238bceSAndroid Build Coastguard Worker m_surface = EGL_NO_SURFACE;
218*35238bceSAndroid Build Coastguard Worker }
219*35238bceSAndroid Build Coastguard Worker
220*35238bceSAndroid Build Coastguard Worker if (m_context != EGL_NO_CONTEXT)
221*35238bceSAndroid Build Coastguard Worker {
222*35238bceSAndroid Build Coastguard Worker egl.destroyContext(m_display, m_context);
223*35238bceSAndroid Build Coastguard Worker m_context = EGL_NO_CONTEXT;
224*35238bceSAndroid Build Coastguard Worker }
225*35238bceSAndroid Build Coastguard Worker
226*35238bceSAndroid Build Coastguard Worker if (m_display != EGL_NO_DISPLAY)
227*35238bceSAndroid Build Coastguard Worker {
228*35238bceSAndroid Build Coastguard Worker egl.terminate(m_display);
229*35238bceSAndroid Build Coastguard Worker m_display = EGL_NO_DISPLAY;
230*35238bceSAndroid Build Coastguard Worker }
231*35238bceSAndroid Build Coastguard Worker }
232*35238bceSAndroid Build Coastguard Worker
iterate(void)233*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void)
234*35238bceSAndroid Build Coastguard Worker {
235*35238bceSAndroid Build Coastguard Worker if (m_iterNdx < m_iterCount)
236*35238bceSAndroid Build Coastguard Worker {
237*35238bceSAndroid Build Coastguard Worker tcu::Maybe<eglu::Error> error;
238*35238bceSAndroid Build Coastguard Worker
239*35238bceSAndroid Build Coastguard Worker Thread thread(m_eglTestCtx.getLibrary(), m_display, m_surface, m_context, m_config, error);
240*35238bceSAndroid Build Coastguard Worker
241*35238bceSAndroid Build Coastguard Worker thread.start();
242*35238bceSAndroid Build Coastguard Worker thread.join();
243*35238bceSAndroid Build Coastguard Worker
244*35238bceSAndroid Build Coastguard Worker if (error)
245*35238bceSAndroid Build Coastguard Worker {
246*35238bceSAndroid Build Coastguard Worker m_testCtx.getLog() << TestLog::Message << "Failed. Got error: " << error->getMessage()
247*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage;
248*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, error->getMessage());
249*35238bceSAndroid Build Coastguard Worker return STOP;
250*35238bceSAndroid Build Coastguard Worker }
251*35238bceSAndroid Build Coastguard Worker
252*35238bceSAndroid Build Coastguard Worker m_iterNdx++;
253*35238bceSAndroid Build Coastguard Worker return CONTINUE;
254*35238bceSAndroid Build Coastguard Worker }
255*35238bceSAndroid Build Coastguard Worker else
256*35238bceSAndroid Build Coastguard Worker {
257*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
258*35238bceSAndroid Build Coastguard Worker return STOP;
259*35238bceSAndroid Build Coastguard Worker }
260*35238bceSAndroid Build Coastguard Worker }
261*35238bceSAndroid Build Coastguard Worker
262*35238bceSAndroid Build Coastguard Worker private:
263*35238bceSAndroid Build Coastguard Worker const ContextType m_contextType;
264*35238bceSAndroid Build Coastguard Worker const SurfaceType m_surfaceType;
265*35238bceSAndroid Build Coastguard Worker const size_t m_iterCount;
266*35238bceSAndroid Build Coastguard Worker size_t m_iterNdx;
267*35238bceSAndroid Build Coastguard Worker EGLDisplay m_display;
268*35238bceSAndroid Build Coastguard Worker EGLConfig m_config;
269*35238bceSAndroid Build Coastguard Worker EGLSurface m_surface;
270*35238bceSAndroid Build Coastguard Worker EGLContext m_context;
271*35238bceSAndroid Build Coastguard Worker };
272*35238bceSAndroid Build Coastguard Worker
273*35238bceSAndroid Build Coastguard Worker } // namespace
274*35238bceSAndroid Build Coastguard Worker
createThreadCleanUpTest(EglTestContext & eglTestCtx)275*35238bceSAndroid Build Coastguard Worker TestCaseGroup *createThreadCleanUpTest(EglTestContext &eglTestCtx)
276*35238bceSAndroid Build Coastguard Worker {
277*35238bceSAndroid Build Coastguard Worker de::MovePtr<TestCaseGroup> group(new TestCaseGroup(eglTestCtx, "thread_cleanup", "Thread cleanup tests"));
278*35238bceSAndroid Build Coastguard Worker
279*35238bceSAndroid Build Coastguard Worker group->addChild(new ThreadCleanUpTest(eglTestCtx, ThreadCleanUpTest::CONTEXTTYPE_SINGLE,
280*35238bceSAndroid Build Coastguard Worker ThreadCleanUpTest::SURFACETYPE_SINGLE));
281*35238bceSAndroid Build Coastguard Worker group->addChild(
282*35238bceSAndroid Build Coastguard Worker new ThreadCleanUpTest(eglTestCtx, ThreadCleanUpTest::CONTEXTTYPE_MULTI, ThreadCleanUpTest::SURFACETYPE_SINGLE));
283*35238bceSAndroid Build Coastguard Worker
284*35238bceSAndroid Build Coastguard Worker group->addChild(
285*35238bceSAndroid Build Coastguard Worker new ThreadCleanUpTest(eglTestCtx, ThreadCleanUpTest::CONTEXTTYPE_SINGLE, ThreadCleanUpTest::SURFACETYPE_MULTI));
286*35238bceSAndroid Build Coastguard Worker group->addChild(
287*35238bceSAndroid Build Coastguard Worker new ThreadCleanUpTest(eglTestCtx, ThreadCleanUpTest::CONTEXTTYPE_MULTI, ThreadCleanUpTest::SURFACETYPE_MULTI));
288*35238bceSAndroid Build Coastguard Worker
289*35238bceSAndroid Build Coastguard Worker return group.release();
290*35238bceSAndroid Build Coastguard Worker }
291*35238bceSAndroid Build Coastguard Worker
292*35238bceSAndroid Build Coastguard Worker } // namespace egl
293*35238bceSAndroid Build Coastguard Worker } // namespace deqp
294