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