[Piglit] [PATCH] egl_khr_get_all_proc_addresses: Add sanity test

Chad Versace chad.versace at intel.com
Tue May 12 15:56:21 PDT 2015


Emil discovered that my implementation in Mesa was bogus. This test
exposes the error.

Cc: Emil Velikov <emil.l.velikov at gmail.com>
---
 tests/all.py                                       |   6 +
 tests/egl/spec/CMakeLists.txt                      |   1 +
 .../CMakeLists.no_api.txt                          |   7 ++
 .../egl_khr_get_all_proc_addresses/CMakeLists.txt  |   1 +
 .../egl_khr_get_all_proc_addresses.c               | 130 +++++++++++++++++++++
 5 files changed, 145 insertions(+)
 create mode 100644 tests/egl/spec/egl_khr_get_all_proc_addresses/CMakeLists.no_api.txt
 create mode 100644 tests/egl/spec/egl_khr_get_all_proc_addresses/CMakeLists.txt
 create mode 100644 tests/egl/spec/egl_khr_get_all_proc_addresses/egl_khr_get_all_proc_addresses.c

diff --git a/tests/all.py b/tests/all.py
index 63a6cf8..5407307 100755
--- a/tests/all.py
+++ b/tests/all.py
@@ -4216,6 +4216,12 @@ with profile.group_manager(
 
 with profile.group_manager(
         PiglitGLTest,
+        grouptools.join('spec', 'egl_khr_get_all_proc_addresses'),
+        exclude_platforms=['glx']) as g:
+    g(['egl_khr_get_all_proc_addresses'], 'conformance')
+
+with profile.group_manager(
+        PiglitGLTest,
         grouptools.join('spec', 'egl_chromium_sync_control'),
         exclude_platforms=['glx']) as g:
     g(['egl_chromium_sync_control'], 'conformance')
diff --git a/tests/egl/spec/CMakeLists.txt b/tests/egl/spec/CMakeLists.txt
index a5e749f..d8f90b1 100644
--- a/tests/egl/spec/CMakeLists.txt
+++ b/tests/egl/spec/CMakeLists.txt
@@ -1,5 +1,6 @@
 add_subdirectory (egl-1.4)
 add_subdirectory (egl_ext_client_extensions)
 add_subdirectory (egl_khr_create_context)
+add_subdirectory (egl_khr_get_all_proc_addresses)
 add_subdirectory (egl_khr_fence_sync)
 add_subdirectory (egl_chromium_sync_control)
diff --git a/tests/egl/spec/egl_khr_get_all_proc_addresses/CMakeLists.no_api.txt b/tests/egl/spec/egl_khr_get_all_proc_addresses/CMakeLists.no_api.txt
new file mode 100644
index 0000000..2b0b39a
--- /dev/null
+++ b/tests/egl/spec/egl_khr_get_all_proc_addresses/CMakeLists.no_api.txt
@@ -0,0 +1,7 @@
+link_libraries(
+	piglitutil
+)
+
+piglit_add_executable(egl_khr_get_all_proc_addresses egl_khr_get_all_proc_addresses.c)
+
+# vim: ft=cmake:
diff --git a/tests/egl/spec/egl_khr_get_all_proc_addresses/CMakeLists.txt b/tests/egl/spec/egl_khr_get_all_proc_addresses/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/egl/spec/egl_khr_get_all_proc_addresses/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/egl/spec/egl_khr_get_all_proc_addresses/egl_khr_get_all_proc_addresses.c b/tests/egl/spec/egl_khr_get_all_proc_addresses/egl_khr_get_all_proc_addresses.c
new file mode 100644
index 0000000..58f6576
--- /dev/null
+++ b/tests/egl/spec/egl_khr_get_all_proc_addresses/egl_khr_get_all_proc_addresses.c
@@ -0,0 +1,130 @@
+/* Copyright 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+/**
+ * \file
+ *
+ * Tests for EGL_KHR_get_all_proc_addresses and
+ * EGL_KHR_client_get_all_proc_addresses.
+ */
+
+#include "piglit-util.h"
+#include "piglit-util-egl.h"
+
+static const char *(*myEGLQueryString)(EGLDisplay dpy, EGLenum name);
+
+static const char *
+bool_to_str(bool b)
+{
+	if (b)
+		return "true";
+	else
+		return "false";
+}
+
+int
+main(void)
+{
+	EGLDisplay dpy;
+	EGLint egl_major, egl_minor;
+
+	const char *client_exts = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
+	bool has_client_ext =
+		client_exts &&
+		piglit_is_extension_in_string(client_exts,
+			"EGL_KHR_client_get_all_proc_addresses");
+
+	dpy = eglGetDisplay(NULL);
+	if (!dpy) {
+		printf("failed to get EGLDisplay\n");
+		piglit_report_result(PIGLIT_SKIP);
+	}
+
+	if (!eglInitialize(dpy, &egl_major, &egl_minor)) {
+		printf("eglInitialize failed\n");
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	bool has_egl15 = (egl_major == 1 && egl_minor >= 5);
+
+	const char *display_exts = eglQueryString(dpy, EGL_EXTENSIONS);
+	size_t display_exts_len = strlen(display_exts);
+	bool has_display_ext = piglit_is_egl_extension_supported(dpy,
+				"EGL_KHR_get_all_proc_addresses");
+
+	if (has_egl15 || has_client_ext || has_display_ext) {
+		printf("eglGetProcAddress should work on core functions "
+		       "because one of the following is true:\n"
+		       "  EGL version >= 1.5 : %s\n"
+		       "  EGL_KHR_get_all_proc_addresses: %s\n"
+		       "  EGL_KHR_client_get_all_proc_addresses: %s\n"
+		       "\n",
+		       bool_to_str(has_egl15),
+		       bool_to_str(has_display_ext),
+		       bool_to_str(has_client_ext));
+
+		/* We already know eglQueryString works because we used it
+		 * above. Let's verify that it still works when called through
+		 * eglGetProcAddress.
+		 */
+		myEGLQueryString = (void *) eglGetProcAddress("eglQueryString");
+		if (!myEGLQueryString) {
+			printf("eglGetProcAddress(\"eglQueryString\") failed\n");
+			piglit_report_result(PIGLIT_FAIL);
+		}
+
+		const char *display_exts2 = myEGLQueryString(dpy, EGL_EXTENSIONS);
+		if (display_exts2 == NULL ||
+		    strncmp(display_exts, display_exts2,
+			    display_exts_len + 1) != 0) {
+			printf("eglQueryString(EGL_EXTENSIONS) result differs "
+			       "when called through eglGetProcAddress\n");
+			piglit_report_result(PIGLIT_FAIL);
+		}
+
+		printf("eglQueryString(EGL_EXTENSIONS) works when called "
+		       "through eglGetProcAddress()\n");
+	}
+
+	if (client_exts) {
+		/* From the EGL_KHR_get_proc_addresses v3 spec:
+		 *
+		 *     The EGL implementation must expose the name
+		 *     EGL_KHR_client_get_all_proc_addresses if and only if it
+		 *     exposes EGL_KHR_get_all_proc_addresses and
+		 *     supports EGL_EXT_client_extensions.
+		 */
+		if (has_display_ext && !has_client_ext) {
+			printf("EGL_KHR_get_all_proc_addresses and "
+			       "EGL_EXT_client_extensions are supported but "
+			       "not EGL_KHR_client_get_all_proc_addresses\n");
+			piglit_report_result(PIGLIT_FAIL);
+		} else if (has_client_ext && !has_display_ext) {
+			printf("EGL_KHR_client_get_all_proc_addresses is "
+			       "supported but not "
+			       "EGL_KHR_get_all_proc_addresses\n");
+			piglit_report_result(PIGLIT_FAIL);
+		}
+	}
+
+	piglit_report_result(PIGLIT_PASS);
+}
-- 
2.4.0



More information about the Piglit mailing list