13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program EGL Module
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ---------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Simple Context construction test.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "teglCreateContextTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "teglSimpleConfigCase.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluStrUtil.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <EGL/eglext.h>
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#if !defined(EGL_OPENGL_ES3_BIT_KHR)
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#	define EGL_OPENGL_ES3_BIT_KHR	0x0040
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#if !defined(EGL_CONTEXT_MAJOR_VERSION_KHR)
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#	define EGL_CONTEXT_MAJOR_VERSION_KHR EGL_CONTEXT_CLIENT_VERSION
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector;
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog;
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace egl
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass CreateContextCase : public SimpleConfigCase
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						CreateContextCase			(EglTestContext& eglTestCtx, const char* name, const char* description, const vector<EGLint>& configIds);
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						~CreateContextCase			(void);
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				executeForConfig			(tcu::egl::Display& display, EGLConfig config);
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
553c827367444ee418f129b2c238299f49d3264554Jarkko PoyryCreateContextCase::CreateContextCase (EglTestContext& eglTestCtx, const char* name, const char* description, const vector<EGLint>& configIds)
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: SimpleConfigCase(eglTestCtx, name, description, configIds)
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
603c827367444ee418f129b2c238299f49d3264554Jarkko PoyryCreateContextCase::~CreateContextCase (void)
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid CreateContextCase::executeForConfig (tcu::egl::Display& display, EGLConfig config)
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestLog&	log		= m_testCtx.getLog();
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	EGLint		id		= display.getConfigAttrib(config, EGL_CONFIG_ID);
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	EGLint		apiBits	= display.getConfigAttrib(config, EGL_RENDERABLE_TYPE);
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const EGLint es1Attrs[] = { EGL_CONTEXT_CLIENT_VERSION,		1, EGL_NONE };
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const EGLint es2Attrs[] = { EGL_CONTEXT_CLIENT_VERSION,		2, EGL_NONE };
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const EGLint es3Attrs[] = { EGL_CONTEXT_MAJOR_VERSION_KHR,	3, EGL_NONE };
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		name;
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		EGLenum			api;
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		EGLint			apiBit;
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const EGLint*	ctxAttrs;
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} apis[] =
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "OpenGL",			EGL_OPENGL_API,		EGL_OPENGL_BIT,			DE_NULL		},
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "OpenGL ES 1",	EGL_OPENGL_ES_API,	EGL_OPENGL_ES_BIT,		es1Attrs	},
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "OpenGL ES 2",	EGL_OPENGL_ES_API,	EGL_OPENGL_ES2_BIT,		es2Attrs	},
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "OpenGL ES 3",	EGL_OPENGL_ES_API,	EGL_OPENGL_ES3_BIT_KHR,	es3Attrs	},
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "OpenVG",			EGL_OPENVG_API,		EGL_OPENVG_BIT,			DE_NULL		}
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int apiNdx = 0; apiNdx < (int)DE_LENGTH_OF_ARRAY(apis); apiNdx++)
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if ((apiBits & apis[apiNdx].apiBit) == 0)
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			continue; // Not supported API
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log << TestLog::Message << "Creating " << apis[apiNdx].name << " context with config ID " << id << TestLog::EndMessage;
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK_EGL();
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK_EGL_CALL(eglBindAPI(apis[apiNdx].api));
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		EGLContext	context = eglCreateContext(display.getEGLDisplay(), config, EGL_NO_CONTEXT, apis[apiNdx].ctxAttrs);
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		EGLenum		err		= eglGetError();
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (context == EGL_NO_CONTEXT || err != EGL_SUCCESS)
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << TestLog::Message << "  Fail, context: " << tcu::toHex(context) << ", error: " << eglu::getErrorName(err) << TestLog::EndMessage;
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Failed to create context");
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			// Destroy
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			TCU_CHECK_EGL_CALL(eglDestroyContext(display.getEGLDisplay(), context));
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << TestLog::Message << "  Pass" << TestLog::EndMessage;
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1173c827367444ee418f129b2c238299f49d3264554Jarkko PoyryCreateContextTests::CreateContextTests (EglTestContext& eglTestCtx)
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(eglTestCtx, "create_context", "Basic eglCreateContext() tests")
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1223c827367444ee418f129b2c238299f49d3264554Jarkko PoyryCreateContextTests::~CreateContextTests (void)
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid CreateContextTests::init (void)
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<NamedConfigIdSet>	configIdSets;
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	eglu::FilterList			filters;
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NamedConfigIdSet::getDefaultSets(configIdSets, m_eglTestCtx.getConfigs(), filters);
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (vector<NamedConfigIdSet>::iterator i = configIdSets.begin(); i != configIdSets.end(); i++)
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(new CreateContextCase(m_eglTestCtx, i->getName(), i->getDescription(), i->getConfigIds()));
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // egl
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
138