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 2014 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 Simple Context construction test.
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker
24*35238bceSAndroid Build Coastguard Worker #include "teglCreateContextTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "teglSimpleConfigCase.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "egluStrUtil.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "egluUtil.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "egluUnique.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "eglwLibrary.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "eglwEnums.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "deSTLUtil.hpp"
33*35238bceSAndroid Build Coastguard Worker
34*35238bceSAndroid Build Coastguard Worker namespace deqp
35*35238bceSAndroid Build Coastguard Worker {
36*35238bceSAndroid Build Coastguard Worker namespace egl
37*35238bceSAndroid Build Coastguard Worker {
38*35238bceSAndroid Build Coastguard Worker
39*35238bceSAndroid Build Coastguard Worker using std::vector;
40*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
41*35238bceSAndroid Build Coastguard Worker using namespace eglw;
42*35238bceSAndroid Build Coastguard Worker
43*35238bceSAndroid Build Coastguard Worker static const EGLint s_es1Attrs[] = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE};
44*35238bceSAndroid Build Coastguard Worker static const EGLint s_es2Attrs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
45*35238bceSAndroid Build Coastguard Worker static const EGLint s_es3Attrs[] = {EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_NONE};
46*35238bceSAndroid Build Coastguard Worker
47*35238bceSAndroid Build Coastguard Worker static const struct
48*35238bceSAndroid Build Coastguard Worker {
49*35238bceSAndroid Build Coastguard Worker const char *name;
50*35238bceSAndroid Build Coastguard Worker EGLenum api;
51*35238bceSAndroid Build Coastguard Worker EGLint apiBit;
52*35238bceSAndroid Build Coastguard Worker bool noConfigOptional;
53*35238bceSAndroid Build Coastguard Worker const EGLint *ctxAttrs;
54*35238bceSAndroid Build Coastguard Worker } s_apis[] = {{"OpenGL", EGL_OPENGL_API, EGL_OPENGL_BIT, false, DE_NULL},
55*35238bceSAndroid Build Coastguard Worker {"OpenGL ES 1", EGL_OPENGL_ES_API, EGL_OPENGL_ES_BIT, true, s_es1Attrs},
56*35238bceSAndroid Build Coastguard Worker {"OpenGL ES 2", EGL_OPENGL_ES_API, EGL_OPENGL_ES2_BIT, true, s_es2Attrs},
57*35238bceSAndroid Build Coastguard Worker {"OpenGL ES 3", EGL_OPENGL_ES_API, EGL_OPENGL_ES3_BIT_KHR, false, s_es3Attrs},
58*35238bceSAndroid Build Coastguard Worker {"OpenVG", EGL_OPENVG_API, EGL_OPENVG_BIT, false, DE_NULL}};
59*35238bceSAndroid Build Coastguard Worker
60*35238bceSAndroid Build Coastguard Worker class CreateContextCase : public SimpleConfigCase
61*35238bceSAndroid Build Coastguard Worker {
62*35238bceSAndroid Build Coastguard Worker public:
63*35238bceSAndroid Build Coastguard Worker CreateContextCase(EglTestContext &eglTestCtx, const char *name, const char *description,
64*35238bceSAndroid Build Coastguard Worker const eglu::FilterList &filters);
65*35238bceSAndroid Build Coastguard Worker ~CreateContextCase(void);
66*35238bceSAndroid Build Coastguard Worker
67*35238bceSAndroid Build Coastguard Worker void executeForConfig(EGLDisplay display, EGLConfig config);
68*35238bceSAndroid Build Coastguard Worker };
69*35238bceSAndroid Build Coastguard Worker
CreateContextCase(EglTestContext & eglTestCtx,const char * name,const char * description,const eglu::FilterList & filters)70*35238bceSAndroid Build Coastguard Worker CreateContextCase::CreateContextCase(EglTestContext &eglTestCtx, const char *name, const char *description,
71*35238bceSAndroid Build Coastguard Worker const eglu::FilterList &filters)
72*35238bceSAndroid Build Coastguard Worker : SimpleConfigCase(eglTestCtx, name, description, filters)
73*35238bceSAndroid Build Coastguard Worker {
74*35238bceSAndroid Build Coastguard Worker }
75*35238bceSAndroid Build Coastguard Worker
~CreateContextCase(void)76*35238bceSAndroid Build Coastguard Worker CreateContextCase::~CreateContextCase(void)
77*35238bceSAndroid Build Coastguard Worker {
78*35238bceSAndroid Build Coastguard Worker }
79*35238bceSAndroid Build Coastguard Worker
executeForConfig(EGLDisplay display,EGLConfig config)80*35238bceSAndroid Build Coastguard Worker void CreateContextCase::executeForConfig(EGLDisplay display, EGLConfig config)
81*35238bceSAndroid Build Coastguard Worker {
82*35238bceSAndroid Build Coastguard Worker const Library &egl = m_eglTestCtx.getLibrary();
83*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
84*35238bceSAndroid Build Coastguard Worker EGLint id = eglu::getConfigAttribInt(egl, display, config, EGL_CONFIG_ID);
85*35238bceSAndroid Build Coastguard Worker EGLint apiBits = eglu::getConfigAttribInt(egl, display, config, EGL_RENDERABLE_TYPE);
86*35238bceSAndroid Build Coastguard Worker
87*35238bceSAndroid Build Coastguard Worker for (int apiNdx = 0; apiNdx < (int)DE_LENGTH_OF_ARRAY(s_apis); apiNdx++)
88*35238bceSAndroid Build Coastguard Worker {
89*35238bceSAndroid Build Coastguard Worker if ((apiBits & s_apis[apiNdx].apiBit) == 0)
90*35238bceSAndroid Build Coastguard Worker continue; // Not supported API
91*35238bceSAndroid Build Coastguard Worker
92*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "Creating " << s_apis[apiNdx].name << " context with config ID " << id
93*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage;
94*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_MSG(egl, "init");
95*35238bceSAndroid Build Coastguard Worker
96*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, bindAPI(s_apis[apiNdx].api));
97*35238bceSAndroid Build Coastguard Worker
98*35238bceSAndroid Build Coastguard Worker EGLContext context = egl.createContext(display, config, EGL_NO_CONTEXT, s_apis[apiNdx].ctxAttrs);
99*35238bceSAndroid Build Coastguard Worker EGLenum err = egl.getError();
100*35238bceSAndroid Build Coastguard Worker
101*35238bceSAndroid Build Coastguard Worker if (context == EGL_NO_CONTEXT || err != EGL_SUCCESS)
102*35238bceSAndroid Build Coastguard Worker {
103*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << " Fail, context: " << tcu::toHex(context)
104*35238bceSAndroid Build Coastguard Worker << ", error: " << eglu::getErrorName(err) << TestLog::EndMessage;
105*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Failed to create context");
106*35238bceSAndroid Build Coastguard Worker }
107*35238bceSAndroid Build Coastguard Worker else
108*35238bceSAndroid Build Coastguard Worker {
109*35238bceSAndroid Build Coastguard Worker // Destroy
110*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, destroyContext(display, context));
111*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << " Pass" << TestLog::EndMessage;
112*35238bceSAndroid Build Coastguard Worker }
113*35238bceSAndroid Build Coastguard Worker }
114*35238bceSAndroid Build Coastguard Worker }
115*35238bceSAndroid Build Coastguard Worker
116*35238bceSAndroid Build Coastguard Worker class CreateContextNoConfigCase : public TestCase
117*35238bceSAndroid Build Coastguard Worker {
118*35238bceSAndroid Build Coastguard Worker public:
CreateContextNoConfigCase(EglTestContext & eglTestCtx)119*35238bceSAndroid Build Coastguard Worker CreateContextNoConfigCase(EglTestContext &eglTestCtx)
120*35238bceSAndroid Build Coastguard Worker : TestCase(eglTestCtx, "no_config", "EGL_KHR_no_config_context")
121*35238bceSAndroid Build Coastguard Worker {
122*35238bceSAndroid Build Coastguard Worker }
123*35238bceSAndroid Build Coastguard Worker
iterate(void)124*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void)
125*35238bceSAndroid Build Coastguard Worker {
126*35238bceSAndroid Build Coastguard Worker const eglw::Library &egl = m_eglTestCtx.getLibrary();
127*35238bceSAndroid Build Coastguard Worker const eglu::UniqueDisplay display(egl, eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay(), DE_NULL));
128*35238bceSAndroid Build Coastguard Worker tcu::TestLog &log = m_testCtx.getLog();
129*35238bceSAndroid Build Coastguard Worker
130*35238bceSAndroid Build Coastguard Worker if (!eglu::hasExtension(egl, *display, "EGL_KHR_no_config_context"))
131*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "EGL_KHR_no_config_context is not supported");
132*35238bceSAndroid Build Coastguard Worker
133*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "pass");
134*35238bceSAndroid Build Coastguard Worker
135*35238bceSAndroid Build Coastguard Worker for (int apiNdx = 0; apiNdx < (int)DE_LENGTH_OF_ARRAY(s_apis); apiNdx++)
136*35238bceSAndroid Build Coastguard Worker {
137*35238bceSAndroid Build Coastguard Worker const EGLenum api = s_apis[apiNdx].api;
138*35238bceSAndroid Build Coastguard Worker
139*35238bceSAndroid Build Coastguard Worker if (egl.bindAPI(api) == EGL_FALSE)
140*35238bceSAndroid Build Coastguard Worker {
141*35238bceSAndroid Build Coastguard Worker TCU_CHECK(egl.getError() == EGL_BAD_PARAMETER);
142*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "eglBindAPI(" << eglu::getAPIStr(api) << ") failed, skipping"
143*35238bceSAndroid Build Coastguard Worker << TestLog::EndMessage;
144*35238bceSAndroid Build Coastguard Worker continue;
145*35238bceSAndroid Build Coastguard Worker }
146*35238bceSAndroid Build Coastguard Worker
147*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << "Creating " << s_apis[apiNdx].name << " context" << TestLog::EndMessage;
148*35238bceSAndroid Build Coastguard Worker
149*35238bceSAndroid Build Coastguard Worker const EGLContext context =
150*35238bceSAndroid Build Coastguard Worker egl.createContext(*display, (EGLConfig)0, EGL_NO_CONTEXT, s_apis[apiNdx].ctxAttrs);
151*35238bceSAndroid Build Coastguard Worker const EGLenum err = egl.getError();
152*35238bceSAndroid Build Coastguard Worker
153*35238bceSAndroid Build Coastguard Worker if (context == EGL_NO_CONTEXT && err == EGL_BAD_MATCH && s_apis[apiNdx].noConfigOptional)
154*35238bceSAndroid Build Coastguard Worker {
155*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << " Unsupported" << TestLog::EndMessage;
156*35238bceSAndroid Build Coastguard Worker }
157*35238bceSAndroid Build Coastguard Worker else if (context == EGL_NO_CONTEXT || err != EGL_SUCCESS)
158*35238bceSAndroid Build Coastguard Worker {
159*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << " Fail, context: " << tcu::toHex(context)
160*35238bceSAndroid Build Coastguard Worker << ", error: " << eglu::getErrorName(err) << TestLog::EndMessage;
161*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Failed to create context");
162*35238bceSAndroid Build Coastguard Worker }
163*35238bceSAndroid Build Coastguard Worker else
164*35238bceSAndroid Build Coastguard Worker {
165*35238bceSAndroid Build Coastguard Worker // Destroy
166*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, destroyContext(*display, context));
167*35238bceSAndroid Build Coastguard Worker log << TestLog::Message << " Pass" << TestLog::EndMessage;
168*35238bceSAndroid Build Coastguard Worker }
169*35238bceSAndroid Build Coastguard Worker }
170*35238bceSAndroid Build Coastguard Worker
171*35238bceSAndroid Build Coastguard Worker return STOP;
172*35238bceSAndroid Build Coastguard Worker }
173*35238bceSAndroid Build Coastguard Worker };
174*35238bceSAndroid Build Coastguard Worker
CreateContextTests(EglTestContext & eglTestCtx)175*35238bceSAndroid Build Coastguard Worker CreateContextTests::CreateContextTests(EglTestContext &eglTestCtx)
176*35238bceSAndroid Build Coastguard Worker : TestCaseGroup(eglTestCtx, "create_context", "Basic eglCreateContext() tests")
177*35238bceSAndroid Build Coastguard Worker {
178*35238bceSAndroid Build Coastguard Worker }
179*35238bceSAndroid Build Coastguard Worker
~CreateContextTests(void)180*35238bceSAndroid Build Coastguard Worker CreateContextTests::~CreateContextTests(void)
181*35238bceSAndroid Build Coastguard Worker {
182*35238bceSAndroid Build Coastguard Worker }
183*35238bceSAndroid Build Coastguard Worker
init(void)184*35238bceSAndroid Build Coastguard Worker void CreateContextTests::init(void)
185*35238bceSAndroid Build Coastguard Worker {
186*35238bceSAndroid Build Coastguard Worker vector<NamedFilterList> filterLists;
187*35238bceSAndroid Build Coastguard Worker getDefaultFilterLists(filterLists, eglu::FilterList());
188*35238bceSAndroid Build Coastguard Worker
189*35238bceSAndroid Build Coastguard Worker for (vector<NamedFilterList>::iterator i = filterLists.begin(); i != filterLists.end(); i++)
190*35238bceSAndroid Build Coastguard Worker addChild(new CreateContextCase(m_eglTestCtx, i->getName(), i->getDescription(), *i));
191*35238bceSAndroid Build Coastguard Worker
192*35238bceSAndroid Build Coastguard Worker addChild(new CreateContextNoConfigCase(m_eglTestCtx));
193*35238bceSAndroid Build Coastguard Worker }
194*35238bceSAndroid Build Coastguard Worker
195*35238bceSAndroid Build Coastguard Worker } // namespace egl
196*35238bceSAndroid Build Coastguard Worker } // namespace deqp
197