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 EGL Test Package
22 *//*--------------------------------------------------------------------*/
23
24#include "teglTestPackage.hpp"
25
26#include "tcuTestLog.hpp"
27#include "tcuPlatform.hpp"
28#include "tcuCommandLine.hpp"
29
30#include "egluPlatform.hpp"
31#include "egluNativeDisplay.hpp"
32#include "egluNativeWindow.hpp"
33#include "egluNativePixmap.hpp"
34
35#include "teglInfoTests.hpp"
36#include "teglCreateContextTests.hpp"
37#include "teglQueryContextTests.hpp"
38#include "teglCreateSurfaceTests.hpp"
39#include "teglQuerySurfaceTests.hpp"
40#include "teglChooseConfigTests.hpp"
41#include "teglQueryConfigTests.hpp"
42#include "teglColorClearTests.hpp"
43#include "teglRenderTests.hpp"
44#include "teglImageTests.hpp"
45#include "teglGLES2SharingTests.hpp"
46#include "teglNegativeApiTests.hpp"
47#include "teglSyncTests.hpp"
48#include "teglMultiThreadTests.hpp"
49#include "teglGetProcAddressTests.hpp"
50#include "teglMemoryStressTests.hpp"
51#include "teglMakeCurrentPerfTests.hpp"
52#include "teglGLES2SharedRenderingPerfTests.hpp"
53#include "teglPreservingSwapTests.hpp"
54#include "teglClientExtensionTests.hpp"
55#include "teglCreateContextExtTests.hpp"
56#include "teglSurfacelessContextTests.hpp"
57#include "teglSwapBuffersTests.hpp"
58#include "teglNativeColorMappingTests.hpp"
59#include "teglNativeCoordMappingTests.hpp"
60#include "teglResizeTests.hpp"
61
62#include <typeinfo>
63
64using std::vector;
65
66namespace deqp
67{
68namespace egl
69{
70
71class StressTests : public TestCaseGroup
72{
73public:
74	StressTests (EglTestContext& eglTestCtx)
75		: TestCaseGroup(eglTestCtx, "stress", "EGL stress tests")
76	{
77	}
78
79	void init (void)
80	{
81		addChild(new MemoryStressTests(m_eglTestCtx));
82	}
83};
84
85class PerformanceTests : public TestCaseGroup
86{
87public:
88	PerformanceTests (EglTestContext& eglTestCtx)
89		: TestCaseGroup(eglTestCtx, "performance", "EGL performance tests")
90	{
91	}
92
93	void init (void)
94	{
95		addChild(new MakeCurrentPerfTests			(m_eglTestCtx));
96		addChild(new GLES2SharedRenderingPerfTests	(m_eglTestCtx));
97	}
98};
99
100class FunctionalTests : public TestCaseGroup
101{
102public:
103	FunctionalTests (EglTestContext& eglTestCtx)
104		: TestCaseGroup(eglTestCtx, "functional", "EGL functional tests")
105	{
106	}
107
108	void init (void)
109	{
110		addChild(new CreateContextTests			(m_eglTestCtx));
111		addChild(new QueryContextTests			(m_eglTestCtx));
112		addChild(new CreateSurfaceTests			(m_eglTestCtx));
113		addChild(new QuerySurfaceTests			(m_eglTestCtx));
114		addChild(new QueryConfigTests			(m_eglTestCtx));
115		addChild(new ChooseConfigTests			(m_eglTestCtx));
116		addChild(new ColorClearTests			(m_eglTestCtx));
117		addChild(new RenderTests				(m_eglTestCtx));
118		addChild(new ImageTests					(m_eglTestCtx));
119		addChild(new SharingTests				(m_eglTestCtx));
120		addChild(new NegativeApiTests			(m_eglTestCtx));
121		addChild(new FenceSyncTests				(m_eglTestCtx));
122		addChild(new MultiThreadedTests			(m_eglTestCtx));
123		addChild(new GetProcAddressTests		(m_eglTestCtx));
124		addChild(new PreservingSwapTests		(m_eglTestCtx));
125		addChild(new ClientExtensionTests		(m_eglTestCtx));
126		addChild(new CreateContextExtTests		(m_eglTestCtx));
127		addChild(new SurfacelessContextTests	(m_eglTestCtx));
128		addChild(new SwapBuffersTests			(m_eglTestCtx));
129		addChild(new NativeColorMappingTests	(m_eglTestCtx));
130		addChild(new NativeCoordMappingTests	(m_eglTestCtx));
131		addChild(new ReusableSyncTests			(m_eglTestCtx));
132		addChild(new ResizeTests				(m_eglTestCtx));
133	}
134};
135
136TestCaseWrapper::TestCaseWrapper (EglTestContext& eglTestCtx)
137	: tcu::TestCaseWrapper	(eglTestCtx.getTestContext())
138	, m_eglTestCtx			(eglTestCtx)
139{
140}
141
142TestCaseWrapper::~TestCaseWrapper (void)
143{
144}
145
146bool TestCaseWrapper::initTestCase (tcu::TestCase* testCase)
147{
148	tcu::TestLog& log = m_eglTestCtx.getTestContext().getLog();
149
150	// Create display
151	try
152	{
153		m_eglTestCtx.createDefaultDisplay();
154	}
155	catch (const std::exception& e)
156	{
157		log << e;
158		m_eglTestCtx.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Failed to initialize EGL for default display");
159		return false;
160	}
161
162	return tcu::TestCaseWrapper::initTestCase(testCase);
163}
164
165bool TestCaseWrapper::deinitTestCase (tcu::TestCase* testCase)
166{
167	tcu::TestLog& log = m_eglTestCtx.getTestContext().getLog();
168
169	bool deinitOk = tcu::TestCaseWrapper::deinitTestCase(testCase);
170
171	// Destroy display
172	try
173	{
174		TCU_CHECK_EGL_CALL(eglMakeCurrent(m_eglTestCtx.getDisplay().getEGLDisplay(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
175		m_eglTestCtx.destroyDefaultDisplay();
176	}
177	catch (const std::exception& e)
178	{
179		log << e;
180		log << tcu::TestLog::Message << "Error in EGL deinit, test program will teminate." << tcu::TestLog::EndMessage;
181		return false;
182	}
183
184	return deinitOk;
185}
186
187tcu::TestNode::IterateResult TestCaseWrapper::iterateTestCase (tcu::TestCase* testCase)
188{
189	return tcu::TestCaseWrapper::iterateTestCase(testCase);
190}
191
192PackageContext::PackageContext (tcu::TestContext& testCtx)
193	: m_eglTestCtx	(DE_NULL)
194	, m_caseWrapper	(DE_NULL)
195{
196	const eglu::NativeDisplayFactoryRegistry&	dpyFactoryRegistry	= testCtx.getPlatform().getEGLPlatform().getNativeDisplayFactoryRegistry();
197	const char* const							displayFactoryName	= testCtx.getCommandLine().getEGLDisplayType();
198	const char* const							windowFactoryName	= testCtx.getCommandLine().getEGLWindowType();
199	const char* const							pixmapFactoryName	= testCtx.getCommandLine().getEGLPixmapType();
200
201	const eglu::NativeDisplayFactory*			displayFactory		= DE_NULL;
202	const eglu::NativeWindowFactory*			windowFactory		= DE_NULL;
203	const eglu::NativePixmapFactory*			pixmapFactory		= DE_NULL;
204
205	if (dpyFactoryRegistry.empty())
206	{
207		tcu::print("ERROR: Platform doesn't support any EGL native display types!\n");
208		throw tcu::NotSupportedError("Platform doesn't have EGL any native display factories", DE_NULL, __FILE__, __LINE__);
209	}
210
211	if (!displayFactoryName)
212		displayFactory = dpyFactoryRegistry.getDefaultFactory();
213	else
214	{
215		displayFactory = dpyFactoryRegistry.getFactoryByName(displayFactoryName);
216
217		if (!displayFactory)
218		{
219			tcu::print("ERROR: Unknown/unsupported EGL native display type '%s'\n", displayFactoryName);
220			tcu::print("Supported EGL native display types:\n");
221
222			for (int factoryNdx = 0; factoryNdx < (int)dpyFactoryRegistry.getFactoryCount(); factoryNdx++)
223			{
224				const char* name = dpyFactoryRegistry.getFactoryByIndex(factoryNdx)->getName();
225				const char* desc = dpyFactoryRegistry.getFactoryByIndex(factoryNdx)->getDescription();
226
227				tcu::print("  %s: %s\n", name, desc);
228			}
229
230			throw tcu::NotSupportedError(("Unknown EGL native display type '" + std::string(displayFactoryName) + "'.").c_str(), DE_NULL, __FILE__, __LINE__);
231		}
232	}
233
234	tcu::print("Using EGL native display type '%s'\n", displayFactory->getName());
235
236	if (!displayFactory->getNativeWindowRegistry().empty())
237	{
238		windowFactory = windowFactoryName ? displayFactory->getNativeWindowRegistry().getFactoryByName(windowFactoryName)
239										  : displayFactory->getNativeWindowRegistry().getDefaultFactory();
240
241		if (!windowFactory)
242		{
243			DE_ASSERT(windowFactoryName);
244			tcu::print("ERROR: Unknown/unsupported EGL native window type '%s'\n", windowFactoryName);
245			tcu::print("Supported EGL native window types for native display '%s':\n", displayFactory->getName());
246
247			for (int factoryNdx = 0; factoryNdx < (int)displayFactory->getNativeWindowRegistry().getFactoryCount(); factoryNdx++)
248			{
249				const char* name = displayFactory->getNativeWindowRegistry().getFactoryByIndex(factoryNdx)->getName();
250				const char* desc = displayFactory->getNativeWindowRegistry().getFactoryByIndex(factoryNdx)->getDescription();
251
252				tcu::print("  %s: %s\n", name, desc);
253			}
254
255			throw tcu::NotSupportedError(("Unknown EGL native window type '" + std::string(windowFactoryName) + "'").c_str(), DE_NULL, __FILE__, __LINE__);
256		}
257	}
258	else
259		tcu::print("Warning: EGL native display doesn't have any native window types.\n");
260
261	if (!displayFactory->getNativePixmapRegistry().empty())
262	{
263		pixmapFactory = pixmapFactoryName ? displayFactory->getNativePixmapRegistry().getFactoryByName(pixmapFactoryName)
264										  : displayFactory->getNativePixmapRegistry().getDefaultFactory();
265
266		if (!pixmapFactory)
267		{
268			DE_ASSERT(pixmapFactoryName);
269			tcu::print("ERROR: Unknown/unsupported EGL native pixmap type '%s'\n", pixmapFactoryName);
270			tcu::print("Supported EGL native pixmap types for native display '%s':\n", displayFactory->getName());
271
272			for (int factoryNdx = 0; factoryNdx < (int)displayFactory->getNativePixmapRegistry().getFactoryCount(); factoryNdx++)
273			{
274				const char* name = displayFactory->getNativePixmapRegistry().getFactoryByIndex(factoryNdx)->getName();
275				const char* desc = displayFactory->getNativePixmapRegistry().getFactoryByIndex(factoryNdx)->getDescription();
276
277				tcu::print("  %s: %s\n", name, desc);
278			}
279
280			throw tcu::NotSupportedError(("Unknown EGL native pixmap type '" + std::string(pixmapFactoryName) + "'").c_str(), DE_NULL, __FILE__, __LINE__);
281		}
282	}
283	else
284		tcu::print("Warning: EGL native display doesn't have any native pixmap types.\n");
285
286	if (windowFactory)
287		tcu::print("Using EGL native window type '%s'\n", windowFactory->getName());
288	if (pixmapFactory)
289		tcu::print("Using EGL native pixmap type '%s'\n", pixmapFactory->getName());
290
291	try
292	{
293		m_eglTestCtx	= new EglTestContext(testCtx, *displayFactory, windowFactory, pixmapFactory);
294		m_caseWrapper	= new TestCaseWrapper(*m_eglTestCtx);
295	}
296	catch (...)
297	{
298		delete m_caseWrapper;
299		delete m_eglTestCtx;
300
301		throw;
302	}
303}
304
305PackageContext::~PackageContext (void)
306{
307	delete m_caseWrapper;
308	delete m_eglTestCtx;
309}
310
311TestPackage::TestPackage (tcu::TestContext& testCtx)
312	: tcu::TestPackage	(testCtx, "dEQP-EGL", "dEQP EGL Tests")
313	, m_packageCtx		(DE_NULL)
314	, m_archive			(testCtx.getRootArchive(), "egl/")
315{
316}
317
318TestPackage::~TestPackage (void)
319{
320	// Destroy children first since destructors may access context.
321	TestNode::deinit();
322	delete m_packageCtx;
323}
324
325void TestPackage::init (void)
326{
327	DE_ASSERT(!m_packageCtx);
328	m_packageCtx = new PackageContext(m_testCtx);
329
330	try
331	{
332		addChild(new InfoTests				(m_packageCtx->getEglTestContext()));
333		addChild(new FunctionalTests		(m_packageCtx->getEglTestContext()));
334		addChild(new PerformanceTests		(m_packageCtx->getEglTestContext()));
335		addChild(new StressTests			(m_packageCtx->getEglTestContext()));
336	}
337	catch (...)
338	{
339		delete m_packageCtx;
340		m_packageCtx = DE_NULL;
341
342		throw;
343	}
344}
345
346void TestPackage::deinit (void)
347{
348	tcu::TestNode::deinit();
349	delete m_packageCtx;
350	m_packageCtx = DE_NULL;
351}
352
353} // egl
354} // deqp
355