[Piglit] [PATCH 2/9] egl: Add basic EGL_MESA_device_software test

Emil Velikov emil.l.velikov at gmail.com
Fri Aug 3 12:46:30 UTC 2018


From: Emil Velikov <emil.velikov at collabora.com>

The extension doesn't do anything useful but report a device ext.
string. Ensure that such a device does not attempt to expose DRM
specifics - nearly missed that during development.

Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
 tests/egl/spec/CMakeLists.txt                 |   1 +
 .../CMakeLists.no_api.txt                     |   7 +
 .../egl_mesa_device_software/CMakeLists.txt   |   1 +
 .../egl_mesa_device_software.c                | 130 ++++++++++++++++++
 tests/opengl.py                               |   6 +
 5 files changed, 145 insertions(+)
 create mode 100644 tests/egl/spec/egl_mesa_device_software/CMakeLists.no_api.txt
 create mode 100644 tests/egl/spec/egl_mesa_device_software/CMakeLists.txt
 create mode 100644 tests/egl/spec/egl_mesa_device_software/egl_mesa_device_software.c

diff --git a/tests/egl/spec/CMakeLists.txt b/tests/egl/spec/CMakeLists.txt
index 772f8258a..bfb55b9de 100644
--- a/tests/egl/spec/CMakeLists.txt
+++ b/tests/egl/spec/CMakeLists.txt
@@ -8,6 +8,7 @@ add_subdirectory (egl_khr_get_all_proc_addresses)
 add_subdirectory (egl_khr_gl_image)
 add_subdirectory (egl_khr_fence_sync)
 add_subdirectory (egl_khr_surfaceless_context)
+add_subdirectory (egl_mesa_device_software)
 add_subdirectory (egl_mesa_platform_surfaceless)
 
 if (PIGLIT_HAS_X11)
diff --git a/tests/egl/spec/egl_mesa_device_software/CMakeLists.no_api.txt b/tests/egl/spec/egl_mesa_device_software/CMakeLists.no_api.txt
new file mode 100644
index 000000000..b1dd9a1f5
--- /dev/null
+++ b/tests/egl/spec/egl_mesa_device_software/CMakeLists.no_api.txt
@@ -0,0 +1,7 @@
+link_libraries(
+	piglitutil
+)
+
+piglit_add_executable(egl_mesa_device_software egl_mesa_device_software.c)
+
+# vim: ft=cmake:
diff --git a/tests/egl/spec/egl_mesa_device_software/CMakeLists.txt b/tests/egl/spec/egl_mesa_device_software/CMakeLists.txt
new file mode 100644
index 000000000..144a306f4
--- /dev/null
+++ b/tests/egl/spec/egl_mesa_device_software/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/egl/spec/egl_mesa_device_software/egl_mesa_device_software.c b/tests/egl/spec/egl_mesa_device_software/egl_mesa_device_software.c
new file mode 100644
index 000000000..5004f0c60
--- /dev/null
+++ b/tests/egl/spec/egl_mesa_device_software/egl_mesa_device_software.c
@@ -0,0 +1,130 @@
+/*
+ * Copyright © 2016 Red Hat, Inc.
+ * Copyright 2015 Intel Corporation
+ * Copyright 2018 Collabora, Ltd.
+ *
+ * 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.
+ */
+
+#include "piglit-util.h"
+#include "piglit-util-egl.h"
+
+#define NDEVS 1024
+
+int
+main(void)
+{
+	enum piglit_result result = PIGLIT_PASS;
+	EGLDeviceEXT devs[NDEVS];
+	EGLint i, numdevs, swdevs;
+	EGLDeviceEXT device = EGL_NO_DEVICE_EXT;
+	EGLAttrib attr;
+	const char *devstring = NULL;
+	PFNEGLQUERYDEVICESEXTPROC queryDevices;
+	PFNEGLQUERYDEVICESTRINGEXTPROC queryDeviceString;
+	PFNEGLQUERYDEVICEATTRIBEXTPROC queryDeviceAttrib;
+
+	const char *client_exts = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
+	bool has_client_ext =
+		client_exts &&
+		((piglit_is_extension_in_string(client_exts,
+			"EGL_EXT_device_query") &&
+		  piglit_is_extension_in_string(client_exts,
+			"EGL_EXT_device_enumeration")) ||
+		 piglit_is_extension_in_string(client_exts,
+			"EGL_EXT_device_base"));
+
+	if (!has_client_ext) {
+		printf("EGL_EXT_device_query not supported\n");
+		piglit_report_result(PIGLIT_SKIP);
+	}
+
+	queryDevices = (void *)eglGetProcAddress("eglQueryDevicesEXT");
+
+	queryDeviceString =
+		(void *)eglGetProcAddress("eglQueryDeviceStringEXT");
+	queryDeviceAttrib =
+		(void *)eglGetProcAddress("eglQueryDeviceAttribEXT");
+
+	if (!queryDevices|| !queryDeviceString || !queryDeviceAttrib) {
+		printf("No device query/enumeration entrypoints\n");
+		piglit_report_result(PIGLIT_SKIP);
+	}
+
+	if (!queryDevices(0, NULL, &numdevs)) {
+		printf("Failed to get device count\n");
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	if (numdevs > NDEVS) {
+		printf("More than %d devices, please fix this test\n", NDEVS);
+		result = PIGLIT_WARN;
+		numdevs = NDEVS;
+	}
+
+	memset(devs, 0, sizeof devs);
+	if (!queryDevices(numdevs, devs, &numdevs)) {
+		printf("Failed to enumerate devices\n");
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	if (!numdevs) {
+		printf("Zero devices enumerated\n");
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	for (i = 0; i < numdevs; i++) {
+		device = devs[i];
+		devstring = queryDeviceString(device, EGL_EXTENSIONS);
+		if (devstring == NULL) {
+			printf("Empty device extension string\n");
+			continue;
+		}
+
+		if (!piglit_is_extension_in_string(devstring,
+					"EGL_MESA_device_software")) {
+			printf("Device is not a software one\n");
+			continue;
+		}
+		swdevs++;
+
+		/* Extension does not define any attrib/string tokens.
+		 *
+		 * Double-check we don't expose claim to support other
+		 * extension's tokens
+		 */
+		queryDeviceAttrib(device, 0xbad1dea, &attr);
+		if (!piglit_check_egl_error(EGL_BAD_ATTRIBUTE))
+			piglit_report_result(PIGLIT_FAIL);
+
+#ifndef EGL_DRM_DEVICE_FILE_EXT
+#define EGL_DRM_DEVICE_FILE_EXT                 0x3233
+#endif
+		devstring = queryDeviceString(device, EGL_DRM_DEVICE_FILE_EXT);
+		if (!piglit_check_egl_error(EGL_BAD_PARAMETER))
+			piglit_report_result(PIGLIT_FAIL);
+	}
+
+	/* SKIP if we fetched all devices with none supporting the extension */
+	if (result == PIGLIT_PASS && !swdevs)
+		result = PIGLIT_SKIP;
+
+	piglit_report_result(result);
+}
diff --git a/tests/opengl.py b/tests/opengl.py
index 397676e65..ec0cf2468 100644
--- a/tests/opengl.py
+++ b/tests/opengl.py
@@ -4572,6 +4572,12 @@ with profile.test_list.group_manager(
         exclude_platforms=['glx']) as g:
     g(['egl_ext_device_enumeration'], 'conformance')
 
+with profile.test_list.group_manager(
+        PiglitGLTest,
+        grouptools.join('spec', 'egl_mesa_device_software'),
+        exclude_platforms=['glx']) as g:
+    g(['egl_mesa_device_software'], 'conformance')
+
 with profile.test_list.group_manager(
         PiglitGLTest,
         grouptools.join('spec', 'egl_mesa_platform_surfaceless'),
-- 
2.18.0



More information about the Piglit mailing list