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