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 Config query tests.
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "teglQueryContextTests.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "teglSimpleConfigCase.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "teglRenderCase.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluCallLogWrapper.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluStrUtil.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuCommandLine.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestContext.hpp"
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluUtil.hpp"
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluNativeDisplay.hpp"
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluNativeWindow.hpp"
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluNativePixmap.hpp"
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deUniquePtr.hpp"
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector>
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <EGL/eglext.h>
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#if !defined(EGL_OPENGL_ES3_BIT_KHR)
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#	define EGL_OPENGL_ES3_BIT_KHR	0x0040
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#if !defined(EGL_CONTEXT_MAJOR_VERSION_KHR)
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#	define EGL_CONTEXT_MAJOR_VERSION_KHR EGL_CONTEXT_CLIENT_VERSION
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace egl
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing eglu::ConfigInfo;
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog;
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct ContextCaseInfo
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	EGLint	surfaceType;
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	EGLint	clientType;
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	EGLint	clientVersion;
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ContextCase : public SimpleConfigCase, protected eglu::CallLogWrapper
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						ContextCase			(EglTestContext& eglTestCtx, const char* name, const char* description, const std::vector<EGLint>& configIds, EGLint surfaceTypeMask);
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual				~ContextCase		(void);
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				executeForConfig	(tcu::egl::Display& display, EGLConfig config);
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void				executeForSurface	(tcu::egl::Display& display, EGLConfig config, EGLSurface surface, ContextCaseInfo& info);
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void		executeForContext	(tcu::egl::Display& display, EGLConfig config, EGLSurface surface, EGLContext context, ContextCaseInfo& info) = 0;
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	EGLint				m_surfaceTypeMask;
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
813c827367444ee418f129b2c238299f49d3264554Jarkko PoyryContextCase::ContextCase (EglTestContext& eglTestCtx, const char* name, const char* description, const std::vector<EGLint>& configIds, EGLint surfaceTypeMask)
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: SimpleConfigCase	(eglTestCtx, name, description, configIds)
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, CallLogWrapper	(eglTestCtx.getTestContext().getLog())
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	, m_surfaceTypeMask	(surfaceTypeMask)
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
883c827367444ee418f129b2c238299f49d3264554Jarkko PoyryContextCase::~ContextCase (void)
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ContextCase::executeForConfig (tcu::egl::Display& display, EGLConfig config)
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	tcu::TestLog&			log				= m_testCtx.getLog();
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				width			= 64;
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const int				height			= 64;
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const EGLint			configId		= display.getConfigAttrib(config, EGL_CONFIG_ID);
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	eglu::NativeDisplay&	nativeDisplay	= m_eglTestCtx.getNativeDisplay();
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool					isOk			= true;
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::string				failReason		= "";
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_surfaceTypeMask & EGL_WINDOW_BIT)
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log << TestLog::Message << "Creating window surface with config ID " << configId << TestLog::EndMessage;
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		try
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			de::UniquePtr<eglu::NativeWindow>	window		(m_eglTestCtx.createNativeWindow(display.getEGLDisplay(), config, DE_NULL, width, height, eglu::parseWindowVisibility(m_testCtx.getCommandLine())));
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::egl::WindowSurface				surface		(display, eglu::createWindowSurface(nativeDisplay, *window, display.getEGLDisplay(), config, DE_NULL));
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			ContextCaseInfo info;
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			info.surfaceType	= EGL_WINDOW_BIT;
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			executeForSurface(m_eglTestCtx.getDisplay(), config, surface.getEGLSurface(), info);
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		catch (const tcu::TestError& e)
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << e;
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			isOk = false;
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			failReason = e.what();
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log << TestLog::Message << TestLog::EndMessage;
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_surfaceTypeMask & EGL_PIXMAP_BIT)
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log << TestLog::Message << "Creating pixmap surface with config ID " << configId << TestLog::EndMessage;
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		try
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			de::UniquePtr<eglu::NativePixmap>	pixmap		(m_eglTestCtx.createNativePixmap(display.getEGLDisplay(), config, DE_NULL, width, height));
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::egl::PixmapSurface				surface		(display, eglu::createPixmapSurface(nativeDisplay, *pixmap, display.getEGLDisplay(), config, DE_NULL));
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			ContextCaseInfo info;
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			info.surfaceType	= EGL_PIXMAP_BIT;
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			executeForSurface(display, config, surface.getEGLSurface(), info);
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		catch (const tcu::TestError& e)
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << e;
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			isOk = false;
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			failReason = e.what();
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log << TestLog::Message << TestLog::EndMessage;
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (m_surfaceTypeMask & EGL_PBUFFER_BIT)
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log << TestLog::Message << "Creating pbuffer surface with config ID " << configId << TestLog::EndMessage;
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		try
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const EGLint surfaceAttribs[] =
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				EGL_WIDTH,	width,
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				EGL_HEIGHT,	height,
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				EGL_NONE
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			};
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			tcu::egl::PbufferSurface surface(display, config, surfaceAttribs);
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			ContextCaseInfo info;
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			info.surfaceType	= EGL_PBUFFER_BIT;
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			executeForSurface(display, config, surface.getEGLSurface(), info);
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		catch (const tcu::TestError& e)
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << e;
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			isOk = false;
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			failReason = e.what();
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log << TestLog::Message << TestLog::EndMessage;
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (!isOk && m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, failReason.c_str());
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ContextCase::executeForSurface (tcu::egl::Display& display, EGLConfig config, EGLSurface surface, ContextCaseInfo& info)
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestLog&	log		= m_testCtx.getLog();
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	EGLint		apiBits	= display.getConfigAttrib(config, EGL_RENDERABLE_TYPE);
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const EGLint es1Attrs[] = { EGL_CONTEXT_CLIENT_VERSION,		1, EGL_NONE };
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const EGLint es2Attrs[] = { EGL_CONTEXT_CLIENT_VERSION,		2, EGL_NONE };
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const EGLint es3Attrs[] = { EGL_CONTEXT_MAJOR_VERSION_KHR,	3, EGL_NONE };
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	static const struct
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const char*		name;
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		EGLenum			api;
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		EGLint			apiBit;
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const EGLint*	ctxAttrs;
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		EGLint			apiVersion;
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	} apis[] =
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "OpenGL",			EGL_OPENGL_API,		EGL_OPENGL_BIT,			DE_NULL,	0	},
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "OpenGL ES 1",	EGL_OPENGL_ES_API,	EGL_OPENGL_ES_BIT,		es1Attrs,	1	},
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "OpenGL ES 2",	EGL_OPENGL_ES_API,	EGL_OPENGL_ES2_BIT,		es2Attrs,	2	},
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "OpenGL ES 3",	EGL_OPENGL_ES_API,	EGL_OPENGL_ES3_BIT_KHR,	es3Attrs,	3	},
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{ "OpenVG",			EGL_OPENVG_API,		EGL_OPENVG_BIT,			DE_NULL,	0	}
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (int apiNdx = 0; apiNdx < (int)DE_LENGTH_OF_ARRAY(apis); apiNdx++)
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if ((apiBits & apis[apiNdx].apiBit) == 0)
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			continue; // Not supported API
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK_EGL_CALL(eglBindAPI(apis[apiNdx].api));
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log << TestLog::Message << "Creating " << apis[apiNdx].name << " context" << TestLog::EndMessage;
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const EGLContext	context = eglCreateContext(display.getEGLDisplay(), config, EGL_NO_CONTEXT, apis[apiNdx].ctxAttrs);
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK_EGL();
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK(context != EGL_NO_CONTEXT);
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK_EGL_CALL(eglMakeCurrent(display.getEGLDisplay(), surface, surface, context));
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		info.clientType		= apis[apiNdx].api;
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		info.clientVersion	= apis[apiNdx].apiVersion;
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		executeForContext(display, config, surface, context, info);
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Destroy
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK_EGL_CALL(eglMakeCurrent(display.getEGLDisplay(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK_EGL_CALL(eglDestroyContext(display.getEGLDisplay(), context));
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass GetCurrentContextCase : public ContextCase
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GetCurrentContextCase (EglTestContext& eglTestCtx, const char* name, const char* description, const std::vector<EGLint>& configIds, EGLint surfaceTypeMask)
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: ContextCase(eglTestCtx, name, description, configIds, surfaceTypeMask)
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void executeForContext (tcu::egl::Display& display, EGLConfig config, EGLSurface surface, EGLContext context, ContextCaseInfo& info)
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TestLog&	log	= m_testCtx.getLog();
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(display);
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(config && surface);
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(info);
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		enableLogging(true);
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const EGLContext	gotContext	= eglGetCurrentContext();
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK_EGL();
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (gotContext == context)
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << TestLog::Message << "  Pass" << TestLog::EndMessage;
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (gotContext == EGL_NO_CONTEXT)
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << TestLog::Message << "  Fail, got EGL_NO_CONTEXT" << TestLog::EndMessage;
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Unexpected EGL_NO_CONTEXT");
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (gotContext != context)
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << TestLog::Message << "  Fail, call returned the wrong context. Expected: " << tcu::toHex(context) << ", got: " << tcu::toHex(gotContext) << TestLog::EndMessage;
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid context");
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		enableLogging(false);
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass GetCurrentSurfaceCase : public ContextCase
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GetCurrentSurfaceCase (EglTestContext& eglTestCtx, const char* name, const char* description, const std::vector<EGLint>& configIds, EGLint surfaceTypeMask)
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: ContextCase(eglTestCtx, name, description, configIds, surfaceTypeMask)
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void executeForContext (tcu::egl::Display& display, EGLConfig config, EGLSurface surface, EGLContext context, ContextCaseInfo& info)
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TestLog&	log	= m_testCtx.getLog();
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(display);
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(config && context);
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(info);
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		enableLogging(true);
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const EGLContext	gotReadSurface	= eglGetCurrentSurface(EGL_READ);
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK_EGL();
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const EGLContext	gotDrawSurface	= eglGetCurrentSurface(EGL_DRAW);
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK_EGL();
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (gotReadSurface == surface && gotDrawSurface == surface)
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << TestLog::Message << "  Pass" << TestLog::EndMessage;
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << TestLog::Message << "  Fail, read surface: " << tcu::toHex(gotReadSurface)
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									<< ", draw surface: " << tcu::toHex(gotDrawSurface)
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry									<< ", expected: " << tcu::toHex(surface) << TestLog::EndMessage;
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid surface");
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		enableLogging(false);
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass GetCurrentDisplayCase : public ContextCase
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	GetCurrentDisplayCase (EglTestContext& eglTestCtx, const char* name, const char* description, const std::vector<EGLint>& configIds, EGLint surfaceTypeMask)
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: ContextCase(eglTestCtx, name, description, configIds, surfaceTypeMask)
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void executeForContext (tcu::egl::Display& display, EGLConfig config, EGLSurface surface, EGLContext context, ContextCaseInfo& info)
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TestLog&	log	= m_testCtx.getLog();
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(config && surface && context);
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(info);
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		enableLogging(true);
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const EGLDisplay	gotDisplay	= eglGetCurrentDisplay();
3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK_EGL();
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (gotDisplay == display.getEGLDisplay())
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << TestLog::Message << "  Pass" << TestLog::EndMessage;
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (gotDisplay == EGL_NO_DISPLAY)
3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << TestLog::Message << "  Fail, got EGL_NO_DISPLAY" << TestLog::EndMessage;
3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Unexpected EGL_NO_DISPLAY");
3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		else if (gotDisplay != display.getEGLDisplay())
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << TestLog::Message << "  Fail, call returned the wrong display. Expected: " << tcu::toHex(display.getEGLDisplay()) << ", got: " << tcu::toHex(gotDisplay) << TestLog::EndMessage;
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid display");
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		enableLogging(false);
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass QueryContextCase : public ContextCase
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	QueryContextCase (EglTestContext& eglTestCtx, const char* name, const char* description, const std::vector<EGLint>& configIds, EGLint surfaceTypeMask)
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: ContextCase(eglTestCtx, name, description, configIds, surfaceTypeMask)
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	EGLint getContextAttrib (tcu::egl::Display& display, EGLContext context, EGLint attrib)
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		EGLint	value;
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK_EGL_CALL(eglQueryContext(display.getEGLDisplay(), context, attrib, &value));
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return value;
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void executeForContext (tcu::egl::Display& display, EGLConfig config, EGLSurface surface, EGLContext context, ContextCaseInfo& info)
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TestLog&			log		= m_testCtx.getLog();
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const eglu::Version	version	(display.getEGLMajorVersion(), display.getEGLMinorVersion());
3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		DE_UNREF(surface);
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		enableLogging(true);
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Config ID
3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const EGLint	configID		= getContextAttrib(display, context, EGL_CONFIG_ID);
3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const EGLint	surfaceConfigID	= display.getConfigAttrib(config, EGL_CONFIG_ID);
3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (configID != surfaceConfigID)
3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				log << TestLog::Message << "  Fail, config ID doesn't match the one used to create the context." << TestLog::EndMessage;
3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid config ID");
3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Client API type
3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (version >= eglu::Version(1, 2))
3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const EGLint	clientType		= getContextAttrib(display, context, EGL_CONTEXT_CLIENT_TYPE);
3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (clientType != info.clientType)
3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				log << TestLog::Message << "  Fail, client API type doesn't match." << TestLog::EndMessage;
3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid client API type");
3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Client API version
4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (version >= eglu::Version(1, 3))
4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const EGLint	clientVersion	= getContextAttrib(display, context, EGL_CONTEXT_CLIENT_VERSION);
4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
40742eb50c1e508d12e8439ae4962ab5aa935ec4574Mika Isojärvi			// \todo [2014-10-21 mika] Query actual supported api version from client api to make this check stricter.
40842eb50c1e508d12e8439ae4962ab5aa935ec4574Mika Isojärvi			if (info.clientType == EGL_OPENGL_ES_API && ((info.clientVersion == 1 && clientVersion != 1) || clientVersion < info.clientVersion))
4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				log << TestLog::Message << "  Fail, client API version doesn't match." << TestLog::EndMessage;
4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid client API version");
4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		// Render buffer
4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		if (version >= eglu::Version(1, 2))
4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const EGLint	renderBuffer	= getContextAttrib(display, context, EGL_RENDER_BUFFER);
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (info.surfaceType == EGL_PIXMAP_BIT && renderBuffer != EGL_SINGLE_BUFFER)
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				log << TestLog::Message << "  Fail, render buffer should be EGL_SINGLE_BUFFER for a pixmap surface." << TestLog::EndMessage;
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid render buffer");
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else if (info.surfaceType == EGL_PBUFFER_BIT && renderBuffer != EGL_BACK_BUFFER)
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				log << TestLog::Message << "  Fail, render buffer should be EGL_BACK_BUFFER for a pbuffer surface." << TestLog::EndMessage;
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid render buffer");
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else if (info.surfaceType == EGL_WINDOW_BIT && renderBuffer != EGL_SINGLE_BUFFER && renderBuffer != EGL_BACK_BUFFER)
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				log << TestLog::Message << "  Fail, render buffer should be either EGL_SINGLE_BUFFER or EGL_BACK_BUFFER for a window surface." << TestLog::EndMessage;
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid render buffer");
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		enableLogging(false);
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		log << TestLog::Message << "  Pass" << TestLog::EndMessage;
4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass QueryAPICase : public TestCase, protected eglu::CallLogWrapper
4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	QueryAPICase (EglTestContext& eglTestCtx, const char* name, const char* description)
4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		: TestCase(eglTestCtx, name, description)
4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		, CallLogWrapper(eglTestCtx.getTestContext().getLog())
4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void init (void)
4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	IterateResult iterate (void)
4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestLog&	log		= m_testCtx.getLog();
4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const EGLenum	apis[]	= { EGL_OPENGL_API, EGL_OPENGL_ES_API, EGL_OPENVG_API };
4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		enableLogging(true);
4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const EGLenum	api	= eglQueryAPI();
4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (api != EGL_OPENGL_ES_API && m_eglTestCtx.isAPISupported(EGL_OPENGL_ES_API))
4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				log << TestLog::Message << "  Fail, initial value should be EGL_OPENGL_ES_API if OpenGL ES is supported." << TestLog::EndMessage;
4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid default value");
4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else if(api != EGL_NONE && !m_eglTestCtx.isAPISupported(EGL_OPENGL_ES_API))
4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				log << TestLog::Message << "  Fail, initial value should be EGL_NONE if OpenGL ES is not supported." << TestLog::EndMessage;
4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid default value");
4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(apis); ndx++)
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			const EGLenum	api	= apis[ndx];
4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			log << TestLog::Message << TestLog::EndMessage;
4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if (m_eglTestCtx.isAPISupported(api))
4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				eglBindAPI(api);
4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				if (api != eglQueryAPI())
4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				{
4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					log << TestLog::Message << "  Fail, return value does not match previously bound API." << TestLog::EndMessage;
4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid return value");
4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				}
4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			else
4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			{
4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				log << TestLog::Message << eglu::getAPIStr(api) << " not supported." << TestLog::EndMessage;
4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			}
4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		enableLogging(false);
5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return STOP;
5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5063c827367444ee418f129b2c238299f49d3264554Jarkko PoyryQueryContextTests::QueryContextTests (EglTestContext& eglTestCtx)
5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	: TestCaseGroup(eglTestCtx, "query_context", "Rendering context query tests")
5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5113c827367444ee418f129b2c238299f49d3264554Jarkko PoyryQueryContextTests::~QueryContextTests (void)
5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<class QueryContextClass>
5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid createQueryContextGroups (EglTestContext& eglTestCtx, tcu::TestCaseGroup* group)
5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<RenderConfigIdSet>	configSets;
5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	eglu::FilterList				filters;
5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	getDefaultRenderConfigIdSets(configSets, eglTestCtx.getConfigs(), filters);
5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for (std::vector<RenderConfigIdSet>::const_iterator setIter = configSets.begin(); setIter != configSets.end(); setIter++)
5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		group->addChild(new QueryContextClass(eglTestCtx, setIter->getName(), "", setIter->getConfigIds(), setIter->getSurfaceTypeMask()));
5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid QueryContextTests::init (void)
5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestCaseGroup* simpleGroup = new tcu::TestCaseGroup(m_testCtx, "simple", "Simple API tests");
5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(simpleGroup);
5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		simpleGroup->addChild(new QueryAPICase(m_eglTestCtx, "query_api", "eglQueryAPI() test"));
5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// eglGetCurrentContext
5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestCaseGroup* getCurrentContextGroup = new tcu::TestCaseGroup(m_testCtx, "get_current_context", "eglGetCurrentContext() tests");
5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(getCurrentContextGroup);
5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		createQueryContextGroups<GetCurrentContextCase>(m_eglTestCtx, getCurrentContextGroup);
5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// eglGetCurrentSurface
5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestCaseGroup* getCurrentSurfaceGroup = new tcu::TestCaseGroup(m_testCtx, "get_current_surface", "eglGetCurrentSurface() tests");
5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(getCurrentSurfaceGroup);
5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		createQueryContextGroups<GetCurrentSurfaceCase>(m_eglTestCtx, getCurrentSurfaceGroup);
5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// eglGetCurrentDisplay
5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestCaseGroup* getCurrentDisplayGroup = new tcu::TestCaseGroup(m_testCtx, "get_current_display", "eglGetCurrentDisplay() tests");
5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(getCurrentDisplayGroup);
5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		createQueryContextGroups<GetCurrentDisplayCase>(m_eglTestCtx, getCurrentDisplayGroup);
5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// eglQueryContext
5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		tcu::TestCaseGroup* queryContextGroup = new tcu::TestCaseGroup(m_testCtx, "query_context", "eglQueryContext() tests");
5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		addChild(queryContextGroup);
5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		createQueryContextGroups<QueryContextCase>(m_eglTestCtx, queryContextGroup);
5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // egl
5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp
571