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_EXT_client_extensions tests
22  *//*--------------------------------------------------------------------*/
23 
24 #include "teglClientExtensionTests.hpp"
25 
26 #include "tcuTestLog.hpp"
27 
28 #include "egluUtil.hpp"
29 
30 #include "eglwLibrary.hpp"
31 #include "eglwEnums.hpp"
32 
33 #include "deStringUtil.hpp"
34 #include "deSTLUtil.hpp"
35 
36 #include <vector>
37 #include <set>
38 #include <string>
39 #include <sstream>
40 
41 using std::string;
42 using std::vector;
43 using std::set;
44 
45 using tcu::TestLog;
46 
47 using namespace eglw;
48 
49 namespace deqp
50 {
51 namespace egl
52 {
53 namespace
54 {
55 
56 static const char* const s_displayExtensionList[] =
57 {
58 	"EGL_KHR_config_attribs",
59 	"EGL_KHR_lock_surface",
60 	"EGL_KHR_image",
61 	"EGL_KHR_vg_parent_image",
62 	"EGL_KHR_gl_texture_2D_image",
63 	"EGL_KHR_gl_texture_cubemap_image",
64 	"EGL_KHR_gl_texture_3D_image",
65 	"EGL_KHR_gl_renderbuffer_image",
66 	"EGL_KHR_reusable_sync",
67 	"EGL_KHR_image_base",
68 	"EGL_KHR_image_pixmap",
69 	"EGL_IMG_context_priority",
70 	"EGL_KHR_lock_surface2",
71 	"EGL_NV_coverage_sample",
72 	"EGL_NV_depth_nonlinear",
73 	"EGL_NV_sync",
74 	"EGL_KHR_fence_sync",
75 	"EGL_HI_clientpixmap",
76 	"EGL_HI_colorformats",
77 	"EGL_MESA_drm_image",
78 	"EGL_NV_post_sub_buffer",
79 	"EGL_ANGLE_query_surface_pointer",
80 	"EGL_ANGLE_surface_d3d_texture_2d_share_handle",
81 	"EGL_NV_coverage_sample_resolve",
82 //	"EGL_NV_system_time",	\todo [mika] Unclear which one this is
83 	"EGL_KHR_stream",
84 	"EGL_KHR_stream_consumer_gltexture",
85 	"EGL_KHR_stream_producer_eglsurface",
86 	"EGL_KHR_stream_producer_aldatalocator",
87 	"EGL_KHR_stream_fifo",
88 	"EGL_EXT_create_context_robustness",
89 	"EGL_ANGLE_d3d_share_handle_client_buffer",
90 	"EGL_KHR_create_context",
91 	"EGL_KHR_surfaceless_context",
92 	"EGL_KHR_stream_cross_process_fd",
93 	"EGL_EXT_multiview_window",
94 	"EGL_KHR_wait_sync",
95 	"EGL_NV_post_convert_rounding",
96 	"EGL_NV_native_query",
97 	"EGL_NV_3dvision_surface",
98 	"EGL_ANDROID_framebuffer_target",
99 	"EGL_ANDROID_blob_cache",
100 	"EGL_ANDROID_image_native_buffer",
101 	"EGL_ANDROID_native_fence_sync",
102 	"EGL_ANDROID_recordable",
103 	"EGL_EXT_buffer_age",
104 	"EGL_EXT_image_dma_buf_import",
105 	"EGL_ARM_pixmap_multisample_discard",
106 	"EGL_EXT_swap_buffers_with_damage",
107 	"EGL_NV_stream_sync",
108 	"EGL_KHR_cl_event",
109 	"EGL_KHR_get_all_proc_addresses"
110 };
111 
112 static const char* const s_clientExtensionList[] =
113 {
114 	"EGL_EXT_platform_base",
115 	"EGL_EXT_client_extensions",
116 	"EGL_EXT_platform_x11",
117 	"EGL_KHR_client_get_all_proc_addresses",
118 	"EGL_MESA_platform_gbm",
119 	"EGL_EXT_platform_wayland"
120 };
121 
122 class BaseTest : public TestCase
123 {
124 public:
125 					BaseTest	(EglTestContext& eglTestCtx);
126 	IterateResult	iterate		(void);
127 };
128 
BaseTest(EglTestContext & eglTestCtx)129 BaseTest::BaseTest (EglTestContext& eglTestCtx)
130 	: TestCase(eglTestCtx, "base", "Basic tests for EGL_EXT_client_extensions")
131 {
132 }
133 
iterate(void)134 TestCase::IterateResult BaseTest::iterate (void)
135 {
136 	const Library&		egl					= m_eglTestCtx.getLibrary();
137 	const char* const	clientExtesionsStr	= egl.queryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
138 	const EGLint		eglError			= egl.getError();
139 
140 	if (eglError == EGL_BAD_DISPLAY)
141 		TCU_THROW(NotSupportedError, "EGL_EXT_client_extensions not supported");
142 	else if (eglError != EGL_SUCCESS)
143 		throw eglu::Error(eglError, "eglQueryString()", DE_NULL, __FILE__, __LINE__);
144 
145 	TCU_CHECK(clientExtesionsStr);
146 
147 	{
148 		bool				found		= false;
149 		std::istringstream	stream		(clientExtesionsStr);
150 		string				extension;
151 
152 		while (std::getline(stream, extension, ' '))
153 		{
154 			if (extension == "EGL_EXT_client_extensions")
155 			{
156 				found = true;
157 				break;
158 			}
159 		}
160 
161 		if (found)
162 			m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
163 		else
164 		{
165 			m_testCtx.getLog() << TestLog::Message << "eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS) didn't fail, but extension string doesn't contain EGL_EXT_client_extensions" <<TestLog::EndMessage;
166 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
167 		}
168 	}
169 
170 	return STOP;
171 }
172 
173 class CheckExtensionsTest : public TestCase
174 {
175 public:
176 					CheckExtensionsTest	(EglTestContext& eglTestCtx);
177 	IterateResult	iterate				(void);
178 };
179 
CheckExtensionsTest(EglTestContext & eglTestCtx)180 CheckExtensionsTest::CheckExtensionsTest (EglTestContext& eglTestCtx)
181 	: TestCase(eglTestCtx, "extensions", "Check that returned extensions are client or display extensions")
182 {
183 }
184 
iterate(void)185 TestCase::IterateResult CheckExtensionsTest::iterate (void)
186 {
187 	const Library&		egl						= m_eglTestCtx.getLibrary();
188 	bool				isOk					= true;
189 	const char* const	clientExtensionsStr		= egl.queryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
190 	const EGLint		eglQueryError			= egl.getError();
191 
192 	set<string>			knownClientExtensions	(s_clientExtensionList, s_clientExtensionList + DE_LENGTH_OF_ARRAY(s_clientExtensionList));
193 	set<string>			knownDisplayExtensions	(s_displayExtensionList, s_displayExtensionList + DE_LENGTH_OF_ARRAY(s_displayExtensionList));
194 
195 	vector<string>		displayExtensions;
196 	vector<string>		clientExtensions;
197 
198 	if (eglQueryError == EGL_BAD_DISPLAY)
199 		TCU_THROW(NotSupportedError, "EGL_EXT_client_extensions not supported");
200 	else if (eglQueryError != EGL_SUCCESS)
201 		throw eglu::Error(eglQueryError, "eglQueryString()", DE_NULL, __FILE__, __LINE__);
202 
203 	TCU_CHECK(clientExtensionsStr);
204 
205 	clientExtensions = de::splitString(clientExtensionsStr, ' ');
206 
207 	{
208 		EGLDisplay	display	= eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
209 
210 		displayExtensions = de::splitString(egl.queryString(display, EGL_EXTENSIONS), ' ');
211 
212 		egl.terminate(display);
213 	}
214 
215 	for (int extNdx = 0; extNdx < (int)clientExtensions.size(); extNdx++)
216 	{
217 		if (knownDisplayExtensions.find(clientExtensions[extNdx]) != knownDisplayExtensions.end())
218 		{
219 			m_testCtx.getLog() << TestLog::Message << "'" << clientExtensions[extNdx] << "' is not client extension" << TestLog::EndMessage;
220 			isOk = false;
221 		}
222 	}
223 
224 	for (int extNdx = 0; extNdx < (int)displayExtensions.size(); extNdx++)
225 	{
226 		if (knownClientExtensions.find(displayExtensions[extNdx]) != knownClientExtensions.end())
227 		{
228 			m_testCtx.getLog() << TestLog::Message << "'" << displayExtensions[extNdx] << "' is not display extension" << TestLog::EndMessage;
229 			isOk = false;
230 		}
231 	}
232 
233 	if (isOk)
234 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
235 	else
236 		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
237 	return STOP;
238 }
239 
240 
241 class DisjointTest : public TestCase
242 {
243 public:
244 					DisjointTest	(EglTestContext& eglTestCtx);
245 	IterateResult	iterate			(void);
246 };
247 
DisjointTest(EglTestContext & eglTestCtx)248 DisjointTest::DisjointTest (EglTestContext& eglTestCtx)
249 	: TestCase(eglTestCtx, "disjoint", "Check that client and display extensions are disjoint")
250 {
251 }
252 
iterate(void)253 TestCase::IterateResult DisjointTest::iterate (void)
254 {
255 	const Library&		egl					= m_eglTestCtx.getLibrary();
256 	const char*	const	clientExtensionsStr	= egl.queryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
257 	const EGLint		eglQueryError		= egl.getError();
258 
259 	if (eglQueryError == EGL_BAD_DISPLAY)
260 		TCU_THROW(NotSupportedError, "EGL_EXT_client_extensions not supported");
261 	else if (eglQueryError != EGL_SUCCESS)
262 		throw eglu::Error(eglQueryError, "eglQueryString()", DE_NULL, __FILE__, __LINE__);
263 
264 	vector<string>		displayExtensions;
265 	vector<string>		clientExtensions;
266 
267 	clientExtensions = de::splitString(clientExtensionsStr, ' ');
268 
269 	{
270 		EGLDisplay	display	= eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
271 
272 		displayExtensions = de::splitString(egl.queryString(display, EGL_EXTENSIONS), ' ');
273 
274 		egl.terminate(display);
275 	}
276 
277 	// Log client extensions
278 	{
279 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Client extensions", "Client extensions");
280 
281 		for (int extNdx = 0; extNdx < (int)clientExtensions.size(); extNdx++)
282 			m_testCtx.getLog() << TestLog::Message << clientExtensions[extNdx] << TestLog::EndMessage;
283 	}
284 
285 	// Log display extensions
286 	{
287 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Display extensions", "Display extensions");
288 
289 		for (int extNdx = 0; extNdx < (int)displayExtensions.size(); extNdx++)
290 			m_testCtx.getLog() << TestLog::Message << displayExtensions[extNdx] << TestLog::EndMessage;
291 	}
292 
293 	// Check that sets are disjoint
294 	{
295 		set<string>			commonExtensionSet;
296 		const set<string>	clientExtensionSet(clientExtensions.begin(), clientExtensions.end());
297 		const set<string>	displayExtensionSet(displayExtensions.begin(), displayExtensions.end());
298 
299 		for (set<string>::const_iterator iter = clientExtensionSet.begin(); iter != clientExtensionSet.end(); ++iter)
300 		{
301 			if (displayExtensionSet.find(*iter) != displayExtensionSet.end())
302 				commonExtensionSet.insert(*iter);
303 		}
304 
305 		for (set<string>::const_iterator iter = commonExtensionSet.begin(); iter != commonExtensionSet.end(); ++iter)
306 			m_testCtx.getLog() << TestLog::Message << "Extension '" << *iter << "' exists in client and display extension sets." << TestLog::EndMessage;
307 
308 		if (commonExtensionSet.empty())
309 			m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
310 		else
311 		{
312 			m_testCtx.getLog() << TestLog::Message << "Extension sets are not disjoint" << TestLog::EndMessage;
313 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
314 		}
315 	}
316 
317 	return STOP;
318 }
319 
320 } // anonymous
321 
ClientExtensionTests(EglTestContext & eglTestCtx)322 ClientExtensionTests::ClientExtensionTests (EglTestContext& eglTestCtx)
323 	: TestCaseGroup(eglTestCtx, "client_extensions", "Test for EGL_EXT_client_extensions")
324 {
325 }
326 
init(void)327 void ClientExtensionTests::init (void)
328 {
329 	addChild(new BaseTest(m_eglTestCtx));
330 	addChild(new DisjointTest(m_eglTestCtx));
331 	addChild(new CheckExtensionsTest(m_eglTestCtx));
332 }
333 
334 } // egl
335 } // deqp
336